]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - share/mk/bsd.prog.mk
MFV r289185: 6250 zvol_dump_init() can hold txg open
[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 !empty(LDFLAGS:M-Wl,*--oformat,*) || !empty(LDFLAGS:M-static)
33 MK_DEBUG_FILES= no
34 .endif
35
36 .if defined(CRUNCH_CFLAGS)
37 CFLAGS+=${CRUNCH_CFLAGS}
38 .else
39 .if ${MK_DEBUG_FILES} != "no" && empty(DEBUG_FLAGS:M-g) && \
40     empty(DEBUG_FLAGS:M-gdwarf-*)
41 CFLAGS+= -g
42 CTFFLAGS+= -g
43 .endif
44 .endif
45
46 .if !defined(DEBUG_FLAGS)
47 STRIP?= -s
48 .endif
49
50 .if defined(NO_SHARED) && (${NO_SHARED} != "no" && ${NO_SHARED} != "NO")
51 LDFLAGS+= -static
52 .endif
53
54 .if ${MK_DEBUG_FILES} != "no"
55 PROG_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      )
63 DEBUGFILEDIR=   ${DEBUGDIR}${BINDIR}
64 .else
65 DEBUGFILEDIR?=  ${BINDIR}/.debug
66 DEBUGMKDIR=
67 .endif
68 .else
69 PROG_FULL=      ${PROG}
70 .endif
71
72 .if defined(PROG)
73 PROGNAME?=      ${PROG}
74
75 .if defined(SRCS)
76
77 OBJS+=  ${SRCS:N*.h:R:S/$/.o/g}
78
79 .if target(beforelinking)
80 beforelinking: ${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)
97 SRCS=   ${PROG}.cc
98 .else
99 SRCS=   ${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.
107 OBJS+=  ${PROG}.o
108
109 .if target(beforelinking)
110 beforelinking: ${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)
139 MAN=    ${PROG}.1
140 MAN1=   ${MAN}
141 .endif
142 .endif # defined(PROG)
143
144 .if defined(_SKIP_BUILD)
145 all:
146 .else
147 all: beforebuild .WAIT ${PROG} ${SCRIPTS}
148 beforebuild: objwarn
149 .if ${MK_MAN} != "no"
150 all: _manpages
151 .endif
152 .endif
153
154 .if defined(PROG)
155 CLEANFILES+= ${PROG}
156 .if ${MK_DEBUG_FILES} != "no"
157 CLEANFILES+=    ${PROG_FULL} ${PROGNAME}.debug
158 .endif
159 .endif
160
161 .if defined(OBJS)
162 CLEANFILES+= ${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)
189 INSTALLFLAGS+= -fschg
190 .endif
191 INSTALLFLAGS+= -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)
200 realinstall: _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)
217 realinstall: _scriptsinstall
218 .ORDER: beforeinstall _scriptsinstall
219
220 SCRIPTSDIR?=    ${BINDIR}
221 SCRIPTSOWN?=    ${BINOWN}
222 SCRIPTSGRP?=    ${BINGRP}
223 SCRIPTSMODE?=   ${BINMODE}
224
225 STAGE_AS_SETS+= scripts
226 stage_as.scripts: ${SCRIPTS}
227 FLAGS.stage_as.scripts= -m ${SCRIPTSMODE}
228 STAGE_FILES_DIR.scripts= ${STAGE_OBJTOP}
229 .for script in ${SCRIPTS}
230 .if defined(SCRIPTSNAME)
231 SCRIPTSNAME_${script:T}?=       ${SCRIPTSNAME}
232 .else
233 SCRIPTSNAME_${script:T}?=       ${script:T:R}
234 .endif
235 SCRIPTSDIR_${script:T}?=        ${SCRIPTSDIR}
236 SCRIPTSOWN_${script:T}?=        ${SCRIPTSOWN}
237 SCRIPTSGRP_${script:T}?=        ${SCRIPTSGRP}
238 SCRIPTSMODE_${script:T}?=       ${SCRIPTSMODE}
239 STAGE_AS_${script:T}=           ${SCRIPTSDIR_${script:T}}/${SCRIPTSNAME_${script:T}}
240 _scriptsinstall: _SCRIPTSINS_${script:T}
241 _SCRIPTSINS_${script:T}: ${script}
242         ${INSTALL} -o ${SCRIPTSOWN_${.ALLSRC:T}} \
243             -g ${SCRIPTSGRP_${.ALLSRC:T}} -m ${SCRIPTSMODE_${.ALLSRC:T}} \
244             ${.ALLSRC} \
245             ${DESTDIR}${SCRIPTSDIR_${.ALLSRC:T}}/${SCRIPTSNAME_${.ALLSRC:T}}
246 .endfor
247 .endif
248
249 NLSNAME?=       ${PROG}
250 .include <bsd.nls.mk>
251
252 .include <bsd.confs.mk>
253 .include <bsd.files.mk>
254 .include <bsd.incs.mk>
255 .include <bsd.links.mk>
256
257 .if ${MK_MAN} != "no"
258 realinstall: _maninstall
259 .ORDER: beforeinstall _maninstall
260 .endif
261
262 .endif  # !target(install)
263
264 .if !target(lint)
265 lint: ${SRCS:M*.c}
266 .if defined(PROG)
267         ${LINT} ${LINTFLAGS} ${CFLAGS:M-[DIU]*} ${.ALLSRC}
268 .endif
269 .endif
270
271 .if ${MK_MAN} != "no"
272 .include <bsd.man.mk>
273 .endif
274
275 .include <bsd.dep.mk>
276
277 .if defined(PROG) && !exists(${.OBJDIR}/${DEPENDFILE})
278 ${OBJS}: ${SRCS:M*.h}
279 .endif
280
281 .include <bsd.obj.mk>
282
283 .include <bsd.sys.mk>