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