1# $Id: sys.mk,v 1.43 2016/04/05 15:58:37 sjg Exp $ 2# 3# @(#) Copyright (c) 2003-2009, 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# We use the following paradigm for preventing multiple inclusion. 19# It relies on the fact that conditionals and dependencies are resolved 20# at the time they are read. 21# 22# _this ?= ${.PARSEFILE} 23# .if !target(__${_this}__) 24# __${_this}__: 25# 26.if ${MAKE_VERSION:U0} > 20100408 27_this = ${.PARSEDIR:tA}/${.PARSEFILE} 28.else 29_this = ${.PARSEDIR}/${.PARSEFILE} 30.endif 31 32# Sometimes we want to turn on debugging in just one or two places 33# if .CURDIR is matched by any entry in DEBUG_MAKE_SYS_DIRS we 34# will apply DEBUG_MAKE_FLAGS now. 35# if an entry in DEBUG_MAKE_DIRS matches, we at the end of sys.mk 36# eg. DEBUG_MAKE_FLAGS=-dv DEBUG_MAKE_SYS_DIRS="*lib/sjg" 37# use DEBUG_MAKE_FLAGS0 to apply only to .MAKE.LEVEL 0 38# 39.if ${.MAKE.LEVEL:U1} == 0 40# we use indirection, to simplify the tests below, and incase 41# DEBUG_* were given on our command line. 42_DEBUG_MAKE_FLAGS = ${DEBUG_MAKE_FLAGS0} 43_DEBUG_MAKE_SYS_DIRS = ${DEBUG_MAKE_SYS_DIRS0:U${DEBUG_MAKE_SYS_DIRS}} 44_DEBUG_MAKE_DIRS = ${DEBUG_MAKE_DIRS0:U${DEBUG_MAKE_DIRS}} 45.else 46_DEBUG_MAKE_FLAGS = ${DEBUG_MAKE_FLAGS} 47_DEBUG_MAKE_SYS_DIRS = ${DEBUG_MAKE_SYS_DIRS} 48_DEBUG_MAKE_DIRS = ${DEBUG_MAKE_DIRS} 49.endif 50 51.if !empty(_DEBUG_MAKE_FLAGS) 52.if ${_DEBUG_MAKE_SYS_DIRS:Uno:@x@${.CURDIR:M$x}@} != "" 53.MAKEFLAGS: ${_DEBUG_MAKE_FLAGS} 54.endif 55.endif 56 57# if this is an ancient version of bmake 58MAKE_VERSION ?= 0 59.if ${MAKE_VERSION:M*make-*} 60# turn it into what we want - just the date 61MAKE_VERSION := ${MAKE_VERSION:[1]:C,.*-,,} 62.endif 63 64# some useful modifiers 65 66# A useful trick for testing multiple :M's against something 67# :L says to use the variable's name as its value - ie. literal 68# got = ${clean* destroy:${M_ListToMatch:S,V,.TARGETS,}} 69M_ListToMatch = L:@m@$${V:M$$m}@ 70# match against our initial targets (see above) 71M_L_TARGETS = ${M_ListToMatch:S,V,_TARGETS,} 72 73# turn a list into a set of :N modifiers 74# NskipFoo = ${Foo:${M_ListToSkip}} 75M_ListToSkip= O:u:ts::S,:,:N,g:S,^,N, 76 77# type should be a builtin in any sh since about 1980, 78# but sadly there are exceptions! 79.if ${.MAKE.OS:Unknown:NBSD/OS} == "" 80_type_sh = which 81.endif 82# AUTOCONF := ${autoconf:L:${M_whence}} 83M_type = @x@(${_type_sh:Utype} $$x) 2> /dev/null; echo;@:sh:[0]:N* found*:[@]:C,[()],,g 84M_whence = ${M_type}:M/*:[1] 85 86# convert a path to a valid shell variable 87M_P2V = tu:C,[./-],_,g 88 89# convert path to absolute 90.if ${MAKE_VERSION:U0} > 20100408 91M_tA = tA 92.else 93M_tA = C,.*,('cd' & \&\& 'pwd') 2> /dev/null || echo &,:sh 94.endif 95 96# absoulte path to what we are reading. 97_PARSEDIR = ${.PARSEDIR:${M_tA}} 98 99# we expect a recent bmake 100.if !defined(_TARGETS) 101# some things we do only once 102_TARGETS := ${.TARGETS} 103.-include <sys.env.mk> 104.endif 105 106# we need HOST_TARGET etc below. 107.include <host-target.mk> 108 109# early customizations 110.-include <local.sys.env.mk> 111 112# Popular suffixes for C++ 113CXX_SUFFIXES += .cc .cpp .cxx .C 114CXX_SUFFIXES := ${CXX_SUFFIXES:O:u} 115 116# find the OS specifics 117.if defined(SYS_OS_MK) 118.include <${SYS_OS_MK}> 119.else 120_sys_mk = 121.for x in ${HOST_OSTYPE} ${HOST_TARGET} ${HOST_OS} ${MACHINE} Generic 122.if empty(_sys_mk) 123.-include <sys/$x.mk> 124_sys_mk := ${.MAKE.MAKEFILES:M*/$x.mk} 125.if !empty(_sys_mk) 126_sys_mk := sys/${_sys_mk:T} 127.endif 128.endif 129.if empty(_sys_mk) 130# might be an old style 131.-include <$x.sys.mk> 132_sys_mk := ${.MAKE.MAKEFILES:M*/$x.sys.mk:T} 133.endif 134.endfor 135 136SYS_OS_MK := ${_sys_mk} 137.export SYS_OS_MK 138.endif 139 140# some options we need to know early 141OPTIONS_DEFAULT_NO += \ 142 DIRDEPS_BUILD \ 143 DIRDEPS_CACHE \ 144 META_MODE 145 146OPTIONS_DEFAULT_DEPENDENT += \ 147 AUTO_OBJ/DIRDEPS_BUILD \ 148 STAGING/DIRDEPS_BUILD \ 149 150.-include <options.mk> 151 152.if ${MK_DIRDEPS_BUILD:Uno} == "yes" 153MK_META_MODE = yes 154.-include <meta.sys.mk> 155.elif ${MK_META_MODE:Uno} == "yes" 156.MAKE.MODE = meta verbose 157.endif 158# make sure we have a harmless value 159.MAKE.MODE ?= normal 160 161# if you want objdirs make them automatic 162# and do it early before we compute .PATH 163.if ${MK_AUTO_OBJ:Uno} == "yes" || ${MKOBJDIRS:Uno} == "auto" 164.include <auto.obj.mk> 165.endif 166 167.if !empty(SRCTOP) 168.if ${.CURDIR} == ${SRCTOP} 169RELDIR = . 170.elif ${.CURDIR:M${SRCTOP}/*} 171RELDIR := ${.CURDIR:S,${SRCTOP}/,,} 172.endif 173.endif 174 175MACHINE_ARCH.host ?= ${_HOST_ARCH} 176MACHINE_ARCH.${MACHINE} ?= ${MACHINE} 177.if empty(MACHINE_ARCH) 178MACHINE_ARCH = ${MACHINE_ARCH.${MACHINE}} 179.endif 180 181.ifndef ROOT_GROUP 182ROOT_GROUP != sed -n /:0:/s/:.*//p /etc/group 183.export ROOT_GROUP 184.endif 185 186unix ?= We run ${_HOST_OSNAME}. 187 188# A race condition in mkdir, means that it can bail if another 189# process made a dir that mkdir expected to. 190# We repeat the mkdir -p a number of times to try and work around this. 191# We stop looping as soon as the dir exists. 192# If we get to the end of the loop, a plain mkdir will issue an error. 193Mkdirs= Mkdirs() { \ 194 for d in $$*; do \ 195 for i in 1 2 3 4 5 6; do \ 196 mkdir -p $$d; \ 197 test -d $$d && return 0; \ 198 done; \ 199 mkdir $$d || exit $$?; \ 200 done; } 201 202# this often helps with debugging 203.SUFFIXES: .cpp-out 204 205.c.cpp-out: 206 @${COMPILE.c:N-c} -E ${.IMPSRC} | grep -v '^[ ]*$$' 207 208${CXX_SUFFIXES:%=%.cpp-out}: 209 @${COMPILE.cc:N-c} -E ${.IMPSRC} | grep -v '^[ ]*$$' 210 211# late customizations 212.-include <local.sys.mk> 213 214# if .CURDIR is matched by any entry in DEBUG_MAKE_DIRS we 215# will apply DEBUG_MAKE_FLAGS, now. 216.if !empty(_DEBUG_MAKE_FLAGS) 217.if ${_DEBUG_MAKE_DIRS:Uno:@x@${.CURDIR:M$x}@} != "" 218.MAKEFLAGS: ${_DEBUG_MAKE_FLAGS} 219.endif 220.endif 221