xref: /freebsd/share/mk/bsd.prog.mk (revision 9160419c7a948786ef010cc398df0b857f714db3)
13585b293SGarrett Wollman#	from: @(#)bsd.prog.mk	5.26 (Berkeley) 6/25/91
27f3dea24SPeter Wemm# $FreeBSD$
3afe61c15SRodney W. Grimes
42bdaf7e8SRuslan Ermilov.include <bsd.init.mk>
5bd871f14SWarner Losh.include <bsd.compiler.mk>
6afe61c15SRodney W. Grimes
75741a42fSMark Murray.SUFFIXES: .out .o .c .cc .cpp .cxx .C .m .y .l .ln .s .S .asm
8afe61c15SRodney W. Grimes
948aea4daSRuslan Ermilov# XXX The use of COPTS in modern makefiles is discouraged.
1041f89315SRuslan Ermilov.if defined(COPTS)
1141f89315SRuslan ErmilovCFLAGS+=${COPTS}
1241f89315SRuslan Ermilov.endif
1341f89315SRuslan Ermilov
144df1f59eSWarner Losh.if ${MK_ASSERT_DEBUG} == "no"
154df1f59eSWarner LoshCFLAGS+= -DNDEBUG
16e2e1ab1cSDavid E. O'BrienNO_WERROR=
174df1f59eSWarner Losh.endif
184df1f59eSWarner Losh
1941f89315SRuslan Ermilov.if defined(DEBUG_FLAGS)
2041f89315SRuslan ErmilovCFLAGS+=${DEBUG_FLAGS}
218eba8cd8SMarcel MoolenaarCXXFLAGS+=${DEBUG_FLAGS}
22770ac3b2SJohn Birrell
2383cb5baeSMax Khon.if ${MK_CTF} != "no" && ${DEBUG_FLAGS:M-g} != ""
24770ac3b2SJohn BirrellCTFFLAGS+= -g
25770ac3b2SJohn Birrell.endif
2641f89315SRuslan Ermilov.endif
2741f89315SRuslan Ermilov
2842f8c5b5SEd Maste.if defined(PROG_CXX)
2942f8c5b5SEd MastePROG=	${PROG_CXX}
3042f8c5b5SEd Maste.endif
3142f8c5b5SEd Maste
326e521732SEd Maste.if !empty(LDFLAGS:M-Wl,*--oformat,*) || !empty(LDFLAGS:M-static)
3342f8c5b5SEd MasteMK_DEBUG_FILES=	no
3442f8c5b5SEd Maste.endif
3542f8c5b5SEd Maste
3641f89315SRuslan Ermilov.if defined(CRUNCH_CFLAGS)
373c9b8563SGordon TetlowCFLAGS+=${CRUNCH_CFLAGS}
3842f8c5b5SEd Maste.else
3942f8c5b5SEd Maste.if ${MK_DEBUG_FILES} != "no" && empty(DEBUG_FLAGS:M-g) && \
4042f8c5b5SEd Maste    empty(DEBUG_FLAGS:M-gdwarf-*)
4142f8c5b5SEd MasteCFLAGS+= -g
4242f8c5b5SEd MasteCTFFLAGS+= -g
4342f8c5b5SEd Maste.endif
4441f89315SRuslan Ermilov.endif
45afe61c15SRodney W. Grimes
46e82b0b99SJordan K. Hubbard.if !defined(DEBUG_FLAGS)
47afe61c15SRodney W. GrimesSTRIP?=	-s
48e82b0b99SJordan K. Hubbard.endif
49afe61c15SRodney W. Grimes
5083c7ade9SRuslan Ermilov.if defined(NO_SHARED) && (${NO_SHARED} != "no" && ${NO_SHARED} != "NO")
513585b293SGarrett WollmanLDFLAGS+= -static
523585b293SGarrett Wollman.endif
53afe61c15SRodney W. Grimes
5442f8c5b5SEd Maste.if ${MK_DEBUG_FILES} != "no"
5542f8c5b5SEd MastePROG_FULL=${PROG}.full
5642f8c5b5SEd Maste# Use ${DEBUGDIR} for base system debug files, else .debug subdirectory
5742f8c5b5SEd Maste.if defined(BINDIR) && (\
5842f8c5b5SEd Maste    ${BINDIR} == "/bin" ||\
595ea4b6d5SEd Maste    ${BINDIR:C%/libexec(/.*)?%/libexec%} == "/libexec" ||\
6042f8c5b5SEd Maste    ${BINDIR} == "/sbin" ||\
61692432bbSEd Maste    ${BINDIR:C%/usr/(bin|bsdinstall|libexec|lpr|sendmail|sm.bin|sbin|tests)(/.*)?%/usr/bin%} == "/usr/bin"\
6242f8c5b5SEd Maste     )
6342f8c5b5SEd MasteDEBUGFILEDIR=	${DEBUGDIR}${BINDIR}
6442f8c5b5SEd Maste.else
6542f8c5b5SEd MasteDEBUGFILEDIR?=	${BINDIR}/.debug
6642f8c5b5SEd MasteDEBUGMKDIR=
6742f8c5b5SEd Maste.endif
6842f8c5b5SEd Maste.else
6942f8c5b5SEd MastePROG_FULL=	${PROG}
7047bf8a5cSRuslan Ermilov.endif
7147bf8a5cSRuslan Ermilov
72afe61c15SRodney W. Grimes.if defined(PROG)
73a0dc5970SEd MastePROGNAME?=	${PROG}
7442f8c5b5SEd Maste
75afe61c15SRodney W. Grimes.if defined(SRCS)
76afe61c15SRodney W. Grimes
773585b293SGarrett WollmanOBJS+=  ${SRCS:N*.h:R:S/$/.o/g}
78afe61c15SRodney W. Grimes
79c2c48445SRui Paulo.if target(beforelinking)
80593c0b49SMark Johnstonbeforelinking: ${OBJS}
8142f8c5b5SEd Maste${PROG_FULL}: beforelinking
82c2c48445SRui Paulo.endif
8342f8c5b5SEd Maste${PROG_FULL}: ${OBJS}
845d68012aSRuslan Ermilov.if defined(PROG_CXX)
85*9160419cSBryan Drewery	${CXX:N${CCACHE_BIN}} ${CXXFLAGS:N-M*} ${LDFLAGS} -o ${.TARGET} \
86*9160419cSBryan Drewery	    ${OBJS} ${LDADD}
875d68012aSRuslan Ermilov.else
88*9160419cSBryan Drewery	${CC:N${CCACHE_BIN}} ${CFLAGS:N-M*} ${LDFLAGS} -o ${.TARGET} ${OBJS} \
89*9160419cSBryan Drewery	    ${LDADD}
905d68012aSRuslan Ermilov.endif
9183cb5baeSMax Khon.if ${MK_CTF} != "no"
92cd49c2e8SMax Khon	${CTFMERGE} ${CTFFLAGS} -o ${.TARGET} ${OBJS}
93cd49c2e8SMax Khon.endif
945d68012aSRuslan Ermilov
9584aac273SHartmut Brandt.else	# !defined(SRCS)
96afe61c15SRodney W. Grimes
975d68012aSRuslan Ermilov.if !target(${PROG})
9847bf8a5cSRuslan Ermilov.if defined(PROG_CXX)
9947bf8a5cSRuslan ErmilovSRCS=	${PROG}.cc
10047bf8a5cSRuslan Ermilov.else
101afe61c15SRodney W. GrimesSRCS=	${PROG}.c
10247bf8a5cSRuslan Ermilov.endif
103afe61c15SRodney W. Grimes
104a4c39c7aSBruce Evans# Always make an intermediate object file because:
105a4c39c7aSBruce Evans# - it saves time rebuilding when only the library has changed
106a4c39c7aSBruce Evans# - the name of the object gets put into the executable symbol table instead of
107a4c39c7aSBruce Evans#   the name of a variable temporary object.
108a4c39c7aSBruce Evans# - it's useful to keep objects around for crunching.
1097f7fc25bSMark JohnstonOBJS+=	${PROG}.o
110f5c75051SEivind Eklund
111c2c48445SRui Paulo.if target(beforelinking)
112593c0b49SMark Johnstonbeforelinking: ${OBJS}
11342f8c5b5SEd Maste${PROG_FULL}: beforelinking
114c2c48445SRui Paulo.endif
11542f8c5b5SEd Maste${PROG_FULL}: ${OBJS}
116f8ba1555SRuslan Ermilov.if defined(PROG_CXX)
117*9160419cSBryan Drewery	${CXX:N${CCACHE_BIN}} ${CXXFLAGS:N-M*} ${LDFLAGS} -o ${.TARGET} \
118*9160419cSBryan Drewery	    ${OBJS} ${LDADD}
119f8ba1555SRuslan Ermilov.else
120*9160419cSBryan Drewery	${CC:N${CCACHE_BIN}} ${CFLAGS:N-M*} ${LDFLAGS} -o ${.TARGET} ${OBJS} \
121*9160419cSBryan Drewery	    ${LDADD}
122afe61c15SRodney W. Grimes.endif
12383cb5baeSMax Khon.if ${MK_CTF} != "no"
124cd49c2e8SMax Khon	${CTFMERGE} ${CTFFLAGS} -o ${.TARGET} ${OBJS}
125cd49c2e8SMax Khon.endif
12642f8c5b5SEd Maste.endif # !target(${PROG})
127f5c75051SEivind Eklund
1280d947ed1SEd Maste.endif # !defined(SRCS)
129afe61c15SRodney W. Grimes
13042f8c5b5SEd Maste.if ${MK_DEBUG_FILES} != "no"
13142f8c5b5SEd Maste${PROG}: ${PROG_FULL} ${PROGNAME}.debug
13242f8c5b5SEd Maste	${OBJCOPY} --strip-debug --add-gnu-debuglink=${PROGNAME}.debug \
13342f8c5b5SEd Maste	    ${PROG_FULL} ${.TARGET}
13442f8c5b5SEd Maste
13542f8c5b5SEd Maste${PROGNAME}.debug: ${PROG_FULL}
13642f8c5b5SEd Maste	${OBJCOPY} --only-keep-debug ${PROG_FULL} ${.TARGET}
13742f8c5b5SEd Maste.endif
13842f8c5b5SEd Maste
139e1fe3dbaSRuslan Ermilov.if	${MK_MAN} != "no" && !defined(MAN) && \
140862d3deaSRuslan Ermilov	!defined(MAN1) && !defined(MAN2) && !defined(MAN3) && \
141afe61c15SRodney W. Grimes	!defined(MAN4) && !defined(MAN5) && !defined(MAN6) && \
1428b4f1f91SBrooks Davis	!defined(MAN7) && !defined(MAN8) && !defined(MAN9)
14319ea15a1SRuslan ErmilovMAN=	${PROG}.1
14419ea15a1SRuslan ErmilovMAN1=	${MAN}
145afe61c15SRodney W. Grimes.endif
1460d947ed1SEd Maste.endif # defined(PROG)
147afe61c15SRodney W. Grimes
1487750ad47SMarcel Moolenaar.if defined(_SKIP_BUILD)
1497750ad47SMarcel Moolenaarall:
1507750ad47SMarcel Moolenaar.else
1519c851217SRui Pauloall: beforebuild .WAIT ${PROG} ${SCRIPTS}
1529c851217SRui Paulobeforebuild: objwarn
153e1fe3dbaSRuslan Ermilov.if ${MK_MAN} != "no"
154afeaaa84SRuslan Ermilovall: _manpages
155862d3deaSRuslan Ermilov.endif
1567750ad47SMarcel Moolenaar.endif
157afe61c15SRodney W. Grimes
15841f89315SRuslan Ermilov.if defined(PROG)
15941f89315SRuslan ErmilovCLEANFILES+= ${PROG}
16042f8c5b5SEd Maste.if ${MK_DEBUG_FILES} != "no"
16142f8c5b5SEd MasteCLEANFILES+=	${PROG_FULL} ${PROGNAME}.debug
16242f8c5b5SEd Maste.endif
16341f89315SRuslan Ermilov.endif
16441f89315SRuslan Ermilov
16541f89315SRuslan Ermilov.if defined(OBJS)
16641f89315SRuslan ErmilovCLEANFILES+= ${OBJS}
16741f89315SRuslan Ermilov.endif
168afe61c15SRodney W. Grimes
16951fa76c4SRuslan Ermilov.include <bsd.libnames.mk>
17051fa76c4SRuslan Ermilov
171218a2cd2SBruce Evans.if defined(PROG)
172663e9677SBruce Evans_EXTRADEPEND:
17351fa76c4SRuslan Ermilov.if defined(LDFLAGS) && !empty(LDFLAGS:M-nostdlib)
17451fa76c4SRuslan Ermilov.if defined(DPADD) && !empty(DPADD)
17537fd8bc2SJohn Baldwin	echo ${PROG_FULL}: ${DPADD} >> ${DEPENDFILE}
17651fa76c4SRuslan Ermilov.endif
17751fa76c4SRuslan Ermilov.else
17837fd8bc2SJohn Baldwin	echo ${PROG_FULL}: ${LIBC} ${DPADD} >> ${DEPENDFILE}
1797273339dSWarner Losh.if defined(PROG_CXX)
18063e4d6f7SWarner Losh.if ${COMPILER_TYPE} == "clang" && empty(CXXFLAGS:M-stdlib=libstdc++)
18137fd8bc2SJohn Baldwin	echo ${PROG_FULL}: ${LIBCPLUSPLUS} >> ${DEPENDFILE}
182d515c63dSDimitry Andric.else
18337fd8bc2SJohn Baldwin	echo ${PROG_FULL}: ${LIBSTDCPLUSPLUS} >> ${DEPENDFILE}
184f8ba1555SRuslan Ermilov.endif
1858c05a446SPeter Wemm.endif
18651fa76c4SRuslan Ermilov.endif
187d515c63dSDimitry Andric.endif
188663e9677SBruce Evans
189afe61c15SRodney W. Grimes.if !target(install)
190afe61c15SRodney W. Grimes
191212acbefSRuslan Ermilov.if defined(PRECIOUSPROG)
19200fbd407SRuslan Ermilov.if !defined(NO_FSCHG)
193dee651ebSRuslan ErmilovINSTALLFLAGS+= -fschg
194dee651ebSRuslan Ermilov.endif
195212acbefSRuslan ErmilovINSTALLFLAGS+= -S
196212acbefSRuslan Ermilov.endif
197dee651ebSRuslan Ermilov
198e902c1bbSTim Vanderhoek_INSTALLFLAGS:=	${INSTALLFLAGS}
199e902c1bbSTim Vanderhoek.for ie in ${INSTALLFLAGS_EDIT}
200e902c1bbSTim Vanderhoek_INSTALLFLAGS:=	${_INSTALLFLAGS${ie}}
201e902c1bbSTim Vanderhoek.endfor
202e902c1bbSTim Vanderhoek
20351fa76c4SRuslan Ermilov.if !target(realinstall) && !defined(INTERNALPROG)
20487829387SRuslan Ermilovrealinstall: _proginstall
205badb7c1cSRuslan Ermilov.ORDER: beforeinstall _proginstall
20687829387SRuslan Ermilov_proginstall:
207afe61c15SRodney W. Grimes.if defined(PROG)
208d2893b16SRuslan Ermilov	${INSTALL} ${STRIP} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
20995f8c826SRuslan Ermilov	    ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${BINDIR}/${PROGNAME}
21042f8c5b5SEd Maste.if ${MK_DEBUG_FILES} != "no"
21142f8c5b5SEd Maste.if defined(DEBUGMKDIR)
21261c20fc7SBryan Drewery	${INSTALL} -T debug -d ${DESTDIR}${DEBUGFILEDIR}/
21342f8c5b5SEd Maste.endif
21442f8c5b5SEd Maste	${INSTALL} -T debug -o ${BINOWN} -g ${BINGRP} -m ${DEBUGMODE} \
21542f8c5b5SEd Maste	    ${PROGNAME}.debug ${DESTDIR}${DEBUGFILEDIR}/${PROGNAME}.debug
21642f8c5b5SEd Maste.endif
21795f8c826SRuslan Ermilov.endif
21884aac273SHartmut Brandt.endif	# !target(realinstall)
219afe61c15SRodney W. Grimes
220f7ee8cfeSRuslan Ermilov.if defined(SCRIPTS) && !empty(SCRIPTS)
221f7ee8cfeSRuslan Ermilovrealinstall: _scriptsinstall
222badb7c1cSRuslan Ermilov.ORDER: beforeinstall _scriptsinstall
223f7ee8cfeSRuslan Ermilov
224f7ee8cfeSRuslan ErmilovSCRIPTSDIR?=	${BINDIR}
225f7ee8cfeSRuslan ErmilovSCRIPTSOWN?=	${BINOWN}
226f7ee8cfeSRuslan ErmilovSCRIPTSGRP?=	${BINGRP}
227f7ee8cfeSRuslan ErmilovSCRIPTSMODE?=	${BINMODE}
228f7ee8cfeSRuslan Ermilov
229116d4508SSimon J. GerratySTAGE_AS_SETS+= scripts
230116d4508SSimon J. Gerratystage_as.scripts: ${SCRIPTS}
231116d4508SSimon J. GerratyFLAGS.stage_as.scripts= -m ${SCRIPTSMODE}
232116d4508SSimon J. GerratySTAGE_FILES_DIR.scripts= ${STAGE_OBJTOP}
233f7ee8cfeSRuslan Ermilov.for script in ${SCRIPTS}
234f7ee8cfeSRuslan Ermilov.if defined(SCRIPTSNAME)
235f7ee8cfeSRuslan ErmilovSCRIPTSNAME_${script:T}?=	${SCRIPTSNAME}
236f7ee8cfeSRuslan Ermilov.else
237f7ee8cfeSRuslan ErmilovSCRIPTSNAME_${script:T}?=	${script:T:R}
238f7ee8cfeSRuslan Ermilov.endif
239f7ee8cfeSRuslan ErmilovSCRIPTSDIR_${script:T}?=	${SCRIPTSDIR}
240f7ee8cfeSRuslan ErmilovSCRIPTSOWN_${script:T}?=	${SCRIPTSOWN}
241f7ee8cfeSRuslan ErmilovSCRIPTSGRP_${script:T}?=	${SCRIPTSGRP}
242f7ee8cfeSRuslan ErmilovSCRIPTSMODE_${script:T}?=	${SCRIPTSMODE}
243116d4508SSimon J. GerratySTAGE_AS_${script:T}=		${SCRIPTSDIR_${script:T}}/${SCRIPTSNAME_${script:T}}
244a7aaf57eSRuslan Ermilov_scriptsinstall: _SCRIPTSINS_${script:T}
245a7aaf57eSRuslan Ermilov_SCRIPTSINS_${script:T}: ${script}
246d2893b16SRuslan Ermilov	${INSTALL} -o ${SCRIPTSOWN_${.ALLSRC:T}} \
247f7ee8cfeSRuslan Ermilov	    -g ${SCRIPTSGRP_${.ALLSRC:T}} -m ${SCRIPTSMODE_${.ALLSRC:T}} \
2484367bda6SRuslan Ermilov	    ${.ALLSRC} \
249f7ee8cfeSRuslan Ermilov	    ${DESTDIR}${SCRIPTSDIR_${.ALLSRC:T}}/${SCRIPTSNAME_${.ALLSRC:T}}
250f7ee8cfeSRuslan Ermilov.endfor
251f7ee8cfeSRuslan Ermilov.endif
252f7ee8cfeSRuslan Ermilov
2538479adc1SRuslan ErmilovNLSNAME?=	${PROG}
2548479adc1SRuslan Ermilov.include <bsd.nls.mk>
2558479adc1SRuslan Ermilov
2569b4f4918SBaptiste Daroussin.include <bsd.confs.mk>
257af2dc868SRuslan Ermilov.include <bsd.files.mk>
2585d862037SRuslan Ermilov.include <bsd.incs.mk>
25984f94a79SRuslan Ermilov.include <bsd.links.mk>
260c7b111cbSRuslan Ermilov
261e1fe3dbaSRuslan Ermilov.if ${MK_MAN} != "no"
262afeaaa84SRuslan Ermilovrealinstall: _maninstall
263badb7c1cSRuslan Ermilov.ORDER: beforeinstall _maninstall
26487829387SRuslan Ermilov.endif
26587829387SRuslan Ermilov
266abb02fa2SBryan Drewery.endif	# !target(install)
267afe61c15SRodney W. Grimes
268afe61c15SRodney W. Grimes.if !target(lint)
2695741a42fSMark Murraylint: ${SRCS:M*.c}
270afe61c15SRodney W. Grimes.if defined(PROG)
2715741a42fSMark Murray	${LINT} ${LINTFLAGS} ${CFLAGS:M-[DIU]*} ${.ALLSRC}
272afe61c15SRodney W. Grimes.endif
273afe61c15SRodney W. Grimes.endif
274afe61c15SRodney W. Grimes
275e1fe3dbaSRuslan Ermilov.if ${MK_MAN} != "no"
276afe61c15SRodney W. Grimes.include <bsd.man.mk>
27769b87d3eSEivind Eklund.endif
27869b87d3eSEivind Eklund
2793585b293SGarrett Wollman.include <bsd.dep.mk>
280987afe2aSBruce Evans
28188505e11SRuslan Ermilov.if defined(PROG) && !exists(${.OBJDIR}/${DEPENDFILE})
282589d9341SBruce Evans${OBJS}: ${SRCS:M*.h}
283987afe2aSBruce Evans.endif
284987afe2aSBruce Evans
285cd9a2f5cSJordan K. Hubbard.include <bsd.obj.mk>
286d510ecb4SKris Kennaway
287d510ecb4SKris Kennaway.include <bsd.sys.mk>
288