xref: /freebsd/share/mk/bsd.progs.mk (revision 23090366f729c56cab62de74c7a51792357e98a9)
1#	from: @(#)bsd.prog.mk	5.26 (Berkeley) 6/25/91
2# $FreeBSD$
3
4.include <bsd.init.mk>
5
6.SUFFIXES: .out .o .c .cc .cpp .cxx .C .m .y .l .ln .s .S .asm
7
8.if ${MK_MAN} == "no"
9NO_MAN=
10.endif
11
12# Legacy knobs
13.if defined(PROG) || defined(PROG_CXX)
14. if defined(PROG)
15PROGS=	${PROG}
16. endif
17. if defined(PROG_CXX)
18PROGS=	${PROG_CXX}
19PROGS_CXX= ${PROG_CXX}
20. endif
21# Loop once to keep pattern and avoid namespace pollution
22. for _P in ${PROGS}
23.  if defined(INTERNALPROG)
24INTERNALPROG.${_P}=
25.  endif
26.  if !defined(NO_MAN)
27.   if defined(MAN)
28MAN.${_P}= ${MAN}
29.   else
30.    for sect in 1 1aout 2 3 4 5 6 7 8 9
31.     if defined(MAN${sect})
32MAN.${_P}= ${MAN${sect}}
33.     endif
34.    endfor
35.   endif
36.  endif # defined(NO_MAN)
37.  if defined(NLSNAME) && !empty(NLSNAME)
38NLSNAME.${P}:=	${NLSNAME}
39.  endif
40.  if defined(OBJS)
41OBJS.${_P}:=	${OBJS}
42.  endif
43.  if defined(PRECIOUSPROG)
44PRECIOUSPROG.${_P}=
45.  endif
46.  if defined(PROGNAME)
47PROGNAME.${_P}=	${PROGNAME}
48.  endif
49.  if defined(SRCS)
50SRCS.${_P}:=	${SRCS}
51.  endif
52. endfor
53.else # !defined(PROG) && !defined(PROG_CXX)
54. if defined(PROGS_CXX) && !empty(PROGS_CXX)
55PROGS+=		${PROGS_CXX}
56. endif
57.endif # defined(PROG) || defined(PROG_CXX)
58
59.if defined(PROGS_CXX) && !empty(PROGS_CXX)
60. for _P in ${PROGS_CXX}
61PROG_CXX.${_P}=
62. endfor
63.endif
64
65# Avoid recursive variables
66.undef NLSNAME
67
68.if defined(COPTS)
69CFLAGS+=${COPTS}
70.endif
71
72.if defined(DEBUG_FLAGS)
73. if ${MK_CTF} != "no" && ${DEBUG_FLAGS:M-g} != ""
74CTFFLAGS+= -g
75. endif
76CFLAGS+=${DEBUG_FLAGS}
77CXXFLAGS+=${DEBUG_FLAGS}
78.endif
79
80STRIP?=	-s
81
82.if ${MK_ASSERT_DEBUG} == "no"
83CFLAGS+= -DNDEBUG
84NO_WERROR=
85.endif
86
87.for _P in ${PROGS}
88
89BINDIR.${_P}?= ${BINDIR}
90BINGRP.${_P}?= ${BINGRP}
91BINMODE.${_P}?=	${BINMODE}
92BINOWN.${_P}?= ${BINOWN}
93
94CFLAGS.${_P}+= ${CFLAGS}
95CXXFLAGS.${_P}+= ${CXXFLAGS}
96DPADD.${_P}+= ${DPADD}
97LDADD.${_P}+= ${LDADD}
98LDFLAGS.${_P}+=	${LDFLAGS}
99
100INSTALLFLAGS.${_P}?= ${INSTALLFLAGS}
101
102. if defined(PRECIOUSPROG.${_P})
103.  if !defined(NO_FSCHG) && !defined(NO_FSCHG.${_P})
104INSTALLFLAGS.${_P}+= -fschg
105.  endif
106INSTALLFLAGS.${_P}+= -S
107. endif
108
109NO_SHARED.${_P}?=	${NO_SHARED}
110
111. if !defined(NLSDIR.${_P})
112NLSDIR.${_P}:=	${NLSDIR}
113. endif
114. undef NLSDIR
115
116. if !empty(NO_SHARED.${_P}) && ${NO_SHARED.${_P}:tl} != "no"
117LDFLAGS.${_P}+= -static
118. endif
119
120. if defined(SRCS.${_P})
121
122_SRCS:=		${SRCS.${_P}}
123OBJS.${_P}+=	${_SRCS:N*.h:R:S/$/.o/g}
124
125.  if target(beforelinking)
126${_P}: ${OBJS.${_P}} beforelinking
127.  else
128${_P}: ${OBJS.${_P}}
129.  endif
130.  if defined(PROG_CXX.${_P})
131	${CXX} ${CXXFLAGS.${_P}} ${LDFLAGS.${_P}} -o ${.TARGET} ${OBJS.${_P}} \
132	    ${LDADD.${_P}}
133.  else
134	${CC} ${CFLAGS.${_P}} ${LDFLAGS.${_P}} -o ${.TARGET} ${OBJS.${_P}} \
135	    ${LDADD.${_P}}
136.  endif
137.  if ${MK_CTF} != "no"
138	${CTFMERGE} ${CTFFLAGS} -o ${.TARGET} ${OBJS.${_P}}
139.  endif
140
141. else # !defined(SRCS.${_P})
142
143.  if !target(${_P})
144.   if defined(PROG_CXX.${_P})
145SRCS.${_P}?= ${_P}.cc
146.   else
147SRCS.${_P}?= ${_P}.c
148.   endif
149
150# Always make an intermediate object file because:
151# - it saves time rebuilding when only the library has changed
152# - the name of the object gets put into the executable symbol table instead of
153#   the name of a variable temporary object.
154# - it's useful to keep objects around for crunching.
155OBJS.${_P}:= ${_P}.o
156
157.   if target(beforelinking)
158${_P}: ${OBJS.${_P}} beforelinking
159.   else
160${_P}: ${OBJS.${_P}}
161.   endif # target(beforelinking)
162.   if defined(PROG_CXX.${_P})
163	${CXX} ${CXXFLAGS.${_P}} ${LDFLAGS.${_P}} -o ${.TARGET} ${OBJS.${_P}} \
164	    ${LDADD.${_P}}
165.   else
166	${CC} ${CFLAGS.${_P}} ${LDFLAGS.${_P}} -o ${.TARGET} ${OBJS.${_P}} \
167	    ${LDADD.${_P}}
168.   endif
169.   if ${MK_CTF} != "no"
170	${CTFMERGE} ${CTFFLAGS} -o ${.TARGET} ${OBJS.${_P}}
171.   endif
172
173.  endif # !target(${_P})
174
175. endif # defined(SRCS.${_P})
176
177CLEANFILES+= ${OBJS.${_P}}
178
179.endfor # for _P in ${PROGS}
180
181all: objwarn ${PROGS} ${SCRIPTS}
182
183.if !defined(NO_MAN)
184. for _P in ${PROGS}
185MAN.${_P}?= ${_P}.1
186MAN:=	${MAN.${_P}}
187.  include <bsd.man.mk>
188. endfor
189. if target(_manpages) # bsd.man.mk was included
190all: _manpages
191. endif
192.endif
193
194CLEANFILES+= ${PROGS}
195
196.include <bsd.libnames.mk>
197
198_EXTRADEPEND:
199.for _P in ${PROGS}
200. if !empty(LDFLAGS.${P}:M-nostdlib)
201.  if !empty(DPADD.${_P})
202	echo ${_P}: ${DPADD.${_P}} >> ${DEPENDFILE}
203.  endif
204. else
205	echo ${_P}: ${LIBC} ${DPADD.${_P}} >> ${DEPENDFILE}
206.  if defined(PROG_CXX.${_P})
207.   if !empty(CXXFLAGS.${P}:M-stdlib=libc++)
208	echo ${_P}: ${LIBCPLUSPLUS} >> ${DEPENDFILE}
209.   else
210	echo ${_P}: ${LIBSTDCPLUSPLUS} >> ${DEPENDFILE}
211.   endif
212.  endif
213. endif
214.endfor
215
216.if !target(install)
217
218. if !target(realinstall)
219
220.  for _P in ${PROGS}
221
222.   if !defined(INTERNALPROG.${_P})
223
224.ORDER: beforeinstall _proginstall.${_P}
225_proginstall.${_P}:
226.    if defined(PROGNAME.${_P})
227	${INSTALL} ${STRIP} -o ${BINOWN.${_P}} -g ${BINGRP.${_P}} \
228	    -m ${BINMODE.${_P}} ${INSTALLFLAGS.${_P}} ${_P} \
229	    ${DESTDIR}${BINDIR.${_P}}/${PROGNAME.${_P}}
230.    else
231	${INSTALL} ${STRIP} -o ${BINOWN.${_P}} -g ${BINGRP.${_P}} \
232	    -m ${BINMODE.${_P}} ${INSTALLFLAGS.${_P}} ${_P} \
233	    ${DESTDIR}${BINDIR.${_P}}
234.    endif
235
236realinstall: _proginstall.${_P}
237
238.   endif # !defined(INTERNALPROG.${_P})
239
240.  endfor # for _P in ${PROGS}
241
242. endif # !target(realinstall)
243
244. if defined(SCRIPTS) && !empty(SCRIPTS)
245SCRIPTSDIR?= ${BINDIR}
246SCRIPTSOWN?= ${BINOWN}
247SCRIPTSGRP?= ${BINGRP}
248SCRIPTSMODE?= ${BINMODE}
249
250.  for S in ${SCRIPTS}
251
252realinstall: scriptsinstall
253.ORDER: beforeinstall scriptsinstall
254
255.   if defined(SCRIPTSNAME)
256SCRIPTSNAME_${S}?= ${SCRIPTSNAME}
257.   else
258SCRIPTSNAME_${S}?= ${S:T:R}
259.   endif
260
261SCRIPTSDIR_${S}?= ${SCRIPTSDIR}
262SCRIPTSOWN_${S}?= ${SCRIPTSOWN}
263SCRIPTSGRP_${S}?= ${SCRIPTSGRP}
264SCRIPTSMODE_${S}?= ${SCRIPTSMODE}
265
266scriptsinstall: ${DESTDIR}${SCRIPTSDIR_${S}}/${SCRIPTSNAME_${S}}
267
268${DESTDIR}${SCRIPTSDIR_${S}}/${SCRIPTSNAME_${S}}: ${S}
269	${INSTALL} -o ${SCRIPTSOWN_${S}} \
270	    -g ${SCRIPTSGRP_${S}} \
271	    -m ${SCRIPTSMODE_${S}} \
272	    ${.ALLSRC} \
273	    ${.TARGET}
274
275.  endfor # for S in ${SCRIPTS}
276
277. endif # defined(SCRIPTS) && !empty(SCRIPTS)
278
279.endif # !target(install)
280
281.if !defined(NO_MAN)
282. if target(_manpages) # bsd.man.mk was included
283realinstall: _maninstall
284. endif
285.endif
286
287# Wrap bsd.nls.mk because I can't force that Makefile snippet to work only with
288# ${PROGS}.
289.for _P in ${PROGS}
290NLSNAME.${_P}?=	${_P}
291NLS:=	${NLS.${_P}}
292NLSDIR:= ${NLSDIR.${_P}}
293NLSNAME:= ${NLSNAME.${_P}}
294.include <bsd.nls.mk>
295.endfor
296
297.include <bsd.files.mk>
298.include <bsd.incs.mk>
299.include <bsd.links.mk>
300
301.if !target(lint)
302. for _P in ${PROGS}
303.  if !target(lint.${_P})
304.   if defined(PROG_CXX.${_P})
305lint.${_P}:
306.   else
307_CFLAGS:= ${CFLAGS.${_P}}
308_SRCS:=	${SRCS.${_P}}
309lint.${_P}: ${_SRCS:M*.c}
310	${LINT} ${LINTFLAGS} ${_CFLAGS:M-[DIU]*} ${.ALLSRC}
311.   endif
312.  endif
313lint: lint.${_P}
314
315. endfor
316.endif # !target(lint)
317
318.for _P in ${PROGS}
319CFLAGS:= ${CFLAGS.${_P}}
320CXXFLAGS:= ${CXXFLAGS.${_P}}
321# XXX: Pollutes DPADD.${_P} and LDADD.${_P} above
322#DPADD:= ${DPADD.${_P}}
323#LDADD:= ${LDADD.${_P}}
324SRCS:=	${SRCS.${_P}}
325. include <bsd.dep.mk>
326# bsd.dep.mk mangles SRCS
327SRCS.${_P}:=	${SRCS}
328. undef DPADD LDADD
329.endfor
330
331# XXX: emulate the old bsd.prog.mk by allowing Makefiles that didn't set
332# ${PROG*} to function with this Makefile snippet.
333.if empty(PROGS)
334. include <bsd.dep.mk>
335.endif
336
337.if !exists(${.OBJDIR}/${DEPENDFILE})
338. for _P in ${PROGS}
339_SRCS:=	${SRCS.${_P}}
340${OBJS.${_P}}: ${_SRCS:M*.h}
341. endfor
342.endif
343
344.include <bsd.obj.mk>
345
346.include <bsd.sys.mk>
347
348.if defined(PORTNAME)
349.include <bsd.pkg.mk>
350.endif
351