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