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+= -g 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:R:S/$/.o/g} 89 90.if target(beforelinking) 91beforelinking: ${OBJS} 92${PROG_FULL}: beforelinking 93.endif 94${PROG_FULL}: ${OBJS} 95.if defined(PROG_CXX) 96 ${CXX:N${CCACHE_BIN}} ${CXXFLAGS:N-M*} ${LDFLAGS} -o ${.TARGET} \ 97 ${OBJS} ${LDADD} 98.else 99 ${CC:N${CCACHE_BIN}} ${CFLAGS:N-M*} ${LDFLAGS} -o ${.TARGET} ${OBJS} \ 100 ${LDADD} 101.endif 102.if ${MK_CTF} != "no" 103 ${CTFMERGE} ${CTFFLAGS} -o ${.TARGET} ${OBJS} 104.endif 105 106.else # !defined(SRCS) 107 108.if !target(${PROG}) 109.if defined(PROG_CXX) 110SRCS= ${PROG}.cc 111.else 112SRCS= ${PROG}.c 113.endif 114 115# Always make an intermediate object file because: 116# - it saves time rebuilding when only the library has changed 117# - the name of the object gets put into the executable symbol table instead of 118# the name of a variable temporary object. 119# - it's useful to keep objects around for crunching. 120OBJS+= ${PROG}.o 121 122.if target(beforelinking) 123beforelinking: ${OBJS} 124${PROG_FULL}: beforelinking 125.endif 126${PROG_FULL}: ${OBJS} 127.if defined(PROG_CXX) 128 ${CXX:N${CCACHE_BIN}} ${CXXFLAGS:N-M*} ${LDFLAGS} -o ${.TARGET} \ 129 ${OBJS} ${LDADD} 130.else 131 ${CC:N${CCACHE_BIN}} ${CFLAGS:N-M*} ${LDFLAGS} -o ${.TARGET} ${OBJS} \ 132 ${LDADD} 133.endif 134.if ${MK_CTF} != "no" 135 ${CTFMERGE} ${CTFFLAGS} -o ${.TARGET} ${OBJS} 136.endif 137.endif # !target(${PROG}) 138 139.endif # !defined(SRCS) 140 141.if ${MK_DEBUG_FILES} != "no" 142${PROG}: ${PROG_FULL} ${PROGNAME}.debug 143 ${OBJCOPY} --strip-debug --add-gnu-debuglink=${PROGNAME}.debug \ 144 ${PROG_FULL} ${.TARGET} 145 146${PROGNAME}.debug: ${PROG_FULL} 147 ${OBJCOPY} --only-keep-debug ${PROG_FULL} ${.TARGET} 148.endif 149 150.if defined(LLVM_LINK) 151# LLVM bitcode / textual IR representations of the program 152BCOBJS= ${OBJS:.o=.bco} 153LLOBJS= ${OBJS:.o=.llo} 154 155${PROG_FULL}.bc: ${BCOBJS} 156 ${LLVM_LINK} -o ${.TARGET} ${BCOBJS} 157 158${PROG_FULL}.ll: ${LLOBJS} 159 ${LLVM_LINK} -S -o ${.TARGET} ${LLOBJS} 160 161.endif # defined(LLVM_LINK) 162 163.if ${MK_MAN} != "no" && !defined(MAN) && \ 164 !defined(MAN1) && !defined(MAN2) && !defined(MAN3) && \ 165 !defined(MAN4) && !defined(MAN5) && !defined(MAN6) && \ 166 !defined(MAN7) && !defined(MAN8) && !defined(MAN9) 167MAN= ${PROG}.1 168MAN1= ${MAN} 169.endif 170.endif # defined(PROG) 171 172.if defined(_SKIP_BUILD) 173all: 174.else 175all: ${PROG} ${SCRIPTS} 176.if ${MK_MAN} != "no" 177all: all-man 178.endif 179.endif 180 181.if defined(PROG) 182CLEANFILES+= ${PROG} ${PROG}.bc ${PROG}.ll 183.if ${MK_DEBUG_FILES} != "no" 184CLEANFILES+= ${PROG_FULL} ${PROG_FULL}.bc ${PROGNAME}.debug ${PROG_FULL}.ll 185.endif 186.endif 187 188.if defined(OBJS) 189CLEANFILES+= ${OBJS} ${BCOBJS} ${LLOBJS} 190.endif 191 192.include <bsd.libnames.mk> 193 194.if defined(PROG) 195.if !defined(NO_EXTRADEPEND) 196_EXTRADEPEND: 197.if defined(LDFLAGS) && !empty(LDFLAGS:M-nostdlib) 198.if defined(DPADD) && !empty(DPADD) 199 echo ${PROG_FULL}: ${DPADD} >> ${DEPENDFILE} 200.endif 201.else 202 echo ${PROG_FULL}: ${LIBC} ${DPADD} >> ${DEPENDFILE} 203.if defined(PROG_CXX) 204.if ${COMPILER_TYPE} == "clang" && empty(CXXFLAGS:M-stdlib=libstdc++) 205 echo ${PROG_FULL}: ${LIBCPLUSPLUS} >> ${DEPENDFILE} 206.else 207 echo ${PROG_FULL}: ${LIBSTDCPLUSPLUS} >> ${DEPENDFILE} 208.endif 209.endif 210.endif 211.endif # !defined(NO_EXTRADEPEND) 212.endif 213 214.if !target(install) 215 216.if defined(PRECIOUSPROG) 217.if !defined(NO_FSCHG) 218INSTALLFLAGS+= -fschg 219.endif 220INSTALLFLAGS+= -S 221.endif 222 223_INSTALLFLAGS:= ${INSTALLFLAGS} 224.for ie in ${INSTALLFLAGS_EDIT} 225_INSTALLFLAGS:= ${_INSTALLFLAGS${ie}} 226.endfor 227 228.if !target(realinstall) && !defined(INTERNALPROG) 229realinstall: _proginstall 230.ORDER: beforeinstall _proginstall 231_proginstall: 232.ifdef _FILESMKDIR 233 ${INSTALL} -d ${DESTDIR}${BINDIR} 234.endif 235.if defined(PROG) 236 ${INSTALL} ${TAG_ARGS} ${STRIP} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \ 237 ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${BINDIR}/${PROGNAME} 238.if ${MK_DEBUG_FILES} != "no" 239.if defined(DEBUGMKDIR) 240 ${INSTALL} ${TAG_ARGS:D${TAG_ARGS},debug} -d ${DESTDIR}${DEBUGFILEDIR}/ 241.endif 242 ${INSTALL} ${TAG_ARGS:D${TAG_ARGS},debug} -o ${BINOWN} -g ${BINGRP} -m ${DEBUGMODE} \ 243 ${PROGNAME}.debug ${DESTDIR}${DEBUGFILEDIR}/${PROGNAME}.debug 244.endif 245.endif 246.endif # !target(realinstall) 247 248.if defined(SCRIPTS) && !empty(SCRIPTS) 249realinstall: _scriptsinstall 250.ORDER: beforeinstall _scriptsinstall 251 252SCRIPTSDIR?= ${BINDIR} 253SCRIPTSOWN?= ${BINOWN} 254SCRIPTSGRP?= ${BINGRP} 255SCRIPTSMODE?= ${BINMODE} 256 257STAGE_AS_SETS+= scripts 258stage_as.scripts: ${SCRIPTS} 259FLAGS.stage_as.scripts= -m ${SCRIPTSMODE} 260STAGE_FILES_DIR.scripts= ${STAGE_OBJTOP} 261.for script in ${SCRIPTS} 262.if defined(SCRIPTSNAME) 263SCRIPTSNAME_${script:T}?= ${SCRIPTSNAME} 264.else 265SCRIPTSNAME_${script:T}?= ${script:T:R} 266.endif 267SCRIPTSDIR_${script:T}?= ${SCRIPTSDIR} 268SCRIPTSOWN_${script:T}?= ${SCRIPTSOWN} 269SCRIPTSGRP_${script:T}?= ${SCRIPTSGRP} 270SCRIPTSMODE_${script:T}?= ${SCRIPTSMODE} 271STAGE_AS_${script:T}= ${SCRIPTSDIR_${script:T}}/${SCRIPTSNAME_${script:T}} 272_scriptsinstall: _SCRIPTSINS_${script:T} 273_SCRIPTSINS_${script:T}: ${script} 274.ifdef _FILESMKDIR 275 ${INSTALL} -d \ 276 ${DESTDIR}${SCRIPTSDIR_${.ALLSRC:T}}/${SCRIPTSNAME_${.ALLSRC:T}:H} 277.endif 278 ${INSTALL} ${TAG_ARGS} -o ${SCRIPTSOWN_${.ALLSRC:T}} \ 279 -g ${SCRIPTSGRP_${.ALLSRC:T}} -m ${SCRIPTSMODE_${.ALLSRC:T}} \ 280 ${.ALLSRC} \ 281 ${DESTDIR}${SCRIPTSDIR_${.ALLSRC:T}}/${SCRIPTSNAME_${.ALLSRC:T}} 282.endfor 283.endif 284 285NLSNAME?= ${PROG} 286.include <bsd.nls.mk> 287 288.include <bsd.confs.mk> 289.include <bsd.files.mk> 290.include <bsd.incs.mk> 291.include <bsd.links.mk> 292 293.if ${MK_MAN} != "no" 294realinstall: maninstall 295.ORDER: beforeinstall maninstall 296.endif 297 298.endif # !target(install) 299 300.if !target(lint) 301lint: ${SRCS:M*.c} 302.if defined(PROG) 303 ${LINT} ${LINTFLAGS} ${CFLAGS:M-[DIU]*} ${.ALLSRC} 304.endif 305.endif 306 307.if ${MK_MAN} != "no" 308.include <bsd.man.mk> 309.endif 310 311.if defined(HAS_TESTS) 312MAKE+= MK_MAKE_CHECK_USE_SANDBOX=yes 313SUBDIR_TARGETS+= check 314TESTS_LD_LIBRARY_PATH+= ${.OBJDIR} 315TESTS_PATH+= ${.OBJDIR} 316.endif 317 318.if defined(PROG) 319OBJS_DEPEND_GUESS+= ${SRCS:M*.h} 320.endif 321 322.include <bsd.dep.mk> 323.include <bsd.clang-analyze.mk> 324.include <bsd.obj.mk> 325.include <bsd.sys.mk> 326