]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - share/mk/sys.mk
MFV r296511: 6537 Panic on zpool scrub with DEBUG kernel
[FreeBSD/FreeBSD.git] / share / mk / sys.mk
1 #       from: @(#)sys.mk        8.2 (Berkeley) 3/21/94
2 # $FreeBSD$
3
4 unix            ?=      We run FreeBSD, not UNIX.
5 .FreeBSD        ?=      true
6
7 .if !defined(%POSIX)
8 #
9 # MACHINE_CPUARCH defines a collection of MACHINE_ARCH.  Machines with
10 # the same MACHINE_ARCH can run each other's binaries, so it necessarily
11 # has word size and endian swizzled in.  However, support files for
12 # these machines often are shared amongst all combinations of size
13 # and/or endian.  This is called MACHINE_CPU in NetBSD, but that's used
14 # for something different in FreeBSD.
15 #
16 MACHINE_CPUARCH=${MACHINE_ARCH:C/mips(n32|64)?(el)?/mips/:C/arm(v6)?(eb|hf)?/arm/:C/powerpc64/powerpc/:C/riscv64/riscv/}
17 .endif
18
19
20 # Some options we need now
21 __DEFAULT_NO_OPTIONS= \
22         DIRDEPS_BUILD \
23         DIRDEPS_CACHE
24
25 __DEFAULT_DEPENDENT_OPTIONS= \
26         AUTO_OBJ/DIRDEPS_BUILD \
27         META_MODE/DIRDEPS_BUILD \
28         STAGING/DIRDEPS_BUILD \
29         SYSROOT/DIRDEPS_BUILD
30
31 __ENV_ONLY_OPTIONS:= \
32         ${__DEFAULT_NO_OPTIONS} \
33         ${__DEFAULT_YES_OPTIONS} \
34         ${__DEFAULT_DEPENDENT_OPTIONS:H}
35
36 # early include for customization
37 # see local.sys.mk below
38 # Not included when building in fmake compatibility mode (still needed
39 # for older system support)
40 .if defined(.PARSEDIR)
41 .sinclude <local.sys.env.mk>
42
43 .include <bsd.mkopt.mk>
44
45 .if ${MK_DIRDEPS_BUILD} == "yes"
46 .sinclude <meta.sys.mk>
47 .elif ${MK_META_MODE} == "yes" && defined(.MAKEFLAGS) && ${.MAKEFLAGS:M-B} == ""
48 # verbose will show .MAKE.META.PREFIX for each target.
49 META_MODE=      meta verbose
50 # silent will hide command output if a .meta file is created.
51 .if !defined(NO_SILENT)
52 META_MODE+=     silent=yes
53 .endif
54 .if !exists(/dev/filemon)
55 META_MODE+= nofilemon
56 .endif
57 .endif
58 META_MODE?= normal
59 .export META_MODE
60 .MAKE.MODE?= ${META_MODE}
61
62 .if ${MK_AUTO_OBJ} == "yes"
63 # This needs to be done early - before .PATH is computed
64 # Don't do this for 'make showconfig' as it enables all options where meta mode
65 # is not expected.
66 .if !make(showconfig)
67 .sinclude <auto.obj.mk>
68 .endif
69 .endif
70 .else # bmake
71 .include <bsd.mkopt.mk>
72 .endif
73
74 # If the special target .POSIX appears (without prerequisites or
75 # commands) before the first noncomment line in the makefile, make shall
76 # process the makefile as specified by the Posix 1003.2 specification.
77 # make(1) sets the special macro %POSIX in this case (to the actual
78 # value "1003.2", for what it's worth).
79 #
80 # The rules below use this macro to distinguish between Posix-compliant
81 # and default behaviour.
82 #
83 # This functionality is currently broken, since make(1) processes sys.mk
84 # before reading any other files, and consequently has no opportunity to
85 # set the %POSIX macro before we read this point.
86
87 .if defined(%POSIX)
88 .SUFFIXES:      .o .c .y .l .a .sh .f
89 .else
90 .SUFFIXES:      .out .a .ln .o .c .cc .cpp .cxx .C .m .F .f .e .r .y .l .S .asm .s .cl .p .h .sh
91 .endif
92
93 AR              ?=      ar
94 .if defined(%POSIX)
95 ARFLAGS         ?=      -rv
96 .else
97 ARFLAGS         ?=      -crD
98 .endif
99 RANLIB          ?=      ranlib
100 .if !defined(%POSIX)
101 RANLIBFLAGS     ?=      -D
102 .endif
103
104 AS              ?=      as
105 AFLAGS          ?=
106 ACFLAGS         ?=
107
108 .if defined(%POSIX)
109 CC              ?=      c89
110 CFLAGS          ?=      -O
111 .else
112 CC              ?=      cc
113 .if ${MACHINE_CPUARCH} == "arm" || ${MACHINE_CPUARCH} == "mips"
114 CFLAGS          ?=      -O -pipe
115 .else
116 CFLAGS          ?=      -O2 -pipe
117 .endif
118 .if defined(NO_STRICT_ALIASING)
119 CFLAGS          +=      -fno-strict-aliasing
120 .endif
121 .endif
122 PO_CFLAGS       ?=      ${CFLAGS}
123
124 # cp(1) is used to copy source files to ${.OBJDIR}, make sure it can handle
125 # read-only files as non-root by passing -f.
126 CP              ?=      cp -f
127
128 CPP             ?=      cpp
129
130 # C Type Format data is required for DTrace
131 CTFFLAGS        ?=      -L VERSION
132
133 CTFCONVERT      ?=      ctfconvert
134 CTFMERGE        ?=      ctfmerge
135
136 .if defined(CFLAGS) && (${CFLAGS:M-g} != "")
137 CTFFLAGS        +=      -g
138 .endif
139
140 CXX             ?=      c++
141 CXXFLAGS        ?=      ${CFLAGS:N-std=*:N-Wnested-externs:N-W*-prototypes:N-Wno-pointer-sign:N-Wold-style-definition}
142 PO_CXXFLAGS     ?=      ${CXXFLAGS}
143
144 DTRACE          ?=      dtrace
145 DTRACEFLAGS     ?=      -C -x nolibs
146
147 .if empty(.MAKEFLAGS:M-s)
148 ECHO            ?=      echo
149 ECHODIR         ?=      echo
150 .else
151 ECHO            ?=      true
152 .if ${.MAKEFLAGS:M-s} == "-s"
153 ECHODIR         ?=      echo
154 .else
155 ECHODIR         ?=      true
156 .endif
157 .endif
158
159 .if ${.MAKEFLAGS:M-N}
160 # bmake -N is supposed to skip executing anything but it does not skip
161 # exeucting '+' commands.  The '+' feature is used where .MAKE
162 # is not safe for the entire target.  -N is intended to skip building sub-makes
163 # so it executing '+' commands is not right.  Work around the bug by not
164 # setting '+' when -N is used.
165 _+_             ?=
166 .else
167 _+_             ?=      +
168 .endif
169
170 .if defined(%POSIX)
171 FC              ?=      fort77
172 FFLAGS          ?=      -O 1
173 .else
174 FC              ?=      f77
175 FFLAGS          ?=      -O
176 .endif
177 EFLAGS          ?=
178
179 INSTALL         ?=      install
180
181 LEX             ?=      lex
182 LFLAGS          ?=
183
184 LD              ?=      ld
185 LDFLAGS         ?=                              # LDFLAGS is for CC, 
186 _LDFLAGS        =       ${LDFLAGS:S/-Wl,//g}    # strip -Wl, for LD
187
188 LINT            ?=      lint
189 LINTFLAGS       ?=      -cghapbx
190 LINTKERNFLAGS   ?=      ${LINTFLAGS}
191 LINTOBJFLAGS    ?=      -cghapbxu -i
192 LINTOBJKERNFLAGS?=      ${LINTOBJFLAGS}
193 LINTLIBFLAGS    ?=      -cghapbxu -C ${LIB}
194
195 MAKE            ?=      make
196
197 .if !defined(%POSIX)
198 NM              ?=      nm
199 NMFLAGS         ?=
200
201 OBJC            ?=      cc
202 OBJCFLAGS       ?=      ${OBJCINCLUDES} ${CFLAGS} -Wno-import
203
204 OBJCOPY         ?=      objcopy
205
206 OBJDUMP         ?=      objdump
207
208 PC              ?=      pc
209 PFLAGS          ?=
210
211 RC              ?=      f77
212 RFLAGS          ?=
213 .endif
214
215 SHELL           ?=      sh
216
217 .if !defined(%POSIX)
218 SIZE            ?=      size
219 .endif
220
221 YACC            ?=      yacc
222 .if defined(%POSIX)
223 YFLAGS          ?=
224 .else
225 YFLAGS          ?=      -d
226 .endif
227
228 .if defined(%POSIX)
229
230 # Posix 1003.2 mandated rules
231 #
232 # Quoted directly from the Posix 1003.2 draft, only the macros
233 # $@, $< and $* have been replaced by ${.TARGET}, ${.IMPSRC}, and
234 # ${.PREFIX}, resp.
235
236 # SINGLE SUFFIX RULES
237 .c:
238         ${CC} ${CFLAGS} ${LDFLAGS} -o ${.TARGET} ${.IMPSRC}
239
240 .f:
241         ${FC} ${FFLAGS} ${LDFLAGS} -o ${.TARGET} ${.IMPSRC}
242
243 .sh:
244         cp -f ${.IMPSRC} ${.TARGET}
245         chmod a+x ${.TARGET}
246
247 # DOUBLE SUFFIX RULES
248
249 .c.o:
250         ${CC} ${CFLAGS} -c ${.IMPSRC}
251
252 .f.o:
253         ${FC} ${FFLAGS} -c ${.IMPSRC}
254
255 .y.o:
256         ${YACC} ${YFLAGS} ${.IMPSRC}
257         ${CC} ${CFLAGS} -c y.tab.c
258         rm -f y.tab.c
259         mv y.tab.o ${.TARGET}
260
261 .l.o:
262         ${LEX} ${LFLAGS} ${.IMPSRC}
263         ${CC} ${CFLAGS} -c lex.yy.c
264         rm -f lex.yy.c
265         mv lex.yy.o ${.TARGET}
266
267 .y.c:
268         ${YACC} ${YFLAGS} ${.IMPSRC}
269         mv y.tab.c ${.TARGET}
270
271 .l.c:
272         ${LEX} ${LFLAGS} ${.IMPSRC}
273         mv lex.yy.c ${.TARGET}
274
275 .c.a:
276         ${CC} ${CFLAGS} -c ${.IMPSRC}
277         ${AR} ${ARFLAGS} ${.TARGET} ${.PREFIX}.o
278         rm -f ${.PREFIX}.o
279
280 .f.a:
281         ${FC} ${FFLAGS} -c ${.IMPSRC}
282         ${AR} ${ARFLAGS} ${.TARGET} ${.PREFIX}.o
283         rm -f ${.PREFIX}.o
284
285 .else
286
287 # non-Posix rule set
288
289 .sh:
290         cp -f ${.IMPSRC} ${.TARGET}
291         chmod a+x ${.TARGET}
292
293 .c.ln:
294         ${LINT} ${LINTOBJFLAGS} ${CFLAGS:M-[DIU]*} ${.IMPSRC} || \
295             touch ${.TARGET}
296
297 .cc.ln .C.ln .cpp.ln .cxx.ln:
298         ${LINT} ${LINTOBJFLAGS} ${CXXFLAGS:M-[DIU]*} ${.IMPSRC} || \
299             touch ${.TARGET}
300
301 .c:
302         ${CC} ${CFLAGS} ${LDFLAGS} ${.IMPSRC} ${LDLIBS} -o ${.TARGET}
303         ${CTFCONVERT_CMD}
304
305 .c.o:
306         ${CC} ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET}
307         ${CTFCONVERT_CMD}
308
309 .cc .cpp .cxx .C:
310         ${CXX} ${CXXFLAGS} ${LDFLAGS} ${.IMPSRC} ${LDLIBS} -o ${.TARGET}
311
312 .cc.o .cpp.o .cxx.o .C.o:
313         ${CXX} ${CXXFLAGS} -c ${.IMPSRC} -o ${.TARGET}
314
315 .m.o:
316         ${OBJC} ${OBJCFLAGS} -c ${.IMPSRC} -o ${.TARGET}
317         ${CTFCONVERT_CMD}
318
319 .p.o:
320         ${PC} ${PFLAGS} -c ${.IMPSRC} -o ${.TARGET}
321         ${CTFCONVERT_CMD}
322
323 .e .r .F .f:
324         ${FC} ${RFLAGS} ${EFLAGS} ${FFLAGS} ${LDFLAGS} ${.IMPSRC} ${LDLIBS} \
325             -o ${.TARGET}
326
327 .e.o .r.o .F.o .f.o:
328         ${FC} ${RFLAGS} ${EFLAGS} ${FFLAGS} -c ${.IMPSRC} -o ${.TARGET}
329
330 .S.o:
331         ${CC:N${CCACHE_BIN}} ${CFLAGS} ${ACFLAGS} -c ${.IMPSRC} -o ${.TARGET}
332         ${CTFCONVERT_CMD}
333
334 .asm.o:
335         ${CC:N${CCACHE_BIN}} -x assembler-with-cpp ${CFLAGS} ${ACFLAGS} -c ${.IMPSRC} \
336             -o ${.TARGET}
337         ${CTFCONVERT_CMD}
338
339 .s.o:
340         ${AS} ${AFLAGS} -o ${.TARGET} ${.IMPSRC}
341         ${CTFCONVERT_CMD}
342
343 # XXX not -j safe
344 .y.o:
345         ${YACC} ${YFLAGS} ${.IMPSRC}
346         ${CC} ${CFLAGS} -c y.tab.c -o ${.TARGET}
347         rm -f y.tab.c
348         ${CTFCONVERT_CMD}
349
350 .l.o:
351         ${LEX} -t ${LFLAGS} ${.IMPSRC} > ${.PREFIX}.tmp.c
352         ${CC} ${CFLAGS} -c ${.PREFIX}.tmp.c -o ${.TARGET}
353         rm -f ${.PREFIX}.tmp.c
354         ${CTFCONVERT_CMD}
355
356 # XXX not -j safe
357 .y.c:
358         ${YACC} ${YFLAGS} ${.IMPSRC}
359         mv y.tab.c ${.TARGET}
360
361 .l.c:
362         ${LEX} -t ${LFLAGS} ${.IMPSRC} > ${.TARGET}
363
364 .s.out .c.out .o.out:
365         ${CC} ${CFLAGS} ${LDFLAGS} ${.IMPSRC} ${LDLIBS} -o ${.TARGET}
366         ${CTFCONVERT_CMD}
367
368 .f.out .F.out .r.out .e.out:
369         ${FC} ${EFLAGS} ${RFLAGS} ${FFLAGS} ${LDFLAGS} ${.IMPSRC} \
370             ${LDLIBS} -o ${.TARGET}
371         rm -f ${.PREFIX}.o
372         ${CTFCONVERT_CMD}
373
374 # XXX not -j safe
375 .y.out:
376         ${YACC} ${YFLAGS} ${.IMPSRC}
377         ${CC} ${CFLAGS} ${LDFLAGS} y.tab.c ${LDLIBS} -ly -o ${.TARGET}
378         rm -f y.tab.c
379         ${CTFCONVERT_CMD}
380
381 .l.out:
382         ${LEX} -t ${LFLAGS} ${.IMPSRC} > ${.PREFIX}.tmp.c
383         ${CC} ${CFLAGS} ${LDFLAGS} ${.PREFIX}.tmp.c ${LDLIBS} -ll -o ${.TARGET}
384         rm -f ${.PREFIX}.tmp.c
385         ${CTFCONVERT_CMD}
386
387 # Pull in global settings.
388 __MAKE_CONF?=/etc/make.conf
389 .if exists(${__MAKE_CONF})
390 .include "${__MAKE_CONF}"
391 .endif
392
393 # late include for customization
394 .sinclude <local.sys.mk>
395
396 .if defined(__MAKE_SHELL) && !empty(__MAKE_SHELL)
397 SHELL=  ${__MAKE_SHELL}
398 .SHELL: path=${__MAKE_SHELL}
399 .endif
400
401 # Tell bmake to expand -V VAR by default
402 .MAKE.EXPAND_VARIABLES= yes
403
404 # Tell bmake the makefile preference
405 .MAKE.MAKEFILE_PREFERENCE= BSDmakefile makefile Makefile
406
407 # Tell bmake to always pass job tokens, regardless of target depending on
408 # .MAKE or looking like ${MAKE}/${.MAKE}/$(MAKE)/$(.MAKE)/make.
409 .MAKE.ALWAYS_PASS_JOB_QUEUE= yes
410
411 # By default bmake does *not* use set -e
412 # when running target scripts, this is a problem for many makefiles here.
413 # So define a shell that will do what FreeBSD expects.
414 .ifndef WITHOUT_SHELL_ERRCTL
415 __MAKE_SHELL?=/bin/sh
416 .SHELL: name=sh \
417         quiet="set -" echo="set -v" filter="set -" \
418         hasErrCtl=yes check="set -e" ignore="set +e" \
419         echoFlag=v errFlag=e \
420         path=${__MAKE_SHELL}
421 .endif
422
423 # Hack for ports compatibility. Historically, ports makefiles have
424 # assumed they can examine MACHINE_CPU without including anything
425 # because this was automatically included in sys.mk. For /usr/src,
426 # this file has moved to being included from bsd.opts.mk. Until all
427 # the ports files are modernized, and a reasonable transition
428 # period has passed, include it while we're in a ports tree here
429 # to preserve historic behavior.
430 .if exists(${.CURDIR}/../../Mk/bsd.port.mk)
431 .include <bsd.cpu.mk>
432 .endif
433
434 .endif # ! Posix