13585b293SGarrett Wollman# from: @(#)bsd.prog.mk 5.26 (Berkeley) 6/25/91 27f3dea24SPeter Wemm# $FreeBSD$ 3afe61c15SRodney W. Grimes 42bdaf7e8SRuslan Ermilov.include <bsd.init.mk> 5*bd871f14SWarner 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 3242f8c5b5SEd Maste.if defined(PROG) && target(${PROG}) 3342f8c5b5SEd MasteMK_DEBUG_FILES= no 3442f8c5b5SEd Maste.elif !empty(LDFLAGS:M-Wl,*--oformat,*) || !empty(LDFLAGS:M-static) 3542f8c5b5SEd MasteMK_DEBUG_FILES= no 3642f8c5b5SEd Maste.endif 3742f8c5b5SEd Maste 3841f89315SRuslan Ermilov.if defined(CRUNCH_CFLAGS) 393c9b8563SGordon TetlowCFLAGS+=${CRUNCH_CFLAGS} 4042f8c5b5SEd Maste.else 4142f8c5b5SEd Maste.if ${MK_DEBUG_FILES} != "no" && empty(DEBUG_FLAGS:M-g) && \ 4242f8c5b5SEd Maste empty(DEBUG_FLAGS:M-gdwarf-*) 4342f8c5b5SEd MasteCFLAGS+= -g 4442f8c5b5SEd MasteCTFFLAGS+= -g 4542f8c5b5SEd Maste.endif 4641f89315SRuslan Ermilov.endif 47afe61c15SRodney W. Grimes 48e82b0b99SJordan K. Hubbard.if !defined(DEBUG_FLAGS) 49afe61c15SRodney W. GrimesSTRIP?= -s 50e82b0b99SJordan K. Hubbard.endif 51afe61c15SRodney W. Grimes 5283c7ade9SRuslan Ermilov.if defined(NO_SHARED) && (${NO_SHARED} != "no" && ${NO_SHARED} != "NO") 533585b293SGarrett WollmanLDFLAGS+= -static 543585b293SGarrett Wollman.endif 55afe61c15SRodney W. Grimes 562442cc58SDag-Erling Smørgrav.if defined(USEPRIVATELIB) 572442cc58SDag-Erling SmørgravLDFLAGS+= -L${_SHLIBDIRPREFIX}${LIBPRIVATEDIR} -rpath ${LIBPRIVATEDIR} 582442cc58SDag-Erling Smørgrav.endif 592442cc58SDag-Erling Smørgrav 6042f8c5b5SEd Maste.if ${MK_DEBUG_FILES} != "no" 6142f8c5b5SEd MastePROG_FULL=${PROG}.full 6242f8c5b5SEd Maste# Use ${DEBUGDIR} for base system debug files, else .debug subdirectory 6342f8c5b5SEd Maste.if defined(BINDIR) && (\ 6442f8c5b5SEd Maste ${BINDIR} == "/bin" ||\ 6542f8c5b5SEd Maste ${BINDIR} == "/libexec" ||\ 6642f8c5b5SEd Maste ${BINDIR} == "/sbin" ||\ 6742f8c5b5SEd Maste ${BINDIR:C%/usr/(bin|bsdinstall|games|libexec|lpr|sendmail|sm.bin|sbin)(/.*)?%/usr/bin%} == "/usr/bin"\ 6842f8c5b5SEd Maste ) 6942f8c5b5SEd MasteDEBUGFILEDIR= ${DEBUGDIR}${BINDIR} 7042f8c5b5SEd Maste.else 7142f8c5b5SEd MasteDEBUGFILEDIR?= ${BINDIR}/.debug 7242f8c5b5SEd MasteDEBUGMKDIR= 7342f8c5b5SEd Maste.endif 7442f8c5b5SEd Maste.else 7542f8c5b5SEd MastePROG_FULL= ${PROG} 7647bf8a5cSRuslan Ermilov.endif 7747bf8a5cSRuslan Ermilov 78afe61c15SRodney W. Grimes.if defined(PROG) 79a0dc5970SEd MastePROGNAME?= ${PROG} 8042f8c5b5SEd Maste 81afe61c15SRodney W. Grimes.if defined(SRCS) 82afe61c15SRodney W. Grimes 833585b293SGarrett WollmanOBJS+= ${SRCS:N*.h:R:S/$/.o/g} 84afe61c15SRodney W. Grimes 85c2c48445SRui Paulo.if target(beforelinking) 86593c0b49SMark Johnstonbeforelinking: ${OBJS} 8742f8c5b5SEd Maste${PROG_FULL}: beforelinking 88c2c48445SRui Paulo.endif 8942f8c5b5SEd Maste${PROG_FULL}: ${OBJS} 905d68012aSRuslan Ermilov.if defined(PROG_CXX) 915d68012aSRuslan Ermilov ${CXX} ${CXXFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD} 925d68012aSRuslan Ermilov.else 935d68012aSRuslan Ermilov ${CC} ${CFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD} 945d68012aSRuslan Ermilov.endif 9583cb5baeSMax Khon.if ${MK_CTF} != "no" 96cd49c2e8SMax Khon ${CTFMERGE} ${CTFFLAGS} -o ${.TARGET} ${OBJS} 97cd49c2e8SMax Khon.endif 985d68012aSRuslan Ermilov 9984aac273SHartmut Brandt.else # !defined(SRCS) 100afe61c15SRodney W. Grimes 1015d68012aSRuslan Ermilov.if !target(${PROG}) 10247bf8a5cSRuslan Ermilov.if defined(PROG_CXX) 10347bf8a5cSRuslan ErmilovSRCS= ${PROG}.cc 10447bf8a5cSRuslan Ermilov.else 105afe61c15SRodney W. GrimesSRCS= ${PROG}.c 10647bf8a5cSRuslan Ermilov.endif 107afe61c15SRodney W. Grimes 108a4c39c7aSBruce Evans# Always make an intermediate object file because: 109a4c39c7aSBruce Evans# - it saves time rebuilding when only the library has changed 110a4c39c7aSBruce Evans# - the name of the object gets put into the executable symbol table instead of 111a4c39c7aSBruce Evans# the name of a variable temporary object. 112a4c39c7aSBruce Evans# - it's useful to keep objects around for crunching. 1137f7fc25bSMark JohnstonOBJS+= ${PROG}.o 114f5c75051SEivind Eklund 115c2c48445SRui Paulo.if target(beforelinking) 116593c0b49SMark Johnstonbeforelinking: ${OBJS} 11742f8c5b5SEd Maste${PROG_FULL}: beforelinking 118c2c48445SRui Paulo.endif 11942f8c5b5SEd Maste${PROG_FULL}: ${OBJS} 120f8ba1555SRuslan Ermilov.if defined(PROG_CXX) 121f8ba1555SRuslan Ermilov ${CXX} ${CXXFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD} 122f8ba1555SRuslan Ermilov.else 123de0d6977SRuslan Ermilov ${CC} ${CFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD} 124afe61c15SRodney W. Grimes.endif 12583cb5baeSMax Khon.if ${MK_CTF} != "no" 126cd49c2e8SMax Khon ${CTFMERGE} ${CTFFLAGS} -o ${.TARGET} ${OBJS} 127cd49c2e8SMax Khon.endif 12842f8c5b5SEd Maste.endif # !target(${PROG}) 129f5c75051SEivind Eklund 1300d947ed1SEd Maste.endif # !defined(SRCS) 131afe61c15SRodney W. Grimes 13242f8c5b5SEd Maste.if ${MK_DEBUG_FILES} != "no" 13342f8c5b5SEd Maste${PROG}: ${PROG_FULL} ${PROGNAME}.debug 13442f8c5b5SEd Maste ${OBJCOPY} --strip-debug --add-gnu-debuglink=${PROGNAME}.debug \ 13542f8c5b5SEd Maste ${PROG_FULL} ${.TARGET} 13642f8c5b5SEd Maste 13742f8c5b5SEd Maste${PROGNAME}.debug: ${PROG_FULL} 13842f8c5b5SEd Maste ${OBJCOPY} --only-keep-debug ${PROG_FULL} ${.TARGET} 13942f8c5b5SEd Maste.endif 14042f8c5b5SEd Maste 141e1fe3dbaSRuslan Ermilov.if ${MK_MAN} != "no" && !defined(MAN) && \ 142862d3deaSRuslan Ermilov !defined(MAN1) && !defined(MAN2) && !defined(MAN3) && \ 143afe61c15SRodney W. Grimes !defined(MAN4) && !defined(MAN5) && !defined(MAN6) && \ 1448b4f1f91SBrooks Davis !defined(MAN7) && !defined(MAN8) && !defined(MAN9) 14519ea15a1SRuslan ErmilovMAN= ${PROG}.1 14619ea15a1SRuslan ErmilovMAN1= ${MAN} 147afe61c15SRodney W. Grimes.endif 1480d947ed1SEd Maste.endif # defined(PROG) 149afe61c15SRodney W. Grimes 150af2dc868SRuslan Ermilovall: objwarn ${PROG} ${SCRIPTS} 151e1fe3dbaSRuslan Ermilov.if ${MK_MAN} != "no" 152afeaaa84SRuslan Ermilovall: _manpages 153862d3deaSRuslan Ermilov.endif 154afe61c15SRodney W. Grimes 15541f89315SRuslan Ermilov.if defined(PROG) 15641f89315SRuslan ErmilovCLEANFILES+= ${PROG} 15742f8c5b5SEd Maste.if ${MK_DEBUG_FILES} != "no" 15842f8c5b5SEd MasteCLEANFILES+= ${PROG_FULL} ${PROGNAME}.debug 15942f8c5b5SEd Maste.endif 16041f89315SRuslan Ermilov.endif 16141f89315SRuslan Ermilov 16241f89315SRuslan Ermilov.if defined(OBJS) 16341f89315SRuslan ErmilovCLEANFILES+= ${OBJS} 16441f89315SRuslan Ermilov.endif 165afe61c15SRodney W. Grimes 16651fa76c4SRuslan Ermilov.include <bsd.libnames.mk> 16751fa76c4SRuslan Ermilov 168218a2cd2SBruce Evans.if defined(PROG) 169663e9677SBruce Evans_EXTRADEPEND: 17051fa76c4SRuslan Ermilov.if defined(LDFLAGS) && !empty(LDFLAGS:M-nostdlib) 17151fa76c4SRuslan Ermilov.if defined(DPADD) && !empty(DPADD) 17251fa76c4SRuslan Ermilov echo ${PROG}: ${DPADD} >> ${DEPENDFILE} 17351fa76c4SRuslan Ermilov.endif 17451fa76c4SRuslan Ermilov.else 1756e19760bSBruce Evans echo ${PROG}: ${LIBC} ${DPADD} >> ${DEPENDFILE} 176756950a1SDimitry Andric.if defined(PROG_CXX) && !defined(EARLY_BUILD) 17763e4d6f7SWarner Losh.if ${COMPILER_TYPE} == "clang" && empty(CXXFLAGS:M-stdlib=libstdc++) 178d515c63dSDimitry Andric echo ${PROG}: ${LIBCPLUSPLUS} >> ${DEPENDFILE} 179d515c63dSDimitry Andric.else 180f8ba1555SRuslan Ermilov echo ${PROG}: ${LIBSTDCPLUSPLUS} >> ${DEPENDFILE} 181f8ba1555SRuslan Ermilov.endif 1828c05a446SPeter Wemm.endif 18351fa76c4SRuslan Ermilov.endif 184d515c63dSDimitry Andric.endif 185663e9677SBruce Evans 186afe61c15SRodney W. Grimes.if !target(install) 187afe61c15SRodney W. Grimes 188212acbefSRuslan Ermilov.if defined(PRECIOUSPROG) 18900fbd407SRuslan Ermilov.if !defined(NO_FSCHG) 190dee651ebSRuslan ErmilovINSTALLFLAGS+= -fschg 191dee651ebSRuslan Ermilov.endif 192212acbefSRuslan ErmilovINSTALLFLAGS+= -S 193212acbefSRuslan Ermilov.endif 194dee651ebSRuslan Ermilov 195e902c1bbSTim Vanderhoek_INSTALLFLAGS:= ${INSTALLFLAGS} 196e902c1bbSTim Vanderhoek.for ie in ${INSTALLFLAGS_EDIT} 197e902c1bbSTim Vanderhoek_INSTALLFLAGS:= ${_INSTALLFLAGS${ie}} 198e902c1bbSTim Vanderhoek.endfor 199e902c1bbSTim Vanderhoek 20051fa76c4SRuslan Ermilov.if !target(realinstall) && !defined(INTERNALPROG) 20187829387SRuslan Ermilovrealinstall: _proginstall 202badb7c1cSRuslan Ermilov.ORDER: beforeinstall _proginstall 20387829387SRuslan Ermilov_proginstall: 204afe61c15SRodney W. Grimes.if defined(PROG) 205d2893b16SRuslan Ermilov ${INSTALL} ${STRIP} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \ 20695f8c826SRuslan Ermilov ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${BINDIR}/${PROGNAME} 20742f8c5b5SEd Maste.if ${MK_DEBUG_FILES} != "no" 20842f8c5b5SEd Maste.if defined(DEBUGMKDIR) 20942f8c5b5SEd Maste ${INSTALL} -T debug -d ${DESTDIR}${DEBUGFILEDIR} 21042f8c5b5SEd Maste.endif 21142f8c5b5SEd Maste ${INSTALL} -T debug -o ${BINOWN} -g ${BINGRP} -m ${DEBUGMODE} \ 21242f8c5b5SEd Maste ${PROGNAME}.debug ${DESTDIR}${DEBUGFILEDIR}/${PROGNAME}.debug 21342f8c5b5SEd Maste.endif 21495f8c826SRuslan Ermilov.endif 21584aac273SHartmut Brandt.endif # !target(realinstall) 216afe61c15SRodney W. Grimes 217f7ee8cfeSRuslan Ermilov.if defined(SCRIPTS) && !empty(SCRIPTS) 218f7ee8cfeSRuslan Ermilovrealinstall: _scriptsinstall 219badb7c1cSRuslan Ermilov.ORDER: beforeinstall _scriptsinstall 220f7ee8cfeSRuslan Ermilov 221f7ee8cfeSRuslan ErmilovSCRIPTSDIR?= ${BINDIR} 222f7ee8cfeSRuslan ErmilovSCRIPTSOWN?= ${BINOWN} 223f7ee8cfeSRuslan ErmilovSCRIPTSGRP?= ${BINGRP} 224f7ee8cfeSRuslan ErmilovSCRIPTSMODE?= ${BINMODE} 225f7ee8cfeSRuslan Ermilov 226f7ee8cfeSRuslan Ermilov.for script in ${SCRIPTS} 227f7ee8cfeSRuslan Ermilov.if defined(SCRIPTSNAME) 228f7ee8cfeSRuslan ErmilovSCRIPTSNAME_${script:T}?= ${SCRIPTSNAME} 229f7ee8cfeSRuslan Ermilov.else 230f7ee8cfeSRuslan ErmilovSCRIPTSNAME_${script:T}?= ${script:T:R} 231f7ee8cfeSRuslan Ermilov.endif 232f7ee8cfeSRuslan ErmilovSCRIPTSDIR_${script:T}?= ${SCRIPTSDIR} 233f7ee8cfeSRuslan ErmilovSCRIPTSOWN_${script:T}?= ${SCRIPTSOWN} 234f7ee8cfeSRuslan ErmilovSCRIPTSGRP_${script:T}?= ${SCRIPTSGRP} 235f7ee8cfeSRuslan ErmilovSCRIPTSMODE_${script:T}?= ${SCRIPTSMODE} 236a7aaf57eSRuslan Ermilov_scriptsinstall: _SCRIPTSINS_${script:T} 237a7aaf57eSRuslan Ermilov_SCRIPTSINS_${script:T}: ${script} 238d2893b16SRuslan Ermilov ${INSTALL} -o ${SCRIPTSOWN_${.ALLSRC:T}} \ 239f7ee8cfeSRuslan Ermilov -g ${SCRIPTSGRP_${.ALLSRC:T}} -m ${SCRIPTSMODE_${.ALLSRC:T}} \ 2404367bda6SRuslan Ermilov ${.ALLSRC} \ 241f7ee8cfeSRuslan Ermilov ${DESTDIR}${SCRIPTSDIR_${.ALLSRC:T}}/${SCRIPTSNAME_${.ALLSRC:T}} 242f7ee8cfeSRuslan Ermilov.endfor 243f7ee8cfeSRuslan Ermilov.endif 244f7ee8cfeSRuslan Ermilov 2458479adc1SRuslan ErmilovNLSNAME?= ${PROG} 2468479adc1SRuslan Ermilov.include <bsd.nls.mk> 2478479adc1SRuslan Ermilov 248af2dc868SRuslan Ermilov.include <bsd.files.mk> 2495d862037SRuslan Ermilov.include <bsd.incs.mk> 25084f94a79SRuslan Ermilov.include <bsd.links.mk> 251c7b111cbSRuslan Ermilov 252e1fe3dbaSRuslan Ermilov.if ${MK_MAN} != "no" 253afeaaa84SRuslan Ermilovrealinstall: _maninstall 254badb7c1cSRuslan Ermilov.ORDER: beforeinstall _maninstall 25587829387SRuslan Ermilov.endif 25687829387SRuslan Ermilov 257afe61c15SRodney W. Grimes.endif 258afe61c15SRodney W. Grimes 259afe61c15SRodney W. Grimes.if !target(lint) 2605741a42fSMark Murraylint: ${SRCS:M*.c} 261afe61c15SRodney W. Grimes.if defined(PROG) 2625741a42fSMark Murray ${LINT} ${LINTFLAGS} ${CFLAGS:M-[DIU]*} ${.ALLSRC} 263afe61c15SRodney W. Grimes.endif 264afe61c15SRodney W. Grimes.endif 265afe61c15SRodney W. Grimes 266e1fe3dbaSRuslan Ermilov.if ${MK_MAN} != "no" 267afe61c15SRodney W. Grimes.include <bsd.man.mk> 26869b87d3eSEivind Eklund.endif 26969b87d3eSEivind Eklund 2703585b293SGarrett Wollman.include <bsd.dep.mk> 271987afe2aSBruce Evans 27288505e11SRuslan Ermilov.if defined(PROG) && !exists(${.OBJDIR}/${DEPENDFILE}) 273589d9341SBruce Evans${OBJS}: ${SRCS:M*.h} 274987afe2aSBruce Evans.endif 275987afe2aSBruce Evans 276cd9a2f5cSJordan K. Hubbard.include <bsd.obj.mk> 277d510ecb4SKris Kennaway 278d510ecb4SKris Kennaway.include <bsd.sys.mk> 27957e3ff64SPaul Richards 28057e3ff64SPaul Richards.if defined(PORTNAME) 28157e3ff64SPaul Richards.include <bsd.pkg.mk> 28257e3ff64SPaul Richards.endif 283