1# from: @(#)bsd.prog.mk 5.26 (Berkeley) 6/25/91 2# $FreeBSD$ 3 4.include <bsd.init.mk> 5.include <bsd.compiler.mk> 6 7.SUFFIXES: .out .o .bc .c .cc .cpp .cxx .C .m .y .l .ll .ln .s .S .asm 8 9# XXX The use of COPTS in modern makefiles is discouraged. 10.if defined(COPTS) 11.warning ${.CURDIR}: COPTS should be CFLAGS. 12CFLAGS+=${COPTS} 13.endif 14 15.if ${MK_ASSERT_DEBUG} == "no" 16CFLAGS+= -DNDEBUG 17NO_WERROR= 18.endif 19 20.if defined(DEBUG_FLAGS) 21CFLAGS+=${DEBUG_FLAGS} 22CXXFLAGS+=${DEBUG_FLAGS} 23 24.if ${MK_CTF} != "no" && ${DEBUG_FLAGS:M-g} != "" 25CTFFLAGS+= -g 26.endif 27.endif 28 29.if defined(PROG_CXX) 30PROG= ${PROG_CXX} 31.endif 32 33.if !empty(LDFLAGS:M-Wl,*--oformat,*) || !empty(LDFLAGS:M-static) 34MK_DEBUG_FILES= no 35.endif 36 37.if defined(CRUNCH_CFLAGS) 38CFLAGS+=${CRUNCH_CFLAGS} 39.else 40.if ${MK_DEBUG_FILES} != "no" && empty(DEBUG_FLAGS:M-g) && \ 41 empty(DEBUG_FLAGS:M-gdwarf-*) 42CFLAGS+= ${DEBUG_FILES_CFLAGS} 43CTFFLAGS+= -g 44.endif 45.endif 46 47.if !defined(DEBUG_FLAGS) 48STRIP?= -s 49.endif 50 51.if defined(NO_ROOT) 52.if !defined(TAGS) || ! ${TAGS:Mpackage=*} 53TAGS+= package=${PACKAGE:Uruntime} 54.endif 55TAG_ARGS= -T ${TAGS:[*]:S/ /,/g} 56.endif 57 58.if defined(NO_SHARED) && (${NO_SHARED} != "no" && ${NO_SHARED} != "NO") 59LDFLAGS+= -static 60.endif 61 62.if ${MK_DEBUG_FILES} != "no" 63PROG_FULL=${PROG}.full 64# Use ${DEBUGDIR} for base system debug files, else .debug subdirectory 65.if defined(BINDIR) && (\ 66 ${BINDIR} == "/bin" ||\ 67 ${BINDIR:C%/libexec(/.*)?%/libexec%} == "/libexec" ||\ 68 ${BINDIR} == "/sbin" ||\ 69 ${BINDIR:C%/usr/(bin|bsdinstall|libexec|lpr|sendmail|sm.bin|sbin|tests)(/.*)?%/usr/bin%} == "/usr/bin" ||\ 70 ${BINDIR} == "/usr/lib" \ 71 ) 72DEBUGFILEDIR= ${DEBUGDIR}${BINDIR} 73.else 74DEBUGFILEDIR?= ${BINDIR}/.debug 75.endif 76.if !exists(${DESTDIR}${DEBUGFILEDIR}) 77DEBUGMKDIR= 78.endif 79.else 80PROG_FULL= ${PROG} 81.endif 82 83.if defined(PROG) 84PROGNAME?= ${PROG} 85 86.if defined(SRCS) 87 88OBJS+= ${SRCS:N*.h:${OBJS_SRCS_FILTER:ts:}:S/$/.o/g} 89 90# LLVM bitcode / textual IR representations of the program 91BCOBJS+=${SRCS:N*.[hsS]:N*.asm:${OBJS_SRCS_FILTER:ts:}:S/$/.bco/g} 92LLOBJS+=${SRCS:N*.[hsS]:N*.asm:${OBJS_SRCS_FILTER:ts:}:S/$/.llo/g} 93 94.if target(beforelinking) 95beforelinking: ${OBJS} 96${PROG_FULL}: beforelinking 97.endif 98${PROG_FULL}: ${OBJS} 99.if defined(PROG_CXX) 100 ${CXX:N${CCACHE_BIN}} ${CXXFLAGS:N-M*} ${LDFLAGS} -o ${.TARGET} \ 101 ${OBJS} ${LDADD} 102.else 103 ${CC:N${CCACHE_BIN}} ${CFLAGS:N-M*} ${LDFLAGS} -o ${.TARGET} ${OBJS} \ 104 ${LDADD} 105.endif 106.if ${MK_CTF} != "no" 107 ${CTFMERGE} ${CTFFLAGS} -o ${.TARGET} ${OBJS} 108.endif 109 110.else # !defined(SRCS) 111 112.if !target(${PROG}) 113.if defined(PROG_CXX) 114SRCS= ${PROG}.cc 115.else 116SRCS= ${PROG}.c 117.endif 118 119# Always make an intermediate object file because: 120# - it saves time rebuilding when only the library has changed 121# - the name of the object gets put into the executable symbol table instead of 122# the name of a variable temporary object. 123# - it's useful to keep objects around for crunching. 124OBJS+= ${PROG}.o 125BCOBJS+= ${PROG}.bc 126LLOBJS+= ${PROG}.ll 127CLEANFILES+= ${PROG}.o ${PROG}.bc ${PROG}.ll 128 129.if target(beforelinking) 130beforelinking: ${OBJS} 131${PROG_FULL}: beforelinking 132.endif 133${PROG_FULL}: ${OBJS} 134.if defined(PROG_CXX) 135 ${CXX:N${CCACHE_BIN}} ${CXXFLAGS:N-M*} ${LDFLAGS} -o ${.TARGET} \ 136 ${OBJS} ${LDADD} 137.else 138 ${CC:N${CCACHE_BIN}} ${CFLAGS:N-M*} ${LDFLAGS} -o ${.TARGET} ${OBJS} \ 139 ${LDADD} 140.endif 141.if ${MK_CTF} != "no" 142 ${CTFMERGE} ${CTFFLAGS} -o ${.TARGET} ${OBJS} 143.endif 144.endif # !target(${PROG}) 145 146.endif # !defined(SRCS) 147 148.if ${MK_DEBUG_FILES} != "no" 149${PROG}: ${PROG_FULL} ${PROGNAME}.debug 150 ${OBJCOPY} --strip-debug --add-gnu-debuglink=${PROGNAME}.debug \ 151 ${PROG_FULL} ${.TARGET} 152 153${PROGNAME}.debug: ${PROG_FULL} 154 ${OBJCOPY} --only-keep-debug ${PROG_FULL} ${.TARGET} 155.endif 156 157.if defined(LLVM_LINK) 158${PROG_FULL}.bc: ${BCOBJS} 159 ${LLVM_LINK} -o ${.TARGET} ${BCOBJS} 160 161${PROG_FULL}.ll: ${LLOBJS} 162 ${LLVM_LINK} -S -o ${.TARGET} ${LLOBJS} 163 164CLEANFILES+= ${PROG_FULL}.bc ${PROG_FULL}.ll 165.endif # defined(LLVM_LINK) 166 167.if ${MK_MAN} != "no" && !defined(MAN) && \ 168 !defined(MAN1) && !defined(MAN2) && !defined(MAN3) && \ 169 !defined(MAN4) && !defined(MAN5) && !defined(MAN6) && \ 170 !defined(MAN7) && !defined(MAN8) && !defined(MAN9) 171MAN= ${PROG}.1 172MAN1= ${MAN} 173.endif 174.endif # defined(PROG) 175 176.if defined(_SKIP_BUILD) 177all: 178.else 179all: ${PROG} ${SCRIPTS} 180.if ${MK_MAN} != "no" 181all: all-man 182.endif 183.endif 184 185.if defined(PROG) 186CLEANFILES+= ${PROG} ${PROG}.bc ${PROG}.ll 187.if ${MK_DEBUG_FILES} != "no" 188CLEANFILES+= ${PROG_FULL} ${PROGNAME}.debug 189.endif 190.endif 191 192.if defined(OBJS) 193CLEANFILES+= ${OBJS} ${BCOBJS} ${LLOBJS} 194.endif 195 196.include <bsd.libnames.mk> 197 198.if defined(PROG) 199.if !defined(NO_EXTRADEPEND) 200_EXTRADEPEND: 201.if defined(LDFLAGS) && !empty(LDFLAGS:M-nostdlib) 202.if defined(DPADD) && !empty(DPADD) 203 echo ${PROG_FULL}: ${DPADD} >> ${DEPENDFILE} 204.endif 205.else 206 echo ${PROG_FULL}: ${LIBC} ${DPADD} >> ${DEPENDFILE} 207.if defined(PROG_CXX) 208.if ${COMPILER_TYPE} == "clang" && empty(CXXFLAGS:M-stdlib=libstdc++) 209 echo ${PROG_FULL}: ${LIBCPLUSPLUS} >> ${DEPENDFILE} 210.else 211 echo ${PROG_FULL}: ${LIBSTDCPLUSPLUS} >> ${DEPENDFILE} 212.endif 213.endif 214.endif 215.endif # !defined(NO_EXTRADEPEND) 216.endif 217 218.if !target(install) 219 220.if defined(PRECIOUSPROG) 221.if !defined(NO_FSCHG) 222INSTALLFLAGS+= -fschg 223.endif 224INSTALLFLAGS+= -S 225.endif 226 227_INSTALLFLAGS:= ${INSTALLFLAGS} 228.for ie in ${INSTALLFLAGS_EDIT} 229_INSTALLFLAGS:= ${_INSTALLFLAGS${ie}} 230.endfor 231 232.if !target(realinstall) && !defined(INTERNALPROG) 233realinstall: _proginstall 234.ORDER: beforeinstall _proginstall 235_proginstall: 236.if defined(PROG) 237 ${INSTALL} ${TAG_ARGS} ${STRIP} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \ 238 ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${BINDIR}/${PROGNAME} 239.if ${MK_DEBUG_FILES} != "no" 240.if defined(DEBUGMKDIR) 241 ${INSTALL} ${TAG_ARGS:D${TAG_ARGS},debug} -d ${DESTDIR}${DEBUGFILEDIR}/ 242.endif 243 ${INSTALL} ${TAG_ARGS:D${TAG_ARGS},debug} -o ${BINOWN} -g ${BINGRP} -m ${DEBUGMODE} \ 244 ${PROGNAME}.debug ${DESTDIR}${DEBUGFILEDIR}/${PROGNAME}.debug 245.endif 246.endif 247.endif # !target(realinstall) 248 249.if defined(SCRIPTS) && !empty(SCRIPTS) 250realinstall: _scriptsinstall 251.ORDER: beforeinstall _scriptsinstall 252 253SCRIPTSDIR?= ${BINDIR} 254SCRIPTSOWN?= ${BINOWN} 255SCRIPTSGRP?= ${BINGRP} 256SCRIPTSMODE?= ${BINMODE} 257 258STAGE_AS_SETS+= scripts 259stage_as.scripts: ${SCRIPTS} 260FLAGS.stage_as.scripts= -m ${SCRIPTSMODE} 261STAGE_FILES_DIR.scripts= ${STAGE_OBJTOP} 262.for script in ${SCRIPTS} 263.if defined(SCRIPTSNAME) 264SCRIPTSNAME_${script:T}?= ${SCRIPTSNAME} 265.else 266SCRIPTSNAME_${script:T}?= ${script:T:R} 267.endif 268SCRIPTSDIR_${script:T}?= ${SCRIPTSDIR} 269SCRIPTSOWN_${script:T}?= ${SCRIPTSOWN} 270SCRIPTSGRP_${script:T}?= ${SCRIPTSGRP} 271SCRIPTSMODE_${script:T}?= ${SCRIPTSMODE} 272STAGE_AS_${script:T}= ${SCRIPTSDIR_${script:T}}/${SCRIPTSNAME_${script:T}} 273_scriptsinstall: _SCRIPTSINS_${script:T} 274_SCRIPTSINS_${script:T}: ${script} 275 ${INSTALL} ${TAG_ARGS} -o ${SCRIPTSOWN_${.ALLSRC:T}} \ 276 -g ${SCRIPTSGRP_${.ALLSRC:T}} -m ${SCRIPTSMODE_${.ALLSRC:T}} \ 277 ${.ALLSRC} \ 278 ${DESTDIR}${SCRIPTSDIR_${.ALLSRC:T}}/${SCRIPTSNAME_${.ALLSRC:T}} 279.endfor 280.endif 281 282NLSNAME?= ${PROG} 283.include <bsd.nls.mk> 284 285.include <bsd.confs.mk> 286.include <bsd.files.mk> 287.include <bsd.incs.mk> 288 289LINKOWN?= ${BINOWN} 290LINKGRP?= ${BINGRP} 291LINKMODE?= ${BINMODE} 292.include <bsd.links.mk> 293 294.if ${MK_MAN} != "no" 295realinstall: maninstall 296.ORDER: beforeinstall maninstall 297.endif 298 299.endif # !target(install) 300 301.if ${MK_MAN} != "no" 302.include <bsd.man.mk> 303.endif 304 305.if defined(HAS_TESTS) 306MAKE+= MK_MAKE_CHECK_USE_SANDBOX=yes 307SUBDIR_TARGETS+= check 308TESTS_LD_LIBRARY_PATH+= ${.OBJDIR} 309TESTS_PATH+= ${.OBJDIR} 310.endif 311 312.if defined(PROG) 313OBJS_DEPEND_GUESS+= ${SRCS:M*.h} 314.endif 315 316.include <bsd.dep.mk> 317.include <bsd.clang-analyze.mk> 318.include <bsd.obj.mk> 319.include <bsd.sys.mk> 320