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