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.
13 .if ${MK_ASSERT_DEBUG} == "no"
18 .if defined(DEBUG_FLAGS)
19 CFLAGS+=${DEBUG_FLAGS}
20 CXXFLAGS+=${DEBUG_FLAGS}
22 .if ${MK_CTF} != "no" && ${DEBUG_FLAGS:M-g} != ""
31 .if !empty(LDFLAGS:M-Wl,*--oformat,*) || !empty(LDFLAGS:M-static)
35 .if defined(CRUNCH_CFLAGS)
36 CFLAGS+=${CRUNCH_CFLAGS}
38 .if ${MK_DEBUG_FILES} != "no" && empty(DEBUG_FLAGS:M-g) && \
39 empty(DEBUG_FLAGS:M-gdwarf-*)
45 .if !defined(DEBUG_FLAGS)
49 .if defined(NO_SHARED) && (${NO_SHARED} != "no" && ${NO_SHARED} != "NO")
53 .if defined(USEPRIVATELIB)
54 LDFLAGS+= -L${_SHLIBDIRPREFIX}${LIBPRIVATEDIR} -rpath ${LIBPRIVATEDIR}
57 .if ${MK_DEBUG_FILES} != "no"
58 PROG_FULL=${PROG}.full
59 # Use ${DEBUGDIR} for base system debug files, else .debug subdirectory
60 .if defined(BINDIR) && (\
61 ${BINDIR} == "/bin" ||\
62 ${BINDIR} == "/libexec" ||\
63 ${BINDIR} == "/sbin" ||\
64 ${BINDIR:C%/usr/(bin|bsdinstall|games|libexec|lpr|sendmail|sm.bin|sbin)(/.*)?%/usr/bin%} == "/usr/bin"\
66 DEBUGFILEDIR= ${DEBUGDIR}${BINDIR}
68 DEBUGFILEDIR?= ${BINDIR}/.debug
80 OBJS+= ${SRCS:N*.h:R:S/$/.o/g}
82 .if target(beforelinking)
83 beforelinking: ${OBJS}
84 ${PROG_FULL}: beforelinking
88 ${CXX} ${CXXFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD}
90 ${CC} ${CFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD}
93 ${CTFMERGE} ${CTFFLAGS} -o ${.TARGET} ${OBJS}
96 .else # !defined(SRCS)
105 # Always make an intermediate object file because:
106 # - it saves time rebuilding when only the library has changed
107 # - the name of the object gets put into the executable symbol table instead of
108 # the name of a variable temporary object.
109 # - it's useful to keep objects around for crunching.
112 .if target(beforelinking)
113 beforelinking: ${OBJS}
114 ${PROG_FULL}: beforelinking
116 ${PROG_FULL}: ${OBJS}
117 .if defined(PROG_CXX)
118 ${CXX} ${CXXFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD}
120 ${CC} ${CFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD}
122 .if ${MK_CTF} != "no"
123 ${CTFMERGE} ${CTFFLAGS} -o ${.TARGET} ${OBJS}
125 .endif # !target(${PROG})
127 .endif # !defined(SRCS)
129 .if ${MK_DEBUG_FILES} != "no"
130 ${PROG}: ${PROG_FULL} ${PROGNAME}.debug
131 ${OBJCOPY} --strip-debug --add-gnu-debuglink=${PROGNAME}.debug \
132 ${PROG_FULL} ${.TARGET}
134 ${PROGNAME}.debug: ${PROG_FULL}
135 ${OBJCOPY} --only-keep-debug ${PROG_FULL} ${.TARGET}
138 .if ${MK_MAN} != "no" && !defined(MAN) && \
139 !defined(MAN1) && !defined(MAN2) && !defined(MAN3) && \
140 !defined(MAN4) && !defined(MAN5) && !defined(MAN6) && \
141 !defined(MAN7) && !defined(MAN8) && !defined(MAN9)
145 .endif # defined(PROG)
147 all: beforebuild .WAIT ${PROG} ${SCRIPTS}
149 .if ${MK_MAN} != "no"
155 .if ${MK_DEBUG_FILES} != "no"
156 CLEANFILES+= ${PROG_FULL} ${PROGNAME}.debug
164 .include <bsd.libnames.mk>
168 .if defined(LDFLAGS) && !empty(LDFLAGS:M-nostdlib)
169 .if defined(DPADD) && !empty(DPADD)
170 echo ${PROG_FULL}: ${DPADD} >> ${DEPENDFILE}
173 echo ${PROG_FULL}: ${LIBC} ${DPADD} >> ${DEPENDFILE}
174 .if defined(PROG_CXX)
175 .if ${MK_CLANG_IS_CC} != "no" && empty(CXXFLAGS:M-stdlib=libstdc++)
176 echo ${PROG_FULL}: ${LIBCPLUSPLUS} >> ${DEPENDFILE}
178 echo ${PROG_FULL}: ${LIBSTDCPLUSPLUS} >> ${DEPENDFILE}
186 .if defined(PRECIOUSPROG)
187 .if !defined(NO_FSCHG)
188 INSTALLFLAGS+= -fschg
193 _INSTALLFLAGS:= ${INSTALLFLAGS}
194 .for ie in ${INSTALLFLAGS_EDIT}
195 _INSTALLFLAGS:= ${_INSTALLFLAGS${ie}}
198 .if !target(realinstall) && !defined(INTERNALPROG)
199 realinstall: _proginstall
200 .ORDER: beforeinstall _proginstall
203 ${INSTALL} ${STRIP} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
204 ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${BINDIR}/${PROGNAME}
205 .if ${MK_DEBUG_FILES} != "no"
206 .if defined(DEBUGMKDIR)
207 ${INSTALL} -T debug -d ${DESTDIR}${DEBUGFILEDIR}
209 ${INSTALL} -T debug -o ${BINOWN} -g ${BINGRP} -m ${DEBUGMODE} \
210 ${PROGNAME}.debug ${DESTDIR}${DEBUGFILEDIR}/${PROGNAME}.debug
213 .endif # !target(realinstall)
215 .if defined(SCRIPTS) && !empty(SCRIPTS)
216 realinstall: _scriptsinstall
217 .ORDER: beforeinstall _scriptsinstall
219 SCRIPTSDIR?= ${BINDIR}
220 SCRIPTSOWN?= ${BINOWN}
221 SCRIPTSGRP?= ${BINGRP}
222 SCRIPTSMODE?= ${BINMODE}
224 .for script in ${SCRIPTS}
225 .if defined(SCRIPTSNAME)
226 SCRIPTSNAME_${script:T}?= ${SCRIPTSNAME}
228 SCRIPTSNAME_${script:T}?= ${script:T:R}
230 SCRIPTSDIR_${script:T}?= ${SCRIPTSDIR}
231 SCRIPTSOWN_${script:T}?= ${SCRIPTSOWN}
232 SCRIPTSGRP_${script:T}?= ${SCRIPTSGRP}
233 SCRIPTSMODE_${script:T}?= ${SCRIPTSMODE}
234 _scriptsinstall: _SCRIPTSINS_${script:T}
235 _SCRIPTSINS_${script:T}: ${script}
236 ${INSTALL} -o ${SCRIPTSOWN_${.ALLSRC:T}} \
237 -g ${SCRIPTSGRP_${.ALLSRC:T}} -m ${SCRIPTSMODE_${.ALLSRC:T}} \
239 ${DESTDIR}${SCRIPTSDIR_${.ALLSRC:T}}/${SCRIPTSNAME_${.ALLSRC:T}}
244 .include <bsd.nls.mk>
246 .include <bsd.files.mk>
247 .include <bsd.incs.mk>
248 .include <bsd.links.mk>
250 .if ${MK_MAN} != "no"
251 realinstall: _maninstall
252 .ORDER: beforeinstall _maninstall
255 .endif # !target(install)
260 ${LINT} ${LINTFLAGS} ${CFLAGS:M-[DIU]*} ${.ALLSRC}
264 .if ${MK_MAN} != "no"
265 .include <bsd.man.mk>
268 .include <bsd.dep.mk>
270 .if defined(PROG) && !exists(${.OBJDIR}/${DEPENDFILE})
271 ${OBJS}: ${SRCS:M*.h}
274 .include <bsd.obj.mk>
276 .include <bsd.sys.mk>
278 .if defined(PORTNAME)
279 .include <bsd.pkg.mk>