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 defined(USEPRIVATELIB) 55LDFLAGS+= -L${_SHLIBDIRPREFIX}${LIBPRIVATEDIR} -rpath ${LIBPRIVATEDIR} 56.endif 57 58.if ${MK_DEBUG_FILES} != "no" 59PROG_FULL=${PROG}.full 60# Use ${DEBUGDIR} for base system debug files, else .debug subdirectory 61.if defined(BINDIR) && (\ 62 ${BINDIR} == "/bin" ||\ 63 ${BINDIR} == "/libexec" ||\ 64 ${BINDIR} == "/sbin" ||\ 65 ${BINDIR:C%/usr/(bin|bsdinstall|libexec|lpr|sendmail|sm.bin|sbin)(/.*)?%/usr/bin%} == "/usr/bin"\ 66 ) 67DEBUGFILEDIR= ${DEBUGDIR}${BINDIR} 68.else 69DEBUGFILEDIR?= ${BINDIR}/.debug 70DEBUGMKDIR= 71.endif 72.else 73PROG_FULL= ${PROG} 74.endif 75 76.if defined(PROG) 77PROGNAME?= ${PROG} 78 79.if defined(SRCS) 80 81OBJS+= ${SRCS:N*.h:R:S/$/.o/g} 82 83.if target(beforelinking) 84beforelinking: ${OBJS} 85${PROG_FULL}: beforelinking 86.endif 87${PROG_FULL}: ${OBJS} 88.if defined(PROG_CXX) 89 ${CXX} ${CXXFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD} 90.else 91 ${CC} ${CFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${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} ${CXXFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD} 120.else 121 ${CC} ${CFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD} 122.endif 123.if ${MK_CTF} != "no" 124 ${CTFMERGE} ${CTFFLAGS} -o ${.TARGET} ${OBJS} 125.endif 126.endif # !target(${PROG}) 127 128.endif # !defined(SRCS) 129 130.if ${MK_DEBUG_FILES} != "no" 131${PROG}: ${PROG_FULL} ${PROGNAME}.debug 132 ${OBJCOPY} --strip-debug --add-gnu-debuglink=${PROGNAME}.debug \ 133 ${PROG_FULL} ${.TARGET} 134 135${PROGNAME}.debug: ${PROG_FULL} 136 ${OBJCOPY} --only-keep-debug ${PROG_FULL} ${.TARGET} 137.endif 138 139.if ${MK_MAN} != "no" && !defined(MAN) && \ 140 !defined(MAN1) && !defined(MAN2) && !defined(MAN3) && \ 141 !defined(MAN4) && !defined(MAN5) && !defined(MAN6) && \ 142 !defined(MAN7) && !defined(MAN8) && !defined(MAN9) 143MAN= ${PROG}.1 144MAN1= ${MAN} 145.endif 146.endif # defined(PROG) 147 148all: beforebuild .WAIT ${PROG} ${SCRIPTS} 149beforebuild: objwarn 150.if ${MK_MAN} != "no" 151all: _manpages 152.endif 153 154.if defined(PROG) 155CLEANFILES+= ${PROG} 156.if ${MK_DEBUG_FILES} != "no" 157CLEANFILES+= ${PROG_FULL} ${PROGNAME}.debug 158.endif 159.endif 160 161.if defined(OBJS) 162CLEANFILES+= ${OBJS} 163.endif 164 165.include <bsd.libnames.mk> 166 167.if defined(PROG) 168_EXTRADEPEND: 169.if defined(LDFLAGS) && !empty(LDFLAGS:M-nostdlib) 170.if defined(DPADD) && !empty(DPADD) 171 echo ${PROG_FULL}: ${DPADD} >> ${DEPENDFILE} 172.endif 173.else 174 echo ${PROG_FULL}: ${LIBC} ${DPADD} >> ${DEPENDFILE} 175.if defined(PROG_CXX) 176.if ${COMPILER_TYPE} == "clang" && empty(CXXFLAGS:M-stdlib=libstdc++) 177 echo ${PROG_FULL}: ${LIBCPLUSPLUS} >> ${DEPENDFILE} 178.else 179 echo ${PROG_FULL}: ${LIBSTDCPLUSPLUS} >> ${DEPENDFILE} 180.endif 181.endif 182.endif 183.endif 184 185.if !target(install) 186 187.if defined(PRECIOUSPROG) 188.if !defined(NO_FSCHG) 189INSTALLFLAGS+= -fschg 190.endif 191INSTALLFLAGS+= -S 192.endif 193 194_INSTALLFLAGS:= ${INSTALLFLAGS} 195.for ie in ${INSTALLFLAGS_EDIT} 196_INSTALLFLAGS:= ${_INSTALLFLAGS${ie}} 197.endfor 198 199.if !target(realinstall) && !defined(INTERNALPROG) 200realinstall: _proginstall 201.ORDER: beforeinstall _proginstall 202_proginstall: 203.if defined(PROG) 204 ${INSTALL} ${STRIP} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \ 205 ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${BINDIR}/${PROGNAME} 206.if ${MK_DEBUG_FILES} != "no" 207.if defined(DEBUGMKDIR) 208 ${INSTALL} -T debug -d ${DESTDIR}${DEBUGFILEDIR} 209.endif 210 ${INSTALL} -T debug -o ${BINOWN} -g ${BINGRP} -m ${DEBUGMODE} \ 211 ${PROGNAME}.debug ${DESTDIR}${DEBUGFILEDIR}/${PROGNAME}.debug 212.endif 213.endif 214.endif # !target(realinstall) 215 216.if defined(SCRIPTS) && !empty(SCRIPTS) 217realinstall: _scriptsinstall 218.ORDER: beforeinstall _scriptsinstall 219 220SCRIPTSDIR?= ${BINDIR} 221SCRIPTSOWN?= ${BINOWN} 222SCRIPTSGRP?= ${BINGRP} 223SCRIPTSMODE?= ${BINMODE} 224 225.for script in ${SCRIPTS} 226.if defined(SCRIPTSNAME) 227SCRIPTSNAME_${script:T}?= ${SCRIPTSNAME} 228.else 229SCRIPTSNAME_${script:T}?= ${script:T:R} 230.endif 231SCRIPTSDIR_${script:T}?= ${SCRIPTSDIR} 232SCRIPTSOWN_${script:T}?= ${SCRIPTSOWN} 233SCRIPTSGRP_${script:T}?= ${SCRIPTSGRP} 234SCRIPTSMODE_${script:T}?= ${SCRIPTSMODE} 235_scriptsinstall: _SCRIPTSINS_${script:T} 236_SCRIPTSINS_${script:T}: ${script} 237 ${INSTALL} -o ${SCRIPTSOWN_${.ALLSRC:T}} \ 238 -g ${SCRIPTSGRP_${.ALLSRC:T}} -m ${SCRIPTSMODE_${.ALLSRC:T}} \ 239 ${.ALLSRC} \ 240 ${DESTDIR}${SCRIPTSDIR_${.ALLSRC:T}}/${SCRIPTSNAME_${.ALLSRC:T}} 241.endfor 242.endif 243 244NLSNAME?= ${PROG} 245.include <bsd.nls.mk> 246 247.include <bsd.files.mk> 248.include <bsd.incs.mk> 249.include <bsd.links.mk> 250 251.if ${MK_MAN} != "no" 252realinstall: _maninstall 253.ORDER: beforeinstall _maninstall 254.endif 255 256.endif 257 258.if !target(lint) 259lint: ${SRCS:M*.c} 260.if defined(PROG) 261 ${LINT} ${LINTFLAGS} ${CFLAGS:M-[DIU]*} ${.ALLSRC} 262.endif 263.endif 264 265.if ${MK_MAN} != "no" 266.include <bsd.man.mk> 267.endif 268 269.include <bsd.dep.mk> 270 271.if defined(PROG) && !exists(${.OBJDIR}/${DEPENDFILE}) 272${OBJS}: ${SRCS:M*.h} 273.endif 274 275.include <bsd.obj.mk> 276 277.include <bsd.sys.mk> 278