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