1 # from: @(#)bsd.prog.mk 5.26 (Berkeley) 6/25/91
6 .SUFFIXES: .out .o .c .cc .cpp .cxx .C .m .y .l .ln .s .S .asm
8 # XXX The use of COPTS in modern makefiles is discouraged.
10 .warning COPTS should be CFLAGS.
14 .if ${MK_ASSERT_DEBUG} == "no"
19 .if defined(DEBUG_FLAGS)
20 CFLAGS+=${DEBUG_FLAGS}
21 CXXFLAGS+=${DEBUG_FLAGS}
23 .if ${MK_CTF} != "no" && ${DEBUG_FLAGS:M-g} != ""
32 .if !empty(LDFLAGS:M-Wl,*--oformat,*) || !empty(LDFLAGS:M-static)
36 .if defined(CRUNCH_CFLAGS)
37 CFLAGS+=${CRUNCH_CFLAGS}
39 .if ${MK_DEBUG_FILES} != "no" && empty(DEBUG_FLAGS:M-g) && \
40 empty(DEBUG_FLAGS:M-gdwarf-*)
46 .if !defined(DEBUG_FLAGS)
50 .if defined(NO_SHARED) && (${NO_SHARED} != "no" && ${NO_SHARED} != "NO")
54 .if defined(USEPRIVATELIB)
55 LDFLAGS+= -L${_SHLIBDIRPREFIX}${LIBPRIVATEDIR} -rpath ${LIBPRIVATEDIR}
58 .if ${MK_DEBUG_FILES} != "no"
59 PROG_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|games|libexec|lpr|sendmail|sm.bin|sbin)(/.*)?%/usr/bin%} == "/usr/bin"\
67 DEBUGFILEDIR= ${DEBUGDIR}${BINDIR}
69 DEBUGFILEDIR?= ${BINDIR}/.debug
81 OBJS+= ${SRCS:N*.h:R:S/$/.o/g}
83 .if target(beforelinking)
84 beforelinking: ${OBJS}
85 ${PROG_FULL}: beforelinking
89 ${CXX} ${CXXFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD}
91 ${CC} ${CFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD}
94 ${CTFMERGE} ${CTFFLAGS} -o ${.TARGET} ${OBJS}
97 .else # !defined(SRCS)
100 .if defined(PROG_CXX)
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.
113 .if target(beforelinking)
114 beforelinking: ${OBJS}
115 ${PROG_FULL}: beforelinking
117 ${PROG_FULL}: ${OBJS}
118 .if defined(PROG_CXX)
119 ${CXX} ${CXXFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD}
121 ${CC} ${CFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD}
123 .if ${MK_CTF} != "no"
124 ${CTFMERGE} ${CTFFLAGS} -o ${.TARGET} ${OBJS}
126 .endif # !target(${PROG})
128 .endif # !defined(SRCS)
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}
135 ${PROGNAME}.debug: ${PROG_FULL}
136 ${OBJCOPY} --only-keep-debug ${PROG_FULL} ${.TARGET}
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)
146 .endif # defined(PROG)
148 all: beforebuild .WAIT ${PROG} ${SCRIPTS}
150 .if ${MK_MAN} != "no"
156 .if ${MK_DEBUG_FILES} != "no"
157 CLEANFILES+= ${PROG_FULL} ${PROGNAME}.debug
165 .include <bsd.libnames.mk>
169 .if defined(LDFLAGS) && !empty(LDFLAGS:M-nostdlib)
170 .if defined(DPADD) && !empty(DPADD)
171 echo ${PROG_FULL}: ${DPADD} >> ${DEPENDFILE}
174 echo ${PROG_FULL}: ${LIBC} ${DPADD} >> ${DEPENDFILE}
175 .if defined(PROG_CXX)
176 .if ${MK_CLANG_IS_CC} != "no" && empty(CXXFLAGS:M-stdlib=libstdc++)
177 echo ${PROG_FULL}: ${LIBCPLUSPLUS} >> ${DEPENDFILE}
179 echo ${PROG_FULL}: ${LIBSTDCPLUSPLUS} >> ${DEPENDFILE}
187 .if defined(PRECIOUSPROG)
188 .if !defined(NO_FSCHG)
189 INSTALLFLAGS+= -fschg
194 _INSTALLFLAGS:= ${INSTALLFLAGS}
195 .for ie in ${INSTALLFLAGS_EDIT}
196 _INSTALLFLAGS:= ${_INSTALLFLAGS${ie}}
199 .if !target(realinstall) && !defined(INTERNALPROG)
200 realinstall: _proginstall
201 .ORDER: beforeinstall _proginstall
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}
210 ${INSTALL} -T debug -o ${BINOWN} -g ${BINGRP} -m ${DEBUGMODE} \
211 ${PROGNAME}.debug ${DESTDIR}${DEBUGFILEDIR}/${PROGNAME}.debug
214 .endif # !target(realinstall)
216 .if defined(SCRIPTS) && !empty(SCRIPTS)
217 realinstall: _scriptsinstall
218 .ORDER: beforeinstall _scriptsinstall
220 SCRIPTSDIR?= ${BINDIR}
221 SCRIPTSOWN?= ${BINOWN}
222 SCRIPTSGRP?= ${BINGRP}
223 SCRIPTSMODE?= ${BINMODE}
225 .for script in ${SCRIPTS}
226 .if defined(SCRIPTSNAME)
227 SCRIPTSNAME_${script:T}?= ${SCRIPTSNAME}
229 SCRIPTSNAME_${script:T}?= ${script:T:R}
231 SCRIPTSDIR_${script:T}?= ${SCRIPTSDIR}
232 SCRIPTSOWN_${script:T}?= ${SCRIPTSOWN}
233 SCRIPTSGRP_${script:T}?= ${SCRIPTSGRP}
234 SCRIPTSMODE_${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}} \
240 ${DESTDIR}${SCRIPTSDIR_${.ALLSRC:T}}/${SCRIPTSNAME_${.ALLSRC:T}}
245 .include <bsd.nls.mk>
247 .include <bsd.files.mk>
248 .include <bsd.incs.mk>
249 .include <bsd.links.mk>
251 .if ${MK_MAN} != "no"
252 realinstall: _maninstall
253 .ORDER: beforeinstall _maninstall
256 .endif # !target(install)
261 ${LINT} ${LINTFLAGS} ${CFLAGS:M-[DIU]*} ${.ALLSRC}
265 .if ${MK_MAN} != "no"
266 .include <bsd.man.mk>
269 .include <bsd.dep.mk>
271 .if defined(PROG) && !exists(${.OBJDIR}/${DEPENDFILE})
272 ${OBJS}: ${SRCS:M*.h}
275 .include <bsd.obj.mk>
277 .include <bsd.sys.mk>
279 .if defined(PORTNAME)
280 .include <bsd.pkg.mk>