xref: /freebsd/contrib/bmake/mk/sys.mk (revision ee3960cba1068e12fb032a68c46d74841d9edab3)
1# SPDX-License-Identifier: BSD-2-Clause
2#
3# $Id: sys.mk,v 1.61 2024/10/30 23:46:26 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
105.-include <options.mk>
106
107# :Uno incase options.mk not installed
108.if ${MK_DIRDEPS_BUILD:Uno} == "yes"
109.-include <sys.dirdeps.mk>
110.endif
111.if ${MK_META_MODE:Uno} == "yes"
112.-include <meta.sys.mk>
113.MAKE.MODE ?= meta verbose {META_MODE}
114.endif
115# make sure we have a harmless value
116.MAKE.MODE ?= normal
117
118# if you want objdirs make them automatic
119# and do it early before we compute .PATH
120.if ${MK_AUTO_OBJ:Uno} == "yes" || ${MKOBJDIRS:Uno} == "auto"
121.include <auto.obj.mk>
122.endif
123
124.if !empty(SRCTOP)
125.if ${.CURDIR} == ${SRCTOP}
126RELDIR = .
127.elif ${.CURDIR:M${SRCTOP}/*}
128RELDIR := ${.CURDIR:S,${SRCTOP}/,,}
129.endif
130.endif
131
132MACHINE_ARCH.host ?= ${_HOST_ARCH}
133MACHINE_ARCH.${MACHINE} ?= ${MACHINE}
134.if empty(MACHINE_ARCH)
135MACHINE_ARCH = ${MACHINE_ARCH.${MACHINE}}
136.endif
137
138.ifndef ROOT_GROUP
139ROOT_GROUP != sed -n '/:0:/{s/:.*//p;q;}' /etc/group
140.export ROOT_GROUP
141.endif
142
143unix ?= We run ${_HOST_OSNAME}.
144
145# We need a Bourne/POSIX shell
146MAKE_SHELL ?= ${.SHELL:Ush}
147SHELL := ${MAKE_SHELL}
148
149# A race condition in mkdir, means that it can bail if another
150# process made a dir that mkdir expected to.
151# We repeat the mkdir -p a number of times to try and work around this.
152# We stop looping as soon as the dir exists.
153# If we get to the end of the loop, a plain mkdir will issue an error.
154Mkdirs= Mkdirs() { \
155	for d in $$*; do \
156		for i in 1 2 3 4 5 6; do \
157			mkdir -p $$d; \
158			test -d $$d && return 0; \
159		done; \
160		mkdir $$d || exit $$?; \
161	done; }
162
163# pick up generic suffix rules
164.include <suffixes.mk>
165
166# late customizations
167.-include <local.sys.mk>
168
169# if .CURDIR is matched by any entry in DEBUG_MAKE_DIRS we
170# will apply DEBUG_MAKE_FLAGS, now.
171.if !empty(_DEBUG_MAKE_FLAGS)
172.if ${_DEBUG_MAKE_DIRS:Uno:@x@${.CURDIR:M$x}@} != ""
173.MAKEFLAGS: ${_DEBUG_MAKE_FLAGS}
174.endif
175.endif
176