xref: /dflybsd-src/contrib/bmake/mk/sys.mk (revision 9e7ae5a0527a977cab412aede3a532cfe2903bbb)
1*6eef5f0cSAntonio Huete Jimenez# $Id: sys.mk,v 1.54 2022/09/09 17:44:29 sjg Exp $
25f1e34d9SAlexandre Perrin#
35f1e34d9SAlexandre Perrin#	@(#) Copyright (c) 2003-2009, Simon J. Gerraty
45f1e34d9SAlexandre Perrin#
55f1e34d9SAlexandre Perrin#	This file is provided in the hope that it will
65f1e34d9SAlexandre Perrin#	be of use.  There is absolutely NO WARRANTY.
75f1e34d9SAlexandre Perrin#	Permission to copy, redistribute or otherwise
85f1e34d9SAlexandre Perrin#	use this file is hereby granted provided that
95f1e34d9SAlexandre Perrin#	the above copyright notice and this notice are
105f1e34d9SAlexandre Perrin#	left intact.
115f1e34d9SAlexandre Perrin#
125f1e34d9SAlexandre Perrin#	Please send copies of changes and bug-fixes to:
135f1e34d9SAlexandre Perrin#	sjg@crufty.net
145f1e34d9SAlexandre Perrin#
155f1e34d9SAlexandre Perrin
165f1e34d9SAlexandre Perrin# Avoid putting anything platform specific in here.
175f1e34d9SAlexandre Perrin
18ca58f742SDaniel Fojt# _DEBUG_MAKE_FLAGS etc.
19ca58f742SDaniel Fojt.include <sys.debug.mk>
205f1e34d9SAlexandre Perrin
215f1e34d9SAlexandre Perrin.if !empty(_DEBUG_MAKE_FLAGS)
225f1e34d9SAlexandre Perrin.if ${_DEBUG_MAKE_SYS_DIRS:Uno:@x@${.CURDIR:M$x}@} != ""
235f1e34d9SAlexandre Perrin.MAKEFLAGS: ${_DEBUG_MAKE_FLAGS}
245f1e34d9SAlexandre Perrin.endif
255f1e34d9SAlexandre Perrin.endif
265f1e34d9SAlexandre Perrin
27ca58f742SDaniel Fojt# useful modifiers
28ca58f742SDaniel Fojt.include <sys.vars.mk>
295f1e34d9SAlexandre Perrin
305f1e34d9SAlexandre Perrin# we expect a recent bmake
315f1e34d9SAlexandre Perrin.if !defined(_TARGETS)
325f1e34d9SAlexandre Perrin# some things we do only once
335f1e34d9SAlexandre Perrin_TARGETS := ${.TARGETS}
345f1e34d9SAlexandre Perrin.-include <sys.env.mk>
355f1e34d9SAlexandre Perrin.endif
365f1e34d9SAlexandre Perrin
375f1e34d9SAlexandre Perrin# we need HOST_TARGET etc below.
385f1e34d9SAlexandre Perrin.include <host-target.mk>
395f1e34d9SAlexandre Perrin
40f445c897SJohn Marino# early customizations
41f445c897SJohn Marino.-include <local.sys.env.mk>
42f445c897SJohn Marino
43f445c897SJohn Marino# Popular suffixes for C++
44f445c897SJohn MarinoCXX_SUFFIXES += .cc .cpp .cxx .C
45f445c897SJohn MarinoCXX_SUFFIXES := ${CXX_SUFFIXES:O:u}
46f445c897SJohn Marino
475f1e34d9SAlexandre Perrin# find the OS specifics
485f1e34d9SAlexandre Perrin.if defined(SYS_OS_MK)
495f1e34d9SAlexandre Perrin.include <${SYS_OS_MK}>
505f1e34d9SAlexandre Perrin.else
515f1e34d9SAlexandre Perrin_sys_mk =
525f1e34d9SAlexandre Perrin.for x in ${HOST_OSTYPE} ${HOST_TARGET} ${HOST_OS} ${MACHINE} Generic
535f1e34d9SAlexandre Perrin.if empty(_sys_mk)
545f1e34d9SAlexandre Perrin.-include <sys/$x.mk>
555f1e34d9SAlexandre Perrin_sys_mk := ${.MAKE.MAKEFILES:M*/$x.mk}
565f1e34d9SAlexandre Perrin.if !empty(_sys_mk)
575f1e34d9SAlexandre Perrin_sys_mk := sys/${_sys_mk:T}
585f1e34d9SAlexandre Perrin.endif
595f1e34d9SAlexandre Perrin.endif
605f1e34d9SAlexandre Perrin.if empty(_sys_mk)
615f1e34d9SAlexandre Perrin# might be an old style
625f1e34d9SAlexandre Perrin.-include <$x.sys.mk>
635f1e34d9SAlexandre Perrin_sys_mk := ${.MAKE.MAKEFILES:M*/$x.sys.mk:T}
645f1e34d9SAlexandre Perrin.endif
655f1e34d9SAlexandre Perrin.endfor
665f1e34d9SAlexandre Perrin
675f1e34d9SAlexandre PerrinSYS_OS_MK := ${_sys_mk}
685f1e34d9SAlexandre Perrin.export SYS_OS_MK
695f1e34d9SAlexandre Perrin.endif
705f1e34d9SAlexandre Perrin
71*6eef5f0cSAntonio Huete Jimenez# some sys/ may have set this to grep -E
72*6eef5f0cSAntonio Huete JimenezEGREP ?= egrep
73*6eef5f0cSAntonio Huete Jimenez
74f445c897SJohn Marino# some options we need to know early
75f445c897SJohn MarinoOPTIONS_DEFAULT_NO += \
76f445c897SJohn Marino	DIRDEPS_BUILD \
77ca58f742SDaniel Fojt	DIRDEPS_CACHE
78f445c897SJohn Marino
79f445c897SJohn MarinoOPTIONS_DEFAULT_DEPENDENT += \
80f445c897SJohn Marino	AUTO_OBJ/DIRDEPS_BUILD \
81ca58f742SDaniel Fojt	META_MODE/DIRDEPS_BUILD \
82f445c897SJohn Marino	STAGING/DIRDEPS_BUILD \
83a34d5fb1SAntonio Huete Jimenez	STATIC_DIRDEPS_CACHE/DIRDEPS_CACHE \
84f445c897SJohn Marino
85f445c897SJohn Marino.-include <options.mk>
86f445c897SJohn Marino
87*6eef5f0cSAntonio Huete Jimenez# :Uno incase options.mk not installed
88*6eef5f0cSAntonio Huete Jimenez.if ${MK_META_MODE:Uno} == "yes"
89f445c897SJohn Marino.-include <meta.sys.mk>
90*6eef5f0cSAntonio Huete Jimenez.MAKE.MODE ?= meta verbose {META_MODE}
91f445c897SJohn Marino.endif
92f445c897SJohn Marino# make sure we have a harmless value
93f445c897SJohn Marino.MAKE.MODE ?= normal
945f1e34d9SAlexandre Perrin
955f1e34d9SAlexandre Perrin# if you want objdirs make them automatic
96f445c897SJohn Marino# and do it early before we compute .PATH
97f445c897SJohn Marino.if ${MK_AUTO_OBJ:Uno} == "yes" || ${MKOBJDIRS:Uno} == "auto"
985f1e34d9SAlexandre Perrin.include <auto.obj.mk>
995f1e34d9SAlexandre Perrin.endif
1005f1e34d9SAlexandre Perrin
1015f1e34d9SAlexandre Perrin.if !empty(SRCTOP)
1025f1e34d9SAlexandre Perrin.if ${.CURDIR} == ${SRCTOP}
1035f1e34d9SAlexandre PerrinRELDIR = .
1045f1e34d9SAlexandre Perrin.elif ${.CURDIR:M${SRCTOP}/*}
1055f1e34d9SAlexandre PerrinRELDIR := ${.CURDIR:S,${SRCTOP}/,,}
1065f1e34d9SAlexandre Perrin.endif
1075f1e34d9SAlexandre Perrin.endif
1085f1e34d9SAlexandre Perrin
1095f1e34d9SAlexandre PerrinMACHINE_ARCH.host ?= ${_HOST_ARCH}
1105f1e34d9SAlexandre PerrinMACHINE_ARCH.${MACHINE} ?= ${MACHINE}
1115f1e34d9SAlexandre Perrin.if empty(MACHINE_ARCH)
1125f1e34d9SAlexandre PerrinMACHINE_ARCH = ${MACHINE_ARCH.${MACHINE}}
1135f1e34d9SAlexandre Perrin.endif
1145f1e34d9SAlexandre Perrin
1155f1e34d9SAlexandre Perrin.ifndef ROOT_GROUP
1165f1e34d9SAlexandre PerrinROOT_GROUP != sed -n /:0:/s/:.*//p /etc/group
1175f1e34d9SAlexandre Perrin.export ROOT_GROUP
1185f1e34d9SAlexandre Perrin.endif
1195f1e34d9SAlexandre Perrin
1205f1e34d9SAlexandre Perrinunix ?= We run ${_HOST_OSNAME}.
1215f1e34d9SAlexandre Perrin
122ca58f742SDaniel Fojt# We need a Bourne/POSIX shell
123a34d5fb1SAntonio Huete JimenezMAKE_SHELL ?= ${.SHELL:Ush}
124a34d5fb1SAntonio Huete JimenezSHELL := ${MAKE_SHELL}
125ca58f742SDaniel Fojt
1265f1e34d9SAlexandre Perrin# A race condition in mkdir, means that it can bail if another
1275f1e34d9SAlexandre Perrin# process made a dir that mkdir expected to.
1285f1e34d9SAlexandre Perrin# We repeat the mkdir -p a number of times to try and work around this.
1295f1e34d9SAlexandre Perrin# We stop looping as soon as the dir exists.
1305f1e34d9SAlexandre Perrin# If we get to the end of the loop, a plain mkdir will issue an error.
1315f1e34d9SAlexandre PerrinMkdirs= Mkdirs() { \
1325f1e34d9SAlexandre Perrin	for d in $$*; do \
1335f1e34d9SAlexandre Perrin		for i in 1 2 3 4 5 6; do \
1345f1e34d9SAlexandre Perrin			mkdir -p $$d; \
1355f1e34d9SAlexandre Perrin			test -d $$d && return 0; \
1365f1e34d9SAlexandre Perrin		done; \
1375f1e34d9SAlexandre Perrin		mkdir $$d || exit $$?; \
1385f1e34d9SAlexandre Perrin	done; }
1395f1e34d9SAlexandre Perrin
1405f1e34d9SAlexandre Perrin# this often helps with debugging
1415f1e34d9SAlexandre Perrin.SUFFIXES:      .cpp-out
1425f1e34d9SAlexandre Perrin
1435f1e34d9SAlexandre Perrin.c.cpp-out:
1445f1e34d9SAlexandre Perrin	@${COMPILE.c:N-c} -E ${.IMPSRC} | grep -v '^[ 	]*$$'
1455f1e34d9SAlexandre Perrin
146f445c897SJohn Marino${CXX_SUFFIXES:%=%.cpp-out}:
1475f1e34d9SAlexandre Perrin	@${COMPILE.cc:N-c} -E ${.IMPSRC} | grep -v '^[ 	]*$$'
1485f1e34d9SAlexandre Perrin
149f445c897SJohn Marino# late customizations
150f445c897SJohn Marino.-include <local.sys.mk>
1515f1e34d9SAlexandre Perrin
1525f1e34d9SAlexandre Perrin# if .CURDIR is matched by any entry in DEBUG_MAKE_DIRS we
1535f1e34d9SAlexandre Perrin# will apply DEBUG_MAKE_FLAGS, now.
1545f1e34d9SAlexandre Perrin.if !empty(_DEBUG_MAKE_FLAGS)
1555f1e34d9SAlexandre Perrin.if ${_DEBUG_MAKE_DIRS:Uno:@x@${.CURDIR:M$x}@} != ""
1565f1e34d9SAlexandre Perrin.MAKEFLAGS: ${_DEBUG_MAKE_FLAGS}
1575f1e34d9SAlexandre Perrin.endif
1585f1e34d9SAlexandre Perrin.endif
159