xref: /freebsd/share/mk/bsd.prog.mk (revision adeb92a24c57f97d5cd3c3c45be239cbb23aed68)
1#	from: @(#)bsd.prog.mk	5.26 (Berkeley) 6/25/91
2# $FreeBSD$
3
4.if !target(__initialized__)
5__initialized__:
6.if exists(${.CURDIR}/../Makefile.inc)
7.include "${.CURDIR}/../Makefile.inc"
8.endif
9.endif
10
11.SUFFIXES: .out .o .c .cc .cpp .cxx .C .m .y .l .s .S
12
13CFLAGS+=${COPTS} ${DEBUG_FLAGS}
14.if defined(DESTDIR) && !defined(BOOTSTRAPPING)
15CFLAGS+= -I${DESTDIR}/usr/include
16CXXINCLUDES+= -I${DESTDIR}/usr/include/g++
17.endif
18
19.if !defined(DEBUG_FLAGS)
20STRIP?=	-s
21.endif
22
23.if defined(NOSHARED) && ( ${NOSHARED} != "no" && ${NOSHARED} != "NO" )
24LDFLAGS+= -static
25.endif
26
27.if defined(PROG)
28.if defined(SRCS)
29
30# If there are Objective C sources, link with Objective C libraries.
31.if ${SRCS:M*.m} != ""
32OBJCLIBS?= -lobjc
33LDADD+=	${OBJCLIBS}
34.endif
35
36OBJS+=  ${SRCS:N*.h:R:S/$/.o/g}
37
38${PROG}: ${OBJS}
39	${CC} ${CFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDDESTDIR} ${LDADD}
40
41.else !defined(SRCS)
42
43.if !target(${PROG})
44SRCS=	${PROG}.c
45
46# Always make an intermediate object file because:
47# - it saves time rebuilding when only the library has changed
48# - the name of the object gets put into the executable symbol table instead of
49#   the name of a variable temporary object.
50# - it's useful to keep objects around for crunching.
51OBJS=	${PROG}.o
52
53${PROG}: ${OBJS}
54	${CC} ${CFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDDESTDIR} ${LDADD}
55.endif
56
57.endif
58
59.if	!defined(NOMAN) && !defined(MAN) && \
60	!defined(MAN1) && !defined(MAN2) && !defined(MAN3) && \
61	!defined(MAN4) && !defined(MAN5) && !defined(MAN6) && \
62	!defined(MAN7) && !defined(MAN8) && !defined(MAN9) && \
63	!defined(MAN1aout)
64MAN=	${PROG}.1
65MAN1=	${MAN}
66.endif
67.endif
68
69.MAIN: all
70all: objwarn ${PROG} ${SCRIPTS} ${FILES}
71.if !defined(NOMAN)
72all: all-man
73.endif
74all: _SUBDIR
75
76CLEANFILES+= ${PROG} ${OBJS}
77
78.if defined(PROG)
79_EXTRADEPEND:
80.if ${OBJFORMAT} == aout
81	echo ${PROG}: `${CC} -Wl,-f ${CFLAGS} ${LDFLAGS} ${LDDESTDIR} \
82	    ${LDADD:S/^/-Wl,/}` >> ${DEPENDFILE}
83.else
84	echo ${PROG}: ${LIBC} ${DPADD} >> ${DEPENDFILE}
85.endif
86.endif
87
88.if !target(install)
89.if !target(beforeinstall)
90beforeinstall:
91.endif
92
93_INSTALLFLAGS:=	${INSTALLFLAGS}
94.for ie in ${INSTALLFLAGS_EDIT}
95_INSTALLFLAGS:=	${_INSTALLFLAGS${ie}}
96.endfor
97
98realinstall: beforeinstall
99.if defined(PROG)
100.if defined(PROGNAME)
101	${INSTALL} ${COPY} ${STRIP} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
102	    ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${BINDIR}/${PROGNAME}
103.else
104	${INSTALL} ${COPY} ${STRIP} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
105	    ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${BINDIR}
106.endif
107.endif
108.if defined(HIDEGAME)
109	(cd ${DESTDIR}${ORIGBINDIR}; ln -fs dm ${PROG}; \
110	    chown -h ${BINOWN}:${ORIGBINGRP} ${PROG})
111.endif
112.if defined(LINKS) && !empty(LINKS)
113	@set ${LINKS}; \
114	while test $$# -ge 2; do \
115		l=${DESTDIR}$$1; \
116		shift; \
117		t=${DESTDIR}$$1; \
118		shift; \
119		${ECHO} $$t -\> $$l; \
120		ln -f $$l $$t; \
121	done; true
122.endif
123.if defined(SYMLINKS) && !empty(SYMLINKS)
124	@set ${SYMLINKS}; \
125	while test $$# -ge 2; do \
126		l=$$1; \
127		shift; \
128		t=${DESTDIR}$$1; \
129		shift; \
130		${ECHO} $$t -\> $$l; \
131		ln -fs $$l $$t; \
132	done; true
133.endif
134
135.if defined(SCRIPTS) && !empty(SCRIPTS)
136realinstall: _scriptsinstall
137
138SCRIPTSDIR?=	${BINDIR}
139SCRIPTSOWN?=	${BINOWN}
140SCRIPTSGRP?=	${BINGRP}
141SCRIPTSMODE?=	${BINMODE}
142
143.for script in ${SCRIPTS}
144.if defined(SCRIPTSNAME)
145SCRIPTSNAME_${script:T}?=	${SCRIPTSNAME}
146.else
147SCRIPTSNAME_${script:T}?=	${script:T:R}
148.endif
149SCRIPTSDIR_${script:T}?=	${SCRIPTSDIR}
150SCRIPTSOWN_${script:T}?=	${SCRIPTSOWN}
151SCRIPTSGRP_${script:T}?=	${SCRIPTSGRP}
152SCRIPTSMODE_${script:T}?=	${SCRIPTSMODE}
153_scriptsinstall: _SCRIPTSINS_${script:T}
154_SCRIPTSINS_${script:T}: ${script}
155	${INSTALL} ${COPY} -o ${SCRIPTSOWN_${.ALLSRC:T}} \
156	    -g ${SCRIPTSGRP_${.ALLSRC:T}} -m ${SCRIPTSMODE_${.ALLSRC:T}} \
157	    ${_INSTALLFLAGS} ${.ALLSRC} \
158	    ${DESTDIR}${SCRIPTSDIR_${.ALLSRC:T}}/${SCRIPTSNAME_${.ALLSRC:T}}
159.endfor
160.endif
161
162.if defined(FILES) && !empty(FILES)
163realinstall: _filesinstall
164
165FILESDIR?=	${BINDIR}
166FILESOWN?=	${SHAREOWN}
167FILESGRP?=	${SHAREGRP}
168FILESMODE?=	${SHAREMODE}
169
170.for file in ${FILES}
171.if defined(FILESNAME)
172FILESNAME_${file:T}?=	${FILESNAME}
173.else
174FILESNAME_${file:T}?=	${file:T}
175.endif
176FILESDIR_${file:T}?=	${FILESDIR}
177FILESOWN_${file:T}?=	${FILESOWN}
178FILESGRP_${file:T}?=	${FILESGRP}
179FILESMODE_${file:T}?=	${FILESMODE}
180_filesinstall: _FILESINS_${file:T}
181_FILESINS_${file:T}: ${file}
182	${INSTALL} ${COPY} -o ${FILESOWN_${.ALLSRC:T}} \
183	    -g ${FILESGRP_${.ALLSRC:T}} -m ${FILESMODE_${.ALLSRC:T}} \
184	    ${_INSTALLFLAGS} ${.ALLSRC} \
185	    ${DESTDIR}${FILESDIR_${.ALLSRC:T}}/${FILESNAME_${.ALLSRC:T}}
186.endfor
187.endif
188
189install: afterinstall _SUBDIR
190.if !defined(NOMAN)
191afterinstall: realinstall maninstall
192.else
193afterinstall: realinstall
194.endif
195.endif
196
197DISTRIBUTION?=	bin
198.if !target(distribute)
199distribute: _SUBDIR
200.for dist in ${DISTRIBUTION}
201	cd ${.CURDIR} ; $(MAKE) install DESTDIR=${DISTDIR}/${dist} SHARED=copies
202.endfor
203.endif
204
205.if !target(lint)
206lint: ${SRCS} _SUBDIR
207.if defined(PROG)
208	${LINT} ${LINTFLAGS} ${CFLAGS:M-[DIU]*} ${.ALLSRC} | more 2>&1
209.endif
210.endif
211
212.if defined(NOTAGS)
213tags:
214.endif
215
216.if !target(tags)
217tags: ${SRCS} _SUBDIR
218.if defined(PROG)
219	@cd ${.CURDIR} && gtags ${GTAGSFLAGS} ${.OBJDIR}
220.if defined(HTML)
221	@cd ${.CURDIR} && htags ${HTAGSFLAGS} -d ${.OBJDIR} ${.OBJDIR}
222.endif
223.endif
224.endif
225
226.if !defined(NOMAN)
227.include <bsd.man.mk>
228.else
229.if !target(all-man)
230all-man:
231.endif
232.if !target(maninstall)
233maninstall:
234.endif
235.endif
236
237.if !target(regress)
238regress:
239.endif
240
241.if ${OBJFORMAT} != aout || make(checkdpadd) || defined(NEED_LIBNAMES)
242.include <bsd.libnames.mk>
243.endif
244
245.include <bsd.dep.mk>
246
247.if defined(PROG) && !exists(${DEPENDFILE})
248${OBJS}: ${SRCS:M*.h}
249.endif
250
251.include <bsd.obj.mk>
252
253.include <bsd.sys.mk>
254