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 7e4195e2eSJonathan Anderson.SUFFIXES: .out .o .bc .c .cc .cpp .cxx .C .m .y .l .ll .ln .s .S .asm 8afe61c15SRodney W. Grimes 948aea4daSRuslan Ermilov# XXX The use of COPTS in modern makefiles is discouraged. 1041f89315SRuslan Ermilov.if defined(COPTS) 119b8d26fdSBryan Drewery.warning ${.CURDIR}: COPTS should be CFLAGS. 1241f89315SRuslan ErmilovCFLAGS+=${COPTS} 1341f89315SRuslan Ermilov.endif 1441f89315SRuslan Ermilov 154df1f59eSWarner Losh.if ${MK_ASSERT_DEBUG} == "no" 164df1f59eSWarner LoshCFLAGS+= -DNDEBUG 17e2e1ab1cSDavid E. O'BrienNO_WERROR= 184df1f59eSWarner Losh.endif 194df1f59eSWarner Losh 2041f89315SRuslan Ermilov.if defined(DEBUG_FLAGS) 2141f89315SRuslan ErmilovCFLAGS+=${DEBUG_FLAGS} 228eba8cd8SMarcel MoolenaarCXXFLAGS+=${DEBUG_FLAGS} 23770ac3b2SJohn Birrell 2483cb5baeSMax Khon.if ${MK_CTF} != "no" && ${DEBUG_FLAGS:M-g} != "" 25770ac3b2SJohn BirrellCTFFLAGS+= -g 26770ac3b2SJohn Birrell.endif 2741f89315SRuslan Ermilov.endif 2841f89315SRuslan Ermilov 2942f8c5b5SEd Maste.if defined(PROG_CXX) 3042f8c5b5SEd MastePROG= ${PROG_CXX} 3142f8c5b5SEd Maste.endif 3242f8c5b5SEd Maste 336e521732SEd Maste.if !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-*) 42*de6feefdSJohn BaldwinCFLAGS+= ${DEBUG_FILES_CFLAGS} 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 51dc6d22c9SBaptiste Daroussin.if defined(NO_ROOT) 52dc6d22c9SBaptiste Daroussin.if !defined(TAGS) || ! ${TAGS:Mpackage=*} 53dc6d22c9SBaptiste DaroussinTAGS+= package=${PACKAGE:Uruntime} 54dc6d22c9SBaptiste Daroussin.endif 55dc6d22c9SBaptiste DaroussinTAG_ARGS= -T ${TAGS:[*]:S/ /,/g} 56dc6d22c9SBaptiste Daroussin.endif 57dc6d22c9SBaptiste Daroussin 5883c7ade9SRuslan Ermilov.if defined(NO_SHARED) && (${NO_SHARED} != "no" && ${NO_SHARED} != "NO") 593585b293SGarrett WollmanLDFLAGS+= -static 603585b293SGarrett Wollman.endif 61afe61c15SRodney W. Grimes 6242f8c5b5SEd Maste.if ${MK_DEBUG_FILES} != "no" 6342f8c5b5SEd MastePROG_FULL=${PROG}.full 6442f8c5b5SEd Maste# Use ${DEBUGDIR} for base system debug files, else .debug subdirectory 6542f8c5b5SEd Maste.if defined(BINDIR) && (\ 6642f8c5b5SEd Maste ${BINDIR} == "/bin" ||\ 675ea4b6d5SEd Maste ${BINDIR:C%/libexec(/.*)?%/libexec%} == "/libexec" ||\ 6842f8c5b5SEd Maste ${BINDIR} == "/sbin" ||\ 69b60371f8SEd Maste ${BINDIR:C%/usr/(bin|bsdinstall|libexec|lpr|sendmail|sm.bin|sbin|tests)(/.*)?%/usr/bin%} == "/usr/bin" ||\ 70b60371f8SEd Maste ${BINDIR} == "/usr/lib" \ 7142f8c5b5SEd Maste ) 7242f8c5b5SEd MasteDEBUGFILEDIR= ${DEBUGDIR}${BINDIR} 7342f8c5b5SEd Maste.else 7442f8c5b5SEd MasteDEBUGFILEDIR?= ${BINDIR}/.debug 75a324b0f0SBryan Drewery.endif 76a324b0f0SBryan Drewery.if !exists(${DESTDIR}${DEBUGFILEDIR}) 7742f8c5b5SEd MasteDEBUGMKDIR= 7842f8c5b5SEd Maste.endif 7942f8c5b5SEd Maste.else 8042f8c5b5SEd MastePROG_FULL= ${PROG} 8147bf8a5cSRuslan Ermilov.endif 8247bf8a5cSRuslan Ermilov 83afe61c15SRodney W. Grimes.if defined(PROG) 84a0dc5970SEd MastePROGNAME?= ${PROG} 8542f8c5b5SEd Maste 86afe61c15SRodney W. Grimes.if defined(SRCS) 87afe61c15SRodney W. Grimes 883585b293SGarrett WollmanOBJS+= ${SRCS:N*.h:R:S/$/.o/g} 89afe61c15SRodney W. Grimes 90c2c48445SRui Paulo.if target(beforelinking) 91593c0b49SMark Johnstonbeforelinking: ${OBJS} 9242f8c5b5SEd Maste${PROG_FULL}: beforelinking 93c2c48445SRui Paulo.endif 945852ae2dSBryan Drewery${PROG_FULL}: ${OBJS} 955d68012aSRuslan Ermilov.if defined(PROG_CXX) 969160419cSBryan Drewery ${CXX:N${CCACHE_BIN}} ${CXXFLAGS:N-M*} ${LDFLAGS} -o ${.TARGET} \ 979160419cSBryan Drewery ${OBJS} ${LDADD} 985d68012aSRuslan Ermilov.else 999160419cSBryan Drewery ${CC:N${CCACHE_BIN}} ${CFLAGS:N-M*} ${LDFLAGS} -o ${.TARGET} ${OBJS} \ 1009160419cSBryan Drewery ${LDADD} 1015d68012aSRuslan Ermilov.endif 10283cb5baeSMax Khon.if ${MK_CTF} != "no" 103cd49c2e8SMax Khon ${CTFMERGE} ${CTFFLAGS} -o ${.TARGET} ${OBJS} 104cd49c2e8SMax Khon.endif 1055d68012aSRuslan Ermilov 10684aac273SHartmut Brandt.else # !defined(SRCS) 107afe61c15SRodney W. Grimes 1085d68012aSRuslan Ermilov.if !target(${PROG}) 10947bf8a5cSRuslan Ermilov.if defined(PROG_CXX) 11047bf8a5cSRuslan ErmilovSRCS= ${PROG}.cc 11147bf8a5cSRuslan Ermilov.else 112afe61c15SRodney W. GrimesSRCS= ${PROG}.c 11347bf8a5cSRuslan Ermilov.endif 114afe61c15SRodney W. Grimes 115a4c39c7aSBruce Evans# Always make an intermediate object file because: 116a4c39c7aSBruce Evans# - it saves time rebuilding when only the library has changed 117a4c39c7aSBruce Evans# - the name of the object gets put into the executable symbol table instead of 118a4c39c7aSBruce Evans# the name of a variable temporary object. 119a4c39c7aSBruce Evans# - it's useful to keep objects around for crunching. 1207f7fc25bSMark JohnstonOBJS+= ${PROG}.o 121f5c75051SEivind Eklund 122c2c48445SRui Paulo.if target(beforelinking) 123593c0b49SMark Johnstonbeforelinking: ${OBJS} 12442f8c5b5SEd Maste${PROG_FULL}: beforelinking 125c2c48445SRui Paulo.endif 1265852ae2dSBryan Drewery${PROG_FULL}: ${OBJS} 127f8ba1555SRuslan Ermilov.if defined(PROG_CXX) 1289160419cSBryan Drewery ${CXX:N${CCACHE_BIN}} ${CXXFLAGS:N-M*} ${LDFLAGS} -o ${.TARGET} \ 1299160419cSBryan Drewery ${OBJS} ${LDADD} 130f8ba1555SRuslan Ermilov.else 1319160419cSBryan Drewery ${CC:N${CCACHE_BIN}} ${CFLAGS:N-M*} ${LDFLAGS} -o ${.TARGET} ${OBJS} \ 1329160419cSBryan Drewery ${LDADD} 133afe61c15SRodney W. Grimes.endif 13483cb5baeSMax Khon.if ${MK_CTF} != "no" 135cd49c2e8SMax Khon ${CTFMERGE} ${CTFFLAGS} -o ${.TARGET} ${OBJS} 136cd49c2e8SMax Khon.endif 13742f8c5b5SEd Maste.endif # !target(${PROG}) 138f5c75051SEivind Eklund 1390d947ed1SEd Maste.endif # !defined(SRCS) 140afe61c15SRodney W. Grimes 14142f8c5b5SEd Maste.if ${MK_DEBUG_FILES} != "no" 1425852ae2dSBryan Drewery${PROG}: ${PROG_FULL} ${PROGNAME}.debug 14342f8c5b5SEd Maste ${OBJCOPY} --strip-debug --add-gnu-debuglink=${PROGNAME}.debug \ 14442f8c5b5SEd Maste ${PROG_FULL} ${.TARGET} 14542f8c5b5SEd Maste 1465852ae2dSBryan Drewery${PROGNAME}.debug: ${PROG_FULL} 14742f8c5b5SEd Maste ${OBJCOPY} --only-keep-debug ${PROG_FULL} ${.TARGET} 14842f8c5b5SEd Maste.endif 14942f8c5b5SEd Maste 150e4195e2eSJonathan Anderson.if defined(LLVM_LINK) 151e4195e2eSJonathan Anderson# LLVM bitcode / textual IR representations of the program 152e4195e2eSJonathan AndersonBCOBJS= ${OBJS:.o=.bco} 153e4195e2eSJonathan AndersonLLOBJS= ${OBJS:.o=.llo} 154e4195e2eSJonathan Anderson 155e4195e2eSJonathan Anderson${PROG_FULL}.bc: ${BCOBJS} 156e4195e2eSJonathan Anderson ${LLVM_LINK} -o ${.TARGET} ${BCOBJS} 157e4195e2eSJonathan Anderson 158e4195e2eSJonathan Anderson${PROG_FULL}.ll: ${LLOBJS} 159e4195e2eSJonathan Anderson ${LLVM_LINK} -S -o ${.TARGET} ${LLOBJS} 160e4195e2eSJonathan Anderson 161e4195e2eSJonathan Anderson.endif # defined(LLVM_LINK) 162e4195e2eSJonathan Anderson 163e1fe3dbaSRuslan Ermilov.if ${MK_MAN} != "no" && !defined(MAN) && \ 164862d3deaSRuslan Ermilov !defined(MAN1) && !defined(MAN2) && !defined(MAN3) && \ 165afe61c15SRodney W. Grimes !defined(MAN4) && !defined(MAN5) && !defined(MAN6) && \ 1668b4f1f91SBrooks Davis !defined(MAN7) && !defined(MAN8) && !defined(MAN9) 16719ea15a1SRuslan ErmilovMAN= ${PROG}.1 16819ea15a1SRuslan ErmilovMAN1= ${MAN} 169afe61c15SRodney W. Grimes.endif 1700d947ed1SEd Maste.endif # defined(PROG) 171afe61c15SRodney W. Grimes 1727750ad47SMarcel Moolenaar.if defined(_SKIP_BUILD) 1737750ad47SMarcel Moolenaarall: 1747750ad47SMarcel Moolenaar.else 1751bd4272fSBryan Dreweryall: ${PROG} ${SCRIPTS} 176e1fe3dbaSRuslan Ermilov.if ${MK_MAN} != "no" 177f1702f87SBryan Dreweryall: all-man 178862d3deaSRuslan Ermilov.endif 1797750ad47SMarcel Moolenaar.endif 180afe61c15SRodney W. Grimes 18141f89315SRuslan Ermilov.if defined(PROG) 182e4195e2eSJonathan AndersonCLEANFILES+= ${PROG} ${PROG}.bc ${PROG}.ll 18342f8c5b5SEd Maste.if ${MK_DEBUG_FILES} != "no" 184e4195e2eSJonathan AndersonCLEANFILES+= ${PROG_FULL} ${PROG_FULL}.bc ${PROGNAME}.debug ${PROG_FULL}.ll 18542f8c5b5SEd Maste.endif 18641f89315SRuslan Ermilov.endif 18741f89315SRuslan Ermilov 18841f89315SRuslan Ermilov.if defined(OBJS) 189e4195e2eSJonathan AndersonCLEANFILES+= ${OBJS} ${BCOBJS} ${LLOBJS} 19041f89315SRuslan Ermilov.endif 191afe61c15SRodney W. Grimes 19251fa76c4SRuslan Ermilov.include <bsd.libnames.mk> 19351fa76c4SRuslan Ermilov 194218a2cd2SBruce Evans.if defined(PROG) 195799483e4SBryan Drewery.if !defined(NO_EXTRADEPEND) 196663e9677SBruce Evans_EXTRADEPEND: 19751fa76c4SRuslan Ermilov.if defined(LDFLAGS) && !empty(LDFLAGS:M-nostdlib) 19851fa76c4SRuslan Ermilov.if defined(DPADD) && !empty(DPADD) 19937fd8bc2SJohn Baldwin echo ${PROG_FULL}: ${DPADD} >> ${DEPENDFILE} 20051fa76c4SRuslan Ermilov.endif 20151fa76c4SRuslan Ermilov.else 20237fd8bc2SJohn Baldwin echo ${PROG_FULL}: ${LIBC} ${DPADD} >> ${DEPENDFILE} 2037273339dSWarner Losh.if defined(PROG_CXX) 20463e4d6f7SWarner Losh.if ${COMPILER_TYPE} == "clang" && empty(CXXFLAGS:M-stdlib=libstdc++) 20537fd8bc2SJohn Baldwin echo ${PROG_FULL}: ${LIBCPLUSPLUS} >> ${DEPENDFILE} 206d515c63dSDimitry Andric.else 20737fd8bc2SJohn Baldwin echo ${PROG_FULL}: ${LIBSTDCPLUSPLUS} >> ${DEPENDFILE} 208f8ba1555SRuslan Ermilov.endif 2098c05a446SPeter Wemm.endif 21051fa76c4SRuslan Ermilov.endif 211799483e4SBryan Drewery.endif # !defined(NO_EXTRADEPEND) 212d515c63dSDimitry Andric.endif 213663e9677SBruce Evans 214afe61c15SRodney W. Grimes.if !target(install) 215afe61c15SRodney W. Grimes 216212acbefSRuslan Ermilov.if defined(PRECIOUSPROG) 21700fbd407SRuslan Ermilov.if !defined(NO_FSCHG) 218dee651ebSRuslan ErmilovINSTALLFLAGS+= -fschg 219dee651ebSRuslan Ermilov.endif 220212acbefSRuslan ErmilovINSTALLFLAGS+= -S 221212acbefSRuslan Ermilov.endif 222dee651ebSRuslan Ermilov 223e902c1bbSTim Vanderhoek_INSTALLFLAGS:= ${INSTALLFLAGS} 224e902c1bbSTim Vanderhoek.for ie in ${INSTALLFLAGS_EDIT} 225e902c1bbSTim Vanderhoek_INSTALLFLAGS:= ${_INSTALLFLAGS${ie}} 226e902c1bbSTim Vanderhoek.endfor 227e902c1bbSTim Vanderhoek 22851fa76c4SRuslan Ermilov.if !target(realinstall) && !defined(INTERNALPROG) 22987829387SRuslan Ermilovrealinstall: _proginstall 230badb7c1cSRuslan Ermilov.ORDER: beforeinstall _proginstall 23187829387SRuslan Ermilov_proginstall: 232afe61c15SRodney W. Grimes.if defined(PROG) 233dc6d22c9SBaptiste Daroussin ${INSTALL} ${TAG_ARGS} ${STRIP} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \ 23495f8c826SRuslan Ermilov ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${BINDIR}/${PROGNAME} 23542f8c5b5SEd Maste.if ${MK_DEBUG_FILES} != "no" 23642f8c5b5SEd Maste.if defined(DEBUGMKDIR) 237b626f5a7SGlen Barber ${INSTALL} ${TAG_ARGS:D${TAG_ARGS},debug} -d ${DESTDIR}${DEBUGFILEDIR}/ 23842f8c5b5SEd Maste.endif 239dc6d22c9SBaptiste Daroussin ${INSTALL} ${TAG_ARGS:D${TAG_ARGS},debug} -o ${BINOWN} -g ${BINGRP} -m ${DEBUGMODE} \ 24042f8c5b5SEd Maste ${PROGNAME}.debug ${DESTDIR}${DEBUGFILEDIR}/${PROGNAME}.debug 24142f8c5b5SEd Maste.endif 24295f8c826SRuslan Ermilov.endif 24384aac273SHartmut Brandt.endif # !target(realinstall) 244afe61c15SRodney W. Grimes 245f7ee8cfeSRuslan Ermilov.if defined(SCRIPTS) && !empty(SCRIPTS) 246f7ee8cfeSRuslan Ermilovrealinstall: _scriptsinstall 247badb7c1cSRuslan Ermilov.ORDER: beforeinstall _scriptsinstall 248f7ee8cfeSRuslan Ermilov 249f7ee8cfeSRuslan ErmilovSCRIPTSDIR?= ${BINDIR} 250f7ee8cfeSRuslan ErmilovSCRIPTSOWN?= ${BINOWN} 251f7ee8cfeSRuslan ErmilovSCRIPTSGRP?= ${BINGRP} 252f7ee8cfeSRuslan ErmilovSCRIPTSMODE?= ${BINMODE} 253f7ee8cfeSRuslan Ermilov 254116d4508SSimon J. GerratySTAGE_AS_SETS+= scripts 255116d4508SSimon J. Gerratystage_as.scripts: ${SCRIPTS} 256116d4508SSimon J. GerratyFLAGS.stage_as.scripts= -m ${SCRIPTSMODE} 257116d4508SSimon J. GerratySTAGE_FILES_DIR.scripts= ${STAGE_OBJTOP} 258f7ee8cfeSRuslan Ermilov.for script in ${SCRIPTS} 259f7ee8cfeSRuslan Ermilov.if defined(SCRIPTSNAME) 260f7ee8cfeSRuslan ErmilovSCRIPTSNAME_${script:T}?= ${SCRIPTSNAME} 261f7ee8cfeSRuslan Ermilov.else 262f7ee8cfeSRuslan ErmilovSCRIPTSNAME_${script:T}?= ${script:T:R} 263f7ee8cfeSRuslan Ermilov.endif 264f7ee8cfeSRuslan ErmilovSCRIPTSDIR_${script:T}?= ${SCRIPTSDIR} 265f7ee8cfeSRuslan ErmilovSCRIPTSOWN_${script:T}?= ${SCRIPTSOWN} 266f7ee8cfeSRuslan ErmilovSCRIPTSGRP_${script:T}?= ${SCRIPTSGRP} 267f7ee8cfeSRuslan ErmilovSCRIPTSMODE_${script:T}?= ${SCRIPTSMODE} 268116d4508SSimon J. GerratySTAGE_AS_${script:T}= ${SCRIPTSDIR_${script:T}}/${SCRIPTSNAME_${script:T}} 269a7aaf57eSRuslan Ermilov_scriptsinstall: _SCRIPTSINS_${script:T} 270a7aaf57eSRuslan Ermilov_SCRIPTSINS_${script:T}: ${script} 271dc6d22c9SBaptiste Daroussin ${INSTALL} ${TAG_ARGS} -o ${SCRIPTSOWN_${.ALLSRC:T}} \ 272f7ee8cfeSRuslan Ermilov -g ${SCRIPTSGRP_${.ALLSRC:T}} -m ${SCRIPTSMODE_${.ALLSRC:T}} \ 2734367bda6SRuslan Ermilov ${.ALLSRC} \ 274f7ee8cfeSRuslan Ermilov ${DESTDIR}${SCRIPTSDIR_${.ALLSRC:T}}/${SCRIPTSNAME_${.ALLSRC:T}} 275f7ee8cfeSRuslan Ermilov.endfor 276f7ee8cfeSRuslan Ermilov.endif 277f7ee8cfeSRuslan Ermilov 2788479adc1SRuslan ErmilovNLSNAME?= ${PROG} 2798479adc1SRuslan Ermilov.include <bsd.nls.mk> 2808479adc1SRuslan Ermilov 2819b4f4918SBaptiste Daroussin.include <bsd.confs.mk> 282af2dc868SRuslan Ermilov.include <bsd.files.mk> 2835d862037SRuslan Ermilov.include <bsd.incs.mk> 28484f94a79SRuslan Ermilov.include <bsd.links.mk> 285c7b111cbSRuslan Ermilov 286e1fe3dbaSRuslan Ermilov.if ${MK_MAN} != "no" 287f1702f87SBryan Dreweryrealinstall: maninstall 288f1702f87SBryan Drewery.ORDER: beforeinstall maninstall 28987829387SRuslan Ermilov.endif 29087829387SRuslan Ermilov 291abb02fa2SBryan Drewery.endif # !target(install) 292afe61c15SRodney W. Grimes 293afe61c15SRodney W. Grimes.if !target(lint) 2945741a42fSMark Murraylint: ${SRCS:M*.c} 295afe61c15SRodney W. Grimes.if defined(PROG) 2965741a42fSMark Murray ${LINT} ${LINTFLAGS} ${CFLAGS:M-[DIU]*} ${.ALLSRC} 297afe61c15SRodney W. Grimes.endif 298afe61c15SRodney W. Grimes.endif 299afe61c15SRodney W. Grimes 300e1fe3dbaSRuslan Ermilov.if ${MK_MAN} != "no" 301afe61c15SRodney W. Grimes.include <bsd.man.mk> 30269b87d3eSEivind Eklund.endif 30369b87d3eSEivind Eklund 30438f8fddfSEnji Cooper.if defined(HAS_TESTS) 30538f8fddfSEnji CooperMAKE+= MK_MAKE_CHECK_USE_SANDBOX=yes 30638f8fddfSEnji CooperSUBDIR_TARGETS+= check 30738f8fddfSEnji CooperTESTS_LD_LIBRARY_PATH+= ${.OBJDIR} 30838f8fddfSEnji CooperTESTS_PATH+= ${.OBJDIR} 30938f8fddfSEnji Cooper.endif 31038f8fddfSEnji Cooper 311d7beff08SBryan Drewery.if defined(PROG) 312d7beff08SBryan DreweryOBJS_DEPEND_GUESS+= ${SRCS:M*.h} 31388fe1f7aSBryan Drewery.endif 31488fe1f7aSBryan Drewery 31588fe1f7aSBryan Drewery.include <bsd.dep.mk> 316aae63957SBryan Drewery.include <bsd.clang-analyze.mk> 317cd9a2f5cSJordan K. Hubbard.include <bsd.obj.mk> 318d510ecb4SKris Kennaway.include <bsd.sys.mk> 319