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