xref: /freebsd/share/mk/bsd.prog.mk (revision 63e4d6f712595bd6f89699253563b65816a0a849)
13585b293SGarrett Wollman#	from: @(#)bsd.prog.mk	5.26 (Berkeley) 6/25/91
27f3dea24SPeter Wemm# $FreeBSD$
3afe61c15SRodney W. Grimes
42bdaf7e8SRuslan Ermilov.include <bsd.init.mk>
5afe61c15SRodney W. Grimes
65741a42fSMark Murray.SUFFIXES: .out .o .c .cc .cpp .cxx .C .m .y .l .ln .s .S .asm
7afe61c15SRodney W. Grimes
848aea4daSRuslan Ermilov# XXX The use of COPTS in modern makefiles is discouraged.
941f89315SRuslan Ermilov.if defined(COPTS)
1041f89315SRuslan ErmilovCFLAGS+=${COPTS}
1141f89315SRuslan Ermilov.endif
1241f89315SRuslan Ermilov
134df1f59eSWarner Losh.if ${MK_ASSERT_DEBUG} == "no"
144df1f59eSWarner LoshCFLAGS+= -DNDEBUG
15e2e1ab1cSDavid E. O'BrienNO_WERROR=
164df1f59eSWarner Losh.endif
174df1f59eSWarner Losh
1841f89315SRuslan Ermilov.if defined(DEBUG_FLAGS)
1941f89315SRuslan ErmilovCFLAGS+=${DEBUG_FLAGS}
208eba8cd8SMarcel MoolenaarCXXFLAGS+=${DEBUG_FLAGS}
21770ac3b2SJohn Birrell
2283cb5baeSMax Khon.if ${MK_CTF} != "no" && ${DEBUG_FLAGS:M-g} != ""
23770ac3b2SJohn BirrellCTFFLAGS+= -g
24770ac3b2SJohn Birrell.endif
2541f89315SRuslan Ermilov.endif
2641f89315SRuslan Ermilov
2742f8c5b5SEd Maste.if defined(PROG_CXX)
2842f8c5b5SEd MastePROG=	${PROG_CXX}
2942f8c5b5SEd Maste.endif
3042f8c5b5SEd Maste
3142f8c5b5SEd Maste.if defined(PROG) && target(${PROG})
3242f8c5b5SEd MasteMK_DEBUG_FILES=	no
3342f8c5b5SEd Maste.elif !empty(LDFLAGS:M-Wl,*--oformat,*) || !empty(LDFLAGS:M-static)
3442f8c5b5SEd MasteMK_DEBUG_FILES=	no
3542f8c5b5SEd Maste.endif
3642f8c5b5SEd Maste
3741f89315SRuslan Ermilov.if defined(CRUNCH_CFLAGS)
383c9b8563SGordon TetlowCFLAGS+=${CRUNCH_CFLAGS}
3942f8c5b5SEd Maste.else
4042f8c5b5SEd Maste.if ${MK_DEBUG_FILES} != "no" && empty(DEBUG_FLAGS:M-g) && \
4142f8c5b5SEd Maste    empty(DEBUG_FLAGS:M-gdwarf-*)
4242f8c5b5SEd MasteCFLAGS+= -g
4342f8c5b5SEd MasteCTFFLAGS+= -g
4442f8c5b5SEd Maste.endif
4541f89315SRuslan Ermilov.endif
46afe61c15SRodney W. Grimes
47e82b0b99SJordan K. Hubbard.if !defined(DEBUG_FLAGS)
48afe61c15SRodney W. GrimesSTRIP?=	-s
49e82b0b99SJordan K. Hubbard.endif
50afe61c15SRodney W. Grimes
5183c7ade9SRuslan Ermilov.if defined(NO_SHARED) && (${NO_SHARED} != "no" && ${NO_SHARED} != "NO")
523585b293SGarrett WollmanLDFLAGS+= -static
533585b293SGarrett Wollman.endif
54afe61c15SRodney W. Grimes
552442cc58SDag-Erling Smørgrav.if defined(USEPRIVATELIB)
562442cc58SDag-Erling SmørgravLDFLAGS+= -L${_SHLIBDIRPREFIX}${LIBPRIVATEDIR} -rpath ${LIBPRIVATEDIR}
572442cc58SDag-Erling Smørgrav.endif
582442cc58SDag-Erling Smørgrav
5942f8c5b5SEd Maste.if ${MK_DEBUG_FILES} != "no"
6042f8c5b5SEd MastePROG_FULL=${PROG}.full
6142f8c5b5SEd Maste# Use ${DEBUGDIR} for base system debug files, else .debug subdirectory
6242f8c5b5SEd Maste.if defined(BINDIR) && (\
6342f8c5b5SEd Maste    ${BINDIR} == "/bin" ||\
6442f8c5b5SEd Maste    ${BINDIR} == "/libexec" ||\
6542f8c5b5SEd Maste    ${BINDIR} == "/sbin" ||\
6642f8c5b5SEd Maste    ${BINDIR:C%/usr/(bin|bsdinstall|games|libexec|lpr|sendmail|sm.bin|sbin)(/.*)?%/usr/bin%} == "/usr/bin"\
6742f8c5b5SEd Maste     )
6842f8c5b5SEd MasteDEBUGFILEDIR=	${DEBUGDIR}${BINDIR}
6942f8c5b5SEd Maste.else
7042f8c5b5SEd MasteDEBUGFILEDIR?=	${BINDIR}/.debug
7142f8c5b5SEd MasteDEBUGMKDIR=
7242f8c5b5SEd Maste.endif
7342f8c5b5SEd Maste.else
7442f8c5b5SEd MastePROG_FULL=	${PROG}
7547bf8a5cSRuslan Ermilov.endif
7647bf8a5cSRuslan Ermilov
77afe61c15SRodney W. Grimes.if defined(PROG)
78a0dc5970SEd MastePROGNAME?=	${PROG}
7942f8c5b5SEd Maste
80afe61c15SRodney W. Grimes.if defined(SRCS)
81afe61c15SRodney W. Grimes
823585b293SGarrett WollmanOBJS+=  ${SRCS:N*.h:R:S/$/.o/g}
83afe61c15SRodney W. Grimes
84c2c48445SRui Paulo.if target(beforelinking)
85593c0b49SMark Johnstonbeforelinking: ${OBJS}
8642f8c5b5SEd Maste${PROG_FULL}: beforelinking
87c2c48445SRui Paulo.endif
8842f8c5b5SEd Maste${PROG_FULL}: ${OBJS}
895d68012aSRuslan Ermilov.if defined(PROG_CXX)
905d68012aSRuslan Ermilov	${CXX} ${CXXFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD}
915d68012aSRuslan Ermilov.else
925d68012aSRuslan Ermilov	${CC} ${CFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD}
935d68012aSRuslan Ermilov.endif
9483cb5baeSMax Khon.if ${MK_CTF} != "no"
95cd49c2e8SMax Khon	${CTFMERGE} ${CTFFLAGS} -o ${.TARGET} ${OBJS}
96cd49c2e8SMax Khon.endif
975d68012aSRuslan Ermilov
9884aac273SHartmut Brandt.else	# !defined(SRCS)
99afe61c15SRodney W. Grimes
1005d68012aSRuslan Ermilov.if !target(${PROG})
10147bf8a5cSRuslan Ermilov.if defined(PROG_CXX)
10247bf8a5cSRuslan ErmilovSRCS=	${PROG}.cc
10347bf8a5cSRuslan Ermilov.else
104afe61c15SRodney W. GrimesSRCS=	${PROG}.c
10547bf8a5cSRuslan Ermilov.endif
106afe61c15SRodney W. Grimes
107a4c39c7aSBruce Evans# Always make an intermediate object file because:
108a4c39c7aSBruce Evans# - it saves time rebuilding when only the library has changed
109a4c39c7aSBruce Evans# - the name of the object gets put into the executable symbol table instead of
110a4c39c7aSBruce Evans#   the name of a variable temporary object.
111a4c39c7aSBruce Evans# - it's useful to keep objects around for crunching.
1127f7fc25bSMark JohnstonOBJS+=	${PROG}.o
113f5c75051SEivind Eklund
114c2c48445SRui Paulo.if target(beforelinking)
115593c0b49SMark Johnstonbeforelinking: ${OBJS}
11642f8c5b5SEd Maste${PROG_FULL}: beforelinking
117c2c48445SRui Paulo.endif
11842f8c5b5SEd Maste${PROG_FULL}: ${OBJS}
119f8ba1555SRuslan Ermilov.if defined(PROG_CXX)
120f8ba1555SRuslan Ermilov	${CXX} ${CXXFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD}
121f8ba1555SRuslan Ermilov.else
122de0d6977SRuslan Ermilov	${CC} ${CFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD}
123afe61c15SRodney W. Grimes.endif
12483cb5baeSMax Khon.if ${MK_CTF} != "no"
125cd49c2e8SMax Khon	${CTFMERGE} ${CTFFLAGS} -o ${.TARGET} ${OBJS}
126cd49c2e8SMax Khon.endif
12742f8c5b5SEd Maste.endif # !target(${PROG})
128f5c75051SEivind Eklund
1290d947ed1SEd Maste.endif # !defined(SRCS)
130afe61c15SRodney W. Grimes
13142f8c5b5SEd Maste.if ${MK_DEBUG_FILES} != "no"
13242f8c5b5SEd Maste${PROG}: ${PROG_FULL} ${PROGNAME}.debug
13342f8c5b5SEd Maste	${OBJCOPY} --strip-debug --add-gnu-debuglink=${PROGNAME}.debug \
13442f8c5b5SEd Maste	    ${PROG_FULL} ${.TARGET}
13542f8c5b5SEd Maste
13642f8c5b5SEd Maste${PROGNAME}.debug: ${PROG_FULL}
13742f8c5b5SEd Maste	${OBJCOPY} --only-keep-debug ${PROG_FULL} ${.TARGET}
13842f8c5b5SEd Maste.endif
13942f8c5b5SEd Maste
140e1fe3dbaSRuslan Ermilov.if	${MK_MAN} != "no" && !defined(MAN) && \
141862d3deaSRuslan Ermilov	!defined(MAN1) && !defined(MAN2) && !defined(MAN3) && \
142afe61c15SRodney W. Grimes	!defined(MAN4) && !defined(MAN5) && !defined(MAN6) && \
1438b4f1f91SBrooks Davis	!defined(MAN7) && !defined(MAN8) && !defined(MAN9)
14419ea15a1SRuslan ErmilovMAN=	${PROG}.1
14519ea15a1SRuslan ErmilovMAN1=	${MAN}
146afe61c15SRodney W. Grimes.endif
1470d947ed1SEd Maste.endif # defined(PROG)
148afe61c15SRodney W. Grimes
149af2dc868SRuslan Ermilovall: objwarn ${PROG} ${SCRIPTS}
150e1fe3dbaSRuslan Ermilov.if ${MK_MAN} != "no"
151afeaaa84SRuslan Ermilovall: _manpages
152862d3deaSRuslan Ermilov.endif
153afe61c15SRodney W. Grimes
15441f89315SRuslan Ermilov.if defined(PROG)
15541f89315SRuslan ErmilovCLEANFILES+= ${PROG}
15642f8c5b5SEd Maste.if ${MK_DEBUG_FILES} != "no"
15742f8c5b5SEd MasteCLEANFILES+=	${PROG_FULL} ${PROGNAME}.debug
15842f8c5b5SEd Maste.endif
15941f89315SRuslan Ermilov.endif
16041f89315SRuslan Ermilov
16141f89315SRuslan Ermilov.if defined(OBJS)
16241f89315SRuslan ErmilovCLEANFILES+= ${OBJS}
16341f89315SRuslan Ermilov.endif
164afe61c15SRodney W. Grimes
16551fa76c4SRuslan Ermilov.include <bsd.libnames.mk>
16651fa76c4SRuslan Ermilov
167218a2cd2SBruce Evans.if defined(PROG)
168663e9677SBruce Evans_EXTRADEPEND:
16951fa76c4SRuslan Ermilov.if defined(LDFLAGS) && !empty(LDFLAGS:M-nostdlib)
17051fa76c4SRuslan Ermilov.if defined(DPADD) && !empty(DPADD)
17151fa76c4SRuslan Ermilov	echo ${PROG}: ${DPADD} >> ${DEPENDFILE}
17251fa76c4SRuslan Ermilov.endif
17351fa76c4SRuslan Ermilov.else
1746e19760bSBruce Evans	echo ${PROG}: ${LIBC} ${DPADD} >> ${DEPENDFILE}
175756950a1SDimitry Andric.if defined(PROG_CXX) && !defined(EARLY_BUILD)
176*63e4d6f7SWarner Losh.if ${COMPILER_TYPE} == "clang" && empty(CXXFLAGS:M-stdlib=libstdc++)
177d515c63dSDimitry Andric	echo ${PROG}: ${LIBCPLUSPLUS} >> ${DEPENDFILE}
178d515c63dSDimitry Andric.else
179f8ba1555SRuslan Ermilov	echo ${PROG}: ${LIBSTDCPLUSPLUS} >> ${DEPENDFILE}
180f8ba1555SRuslan Ermilov.endif
1818c05a446SPeter Wemm.endif
18251fa76c4SRuslan Ermilov.endif
183d515c63dSDimitry Andric.endif
184663e9677SBruce Evans
185afe61c15SRodney W. Grimes.if !target(install)
186afe61c15SRodney W. Grimes
187212acbefSRuslan Ermilov.if defined(PRECIOUSPROG)
18800fbd407SRuslan Ermilov.if !defined(NO_FSCHG)
189dee651ebSRuslan ErmilovINSTALLFLAGS+= -fschg
190dee651ebSRuslan Ermilov.endif
191212acbefSRuslan ErmilovINSTALLFLAGS+= -S
192212acbefSRuslan Ermilov.endif
193dee651ebSRuslan Ermilov
194e902c1bbSTim Vanderhoek_INSTALLFLAGS:=	${INSTALLFLAGS}
195e902c1bbSTim Vanderhoek.for ie in ${INSTALLFLAGS_EDIT}
196e902c1bbSTim Vanderhoek_INSTALLFLAGS:=	${_INSTALLFLAGS${ie}}
197e902c1bbSTim Vanderhoek.endfor
198e902c1bbSTim Vanderhoek
19951fa76c4SRuslan Ermilov.if !target(realinstall) && !defined(INTERNALPROG)
20087829387SRuslan Ermilovrealinstall: _proginstall
201badb7c1cSRuslan Ermilov.ORDER: beforeinstall _proginstall
20287829387SRuslan Ermilov_proginstall:
203afe61c15SRodney W. Grimes.if defined(PROG)
204d2893b16SRuslan Ermilov	${INSTALL} ${STRIP} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
20595f8c826SRuslan Ermilov	    ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${BINDIR}/${PROGNAME}
20642f8c5b5SEd Maste.if ${MK_DEBUG_FILES} != "no"
20742f8c5b5SEd Maste.if defined(DEBUGMKDIR)
20842f8c5b5SEd Maste	${INSTALL} -T debug -d ${DESTDIR}${DEBUGFILEDIR}
20942f8c5b5SEd Maste.endif
21042f8c5b5SEd Maste	${INSTALL} -T debug -o ${BINOWN} -g ${BINGRP} -m ${DEBUGMODE} \
21142f8c5b5SEd Maste	    ${PROGNAME}.debug ${DESTDIR}${DEBUGFILEDIR}/${PROGNAME}.debug
21242f8c5b5SEd Maste.endif
21395f8c826SRuslan Ermilov.endif
21484aac273SHartmut Brandt.endif	# !target(realinstall)
215afe61c15SRodney W. Grimes
216f7ee8cfeSRuslan Ermilov.if defined(SCRIPTS) && !empty(SCRIPTS)
217f7ee8cfeSRuslan Ermilovrealinstall: _scriptsinstall
218badb7c1cSRuslan Ermilov.ORDER: beforeinstall _scriptsinstall
219f7ee8cfeSRuslan Ermilov
220f7ee8cfeSRuslan ErmilovSCRIPTSDIR?=	${BINDIR}
221f7ee8cfeSRuslan ErmilovSCRIPTSOWN?=	${BINOWN}
222f7ee8cfeSRuslan ErmilovSCRIPTSGRP?=	${BINGRP}
223f7ee8cfeSRuslan ErmilovSCRIPTSMODE?=	${BINMODE}
224f7ee8cfeSRuslan Ermilov
225f7ee8cfeSRuslan Ermilov.for script in ${SCRIPTS}
226f7ee8cfeSRuslan Ermilov.if defined(SCRIPTSNAME)
227f7ee8cfeSRuslan ErmilovSCRIPTSNAME_${script:T}?=	${SCRIPTSNAME}
228f7ee8cfeSRuslan Ermilov.else
229f7ee8cfeSRuslan ErmilovSCRIPTSNAME_${script:T}?=	${script:T:R}
230f7ee8cfeSRuslan Ermilov.endif
231f7ee8cfeSRuslan ErmilovSCRIPTSDIR_${script:T}?=	${SCRIPTSDIR}
232f7ee8cfeSRuslan ErmilovSCRIPTSOWN_${script:T}?=	${SCRIPTSOWN}
233f7ee8cfeSRuslan ErmilovSCRIPTSGRP_${script:T}?=	${SCRIPTSGRP}
234f7ee8cfeSRuslan ErmilovSCRIPTSMODE_${script:T}?=	${SCRIPTSMODE}
235a7aaf57eSRuslan Ermilov_scriptsinstall: _SCRIPTSINS_${script:T}
236a7aaf57eSRuslan Ermilov_SCRIPTSINS_${script:T}: ${script}
237d2893b16SRuslan Ermilov	${INSTALL} -o ${SCRIPTSOWN_${.ALLSRC:T}} \
238f7ee8cfeSRuslan Ermilov	    -g ${SCRIPTSGRP_${.ALLSRC:T}} -m ${SCRIPTSMODE_${.ALLSRC:T}} \
2394367bda6SRuslan Ermilov	    ${.ALLSRC} \
240f7ee8cfeSRuslan Ermilov	    ${DESTDIR}${SCRIPTSDIR_${.ALLSRC:T}}/${SCRIPTSNAME_${.ALLSRC:T}}
241f7ee8cfeSRuslan Ermilov.endfor
242f7ee8cfeSRuslan Ermilov.endif
243f7ee8cfeSRuslan Ermilov
2448479adc1SRuslan ErmilovNLSNAME?=	${PROG}
2458479adc1SRuslan Ermilov.include <bsd.nls.mk>
2468479adc1SRuslan Ermilov
247af2dc868SRuslan Ermilov.include <bsd.files.mk>
2485d862037SRuslan Ermilov.include <bsd.incs.mk>
24984f94a79SRuslan Ermilov.include <bsd.links.mk>
250c7b111cbSRuslan Ermilov
251e1fe3dbaSRuslan Ermilov.if ${MK_MAN} != "no"
252afeaaa84SRuslan Ermilovrealinstall: _maninstall
253badb7c1cSRuslan Ermilov.ORDER: beforeinstall _maninstall
25487829387SRuslan Ermilov.endif
25587829387SRuslan Ermilov
256afe61c15SRodney W. Grimes.endif
257afe61c15SRodney W. Grimes
258afe61c15SRodney W. Grimes.if !target(lint)
2595741a42fSMark Murraylint: ${SRCS:M*.c}
260afe61c15SRodney W. Grimes.if defined(PROG)
2615741a42fSMark Murray	${LINT} ${LINTFLAGS} ${CFLAGS:M-[DIU]*} ${.ALLSRC}
262afe61c15SRodney W. Grimes.endif
263afe61c15SRodney W. Grimes.endif
264afe61c15SRodney W. Grimes
265e1fe3dbaSRuslan Ermilov.if ${MK_MAN} != "no"
266afe61c15SRodney W. Grimes.include <bsd.man.mk>
26769b87d3eSEivind Eklund.endif
26869b87d3eSEivind Eklund
2693585b293SGarrett Wollman.include <bsd.dep.mk>
270987afe2aSBruce Evans
27188505e11SRuslan Ermilov.if defined(PROG) && !exists(${.OBJDIR}/${DEPENDFILE})
272589d9341SBruce Evans${OBJS}: ${SRCS:M*.h}
273987afe2aSBruce Evans.endif
274987afe2aSBruce Evans
275cd9a2f5cSJordan K. Hubbard.include <bsd.obj.mk>
276d510ecb4SKris Kennaway
277d510ecb4SKris Kennaway.include <bsd.sys.mk>
27857e3ff64SPaul Richards
27957e3ff64SPaul Richards.if defined(PORTNAME)
28057e3ff64SPaul Richards.include <bsd.pkg.mk>
28157e3ff64SPaul Richards.endif
282