1c59c3bf3SSimon J. Gerraty# SPDX-License-Identifier: BSD-2-Clause 2c59c3bf3SSimon J. Gerraty# 3*6a7405f5SSimon J. Gerraty# $Id: sys.mk,v 1.61 2024/10/30 23:46:26 sjg Exp $ 43cbdda60SSimon J. Gerraty# 598875883SSimon J. Gerraty# @(#) Copyright (c) 2003-2023, Simon J. Gerraty 63cbdda60SSimon J. Gerraty# 73cbdda60SSimon J. Gerraty# This file is provided in the hope that it will 83cbdda60SSimon J. Gerraty# be of use. There is absolutely NO WARRANTY. 93cbdda60SSimon J. Gerraty# Permission to copy, redistribute or otherwise 103cbdda60SSimon J. Gerraty# use this file is hereby granted provided that 113cbdda60SSimon J. Gerraty# the above copyright notice and this notice are 123cbdda60SSimon J. Gerraty# left intact. 133cbdda60SSimon J. Gerraty# 143cbdda60SSimon J. Gerraty# Please send copies of changes and bug-fixes to: 153cbdda60SSimon J. Gerraty# sjg@crufty.net 163cbdda60SSimon J. Gerraty# 173cbdda60SSimon J. Gerraty 183cbdda60SSimon J. Gerraty# Avoid putting anything platform specific in here. 193cbdda60SSimon J. Gerraty 2098875883SSimon J. Gerraty# just in case we are an older bmake 2198875883SSimon J. Gerraty.MAKE.OS ?= ${HOST_OS} 2298875883SSimon J. Gerraty 2345447996SSimon J. Gerraty# _DEBUG_MAKE_FLAGS etc. 2445447996SSimon J. Gerraty.include <sys.debug.mk> 253cbdda60SSimon J. Gerraty 263cbdda60SSimon J. Gerraty.if !empty(_DEBUG_MAKE_FLAGS) 273cbdda60SSimon J. Gerraty.if ${_DEBUG_MAKE_SYS_DIRS:Uno:@x@${.CURDIR:M$x}@} != "" 283cbdda60SSimon J. Gerraty.MAKEFLAGS: ${_DEBUG_MAKE_FLAGS} 293cbdda60SSimon J. Gerraty.endif 303cbdda60SSimon J. Gerraty.endif 313cbdda60SSimon J. Gerraty 3245447996SSimon J. Gerraty# useful modifiers 3345447996SSimon J. Gerraty.include <sys.vars.mk> 343cbdda60SSimon J. Gerraty 353cbdda60SSimon J. Gerraty# we expect a recent bmake 363cbdda60SSimon J. Gerraty.if !defined(_TARGETS) 373cbdda60SSimon J. Gerraty# some things we do only once 383cbdda60SSimon J. Gerraty_TARGETS := ${.TARGETS} 393cbdda60SSimon J. Gerraty.-include <sys.env.mk> 403cbdda60SSimon J. Gerraty.endif 413cbdda60SSimon J. Gerraty 423cbdda60SSimon J. Gerraty# we need HOST_TARGET etc below. 433cbdda60SSimon J. Gerraty.include <host-target.mk> 443cbdda60SSimon J. Gerraty 45ac3446e9SSimon J. Gerraty# early customizations 46ac3446e9SSimon J. Gerraty.-include <local.sys.env.mk> 47ac3446e9SSimon J. Gerraty 48e48f47ddSSimon J. Gerraty# Popular suffixes for C++ 49e48f47ddSSimon J. GerratyCXX_SUFFIXES += .cc .cpp .cxx .C 50e48f47ddSSimon J. GerratyCXX_SUFFIXES := ${CXX_SUFFIXES:O:u} 51c59c3bf3SSimon J. Gerraty# and C++ Modules 52c59c3bf3SSimon J. GerratyCCM_SUFFIXES += .ccm 53c59c3bf3SSimon J. GerratyCCM_SUFFIXES := ${CCM_SUFFIXES:O:u} 54c59c3bf3SSimon J. Gerraty# precompiled modules 55c59c3bf3SSimon J. GerratyPCM ?= .pcm 56e48f47ddSSimon J. Gerraty 5798875883SSimon J. GerratySYS_MK ?= ${.PARSEDIR:tA}/${.PARSEFILE} 5898875883SSimon J. GerratySYS_MK := ${SYS_MK} 5998875883SSimon J. Gerraty 6098875883SSimon J. Gerraty# for systems that have an incompatible install 6198875883SSimon J. GerratyINSTALL_SH ?= ${SYS_MK:H}/install-sh 6298875883SSimon J. Gerraty 633cbdda60SSimon J. Gerraty# find the OS specifics 643cbdda60SSimon J. Gerraty.if defined(SYS_OS_MK) 653cbdda60SSimon J. Gerraty.include <${SYS_OS_MK}> 663cbdda60SSimon J. Gerraty.else 673cbdda60SSimon J. Gerraty_sys_mk = 6898875883SSimon J. Gerraty.for x in ${HOST_TARGET} ${.MAKE.OS} ${.MAKE.OS:S,64,,} ${HOST_OSTYPE} ${MACHINE} Generic 693cbdda60SSimon J. Gerraty.if empty(_sys_mk) 703cbdda60SSimon J. Gerraty.-include <sys/$x.mk> 713cbdda60SSimon J. Gerraty_sys_mk := ${.MAKE.MAKEFILES:M*/$x.mk} 723cbdda60SSimon J. Gerraty.if !empty(_sys_mk) 733cbdda60SSimon J. Gerraty_sys_mk := sys/${_sys_mk:T} 743cbdda60SSimon J. Gerraty.endif 753cbdda60SSimon J. Gerraty.endif 763cbdda60SSimon J. Gerraty.if empty(_sys_mk) 773cbdda60SSimon J. Gerraty# might be an old style 783cbdda60SSimon J. Gerraty.-include <$x.sys.mk> 793cbdda60SSimon J. Gerraty_sys_mk := ${.MAKE.MAKEFILES:M*/$x.sys.mk:T} 803cbdda60SSimon J. Gerraty.endif 8198875883SSimon J. Gerraty.if !empty(_sys_mk) && ${MAKE_VERSION} >= 20220924 8298875883SSimon J. Gerraty.break 8398875883SSimon J. Gerraty.endif 843cbdda60SSimon J. Gerraty.endfor 853cbdda60SSimon J. Gerraty 863cbdda60SSimon J. GerratySYS_OS_MK := ${_sys_mk} 873cbdda60SSimon J. Gerraty.export SYS_OS_MK 883cbdda60SSimon J. Gerraty.endif 893cbdda60SSimon J. Gerraty 904fde40d9SSimon J. Gerraty# some sys/ may have set this to grep -E 914fde40d9SSimon J. GerratyEGREP ?= egrep 924fde40d9SSimon J. Gerraty 93ac3446e9SSimon J. Gerraty# some options we need to know early 94ac3446e9SSimon J. GerratyOPTIONS_DEFAULT_NO += \ 95ac3446e9SSimon J. Gerraty DIRDEPS_BUILD \ 961ce939a7SSimon J. Gerraty DIRDEPS_CACHE 97ac3446e9SSimon J. Gerraty 98ac3446e9SSimon J. GerratyOPTIONS_DEFAULT_DEPENDENT += \ 99ac3446e9SSimon J. Gerraty AUTO_OBJ/DIRDEPS_BUILD \ 100*6a7405f5SSimon J. Gerraty META_ERROR_TARGET/DIRDEPS_BUILD \ 1011ce939a7SSimon J. Gerraty META_MODE/DIRDEPS_BUILD \ 102ac3446e9SSimon J. Gerraty STAGING/DIRDEPS_BUILD \ 1032c3632d1SSimon J. Gerraty STATIC_DIRDEPS_CACHE/DIRDEPS_CACHE \ 104ac3446e9SSimon J. Gerraty 105e48f47ddSSimon J. Gerraty.-include <options.mk> 106ac3446e9SSimon J. Gerraty 10712904384SSimon J. Gerraty# :Uno incase options.mk not installed 108c1d01b5fSSimon J. Gerraty.if ${MK_DIRDEPS_BUILD:Uno} == "yes" 109c1d01b5fSSimon J. Gerraty.-include <sys.dirdeps.mk> 110c1d01b5fSSimon J. Gerraty.endif 11112904384SSimon J. Gerraty.if ${MK_META_MODE:Uno} == "yes" 112ac3446e9SSimon J. Gerraty.-include <meta.sys.mk> 11312904384SSimon J. Gerraty.MAKE.MODE ?= meta verbose {META_MODE} 114ac3446e9SSimon J. Gerraty.endif 115ac3446e9SSimon J. Gerraty# make sure we have a harmless value 116ac3446e9SSimon J. Gerraty.MAKE.MODE ?= normal 1173cbdda60SSimon J. Gerraty 1183cbdda60SSimon J. Gerraty# if you want objdirs make them automatic 119ac3446e9SSimon J. Gerraty# and do it early before we compute .PATH 120ac3446e9SSimon J. Gerraty.if ${MK_AUTO_OBJ:Uno} == "yes" || ${MKOBJDIRS:Uno} == "auto" 1213cbdda60SSimon J. Gerraty.include <auto.obj.mk> 1223cbdda60SSimon J. Gerraty.endif 1233cbdda60SSimon J. Gerraty 1243cbdda60SSimon J. Gerraty.if !empty(SRCTOP) 1253cbdda60SSimon J. Gerraty.if ${.CURDIR} == ${SRCTOP} 1263cbdda60SSimon J. GerratyRELDIR = . 1273cbdda60SSimon J. Gerraty.elif ${.CURDIR:M${SRCTOP}/*} 1283cbdda60SSimon J. GerratyRELDIR := ${.CURDIR:S,${SRCTOP}/,,} 1293cbdda60SSimon J. Gerraty.endif 1303cbdda60SSimon J. Gerraty.endif 1313cbdda60SSimon J. Gerraty 1323cbdda60SSimon J. GerratyMACHINE_ARCH.host ?= ${_HOST_ARCH} 1333cbdda60SSimon J. GerratyMACHINE_ARCH.${MACHINE} ?= ${MACHINE} 1343cbdda60SSimon J. Gerraty.if empty(MACHINE_ARCH) 1353cbdda60SSimon J. GerratyMACHINE_ARCH = ${MACHINE_ARCH.${MACHINE}} 1363cbdda60SSimon J. Gerraty.endif 1373cbdda60SSimon J. Gerraty 1383cbdda60SSimon J. Gerraty.ifndef ROOT_GROUP 13998875883SSimon J. GerratyROOT_GROUP != sed -n '/:0:/{s/:.*//p;q;}' /etc/group 1403cbdda60SSimon J. Gerraty.export ROOT_GROUP 1413cbdda60SSimon J. Gerraty.endif 1423cbdda60SSimon J. Gerraty 1433cbdda60SSimon J. Gerratyunix ?= We run ${_HOST_OSNAME}. 1443cbdda60SSimon J. Gerraty 14549caa483SSimon J. Gerraty# We need a Bourne/POSIX shell 14606b9b3e0SSimon J. GerratyMAKE_SHELL ?= ${.SHELL:Ush} 14706b9b3e0SSimon J. GerratySHELL := ${MAKE_SHELL} 14849caa483SSimon J. Gerraty 1493cbdda60SSimon J. Gerraty# A race condition in mkdir, means that it can bail if another 1503cbdda60SSimon J. Gerraty# process made a dir that mkdir expected to. 1513cbdda60SSimon J. Gerraty# We repeat the mkdir -p a number of times to try and work around this. 1523cbdda60SSimon J. Gerraty# We stop looping as soon as the dir exists. 1533cbdda60SSimon J. Gerraty# If we get to the end of the loop, a plain mkdir will issue an error. 1543cbdda60SSimon J. GerratyMkdirs= Mkdirs() { \ 1553cbdda60SSimon J. Gerraty for d in $$*; do \ 1563cbdda60SSimon J. Gerraty for i in 1 2 3 4 5 6; do \ 1573cbdda60SSimon J. Gerraty mkdir -p $$d; \ 1583cbdda60SSimon J. Gerraty test -d $$d && return 0; \ 1593cbdda60SSimon J. Gerraty done; \ 1603cbdda60SSimon J. Gerraty mkdir $$d || exit $$?; \ 1613cbdda60SSimon J. Gerraty done; } 1623cbdda60SSimon J. Gerraty 163c59c3bf3SSimon J. Gerraty# pick up generic suffix rules 164c59c3bf3SSimon J. Gerraty.include <suffixes.mk> 1653cbdda60SSimon J. Gerraty 166ac3446e9SSimon J. Gerraty# late customizations 167ac3446e9SSimon J. Gerraty.-include <local.sys.mk> 1683cbdda60SSimon J. Gerraty 1693cbdda60SSimon J. Gerraty# if .CURDIR is matched by any entry in DEBUG_MAKE_DIRS we 1703cbdda60SSimon J. Gerraty# will apply DEBUG_MAKE_FLAGS, now. 1713cbdda60SSimon J. Gerraty.if !empty(_DEBUG_MAKE_FLAGS) 1723cbdda60SSimon J. Gerraty.if ${_DEBUG_MAKE_DIRS:Uno:@x@${.CURDIR:M$x}@} != "" 1733cbdda60SSimon J. Gerraty.MAKEFLAGS: ${_DEBUG_MAKE_FLAGS} 1743cbdda60SSimon J. Gerraty.endif 1753cbdda60SSimon J. Gerraty.endif 176