]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - share/mk/bsd.prog.mk
Upgrade to latest ldns (1.6.17) and unbound (1.4.22).
[FreeBSD/FreeBSD.git] / share / mk / bsd.prog.mk
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)
11 CFLAGS+=${COPTS}
12 .endif
13
14 .if ${MK_ASSERT_DEBUG} == "no"
15 CFLAGS+= -DNDEBUG
16 NO_WERROR=
17 .endif
18
19 .if defined(DEBUG_FLAGS)
20 CFLAGS+=${DEBUG_FLAGS}
21 CXXFLAGS+=${DEBUG_FLAGS}
22
23 .if ${MK_CTF} != "no" && ${DEBUG_FLAGS:M-g} != ""
24 CTFFLAGS+= -g
25 .endif
26 .endif
27
28 .if defined(PROG_CXX)
29 PROG=   ${PROG_CXX}
30 .endif
31
32 .if defined(PROG) && target(${PROG})
33 MK_DEBUG_FILES= no
34 .elif !empty(LDFLAGS:M-Wl,*--oformat,*) || !empty(LDFLAGS:M-static)
35 MK_DEBUG_FILES= no
36 .endif
37
38 .if defined(CRUNCH_CFLAGS)
39 CFLAGS+=${CRUNCH_CFLAGS}
40 .else
41 .if ${MK_DEBUG_FILES} != "no" && empty(DEBUG_FLAGS:M-g) && \
42     empty(DEBUG_FLAGS:M-gdwarf-*)
43 CFLAGS+= -g
44 CTFFLAGS+= -g
45 .endif
46 .endif
47
48 .if !defined(DEBUG_FLAGS)
49 STRIP?= -s
50 .endif
51
52 .if defined(NO_SHARED) && (${NO_SHARED} != "no" && ${NO_SHARED} != "NO")
53 LDFLAGS+= -static
54 .endif
55
56 .if defined(USEPRIVATELIB)
57 LDFLAGS+= -L${_SHLIBDIRPREFIX}${LIBPRIVATEDIR} -rpath ${LIBPRIVATEDIR}
58 .endif
59
60 .if ${MK_DEBUG_FILES} != "no"
61 PROG_FULL=${PROG}.full
62 # Use ${DEBUGDIR} for base system debug files, else .debug subdirectory
63 .if defined(BINDIR) && (\
64     ${BINDIR} == "/bin" ||\
65     ${BINDIR} == "/libexec" ||\
66     ${BINDIR} == "/sbin" ||\
67     ${BINDIR:C%/usr/(bin|bsdinstall|games|libexec|lpr|sendmail|sm.bin|sbin)(/.*)?%/usr/bin%} == "/usr/bin"\
68      )
69 DEBUGFILEDIR=   ${DEBUGDIR}${BINDIR}
70 .else
71 DEBUGFILEDIR?=  ${BINDIR}/.debug
72 DEBUGMKDIR=
73 .endif
74 .else
75 PROG_FULL=      ${PROG}
76 .endif
77
78 .if defined(PROG)
79 PROGNAME?=      ${PROG}
80
81 .if defined(SRCS)
82
83 OBJS+=  ${SRCS:N*.h:R:S/$/.o/g}
84
85 .if target(beforelinking)
86 beforelinking: ${OBJS}
87 ${PROG_FULL}: beforelinking
88 .endif
89 ${PROG_FULL}: ${OBJS}
90 .if defined(PROG_CXX)
91         ${CXX} ${CXXFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD}
92 .else
93         ${CC} ${CFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD}
94 .endif
95 .if ${MK_CTF} != "no"
96         ${CTFMERGE} ${CTFFLAGS} -o ${.TARGET} ${OBJS}
97 .endif
98
99 .else   # !defined(SRCS)
100
101 .if !target(${PROG})
102 .if defined(PROG_CXX)
103 SRCS=   ${PROG}.cc
104 .else
105 SRCS=   ${PROG}.c
106 .endif
107
108 # Always make an intermediate object file because:
109 # - it saves time rebuilding when only the library has changed
110 # - the name of the object gets put into the executable symbol table instead of
111 #   the name of a variable temporary object.
112 # - it's useful to keep objects around for crunching.
113 OBJS+=  ${PROG}.o
114
115 .if target(beforelinking)
116 beforelinking: ${OBJS}
117 ${PROG_FULL}: beforelinking
118 .endif
119 ${PROG_FULL}: ${OBJS}
120 .if defined(PROG_CXX)
121         ${CXX} ${CXXFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD}
122 .else
123         ${CC} ${CFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${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)
145 MAN=    ${PROG}.1
146 MAN1=   ${MAN}
147 .endif
148 .endif # defined(PROG)
149
150 all: objwarn ${PROG} ${SCRIPTS}
151 .if ${MK_MAN} != "no"
152 all: _manpages
153 .endif
154
155 .if defined(PROG)
156 CLEANFILES+= ${PROG}
157 .if ${MK_DEBUG_FILES} != "no"
158 CLEANFILES+=    ${PROG_FULL} ${PROGNAME}.debug
159 .endif
160 .endif
161
162 .if defined(OBJS)
163 CLEANFILES+= ${OBJS}
164 .endif
165
166 .include <bsd.libnames.mk>
167
168 .if defined(PROG)
169 _EXTRADEPEND:
170 .if defined(LDFLAGS) && !empty(LDFLAGS:M-nostdlib)
171 .if defined(DPADD) && !empty(DPADD)
172         echo ${PROG}: ${DPADD} >> ${DEPENDFILE}
173 .endif
174 .else
175         echo ${PROG}: ${LIBC} ${DPADD} >> ${DEPENDFILE}
176 .if defined(PROG_CXX)
177 .if ${COMPILER_TYPE} == "clang" && empty(CXXFLAGS:M-stdlib=libstdc++)
178         echo ${PROG}: ${LIBCPLUSPLUS} >> ${DEPENDFILE}
179 .else
180         echo ${PROG}: ${LIBSTDCPLUSPLUS} >> ${DEPENDFILE}
181 .endif
182 .endif
183 .endif
184 .endif
185
186 .if !target(install)
187
188 .if defined(PRECIOUSPROG)
189 .if !defined(NO_FSCHG)
190 INSTALLFLAGS+= -fschg
191 .endif
192 INSTALLFLAGS+= -S
193 .endif
194
195 _INSTALLFLAGS:= ${INSTALLFLAGS}
196 .for ie in ${INSTALLFLAGS_EDIT}
197 _INSTALLFLAGS:= ${_INSTALLFLAGS${ie}}
198 .endfor
199
200 .if !target(realinstall) && !defined(INTERNALPROG)
201 realinstall: _proginstall
202 .ORDER: beforeinstall _proginstall
203 _proginstall:
204 .if defined(PROG)
205         ${INSTALL} ${STRIP} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
206             ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${BINDIR}/${PROGNAME}
207 .if ${MK_DEBUG_FILES} != "no"
208 .if defined(DEBUGMKDIR)
209         ${INSTALL} -T debug -d ${DESTDIR}${DEBUGFILEDIR}
210 .endif
211         ${INSTALL} -T debug -o ${BINOWN} -g ${BINGRP} -m ${DEBUGMODE} \
212             ${PROGNAME}.debug ${DESTDIR}${DEBUGFILEDIR}/${PROGNAME}.debug
213 .endif
214 .endif
215 .endif  # !target(realinstall)
216
217 .if defined(SCRIPTS) && !empty(SCRIPTS)
218 realinstall: _scriptsinstall
219 .ORDER: beforeinstall _scriptsinstall
220
221 SCRIPTSDIR?=    ${BINDIR}
222 SCRIPTSOWN?=    ${BINOWN}
223 SCRIPTSGRP?=    ${BINGRP}
224 SCRIPTSMODE?=   ${BINMODE}
225
226 .for script in ${SCRIPTS}
227 .if defined(SCRIPTSNAME)
228 SCRIPTSNAME_${script:T}?=       ${SCRIPTSNAME}
229 .else
230 SCRIPTSNAME_${script:T}?=       ${script:T:R}
231 .endif
232 SCRIPTSDIR_${script:T}?=        ${SCRIPTSDIR}
233 SCRIPTSOWN_${script:T}?=        ${SCRIPTSOWN}
234 SCRIPTSGRP_${script:T}?=        ${SCRIPTSGRP}
235 SCRIPTSMODE_${script:T}?=       ${SCRIPTSMODE}
236 _scriptsinstall: _SCRIPTSINS_${script:T}
237 _SCRIPTSINS_${script:T}: ${script}
238         ${INSTALL} -o ${SCRIPTSOWN_${.ALLSRC:T}} \
239             -g ${SCRIPTSGRP_${.ALLSRC:T}} -m ${SCRIPTSMODE_${.ALLSRC:T}} \
240             ${.ALLSRC} \
241             ${DESTDIR}${SCRIPTSDIR_${.ALLSRC:T}}/${SCRIPTSNAME_${.ALLSRC:T}}
242 .endfor
243 .endif
244
245 NLSNAME?=       ${PROG}
246 .include <bsd.nls.mk>
247
248 .include <bsd.files.mk>
249 .include <bsd.incs.mk>
250 .include <bsd.links.mk>
251
252 .if ${MK_MAN} != "no"
253 realinstall: _maninstall
254 .ORDER: beforeinstall _maninstall
255 .endif
256
257 .endif
258
259 .if !target(lint)
260 lint: ${SRCS:M*.c}
261 .if defined(PROG)
262         ${LINT} ${LINTFLAGS} ${CFLAGS:M-[DIU]*} ${.ALLSRC}
263 .endif
264 .endif
265
266 .if ${MK_MAN} != "no"
267 .include <bsd.man.mk>
268 .endif
269
270 .include <bsd.dep.mk>
271
272 .if defined(PROG) && !exists(${.OBJDIR}/${DEPENDFILE})
273 ${OBJS}: ${SRCS:M*.h}
274 .endif
275
276 .include <bsd.obj.mk>
277
278 .include <bsd.sys.mk>