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 23e977d70fSMark Johnston.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 542442cc58SDag-Erling Smørgrav.if defined(USEPRIVATELIB) 552442cc58SDag-Erling SmørgravLDFLAGS+= -L${_SHLIBDIRPREFIX}${LIBPRIVATEDIR} -rpath ${LIBPRIVATEDIR} 562442cc58SDag-Erling Smørgrav.endif 572442cc58SDag-Erling Smørgrav 5842f8c5b5SEd Maste.if ${MK_DEBUG_FILES} != "no" 5942f8c5b5SEd MastePROG_FULL=${PROG}.full 6042f8c5b5SEd Maste# Use ${DEBUGDIR} for base system debug files, else .debug subdirectory 6142f8c5b5SEd Maste.if defined(BINDIR) && (\ 6242f8c5b5SEd Maste ${BINDIR} == "/bin" ||\ 6342f8c5b5SEd Maste ${BINDIR} == "/libexec" ||\ 6442f8c5b5SEd Maste ${BINDIR} == "/sbin" ||\ 6511d9aa67SColin Percival ${BINDIR:C%/usr/(bin|bsdinstall|libexec|lpr|sendmail|sm.bin|sbin)(/.*)?%/usr/bin%} == "/usr/bin"\ 6642f8c5b5SEd Maste ) 6742f8c5b5SEd MasteDEBUGFILEDIR= ${DEBUGDIR}${BINDIR} 6842f8c5b5SEd Maste.else 6942f8c5b5SEd MasteDEBUGFILEDIR?= ${BINDIR}/.debug 7042f8c5b5SEd MasteDEBUGMKDIR= 7142f8c5b5SEd Maste.endif 7242f8c5b5SEd Maste.else 7342f8c5b5SEd MastePROG_FULL= ${PROG} 7447bf8a5cSRuslan Ermilov.endif 7547bf8a5cSRuslan Ermilov 76afe61c15SRodney W. Grimes.if defined(PROG) 77a0dc5970SEd MastePROGNAME?= ${PROG} 7842f8c5b5SEd Maste 79afe61c15SRodney W. Grimes.if defined(SRCS) 80afe61c15SRodney W. Grimes 813585b293SGarrett WollmanOBJS+= ${SRCS:N*.h:R:S/$/.o/g} 82afe61c15SRodney W. Grimes 83c2c48445SRui Paulo.if target(beforelinking) 84593c0b49SMark Johnstonbeforelinking: ${OBJS} 8542f8c5b5SEd Maste${PROG_FULL}: beforelinking 86c2c48445SRui Paulo.endif 8742f8c5b5SEd Maste${PROG_FULL}: ${OBJS} 885d68012aSRuslan Ermilov.if defined(PROG_CXX) 895d68012aSRuslan Ermilov ${CXX} ${CXXFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD} 905d68012aSRuslan Ermilov.else 915d68012aSRuslan Ermilov ${CC} ${CFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD} 925d68012aSRuslan Ermilov.endif 9383cb5baeSMax Khon.if ${MK_CTF} != "no" 94cd49c2e8SMax Khon ${CTFMERGE} ${CTFFLAGS} -o ${.TARGET} ${OBJS} 95cd49c2e8SMax Khon.endif 965d68012aSRuslan Ermilov 9784aac273SHartmut Brandt.else # !defined(SRCS) 98afe61c15SRodney W. Grimes 995d68012aSRuslan Ermilov.if !target(${PROG}) 10047bf8a5cSRuslan Ermilov.if defined(PROG_CXX) 10147bf8a5cSRuslan ErmilovSRCS= ${PROG}.cc 10247bf8a5cSRuslan Ermilov.else 103afe61c15SRodney W. GrimesSRCS= ${PROG}.c 10447bf8a5cSRuslan Ermilov.endif 105afe61c15SRodney W. Grimes 106a4c39c7aSBruce Evans# Always make an intermediate object file because: 107a4c39c7aSBruce Evans# - it saves time rebuilding when only the library has changed 108a4c39c7aSBruce Evans# - the name of the object gets put into the executable symbol table instead of 109a4c39c7aSBruce Evans# the name of a variable temporary object. 110a4c39c7aSBruce Evans# - it's useful to keep objects around for crunching. 1117f7fc25bSMark JohnstonOBJS+= ${PROG}.o 112f5c75051SEivind Eklund 113c2c48445SRui Paulo.if target(beforelinking) 114593c0b49SMark Johnstonbeforelinking: ${OBJS} 11542f8c5b5SEd Maste${PROG_FULL}: beforelinking 116c2c48445SRui Paulo.endif 11742f8c5b5SEd Maste${PROG_FULL}: ${OBJS} 118f8ba1555SRuslan Ermilov.if defined(PROG_CXX) 119f8ba1555SRuslan Ermilov ${CXX} ${CXXFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD} 120f8ba1555SRuslan Ermilov.else 121de0d6977SRuslan Ermilov ${CC} ${CFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${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 1489c851217SRui Pauloall: beforebuild .WAIT ${PROG} ${SCRIPTS} 1499c851217SRui Paulobeforebuild: objwarn 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) 171*37fd8bc2SJohn Baldwin echo ${PROG_FULL}: ${DPADD} >> ${DEPENDFILE} 17251fa76c4SRuslan Ermilov.endif 17351fa76c4SRuslan Ermilov.else 174*37fd8bc2SJohn Baldwin echo ${PROG_FULL}: ${LIBC} ${DPADD} >> ${DEPENDFILE} 1757273339dSWarner Losh.if defined(PROG_CXX) 17663e4d6f7SWarner Losh.if ${COMPILER_TYPE} == "clang" && empty(CXXFLAGS:M-stdlib=libstdc++) 177*37fd8bc2SJohn Baldwin echo ${PROG_FULL}: ${LIBCPLUSPLUS} >> ${DEPENDFILE} 178d515c63dSDimitry Andric.else 179*37fd8bc2SJohn Baldwin echo ${PROG_FULL}: ${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> 278