1# $Id: sys.vars.mk,v 1.14 2023/02/17 22:32:47 sjg Exp $ 2# 3# @(#) Copyright (c) 2003-2023, 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# We use the following paradigm for preventing multiple inclusion. 17# It relies on the fact that conditionals and dependencies are resolved 18# at the time they are read. 19# 20# _this ?= ${.PARSEDIR:tA}/${.PARSEFILE} 21# .if !target(__${_this}__) 22# __${_this}__: .NOTMAIN 23# 24 25# if this is an ancient version of bmake 26MAKE_VERSION ?= 0 27.if ${MAKE_VERSION:M*make-*} 28# turn it into what we want - just the date 29MAKE_VERSION := ${MAKE_VERSION:[1]:C,.*-,,} 30.endif 31 32.if ${MAKE_VERSION} < 20100414 33_this = ${.PARSEDIR}/${.PARSEFILE} 34.else 35_this = ${.PARSEDIR:tA}/${.PARSEFILE} 36.endif 37 38# some useful modifiers 39 40# A useful trick for testing multiple :M's against something 41# :L says to use the variable's name as its value - ie. literal 42# got = ${clean* destroy:${M_ListToMatch:S,V,.TARGETS,}} 43M_ListToMatch = L:@m@$${V:U:M$$m}@ 44# match against our initial targets (see above) 45M_L_TARGETS = ${M_ListToMatch:S,V,_TARGETS,} 46 47# turn a list into a set of :N modifiers 48# NskipFoo = ${Foo:${M_ListToSkip}} 49M_ListToSkip= O:u:S,^,N,:ts: 50 51# type should be a builtin in any sh since about 1980, 52# but sadly there are exceptions! 53.if ${.MAKE.OS:Unknown:NBSD/OS} == "" 54_type_sh = which 55.endif 56 57# AUTOCONF := ${autoconf:L:${M_whence}} 58M_type = @x@(${_type_sh:Utype} $$x) 2> /dev/null; echo;@:sh:[0]:N* found*:[@]:C,[()],,g 59M_whence = ${M_type}:M/*:[1] 60 61# produce similar output to jot(1) or seq(1) 62# eg. ${LIST:[#]:${M_JOT}} 63# would be 1 2 3 4 5 if LIST has 5 words 64# ${9:L:${M_JOT}} 65# would be 1 2 3 4 5 6 7 8 9 66.if ${.MAKE.LEVEL} == 0 67.for x in jot seq 68.if empty(JOT_CMD) 69JOT_CMD := ${$x:L:${M_whence}} 70.endif 71.endfor 72.if !empty(JOT_CMD) 73.export JOT_CMD 74.endif 75.endif 76.if !empty(JOT_CMD) 77M_JOT = [1]:S,^,${JOT_CMD} ,:sh 78.else 79M_JOT = [1]:@x@i=1;while [ $$$$i -le $$x ]; do echo $$$$i; i=$$$$((i + 1)); done;@:sh 80.endif 81 82# ${LIST:${M_RANGE}} is 1 2 3 4 5 if LIST has 5 words 83.if ${MAKE_VERSION} < 20170130 84M_RANGE = [#]:${M_JOT} 85.else 86M_RANGE = range 87.endif 88 89# convert a path to a valid shell variable 90M_P2V = tu:C,[./-],_,g 91 92# convert path to absolute 93.if ${MAKE_VERSION} < 20100414 94M_tA = C,.*,('cd' & \&\& 'pwd') 2> /dev/null || echo &,:sh 95.else 96M_tA = tA 97.endif 98 99# absoulte path to what we are reading. 100_PARSEDIR = ${.PARSEDIR:${M_tA}} 101 102.if ${MAKE_VERSION} >= 20170130 103# M_cmpv allows comparing dotted versions like 3.1.2 104# ${3.1.2:L:${M_cmpv}} -> 3001002 105# we use big jumps to handle 3 digits per dot: 106# ${123.456.789:L:${M_cmpv}} -> 123456789 107M_cmpv.units = 1 1000 1000000 1000000000 1000000000000 108M_cmpv = S,., ,g:C,^0*([0-9]),\1,:_:range:@i@+ $${_:[-$$i]} \* $${M_cmpv.units:[$$i]}@:S,^,expr 0 ,1:sh 109.endif 110 111# many projects use MAJOR MINOR PATCH versioning 112# ${OPENSSL:${M_M.M.P_VERSION}} is equivalent to 113# ${OPENSSL_MAJOR_VERSION}.${OPENSSL_MINOR_VERSION}.${OPENSSL_PATCH_VERSION} 114M_M.M.P_VERSION = L:@v@$${MAJOR MINOR PATCH:L:@t@$${$$v_$$t_VERSION:U0}@}@:ts. 115 116# numeric sort 117.if ${MAKE_VERSION} < 20210803 118M_On = O 119M_Onr = O 120.else 121M_On = On 122M_Onr = Onr 123.endif 124 125# Index of a word in a list. 126# eg. ${LIST:${M_Index:S,K,key,}} is the index of 127# the word "key" in ${LIST}, of course any pattern can be used. 128# If "key" appears more than once, there will be multiple 129# index values use ${M_Index:S,K,key,}:[1] to select only the first. 130M_Index = _:${M_RANGE}:@i@$${"$${_:[$$i]:MK}":?$$i:}@ 131 132