xref: /freebsd/share/mk/bsd.prog.mk (revision aae63957af7fde624579121b9cd72166ef3c0a8f)
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)
859160419cSBryan Drewery	${CXX:N${CCACHE_BIN}} ${CXXFLAGS:N-M*} ${LDFLAGS} -o ${.TARGET} \
869160419cSBryan Drewery	    ${OBJS} ${LDADD}
875d68012aSRuslan Ermilov.else
889160419cSBryan Drewery	${CC:N${CCACHE_BIN}} ${CFLAGS:N-M*} ${LDFLAGS} -o ${.TARGET} ${OBJS} \
899160419cSBryan 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)
1179160419cSBryan Drewery	${CXX:N${CCACHE_BIN}} ${CXXFLAGS:N-M*} ${LDFLAGS} -o ${.TARGET} \
1189160419cSBryan Drewery	    ${OBJS} ${LDADD}
119f8ba1555SRuslan Ermilov.else
1209160419cSBryan Drewery	${CC:N${CCACHE_BIN}} ${CFLAGS:N-M*} ${LDFLAGS} -o ${.TARGET} ${OBJS} \
1219160419cSBryan 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
1511bd4272fSBryan Dreweryall: ${PROG} ${SCRIPTS}
152e1fe3dbaSRuslan Ermilov.if ${MK_MAN} != "no"
153f1702f87SBryan Dreweryall: all-man
154862d3deaSRuslan Ermilov.endif
1557750ad47SMarcel Moolenaar.endif
156afe61c15SRodney W. Grimes
15741f89315SRuslan Ermilov.if defined(PROG)
15841f89315SRuslan ErmilovCLEANFILES+= ${PROG}
15942f8c5b5SEd Maste.if ${MK_DEBUG_FILES} != "no"
16042f8c5b5SEd MasteCLEANFILES+=	${PROG_FULL} ${PROGNAME}.debug
16142f8c5b5SEd Maste.endif
16241f89315SRuslan Ermilov.endif
16341f89315SRuslan Ermilov
16441f89315SRuslan Ermilov.if defined(OBJS)
16541f89315SRuslan ErmilovCLEANFILES+= ${OBJS}
16641f89315SRuslan Ermilov.endif
167afe61c15SRodney W. Grimes
16851fa76c4SRuslan Ermilov.include <bsd.libnames.mk>
16951fa76c4SRuslan Ermilov
170218a2cd2SBruce Evans.if defined(PROG)
171663e9677SBruce Evans_EXTRADEPEND:
17251fa76c4SRuslan Ermilov.if defined(LDFLAGS) && !empty(LDFLAGS:M-nostdlib)
17351fa76c4SRuslan Ermilov.if defined(DPADD) && !empty(DPADD)
17437fd8bc2SJohn Baldwin	echo ${PROG_FULL}: ${DPADD} >> ${DEPENDFILE}
17551fa76c4SRuslan Ermilov.endif
17651fa76c4SRuslan Ermilov.else
17737fd8bc2SJohn Baldwin	echo ${PROG_FULL}: ${LIBC} ${DPADD} >> ${DEPENDFILE}
1787273339dSWarner Losh.if defined(PROG_CXX)
17963e4d6f7SWarner Losh.if ${COMPILER_TYPE} == "clang" && empty(CXXFLAGS:M-stdlib=libstdc++)
18037fd8bc2SJohn Baldwin	echo ${PROG_FULL}: ${LIBCPLUSPLUS} >> ${DEPENDFILE}
181d515c63dSDimitry Andric.else
18237fd8bc2SJohn Baldwin	echo ${PROG_FULL}: ${LIBSTDCPLUSPLUS} >> ${DEPENDFILE}
183f8ba1555SRuslan Ermilov.endif
1848c05a446SPeter Wemm.endif
18551fa76c4SRuslan Ermilov.endif
186d515c63dSDimitry Andric.endif
187663e9677SBruce Evans
188afe61c15SRodney W. Grimes.if !target(install)
189afe61c15SRodney W. Grimes
190212acbefSRuslan Ermilov.if defined(PRECIOUSPROG)
19100fbd407SRuslan Ermilov.if !defined(NO_FSCHG)
192dee651ebSRuslan ErmilovINSTALLFLAGS+= -fschg
193dee651ebSRuslan Ermilov.endif
194212acbefSRuslan ErmilovINSTALLFLAGS+= -S
195212acbefSRuslan Ermilov.endif
196dee651ebSRuslan Ermilov
197e902c1bbSTim Vanderhoek_INSTALLFLAGS:=	${INSTALLFLAGS}
198e902c1bbSTim Vanderhoek.for ie in ${INSTALLFLAGS_EDIT}
199e902c1bbSTim Vanderhoek_INSTALLFLAGS:=	${_INSTALLFLAGS${ie}}
200e902c1bbSTim Vanderhoek.endfor
201e902c1bbSTim Vanderhoek
20251fa76c4SRuslan Ermilov.if !target(realinstall) && !defined(INTERNALPROG)
20387829387SRuslan Ermilovrealinstall: _proginstall
204badb7c1cSRuslan Ermilov.ORDER: beforeinstall _proginstall
20587829387SRuslan Ermilov_proginstall:
206afe61c15SRodney W. Grimes.if defined(PROG)
207d2893b16SRuslan Ermilov	${INSTALL} ${STRIP} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
20895f8c826SRuslan Ermilov	    ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${BINDIR}/${PROGNAME}
20942f8c5b5SEd Maste.if ${MK_DEBUG_FILES} != "no"
21042f8c5b5SEd Maste.if defined(DEBUGMKDIR)
21161c20fc7SBryan Drewery	${INSTALL} -T debug -d ${DESTDIR}${DEBUGFILEDIR}/
21242f8c5b5SEd Maste.endif
21342f8c5b5SEd Maste	${INSTALL} -T debug -o ${BINOWN} -g ${BINGRP} -m ${DEBUGMODE} \
21442f8c5b5SEd Maste	    ${PROGNAME}.debug ${DESTDIR}${DEBUGFILEDIR}/${PROGNAME}.debug
21542f8c5b5SEd Maste.endif
21695f8c826SRuslan Ermilov.endif
21784aac273SHartmut Brandt.endif	# !target(realinstall)
218afe61c15SRodney W. Grimes
219f7ee8cfeSRuslan Ermilov.if defined(SCRIPTS) && !empty(SCRIPTS)
220f7ee8cfeSRuslan Ermilovrealinstall: _scriptsinstall
221badb7c1cSRuslan Ermilov.ORDER: beforeinstall _scriptsinstall
222f7ee8cfeSRuslan Ermilov
223f7ee8cfeSRuslan ErmilovSCRIPTSDIR?=	${BINDIR}
224f7ee8cfeSRuslan ErmilovSCRIPTSOWN?=	${BINOWN}
225f7ee8cfeSRuslan ErmilovSCRIPTSGRP?=	${BINGRP}
226f7ee8cfeSRuslan ErmilovSCRIPTSMODE?=	${BINMODE}
227f7ee8cfeSRuslan Ermilov
228116d4508SSimon J. GerratySTAGE_AS_SETS+= scripts
229116d4508SSimon J. Gerratystage_as.scripts: ${SCRIPTS}
230116d4508SSimon J. GerratyFLAGS.stage_as.scripts= -m ${SCRIPTSMODE}
231116d4508SSimon J. GerratySTAGE_FILES_DIR.scripts= ${STAGE_OBJTOP}
232f7ee8cfeSRuslan Ermilov.for script in ${SCRIPTS}
233f7ee8cfeSRuslan Ermilov.if defined(SCRIPTSNAME)
234f7ee8cfeSRuslan ErmilovSCRIPTSNAME_${script:T}?=	${SCRIPTSNAME}
235f7ee8cfeSRuslan Ermilov.else
236f7ee8cfeSRuslan ErmilovSCRIPTSNAME_${script:T}?=	${script:T:R}
237f7ee8cfeSRuslan Ermilov.endif
238f7ee8cfeSRuslan ErmilovSCRIPTSDIR_${script:T}?=	${SCRIPTSDIR}
239f7ee8cfeSRuslan ErmilovSCRIPTSOWN_${script:T}?=	${SCRIPTSOWN}
240f7ee8cfeSRuslan ErmilovSCRIPTSGRP_${script:T}?=	${SCRIPTSGRP}
241f7ee8cfeSRuslan ErmilovSCRIPTSMODE_${script:T}?=	${SCRIPTSMODE}
242116d4508SSimon J. GerratySTAGE_AS_${script:T}=		${SCRIPTSDIR_${script:T}}/${SCRIPTSNAME_${script:T}}
243a7aaf57eSRuslan Ermilov_scriptsinstall: _SCRIPTSINS_${script:T}
244a7aaf57eSRuslan Ermilov_SCRIPTSINS_${script:T}: ${script}
245d2893b16SRuslan Ermilov	${INSTALL} -o ${SCRIPTSOWN_${.ALLSRC:T}} \
246f7ee8cfeSRuslan Ermilov	    -g ${SCRIPTSGRP_${.ALLSRC:T}} -m ${SCRIPTSMODE_${.ALLSRC:T}} \
2474367bda6SRuslan Ermilov	    ${.ALLSRC} \
248f7ee8cfeSRuslan Ermilov	    ${DESTDIR}${SCRIPTSDIR_${.ALLSRC:T}}/${SCRIPTSNAME_${.ALLSRC:T}}
249f7ee8cfeSRuslan Ermilov.endfor
250f7ee8cfeSRuslan Ermilov.endif
251f7ee8cfeSRuslan Ermilov
2528479adc1SRuslan ErmilovNLSNAME?=	${PROG}
2538479adc1SRuslan Ermilov.include <bsd.nls.mk>
2548479adc1SRuslan Ermilov
2559b4f4918SBaptiste Daroussin.include <bsd.confs.mk>
256af2dc868SRuslan Ermilov.include <bsd.files.mk>
2575d862037SRuslan Ermilov.include <bsd.incs.mk>
25884f94a79SRuslan Ermilov.include <bsd.links.mk>
259c7b111cbSRuslan Ermilov
260e1fe3dbaSRuslan Ermilov.if ${MK_MAN} != "no"
261f1702f87SBryan Dreweryrealinstall: maninstall
262f1702f87SBryan Drewery.ORDER: beforeinstall maninstall
26387829387SRuslan Ermilov.endif
26487829387SRuslan Ermilov
265abb02fa2SBryan Drewery.endif	# !target(install)
266afe61c15SRodney W. Grimes
267afe61c15SRodney W. Grimes.if !target(lint)
2685741a42fSMark Murraylint: ${SRCS:M*.c}
269afe61c15SRodney W. Grimes.if defined(PROG)
2705741a42fSMark Murray	${LINT} ${LINTFLAGS} ${CFLAGS:M-[DIU]*} ${.ALLSRC}
271afe61c15SRodney W. Grimes.endif
272afe61c15SRodney W. Grimes.endif
273afe61c15SRodney W. Grimes
274e1fe3dbaSRuslan Ermilov.if ${MK_MAN} != "no"
275afe61c15SRodney W. Grimes.include <bsd.man.mk>
27669b87d3eSEivind Eklund.endif
27769b87d3eSEivind Eklund
278d7beff08SBryan Drewery.if defined(PROG)
279d7beff08SBryan DreweryOBJS_DEPEND_GUESS+= ${SRCS:M*.h}
280d7beff08SBryan Drewery.if ${MK_FAST_DEPEND} == "no" && !exists(${.OBJDIR}/${DEPENDFILE})
281d7beff08SBryan Drewery${OBJS}: ${OBJS_DEPEND_GUESS}
282d7beff08SBryan Drewery.endif
283987afe2aSBruce Evans.endif
284987afe2aSBruce Evans
285d7beff08SBryan Drewery.include <bsd.dep.mk>
286*aae63957SBryan Drewery.include <bsd.clang-analyze.mk>
287cd9a2f5cSJordan K. Hubbard.include <bsd.obj.mk>
288d510ecb4SKris Kennaway.include <bsd.sys.mk>
289