]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - share/mk/bsd.prog.mk
Revert "ossl: Add support for AES-CBC cipher"
[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 .include <bsd.linker.mk>
7
8 .SUFFIXES: .out .o .bc .c .cc .cpp .cxx .C .m .y .l .ll .ln .s .S .asm
9
10 # XXX The use of COPTS in modern makefiles is discouraged.
11 .if defined(COPTS)
12 .warning ${.CURDIR}: COPTS should be CFLAGS.
13 CFLAGS+=${COPTS}
14 .endif
15
16 .if ${MK_ASSERT_DEBUG} == "no"
17 CFLAGS+= -DNDEBUG
18 # XXX: shouldn't we ensure that !asserts marks potentially unused variables as
19 # __unused instead of disabling -Werror globally?
20 MK_WERROR=      no
21 .endif
22
23 .if defined(DEBUG_FLAGS)
24 CFLAGS+=${DEBUG_FLAGS}
25 CXXFLAGS+=${DEBUG_FLAGS}
26
27 .if ${MK_CTF} != "no" && ${DEBUG_FLAGS:M-g} != ""
28 CTFFLAGS+= -g
29 .endif
30 .endif
31
32 .if defined(PROG_CXX)
33 PROG=   ${PROG_CXX}
34 .endif
35
36 .if !empty(LDFLAGS:M-Wl,*--oformat,*) || !empty(LDFLAGS:M-static)
37 MK_DEBUG_FILES= no
38 .endif
39
40 # ELF hardening knobs
41 .if ${MK_BIND_NOW} != "no"
42 LDFLAGS+= -Wl,-znow
43 .endif
44 .if ${MK_PIE} != "no"
45 # Static PIE is not yet supported/tested.
46 .if !defined(NO_SHARED) || ${NO_SHARED:tl} == "no"
47 CFLAGS+= -fPIE
48 CXXFLAGS+= -fPIE
49 LDFLAGS+= -pie
50 .endif
51 .endif
52 .if ${MK_RETPOLINE} != "no"
53 .if ${COMPILER_FEATURES:Mretpoline} && ${LINKER_FEATURES:Mretpoline}
54 CFLAGS+= -mretpoline
55 CXXFLAGS+= -mretpoline
56 # retpolineplt is broken with static linking (PR 233336)
57 .if !defined(NO_SHARED) || ${NO_SHARED:tl} == "no"
58 LDFLAGS+= -Wl,-zretpolineplt
59 .endif
60 .else
61 .warning Retpoline requested but not supported by compiler or linker
62 .endif
63 .endif
64
65 # Initialize stack variables on function entry
66 .if ${MK_INIT_ALL_ZERO} == "yes"
67 .if ${COMPILER_FEATURES:Minit-all}
68 CFLAGS+= -ftrivial-auto-var-init=zero \
69     -enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang
70 CXXFLAGS+= -ftrivial-auto-var-init=zero \
71     -enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang
72 .else
73 .warning InitAll (zeros) requested but not support by compiler
74 .endif
75 .elif ${MK_INIT_ALL_PATTERN} == "yes"
76 .if ${COMPILER_FEATURES:Minit-all}
77 CFLAGS+= -ftrivial-auto-var-init=pattern
78 CXXFLAGS+= -ftrivial-auto-var-init=pattern
79 .else
80 .warning InitAll (pattern) requested but not support by compiler
81 .endif
82 .endif
83
84 # bsd.sanitizer.mk is not installed, so don't require it (e.g. for ports).
85 .sinclude "bsd.sanitizer.mk"
86
87 .if ${MACHINE_CPUARCH} == "riscv" && ${LINKER_FEATURES:Mriscv-relaxations} == ""
88 CFLAGS += -mno-relax
89 .endif
90
91 .if defined(CRUNCH_CFLAGS)
92 CFLAGS+=${CRUNCH_CFLAGS}
93 .else
94 .if ${MK_DEBUG_FILES} != "no" && empty(DEBUG_FLAGS:M-g) && \
95     empty(DEBUG_FLAGS:M-gdwarf-*)
96 .if !${COMPILER_FEATURES:Mcompressed-debug}
97 CFLAGS+= ${DEBUG_FILES_CFLAGS:N-gz*}
98 .else
99 CFLAGS+= ${DEBUG_FILES_CFLAGS}
100 .endif
101 CTFFLAGS+= -g
102 .endif
103 .endif
104
105 .if !defined(DEBUG_FLAGS)
106 STRIP?= -s
107 .endif
108
109 .if defined(NO_ROOT)
110 .if !defined(TAGS) || ! ${TAGS:Mpackage=*}
111 TAGS+=          package=${PACKAGE:Uutilities}
112 .endif
113 TAG_ARGS=       -T ${TAGS:[*]:S/ /,/g}
114 .endif
115
116 .if defined(NO_SHARED) && ${NO_SHARED:tl} != "no"
117 LDFLAGS+= -static
118 .endif
119
120 # clang currently defaults to dynamic TLS for mips64 binaries
121 .if ${MACHINE_ARCH:Mmips64*} && ${COMPILER_TYPE} == "clang"
122 CFLAGS+= -ftls-model=initial-exec
123 .endif
124
125 .if ${MK_DEBUG_FILES} != "no"
126 PROG_FULL=${PROG}.full
127 # Use ${DEBUGDIR} for base system debug files, else .debug subdirectory
128 .if defined(BINDIR) && (\
129     ${BINDIR} == "/bin" ||\
130     ${BINDIR:C%/libexec(/.*)?%/libexec%} == "/libexec" ||\
131     ${BINDIR} == "/sbin" ||\
132     ${BINDIR:C%/usr/(bin|bsdinstall|libexec|lpr|sendmail|sm.bin|sbin|tests)(/.*)?%/usr/bin%} == "/usr/bin" ||\
133     ${BINDIR} == "/usr/lib" \
134      )
135 DEBUGFILEDIR=   ${DEBUGDIR}${BINDIR}
136 .else
137 DEBUGFILEDIR?=  ${BINDIR}/.debug
138 .endif
139 .if !exists(${DESTDIR}${DEBUGFILEDIR})
140 DEBUGMKDIR=
141 .endif
142 .else
143 PROG_FULL=      ${PROG}
144 .endif
145
146 .if defined(PROG)
147 PROGNAME?=      ${PROG}
148
149 .if defined(SRCS)
150
151 OBJS+=  ${SRCS:N*.h:${OBJS_SRCS_FILTER:ts:}:S/$/.o/g}
152
153 # LLVM bitcode / textual IR representations of the program
154 BCOBJS+=${SRCS:N*.[hsS]:N*.asm:${OBJS_SRCS_FILTER:ts:}:S/$/.bco/g}
155 LLOBJS+=${SRCS:N*.[hsS]:N*.asm:${OBJS_SRCS_FILTER:ts:}:S/$/.llo/g}
156
157 .if target(beforelinking)
158 beforelinking: ${OBJS}
159 ${PROG_FULL}: beforelinking
160 .endif
161 ${PROG_FULL}: ${OBJS}
162 .if defined(PROG_CXX)
163         ${CXX:N${CCACHE_BIN}} ${CXXFLAGS:N-M*} ${LDFLAGS} -o ${.TARGET} \
164             ${OBJS} ${LDADD}
165 .else
166         ${CC:N${CCACHE_BIN}} ${CFLAGS:N-M*} ${LDFLAGS} -o ${.TARGET} ${OBJS} \
167             ${LDADD}
168 .endif
169 .if ${MK_CTF} != "no"
170         ${CTFMERGE} ${CTFFLAGS} -o ${.TARGET} ${OBJS}
171 .endif
172
173 .else   # !defined(SRCS)
174
175 .if !target(${PROG})
176 .if defined(PROG_CXX)
177 SRCS=   ${PROG}.cc
178 .else
179 SRCS=   ${PROG}.c
180 .endif
181
182 # Always make an intermediate object file because:
183 # - it saves time rebuilding when only the library has changed
184 # - the name of the object gets put into the executable symbol table instead of
185 #   the name of a variable temporary object.
186 # - it's useful to keep objects around for crunching.
187 OBJS+=          ${PROG}.o
188 BCOBJS+=        ${PROG}.bc
189 LLOBJS+=        ${PROG}.ll
190 CLEANFILES+=    ${PROG}.o ${PROG}.bc ${PROG}.ll
191
192 .if target(beforelinking)
193 beforelinking: ${OBJS}
194 ${PROG_FULL}: beforelinking
195 .endif
196 ${PROG_FULL}: ${OBJS}
197 .if defined(PROG_CXX)
198         ${CXX:N${CCACHE_BIN}} ${CXXFLAGS:N-M*} ${LDFLAGS} -o ${.TARGET} \
199             ${OBJS} ${LDADD}
200 .else
201         ${CC:N${CCACHE_BIN}} ${CFLAGS:N-M*} ${LDFLAGS} -o ${.TARGET} ${OBJS} \
202             ${LDADD}
203 .endif
204 .if ${MK_CTF} != "no"
205         ${CTFMERGE} ${CTFFLAGS} -o ${.TARGET} ${OBJS}
206 .endif
207 .endif # !target(${PROG})
208
209 .endif # !defined(SRCS)
210
211 .if ${MK_DEBUG_FILES} != "no"
212 ${PROG}: ${PROG_FULL} ${PROGNAME}.debug
213         ${OBJCOPY} --strip-debug --add-gnu-debuglink=${PROGNAME}.debug \
214             ${PROG_FULL} ${.TARGET}
215
216 ${PROGNAME}.debug: ${PROG_FULL}
217         ${OBJCOPY} --only-keep-debug ${PROG_FULL} ${.TARGET}
218 .endif
219
220 .if defined(LLVM_LINK)
221 ${PROG_FULL}.bc: ${BCOBJS}
222         ${LLVM_LINK} -o ${.TARGET} ${BCOBJS}
223
224 ${PROG_FULL}.ll: ${LLOBJS}
225         ${LLVM_LINK} -S -o ${.TARGET} ${LLOBJS}
226
227 CLEANFILES+=    ${PROG_FULL}.bc ${PROG_FULL}.ll
228 .endif # defined(LLVM_LINK)
229
230 .if     ${MK_MAN} != "no" && !defined(MAN) && \
231         !defined(MAN1) && !defined(MAN2) && !defined(MAN3) && \
232         !defined(MAN4) && !defined(MAN5) && !defined(MAN6) && \
233         !defined(MAN7) && !defined(MAN8) && !defined(MAN9)
234 MAN=    ${PROG}.1
235 MAN1=   ${MAN}
236 .endif
237 .endif # defined(PROG)
238
239 .if defined(_SKIP_BUILD)
240 all:
241 .else
242 .if target(afterbuild)
243 .ORDER: ${PROG} afterbuild
244 all: ${PROG} ${SCRIPTS} afterbuild
245 .else
246 all: ${PROG} ${SCRIPTS}
247 .endif
248 .if ${MK_MAN} != "no"
249 all: all-man
250 .endif
251 .endif
252
253 .if defined(PROG)
254 CLEANFILES+= ${PROG} ${PROG}.bc ${PROG}.ll
255 .if ${MK_DEBUG_FILES} != "no"
256 CLEANFILES+= ${PROG_FULL} ${PROGNAME}.debug
257 .endif
258 .endif
259
260 .if defined(OBJS)
261 CLEANFILES+= ${OBJS} ${BCOBJS} ${LLOBJS}
262 .endif
263
264 .include <bsd.libnames.mk>
265
266 .if defined(PROG)
267 .if !defined(NO_EXTRADEPEND)
268 _EXTRADEPEND:
269 .if defined(LDFLAGS) && !empty(LDFLAGS:M-nostdlib)
270 .if defined(DPADD) && !empty(DPADD)
271         echo ${PROG_FULL}: ${DPADD} >> ${DEPENDFILE}
272 .endif
273 .else
274         echo ${PROG_FULL}: ${LIBC} ${DPADD} >> ${DEPENDFILE}
275 .if defined(PROG_CXX)
276         echo ${PROG_FULL}: ${LIBCPLUSPLUS} >> ${DEPENDFILE}
277 .endif
278 .endif
279 .endif  # !defined(NO_EXTRADEPEND)
280 .endif
281
282 .if !target(install)
283
284 .if defined(PRECIOUSPROG)
285 .if !defined(NO_FSCHG)
286 INSTALLFLAGS+= -fschg
287 .endif
288 INSTALLFLAGS+= -S
289 .endif
290
291 _INSTALLFLAGS:= ${INSTALLFLAGS}
292 .for ie in ${INSTALLFLAGS_EDIT}
293 _INSTALLFLAGS:= ${_INSTALLFLAGS${ie}}
294 .endfor
295
296 .if !target(realinstall) && !defined(INTERNALPROG)
297 realinstall: _proginstall
298 .ORDER: beforeinstall _proginstall
299 _proginstall:
300 .if defined(PROG)
301         ${INSTALL} ${TAG_ARGS} ${STRIP} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
302             ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${BINDIR}/${PROGNAME}
303 .if ${MK_DEBUG_FILES} != "no"
304 .if defined(DEBUGMKDIR)
305         ${INSTALL} ${TAG_ARGS:D${TAG_ARGS},dbg} -d ${DESTDIR}${DEBUGFILEDIR}/
306 .endif
307         ${INSTALL} ${TAG_ARGS:D${TAG_ARGS},dbg} -o ${BINOWN} -g ${BINGRP} -m ${DEBUGMODE} \
308             ${PROGNAME}.debug ${DESTDIR}${DEBUGFILEDIR}/${PROGNAME}.debug
309 .endif
310 .endif
311 .endif  # !target(realinstall)
312
313 .if defined(SCRIPTS) && !empty(SCRIPTS)
314 realinstall: _scriptsinstall
315 .ORDER: beforeinstall _scriptsinstall
316
317 SCRIPTSDIR?=    ${BINDIR}
318 SCRIPTSOWN?=    ${BINOWN}
319 SCRIPTSGRP?=    ${BINGRP}
320 SCRIPTSMODE?=   ${BINMODE}
321
322 STAGE_AS_SETS+= scripts
323 stage_as.scripts: ${SCRIPTS}
324 FLAGS.stage_as.scripts= -m ${SCRIPTSMODE}
325 STAGE_FILES_DIR.scripts= ${STAGE_OBJTOP}
326 .for script in ${SCRIPTS}
327 .if defined(SCRIPTSNAME)
328 SCRIPTSNAME_${script:T}?=       ${SCRIPTSNAME}
329 .else
330 SCRIPTSNAME_${script:T}?=       ${script:T:R}
331 .endif
332 SCRIPTSDIR_${script:T}?=        ${SCRIPTSDIR}
333 SCRIPTSOWN_${script:T}?=        ${SCRIPTSOWN}
334 SCRIPTSGRP_${script:T}?=        ${SCRIPTSGRP}
335 SCRIPTSMODE_${script:T}?=       ${SCRIPTSMODE}
336 STAGE_AS_${script:T}=           ${SCRIPTSDIR_${script:T}}/${SCRIPTSNAME_${script:T}}
337 _scriptsinstall: _SCRIPTSINS_${script:T}
338 _SCRIPTSINS_${script:T}: ${script}
339         ${INSTALL} ${TAG_ARGS} -o ${SCRIPTSOWN_${.ALLSRC:T}} \
340             -g ${SCRIPTSGRP_${.ALLSRC:T}} -m ${SCRIPTSMODE_${.ALLSRC:T}} \
341             ${.ALLSRC} \
342             ${DESTDIR}${SCRIPTSDIR_${.ALLSRC:T}}/${SCRIPTSNAME_${.ALLSRC:T}}
343 .endfor
344 .endif
345
346 NLSNAME?=       ${PROG}
347 .include <bsd.nls.mk>
348
349 .include <bsd.confs.mk>
350 .include <bsd.files.mk>
351 .include <bsd.incs.mk>
352
353 LINKOWN?=       ${BINOWN}
354 LINKGRP?=       ${BINGRP}
355 LINKMODE?=      ${BINMODE}
356 .include <bsd.links.mk>
357
358 .if ${MK_MAN} != "no"
359 realinstall: maninstall
360 .ORDER: beforeinstall maninstall
361 .endif
362
363 .endif  # !target(install)
364
365 .if ${MK_MAN} != "no"
366 .include <bsd.man.mk>
367 .endif
368
369 .if defined(HAS_TESTS)
370 MAKE+=                  MK_MAKE_CHECK_USE_SANDBOX=yes
371 SUBDIR_TARGETS+=        check
372 TESTS_LD_LIBRARY_PATH+= ${.OBJDIR}
373 TESTS_PATH+=            ${.OBJDIR}
374 .endif
375
376 .if defined(PROG)
377 OBJS_DEPEND_GUESS+= ${SRCS:M*.h}
378 .endif
379
380 .include <bsd.dep.mk>
381 .include <bsd.clang-analyze.mk>
382 .include <bsd.obj.mk>
383 .include <bsd.sys.mk>