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