1321964Ssjg# $Id: sys.mk,v 1.45 2017/02/05 01:26:13 sjg Exp $ 2246149Ssjg# 3246149Ssjg# @(#) Copyright (c) 2003-2009, Simon J. Gerraty 4246149Ssjg# 5246149Ssjg# This file is provided in the hope that it will 6246149Ssjg# be of use. There is absolutely NO WARRANTY. 7246149Ssjg# Permission to copy, redistribute or otherwise 8246149Ssjg# use this file is hereby granted provided that 9246149Ssjg# the above copyright notice and this notice are 10246149Ssjg# left intact. 11246149Ssjg# 12246149Ssjg# Please send copies of changes and bug-fixes to: 13246149Ssjg# sjg@crufty.net 14246149Ssjg# 15246149Ssjg 16246149Ssjg# Avoid putting anything platform specific in here. 17246149Ssjg 18321964Ssjg# _DEBUG_MAKE_FLAGS etc. 19321964Ssjg.include <sys.debug.mk> 20246149Ssjg 21246149Ssjg.if !empty(_DEBUG_MAKE_FLAGS) 22246149Ssjg.if ${_DEBUG_MAKE_SYS_DIRS:Uno:@x@${.CURDIR:M$x}@} != "" 23246149Ssjg.MAKEFLAGS: ${_DEBUG_MAKE_FLAGS} 24246149Ssjg.endif 25246149Ssjg.endif 26246149Ssjg 27321964Ssjg# useful modifiers 28321964Ssjg.include <sys.vars.mk> 29246149Ssjg 30246149Ssjg# we expect a recent bmake 31246149Ssjg.if !defined(_TARGETS) 32246149Ssjg# some things we do only once 33246149Ssjg_TARGETS := ${.TARGETS} 34246149Ssjg.-include <sys.env.mk> 35246149Ssjg.endif 36246149Ssjg 37246149Ssjg# we need HOST_TARGET etc below. 38246149Ssjg.include <host-target.mk> 39246149Ssjg 40292068Ssjg# early customizations 41292068Ssjg.-include <local.sys.env.mk> 42292068Ssjg 43321964Ssjg# Popular suffixes for C++ 44321964SsjgCXX_SUFFIXES += .cc .cpp .cxx .C 45321964SsjgCXX_SUFFIXES := ${CXX_SUFFIXES:O:u} 46321964Ssjg 47246149Ssjg# find the OS specifics 48246149Ssjg.if defined(SYS_OS_MK) 49246149Ssjg.include <${SYS_OS_MK}> 50246149Ssjg.else 51246149Ssjg_sys_mk = 52246149Ssjg.for x in ${HOST_OSTYPE} ${HOST_TARGET} ${HOST_OS} ${MACHINE} Generic 53246149Ssjg.if empty(_sys_mk) 54246149Ssjg.-include <sys/$x.mk> 55246149Ssjg_sys_mk := ${.MAKE.MAKEFILES:M*/$x.mk} 56246149Ssjg.if !empty(_sys_mk) 57246149Ssjg_sys_mk := sys/${_sys_mk:T} 58246149Ssjg.endif 59246149Ssjg.endif 60246149Ssjg.if empty(_sys_mk) 61246149Ssjg# might be an old style 62246149Ssjg.-include <$x.sys.mk> 63246149Ssjg_sys_mk := ${.MAKE.MAKEFILES:M*/$x.sys.mk:T} 64246149Ssjg.endif 65246149Ssjg.endfor 66246149Ssjg 67246149SsjgSYS_OS_MK := ${_sys_mk} 68246149Ssjg.export SYS_OS_MK 69246149Ssjg.endif 70246149Ssjg 71292068Ssjg# some options we need to know early 72292068SsjgOPTIONS_DEFAULT_NO += \ 73292068Ssjg DIRDEPS_BUILD \ 74321964Ssjg DIRDEPS_CACHE 75246149Ssjg 76292068SsjgOPTIONS_DEFAULT_DEPENDENT += \ 77292068Ssjg AUTO_OBJ/DIRDEPS_BUILD \ 78321964Ssjg META_MODE/DIRDEPS_BUILD \ 79292068Ssjg STAGING/DIRDEPS_BUILD \ 80292068Ssjg 81321964Ssjg.-include <options.mk> 82292068Ssjg 83292068Ssjg.if ${MK_DIRDEPS_BUILD:Uno} == "yes" 84292068SsjgMK_META_MODE = yes 85292068Ssjg.-include <meta.sys.mk> 86292068Ssjg.elif ${MK_META_MODE:Uno} == "yes" 87292068Ssjg.MAKE.MODE = meta verbose 88292068Ssjg.endif 89292068Ssjg# make sure we have a harmless value 90292068Ssjg.MAKE.MODE ?= normal 91292068Ssjg 92246149Ssjg# if you want objdirs make them automatic 93292068Ssjg# and do it early before we compute .PATH 94292068Ssjg.if ${MK_AUTO_OBJ:Uno} == "yes" || ${MKOBJDIRS:Uno} == "auto" 95246149Ssjg.include <auto.obj.mk> 96246149Ssjg.endif 97246149Ssjg 98246149Ssjg.if !empty(SRCTOP) 99246149Ssjg.if ${.CURDIR} == ${SRCTOP} 100246149SsjgRELDIR = . 101246149Ssjg.elif ${.CURDIR:M${SRCTOP}/*} 102246149SsjgRELDIR := ${.CURDIR:S,${SRCTOP}/,,} 103246149Ssjg.endif 104246149Ssjg.endif 105246149Ssjg 106246149SsjgMACHINE_ARCH.host ?= ${_HOST_ARCH} 107246149SsjgMACHINE_ARCH.${MACHINE} ?= ${MACHINE} 108246149Ssjg.if empty(MACHINE_ARCH) 109246149SsjgMACHINE_ARCH = ${MACHINE_ARCH.${MACHINE}} 110246149Ssjg.endif 111246149Ssjg 112246149Ssjg.ifndef ROOT_GROUP 113246149SsjgROOT_GROUP != sed -n /:0:/s/:.*//p /etc/group 114246149Ssjg.export ROOT_GROUP 115246149Ssjg.endif 116246149Ssjg 117246149Ssjgunix ?= We run ${_HOST_OSNAME}. 118246149Ssjg 119246149Ssjg# A race condition in mkdir, means that it can bail if another 120246149Ssjg# process made a dir that mkdir expected to. 121246149Ssjg# We repeat the mkdir -p a number of times to try and work around this. 122246149Ssjg# We stop looping as soon as the dir exists. 123246149Ssjg# If we get to the end of the loop, a plain mkdir will issue an error. 124246149SsjgMkdirs= Mkdirs() { \ 125246149Ssjg for d in $$*; do \ 126246149Ssjg for i in 1 2 3 4 5 6; do \ 127246149Ssjg mkdir -p $$d; \ 128246149Ssjg test -d $$d && return 0; \ 129246149Ssjg done; \ 130246149Ssjg mkdir $$d || exit $$?; \ 131246149Ssjg done; } 132246149Ssjg 133246149Ssjg# this often helps with debugging 134246149Ssjg.SUFFIXES: .cpp-out 135246149Ssjg 136246149Ssjg.c.cpp-out: 137246149Ssjg @${COMPILE.c:N-c} -E ${.IMPSRC} | grep -v '^[ ]*$$' 138246149Ssjg 139321964Ssjg${CXX_SUFFIXES:%=%.cpp-out}: 140246149Ssjg @${COMPILE.cc:N-c} -E ${.IMPSRC} | grep -v '^[ ]*$$' 141246149Ssjg 142292068Ssjg# late customizations 143292068Ssjg.-include <local.sys.mk> 144246149Ssjg 145246149Ssjg# if .CURDIR is matched by any entry in DEBUG_MAKE_DIRS we 146246149Ssjg# will apply DEBUG_MAKE_FLAGS, now. 147246149Ssjg.if !empty(_DEBUG_MAKE_FLAGS) 148246149Ssjg.if ${_DEBUG_MAKE_DIRS:Uno:@x@${.CURDIR:M$x}@} != "" 149246149Ssjg.MAKEFLAGS: ${_DEBUG_MAKE_FLAGS} 150246149Ssjg.endif 151246149Ssjg.endif 152