xref: /freebsd/share/mk/bsd.prog.mk (revision 7cd2dcf07629713e5a3d60472cfe4701b705a167)
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# XXX The use of COPTS in modern makefiles is discouraged.
9.if defined(COPTS)
10CFLAGS+=${COPTS}
11.endif
12
13.if ${MK_ASSERT_DEBUG} == "no"
14CFLAGS+= -DNDEBUG
15NO_WERROR=
16.endif
17
18.if defined(DEBUG_FLAGS)
19CFLAGS+=${DEBUG_FLAGS}
20CXXFLAGS+=${DEBUG_FLAGS}
21
22.if ${MK_CTF} != "no" && ${DEBUG_FLAGS:M-g} != ""
23CTFFLAGS+= -g
24.endif
25.endif
26
27.if defined(CRUNCH_CFLAGS)
28CFLAGS+=${CRUNCH_CFLAGS}
29.endif
30
31.if !defined(DEBUG_FLAGS)
32STRIP?=	-s
33.endif
34
35.if defined(NO_SHARED) && (${NO_SHARED} != "no" && ${NO_SHARED} != "NO")
36LDFLAGS+= -static
37.endif
38
39.if defined(PROG_CXX)
40PROG=	${PROG_CXX}
41.endif
42
43.if defined(PROG)
44.if defined(SRCS)
45
46OBJS+=  ${SRCS:N*.h:R:S/$/.o/g}
47
48.if target(beforelinking)
49${PROG}: ${OBJS} beforelinking
50.else
51${PROG}: ${OBJS}
52.endif
53.if defined(PROG_CXX)
54	${CXX} ${CXXFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD}
55.else
56	${CC} ${CFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD}
57.endif
58.if ${MK_CTF} != "no"
59	${CTFMERGE} ${CTFFLAGS} -o ${.TARGET} ${OBJS}
60.endif
61
62.else	# !defined(SRCS)
63
64.if !target(${PROG})
65.if defined(PROG_CXX)
66SRCS=	${PROG}.cc
67.else
68SRCS=	${PROG}.c
69.endif
70
71# Always make an intermediate object file because:
72# - it saves time rebuilding when only the library has changed
73# - the name of the object gets put into the executable symbol table instead of
74#   the name of a variable temporary object.
75# - it's useful to keep objects around for crunching.
76OBJS=	${PROG}.o
77
78.if target(beforelinking)
79${PROG}: ${OBJS} beforelinking
80.else
81${PROG}: ${OBJS}
82.endif
83.if defined(PROG_CXX)
84	${CXX} ${CXXFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD}
85.else
86	${CC} ${CFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD}
87.endif
88.if ${MK_CTF} != "no"
89	${CTFMERGE} ${CTFFLAGS} -o ${.TARGET} ${OBJS}
90.endif
91.endif
92
93.endif
94
95.if	${MK_MAN} != "no" && !defined(MAN) && \
96	!defined(MAN1) && !defined(MAN2) && !defined(MAN3) && \
97	!defined(MAN4) && !defined(MAN5) && !defined(MAN6) && \
98	!defined(MAN7) && !defined(MAN8) && !defined(MAN9) && \
99	!defined(MAN1aout)
100MAN=	${PROG}.1
101MAN1=	${MAN}
102.endif
103.endif
104
105.if defined(_SKIP_BUILD)
106all:
107.else
108all: objwarn ${PROG} ${SCRIPTS}
109.if ${MK_MAN} != "no"
110all: _manpages
111.endif
112.endif
113
114.if defined(PROG)
115CLEANFILES+= ${PROG}
116.endif
117
118.if defined(OBJS)
119CLEANFILES+= ${OBJS}
120.endif
121
122.include <bsd.libnames.mk>
123
124.if defined(PROG)
125_EXTRADEPEND:
126.if defined(LDFLAGS) && !empty(LDFLAGS:M-nostdlib)
127.if defined(DPADD) && !empty(DPADD)
128	echo ${PROG}: ${DPADD} >> ${DEPENDFILE}
129.endif
130.else
131	echo ${PROG}: ${LIBC} ${DPADD} >> ${DEPENDFILE}
132.if defined(PROG_CXX)
133.if !empty(CXXFLAGS:M-stdlib=libc++)
134	echo ${PROG}: ${LIBCPLUSPLUS} >> ${DEPENDFILE}
135.else
136	echo ${PROG}: ${LIBSTDCPLUSPLUS} >> ${DEPENDFILE}
137.endif
138.endif
139.endif
140.endif
141
142.if !target(install)
143
144.if defined(PRECIOUSPROG)
145.if !defined(NO_FSCHG)
146INSTALLFLAGS+= -fschg
147.endif
148INSTALLFLAGS+= -S
149.endif
150
151_INSTALLFLAGS:=	${INSTALLFLAGS}
152.for ie in ${INSTALLFLAGS_EDIT}
153_INSTALLFLAGS:=	${_INSTALLFLAGS${ie}}
154.endfor
155
156.if !target(realinstall) && !defined(INTERNALPROG)
157realinstall: _proginstall
158.ORDER: beforeinstall _proginstall
159_proginstall:
160.if defined(PROG)
161.if defined(PROGNAME)
162	${INSTALL} ${STRIP} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
163	    ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${BINDIR}/${PROGNAME}
164.else
165	${INSTALL} ${STRIP} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
166	    ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${BINDIR}
167.endif
168.endif
169.endif	# !target(realinstall)
170
171.if defined(SCRIPTS) && !empty(SCRIPTS)
172realinstall: _scriptsinstall
173.ORDER: beforeinstall _scriptsinstall
174
175SCRIPTSDIR?=	${BINDIR}
176SCRIPTSOWN?=	${BINOWN}
177SCRIPTSGRP?=	${BINGRP}
178SCRIPTSMODE?=	${BINMODE}
179
180.for script in ${SCRIPTS}
181.if defined(SCRIPTSNAME)
182SCRIPTSNAME_${script:T}?=	${SCRIPTSNAME}
183.else
184SCRIPTSNAME_${script:T}?=	${script:T:R}
185.endif
186SCRIPTSDIR_${script:T}?=	${SCRIPTSDIR}
187SCRIPTSOWN_${script:T}?=	${SCRIPTSOWN}
188SCRIPTSGRP_${script:T}?=	${SCRIPTSGRP}
189SCRIPTSMODE_${script:T}?=	${SCRIPTSMODE}
190_scriptsinstall: _SCRIPTSINS_${script:T}
191_SCRIPTSINS_${script:T}: ${script}
192	${INSTALL} -o ${SCRIPTSOWN_${.ALLSRC:T}} \
193	    -g ${SCRIPTSGRP_${.ALLSRC:T}} -m ${SCRIPTSMODE_${.ALLSRC:T}} \
194	    ${.ALLSRC} \
195	    ${DESTDIR}${SCRIPTSDIR_${.ALLSRC:T}}/${SCRIPTSNAME_${.ALLSRC:T}}
196.endfor
197.endif
198
199NLSNAME?=	${PROG}
200.include <bsd.nls.mk>
201
202.include <bsd.files.mk>
203.include <bsd.incs.mk>
204.include <bsd.links.mk>
205
206.if ${MK_MAN} != "no"
207realinstall: _maninstall
208.ORDER: beforeinstall _maninstall
209.endif
210
211.endif
212
213.if !target(lint)
214lint: ${SRCS:M*.c}
215.if defined(PROG)
216	${LINT} ${LINTFLAGS} ${CFLAGS:M-[DIU]*} ${.ALLSRC}
217.endif
218.endif
219
220.if ${MK_MAN} != "no"
221.include <bsd.man.mk>
222.endif
223
224.include <bsd.dep.mk>
225
226.if defined(PROG) && !exists(${.OBJDIR}/${DEPENDFILE})
227${OBJS}: ${SRCS:M*.h}
228.endif
229
230.include <bsd.obj.mk>
231
232.include <bsd.sys.mk>
233
234.if defined(PORTNAME)
235.include <bsd.pkg.mk>
236.endif
237
238.if ${MK_STAGING} != "no"
239.if defined(_SKIP_BUILD)
240stage_files stage_as:
241.else
242# normally only libs and includes are staged
243.if ${MK_STAGING_PROG:Uno} != "no"
244STAGE_SETS+= prog
245STAGE_DIR.prog= ${STAGE_OBJTOP}${BINDIR}
246.if !empty(PROG)
247all: stage_files
248stage_files.prog: ${PROG}
249.endif
250.if !empty(SYMLINKS)
251all:   stage_symlinks
252STAGE_SYMLINKS.prog= ${SYMLINKS}
253.endif
254
255.endif
256.include <meta.stage.mk>
257.endif
258.endif
259