xref: /freebsd/contrib/bmake/mk/sys.mk (revision 4b9d6057)
1# $Id: sys.mk,v 1.57 2023/07/14 16:30:37 sjg Exp $
2#
3#	@(#) Copyright (c) 2003-2023, 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# just in case we are an older bmake
19.MAKE.OS ?= ${HOST_OS}
20
21# _DEBUG_MAKE_FLAGS etc.
22.include <sys.debug.mk>
23
24.if !empty(_DEBUG_MAKE_FLAGS)
25.if ${_DEBUG_MAKE_SYS_DIRS:Uno:@x@${.CURDIR:M$x}@} != ""
26.MAKEFLAGS: ${_DEBUG_MAKE_FLAGS}
27.endif
28.endif
29
30# useful modifiers
31.include <sys.vars.mk>
32
33# we expect a recent bmake
34.if !defined(_TARGETS)
35# some things we do only once
36_TARGETS := ${.TARGETS}
37.-include <sys.env.mk>
38.endif
39
40# we need HOST_TARGET etc below.
41.include <host-target.mk>
42
43# early customizations
44.-include <local.sys.env.mk>
45
46# Popular suffixes for C++
47CXX_SUFFIXES += .cc .cpp .cxx .C
48CXX_SUFFIXES := ${CXX_SUFFIXES:O:u}
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_MODE/DIRDEPS_BUILD \
94	STAGING/DIRDEPS_BUILD \
95	STATIC_DIRDEPS_CACHE/DIRDEPS_CACHE \
96
97.-include <options.mk>
98
99# :Uno incase options.mk not installed
100.if ${MK_DIRDEPS_BUILD:Uno} == "yes"
101.-include <sys.dirdeps.mk>
102.endif
103.if ${MK_META_MODE:Uno} == "yes"
104.-include <meta.sys.mk>
105.MAKE.MODE ?= meta verbose {META_MODE}
106.endif
107# make sure we have a harmless value
108.MAKE.MODE ?= normal
109
110# if you want objdirs make them automatic
111# and do it early before we compute .PATH
112.if ${MK_AUTO_OBJ:Uno} == "yes" || ${MKOBJDIRS:Uno} == "auto"
113.include <auto.obj.mk>
114.endif
115
116.if !empty(SRCTOP)
117.if ${.CURDIR} == ${SRCTOP}
118RELDIR = .
119.elif ${.CURDIR:M${SRCTOP}/*}
120RELDIR := ${.CURDIR:S,${SRCTOP}/,,}
121.endif
122.endif
123
124MACHINE_ARCH.host ?= ${_HOST_ARCH}
125MACHINE_ARCH.${MACHINE} ?= ${MACHINE}
126.if empty(MACHINE_ARCH)
127MACHINE_ARCH = ${MACHINE_ARCH.${MACHINE}}
128.endif
129
130.ifndef ROOT_GROUP
131ROOT_GROUP != sed -n '/:0:/{s/:.*//p;q;}' /etc/group
132.export ROOT_GROUP
133.endif
134
135unix ?= We run ${_HOST_OSNAME}.
136
137# We need a Bourne/POSIX shell
138MAKE_SHELL ?= ${.SHELL:Ush}
139SHELL := ${MAKE_SHELL}
140
141# A race condition in mkdir, means that it can bail if another
142# process made a dir that mkdir expected to.
143# We repeat the mkdir -p a number of times to try and work around this.
144# We stop looping as soon as the dir exists.
145# If we get to the end of the loop, a plain mkdir will issue an error.
146Mkdirs= Mkdirs() { \
147	for d in $$*; do \
148		for i in 1 2 3 4 5 6; do \
149			mkdir -p $$d; \
150			test -d $$d && return 0; \
151		done; \
152		mkdir $$d || exit $$?; \
153	done; }
154
155# this often helps with debugging
156.SUFFIXES:      .cpp-out
157
158.c.cpp-out:
159	@${COMPILE.c:N-c} -E ${.IMPSRC} | grep -v '^[ 	]*$$'
160
161${CXX_SUFFIXES:%=%.cpp-out}:
162	@${COMPILE.cc:N-c} -E ${.IMPSRC} | grep -v '^[ 	]*$$'
163
164# late customizations
165.-include <local.sys.mk>
166
167# if .CURDIR is matched by any entry in DEBUG_MAKE_DIRS we
168# will apply DEBUG_MAKE_FLAGS, now.
169.if !empty(_DEBUG_MAKE_FLAGS)
170.if ${_DEBUG_MAKE_DIRS:Uno:@x@${.CURDIR:M$x}@} != ""
171.MAKEFLAGS: ${_DEBUG_MAKE_FLAGS}
172.endif
173.endif
174