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