xref: /freebsd/contrib/bmake/mk/sys.mk (revision bdd1243df58e60e85101c09001d9812a789b6bc4)
1# $Id: sys.mk,v 1.55 2023/05/10 19:23:26 sjg Exp $
2#
3#	@(#) Copyright (c) 2003-2009, Simon J. Gerraty
4#
5#	This file is provided in the hope that it will
6#	be of use.  There is absolutely NO WARRANTY.
7#	Permission to copy, redistribute or otherwise
8#	use this file is hereby granted provided that
9#	the above copyright notice and this notice are
10#	left intact.
11#
12#	Please send copies of changes and bug-fixes to:
13#	sjg@crufty.net
14#
15
16# Avoid putting anything platform specific in here.
17
18# _DEBUG_MAKE_FLAGS etc.
19.include <sys.debug.mk>
20
21.if !empty(_DEBUG_MAKE_FLAGS)
22.if ${_DEBUG_MAKE_SYS_DIRS:Uno:@x@${.CURDIR:M$x}@} != ""
23.MAKEFLAGS: ${_DEBUG_MAKE_FLAGS}
24.endif
25.endif
26
27# useful modifiers
28.include <sys.vars.mk>
29
30# we expect a recent bmake
31.if !defined(_TARGETS)
32# some things we do only once
33_TARGETS := ${.TARGETS}
34.-include <sys.env.mk>
35.endif
36
37# we need HOST_TARGET etc below.
38.include <host-target.mk>
39
40# early customizations
41.-include <local.sys.env.mk>
42
43# Popular suffixes for C++
44CXX_SUFFIXES += .cc .cpp .cxx .C
45CXX_SUFFIXES := ${CXX_SUFFIXES:O:u}
46
47# find the OS specifics
48.if defined(SYS_OS_MK)
49.include <${SYS_OS_MK}>
50.else
51_sys_mk =
52.for x in ${HOST_OSTYPE} ${HOST_TARGET} ${HOST_OS} ${MACHINE} Generic
53.if empty(_sys_mk)
54.-include <sys/$x.mk>
55_sys_mk := ${.MAKE.MAKEFILES:M*/$x.mk}
56.if !empty(_sys_mk)
57_sys_mk := sys/${_sys_mk:T}
58.endif
59.endif
60.if empty(_sys_mk)
61# might be an old style
62.-include <$x.sys.mk>
63_sys_mk := ${.MAKE.MAKEFILES:M*/$x.sys.mk:T}
64.endif
65.endfor
66
67SYS_OS_MK := ${_sys_mk}
68.export SYS_OS_MK
69.endif
70
71# some sys/ may have set this to grep -E
72EGREP ?= egrep
73
74# some options we need to know early
75OPTIONS_DEFAULT_NO += \
76	DIRDEPS_BUILD \
77	DIRDEPS_CACHE
78
79OPTIONS_DEFAULT_DEPENDENT += \
80	AUTO_OBJ/DIRDEPS_BUILD \
81	META_MODE/DIRDEPS_BUILD \
82	STAGING/DIRDEPS_BUILD \
83	STATIC_DIRDEPS_CACHE/DIRDEPS_CACHE \
84
85.-include <options.mk>
86
87# :Uno incase options.mk not installed
88.if ${MK_DIRDEPS_BUILD:Uno} == "yes"
89.-include <sys.dirdeps.mk>
90.endif
91.if ${MK_META_MODE:Uno} == "yes"
92.-include <meta.sys.mk>
93.MAKE.MODE ?= meta verbose {META_MODE}
94.endif
95# make sure we have a harmless value
96.MAKE.MODE ?= normal
97
98# if you want objdirs make them automatic
99# and do it early before we compute .PATH
100.if ${MK_AUTO_OBJ:Uno} == "yes" || ${MKOBJDIRS:Uno} == "auto"
101.include <auto.obj.mk>
102.endif
103
104.if !empty(SRCTOP)
105.if ${.CURDIR} == ${SRCTOP}
106RELDIR = .
107.elif ${.CURDIR:M${SRCTOP}/*}
108RELDIR := ${.CURDIR:S,${SRCTOP}/,,}
109.endif
110.endif
111
112MACHINE_ARCH.host ?= ${_HOST_ARCH}
113MACHINE_ARCH.${MACHINE} ?= ${MACHINE}
114.if empty(MACHINE_ARCH)
115MACHINE_ARCH = ${MACHINE_ARCH.${MACHINE}}
116.endif
117
118.ifndef ROOT_GROUP
119ROOT_GROUP != sed -n /:0:/s/:.*//p /etc/group
120.export ROOT_GROUP
121.endif
122
123unix ?= We run ${_HOST_OSNAME}.
124
125# We need a Bourne/POSIX shell
126MAKE_SHELL ?= ${.SHELL:Ush}
127SHELL := ${MAKE_SHELL}
128
129# A race condition in mkdir, means that it can bail if another
130# process made a dir that mkdir expected to.
131# We repeat the mkdir -p a number of times to try and work around this.
132# We stop looping as soon as the dir exists.
133# If we get to the end of the loop, a plain mkdir will issue an error.
134Mkdirs= Mkdirs() { \
135	for d in $$*; do \
136		for i in 1 2 3 4 5 6; do \
137			mkdir -p $$d; \
138			test -d $$d && return 0; \
139		done; \
140		mkdir $$d || exit $$?; \
141	done; }
142
143# this often helps with debugging
144.SUFFIXES:      .cpp-out
145
146.c.cpp-out:
147	@${COMPILE.c:N-c} -E ${.IMPSRC} | grep -v '^[ 	]*$$'
148
149${CXX_SUFFIXES:%=%.cpp-out}:
150	@${COMPILE.cc:N-c} -E ${.IMPSRC} | grep -v '^[ 	]*$$'
151
152# late customizations
153.-include <local.sys.mk>
154
155# if .CURDIR is matched by any entry in DEBUG_MAKE_DIRS we
156# will apply DEBUG_MAKE_FLAGS, now.
157.if !empty(_DEBUG_MAKE_FLAGS)
158.if ${_DEBUG_MAKE_DIRS:Uno:@x@${.CURDIR:M$x}@} != ""
159.MAKEFLAGS: ${_DEBUG_MAKE_FLAGS}
160.endif
161.endif
162