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