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