1292068Ssjg# $Id: sys.mk,v 1.41 2015/11/14 20:20:34 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 18246149Ssjg# We use the following paradigm for preventing multiple inclusion. 19246149Ssjg# It relies on the fact that conditionals and dependencies are resolved 20246149Ssjg# at the time they are read. 21246149Ssjg# 22246149Ssjg# _this ?= ${.PARSEFILE} 23246149Ssjg# .if !target(__${_this}__) 24246149Ssjg# __${_this}__: 25246149Ssjg# 26246149Ssjg.if ${MAKE_VERSION:U0} > 20100408 27246149Ssjg_this = ${.PARSEDIR:tA}/${.PARSEFILE} 28246149Ssjg.else 29246149Ssjg_this = ${.PARSEDIR}/${.PARSEFILE} 30246149Ssjg.endif 31246149Ssjg 32246149Ssjg# Sometimes we want to turn on debugging in just one or two places 33246149Ssjg# if .CURDIR is matched by any entry in DEBUG_MAKE_SYS_DIRS we 34246149Ssjg# will apply DEBUG_MAKE_FLAGS now. 35246149Ssjg# if an entry in DEBUG_MAKE_DIRS matches, we at the end of sys.mk 36246149Ssjg# eg. DEBUG_MAKE_FLAGS=-dv DEBUG_MAKE_SYS_DIRS="*lib/sjg" 37246149Ssjg# use DEBUG_MAKE_FLAGS0 to apply only to .MAKE.LEVEL 0 38246149Ssjg# 39246149Ssjg.if ${.MAKE.LEVEL:U1} == 0 40246149Ssjg# we use indirection, to simplify the tests below, and incase 41246149Ssjg# DEBUG_* were given on our command line. 42246149Ssjg_DEBUG_MAKE_FLAGS = ${DEBUG_MAKE_FLAGS0} 43246149Ssjg_DEBUG_MAKE_SYS_DIRS = ${DEBUG_MAKE_SYS_DIRS0:U${DEBUG_MAKE_SYS_DIRS}} 44246149Ssjg_DEBUG_MAKE_DIRS = ${DEBUG_MAKE_DIRS0:U${DEBUG_MAKE_DIRS}} 45246149Ssjg.else 46246149Ssjg_DEBUG_MAKE_FLAGS = ${DEBUG_MAKE_FLAGS} 47246149Ssjg_DEBUG_MAKE_SYS_DIRS = ${DEBUG_MAKE_SYS_DIRS} 48246149Ssjg_DEBUG_MAKE_DIRS = ${DEBUG_MAKE_DIRS} 49246149Ssjg.endif 50246149Ssjg 51246149Ssjg.if !empty(_DEBUG_MAKE_FLAGS) 52246149Ssjg.if ${_DEBUG_MAKE_SYS_DIRS:Uno:@x@${.CURDIR:M$x}@} != "" 53246149Ssjg.MAKEFLAGS: ${_DEBUG_MAKE_FLAGS} 54246149Ssjg.endif 55246149Ssjg.endif 56246149Ssjg 57246149Ssjg# if this is an ancient version of bmake 58246149SsjgMAKE_VERSION ?= 0 59246149Ssjg.if ${MAKE_VERSION:M*make-*} 60246149Ssjg# turn it into what we want - just the date 61246149SsjgMAKE_VERSION := ${MAKE_VERSION:[1]:C,.*-,,} 62246149Ssjg.endif 63246149Ssjg 64246149Ssjg# some useful modifiers 65246149Ssjg 66246149Ssjg# A useful trick for testing multiple :M's against something 67246149Ssjg# :L says to use the variable's name as its value - ie. literal 68246149Ssjg# got = ${clean* destroy:${M_ListToMatch:S,V,.TARGETS,}} 69246149SsjgM_ListToMatch = L:@m@$${V:M$$m}@ 70246149Ssjg# match against our initial targets (see above) 71246149SsjgM_L_TARGETS = ${M_ListToMatch:S,V,_TARGETS,} 72246149Ssjg 73246149Ssjg# turn a list into a set of :N modifiers 74246149Ssjg# NskipFoo = ${Foo:${M_ListToSkip}} 75246149SsjgM_ListToSkip= O:u:ts::S,:,:N,g:S,^,N, 76246149Ssjg 77246149Ssjg# type should be a builtin in any sh since about 1980, 78292068Ssjg# but sadly there are exceptions! 79292068Ssjg.if ${.MAKE.OS:Unknown:NBSD/OS} == "" 80292068Ssjg_type_sh = which 81292068Ssjg.endif 82246149Ssjg# AUTOCONF := ${autoconf:L:${M_whence}} 83292068SsjgM_type = @x@(${_type_sh:Utype} $$x) 2> /dev/null; echo;@:sh:[0]:N* found*:[@]:C,[()],,g 84276305SngieM_whence = ${M_type}:M/*:[1] 85246149Ssjg 86246149Ssjg# convert a path to a valid shell variable 87246149SsjgM_P2V = tu:C,[./-],_,g 88246149Ssjg 89246149Ssjg# convert path to absolute 90246149Ssjg.if ${MAKE_VERSION:U0} > 20100408 91246149SsjgM_tA = tA 92246149Ssjg.else 93246149SsjgM_tA = C,.*,('cd' & \&\& 'pwd') 2> /dev/null || echo &,:sh 94246149Ssjg.endif 95246149Ssjg 96246149Ssjg# absoulte path to what we are reading. 97246149Ssjg_PARSEDIR = ${.PARSEDIR:${M_tA}} 98246149Ssjg 99246149Ssjg# we expect a recent bmake 100246149Ssjg.if !defined(_TARGETS) 101246149Ssjg# some things we do only once 102246149Ssjg_TARGETS := ${.TARGETS} 103246149Ssjg.-include <sys.env.mk> 104246149Ssjg.endif 105246149Ssjg 106246149Ssjg# we need HOST_TARGET etc below. 107246149Ssjg.include <host-target.mk> 108246149Ssjg 109292068Ssjg# early customizations 110292068Ssjg.-include <local.sys.env.mk> 111292068Ssjg 112246149Ssjg# find the OS specifics 113246149Ssjg.if defined(SYS_OS_MK) 114246149Ssjg.include <${SYS_OS_MK}> 115246149Ssjg.else 116246149Ssjg_sys_mk = 117246149Ssjg.for x in ${HOST_OSTYPE} ${HOST_TARGET} ${HOST_OS} ${MACHINE} Generic 118246149Ssjg.if empty(_sys_mk) 119246149Ssjg.-include <sys/$x.mk> 120246149Ssjg_sys_mk := ${.MAKE.MAKEFILES:M*/$x.mk} 121246149Ssjg.if !empty(_sys_mk) 122246149Ssjg_sys_mk := sys/${_sys_mk:T} 123246149Ssjg.endif 124246149Ssjg.endif 125246149Ssjg.if empty(_sys_mk) 126246149Ssjg# might be an old style 127246149Ssjg.-include <$x.sys.mk> 128246149Ssjg_sys_mk := ${.MAKE.MAKEFILES:M*/$x.sys.mk:T} 129246149Ssjg.endif 130246149Ssjg.endfor 131246149Ssjg 132246149SsjgSYS_OS_MK := ${_sys_mk} 133246149Ssjg.export SYS_OS_MK 134246149Ssjg.endif 135246149Ssjg 136292068Ssjg# some options we need to know early 137292068SsjgOPTIONS_DEFAULT_NO += \ 138292068Ssjg DIRDEPS_BUILD \ 139292068Ssjg DIRDEPS_CACHE \ 140292068Ssjg META_MODE 141246149Ssjg 142292068SsjgOPTIONS_DEFAULT_DEPENDENT += \ 143292068Ssjg AUTO_OBJ/DIRDEPS_BUILD \ 144292068Ssjg STAGING/DIRDEPS_BUILD \ 145292068Ssjg 146292068Ssjg.-include "options.mk" 147292068Ssjg 148292068Ssjg.if ${MK_DIRDEPS_BUILD:Uno} == "yes" 149292068SsjgMK_META_MODE = yes 150292068Ssjg.-include <meta.sys.mk> 151292068Ssjg.elif ${MK_META_MODE:Uno} == "yes" 152292068Ssjg.MAKE.MODE = meta verbose 153292068Ssjg.endif 154292068Ssjg# make sure we have a harmless value 155292068Ssjg.MAKE.MODE ?= normal 156292068Ssjg 157246149Ssjg# if you want objdirs make them automatic 158292068Ssjg# and do it early before we compute .PATH 159292068Ssjg.if ${MK_AUTO_OBJ:Uno} == "yes" || ${MKOBJDIRS:Uno} == "auto" 160246149Ssjg.include <auto.obj.mk> 161246149Ssjg.endif 162246149Ssjg 163246149Ssjg.if !empty(SRCTOP) 164246149Ssjg.if ${.CURDIR} == ${SRCTOP} 165246149SsjgRELDIR = . 166246149Ssjg.elif ${.CURDIR:M${SRCTOP}/*} 167246149SsjgRELDIR := ${.CURDIR:S,${SRCTOP}/,,} 168246149Ssjg.endif 169246149Ssjg.endif 170246149Ssjg 171246149SsjgMACHINE_ARCH.host ?= ${_HOST_ARCH} 172246149SsjgMACHINE_ARCH.${MACHINE} ?= ${MACHINE} 173246149Ssjg.if empty(MACHINE_ARCH) 174246149SsjgMACHINE_ARCH = ${MACHINE_ARCH.${MACHINE}} 175246149Ssjg.endif 176246149Ssjg 177246149Ssjg.ifndef ROOT_GROUP 178246149SsjgROOT_GROUP != sed -n /:0:/s/:.*//p /etc/group 179246149Ssjg.export ROOT_GROUP 180246149Ssjg.endif 181246149Ssjg 182246149Ssjgunix ?= We run ${_HOST_OSNAME}. 183246149Ssjg 184246149Ssjg# A race condition in mkdir, means that it can bail if another 185246149Ssjg# process made a dir that mkdir expected to. 186246149Ssjg# We repeat the mkdir -p a number of times to try and work around this. 187246149Ssjg# We stop looping as soon as the dir exists. 188246149Ssjg# If we get to the end of the loop, a plain mkdir will issue an error. 189246149SsjgMkdirs= Mkdirs() { \ 190246149Ssjg for d in $$*; do \ 191246149Ssjg for i in 1 2 3 4 5 6; do \ 192246149Ssjg mkdir -p $$d; \ 193246149Ssjg test -d $$d && return 0; \ 194246149Ssjg done; \ 195246149Ssjg mkdir $$d || exit $$?; \ 196246149Ssjg done; } 197246149Ssjg 198246149Ssjg# this often helps with debugging 199246149Ssjg.SUFFIXES: .cpp-out 200246149Ssjg 201246149Ssjg.c.cpp-out: 202246149Ssjg @${COMPILE.c:N-c} -E ${.IMPSRC} | grep -v '^[ ]*$$' 203246149Ssjg 204246149Ssjg.cc.cpp-out: 205246149Ssjg @${COMPILE.cc:N-c} -E ${.IMPSRC} | grep -v '^[ ]*$$' 206246149Ssjg 207292068Ssjg# late customizations 208292068Ssjg.-include <local.sys.mk> 209246149Ssjg 210246149Ssjg# if .CURDIR is matched by any entry in DEBUG_MAKE_DIRS we 211246149Ssjg# will apply DEBUG_MAKE_FLAGS, now. 212246149Ssjg.if !empty(_DEBUG_MAKE_FLAGS) 213246149Ssjg.if ${_DEBUG_MAKE_DIRS:Uno:@x@${.CURDIR:M$x}@} != "" 214246149Ssjg.MAKEFLAGS: ${_DEBUG_MAKE_FLAGS} 215246149Ssjg.endif 216246149Ssjg.endif 217