1c59c3bf3SSimon J. Gerraty# SPDX-License-Identifier: BSD-2-Clause 2c59c3bf3SSimon J. Gerraty# 3*d9a65c5dSSimon J. Gerraty# $Id: sys.vars.mk,v 1.18 2025/03/09 02:47:59 sjg Exp $ 445447996SSimon J. Gerraty# 54fde40d9SSimon J. Gerraty# @(#) Copyright (c) 2003-2023, Simon J. Gerraty 645447996SSimon J. Gerraty# 745447996SSimon J. Gerraty# This file is provided in the hope that it will 845447996SSimon J. Gerraty# be of use. There is absolutely NO WARRANTY. 945447996SSimon J. Gerraty# Permission to copy, redistribute or otherwise 1045447996SSimon J. Gerraty# use this file is hereby granted provided that 1145447996SSimon J. Gerraty# the above copyright notice and this notice are 1245447996SSimon J. Gerraty# left intact. 1345447996SSimon J. Gerraty# 1445447996SSimon J. Gerraty# Please send copies of changes and bug-fixes to: 1545447996SSimon J. Gerraty# sjg@crufty.net 1645447996SSimon J. Gerraty# 1745447996SSimon J. Gerraty 1845447996SSimon J. Gerraty# We use the following paradigm for preventing multiple inclusion. 1945447996SSimon J. Gerraty# It relies on the fact that conditionals and dependencies are resolved 2045447996SSimon J. Gerraty# at the time they are read. 2145447996SSimon J. Gerraty# 224fde40d9SSimon J. Gerraty# _this ?= ${.PARSEDIR:tA}/${.PARSEFILE} 2345447996SSimon J. Gerraty# .if !target(__${_this}__) 2412904384SSimon J. Gerraty# __${_this}__: .NOTMAIN 2545447996SSimon J. Gerraty# 2645447996SSimon J. Gerraty 2745447996SSimon J. Gerraty# if this is an ancient version of bmake 2845447996SSimon J. GerratyMAKE_VERSION ?= 0 2945447996SSimon J. Gerraty.if ${MAKE_VERSION:M*make-*} 3045447996SSimon J. Gerraty# turn it into what we want - just the date 3145447996SSimon J. GerratyMAKE_VERSION := ${MAKE_VERSION:[1]:C,.*-,,} 3245447996SSimon J. Gerraty.endif 3345447996SSimon J. Gerraty 344fde40d9SSimon J. Gerraty.if ${MAKE_VERSION} < 20100414 354fde40d9SSimon J. Gerraty_this = ${.PARSEDIR}/${.PARSEFILE} 364fde40d9SSimon J. Gerraty.else 374fde40d9SSimon J. Gerraty_this = ${.PARSEDIR:tA}/${.PARSEFILE} 384fde40d9SSimon J. Gerraty.endif 394fde40d9SSimon J. Gerraty 4045447996SSimon J. Gerraty# some useful modifiers 4145447996SSimon J. Gerraty 4245447996SSimon J. Gerraty# A useful trick for testing multiple :M's against something 4345447996SSimon J. Gerraty# :L says to use the variable's name as its value - ie. literal 4445447996SSimon J. Gerraty# got = ${clean* destroy:${M_ListToMatch:S,V,.TARGETS,}} 454fde40d9SSimon J. GerratyM_ListToMatch = L:@m@$${V:U:M$$m}@ 4645447996SSimon J. Gerraty# match against our initial targets (see above) 4745447996SSimon J. GerratyM_L_TARGETS = ${M_ListToMatch:S,V,_TARGETS,} 4845447996SSimon J. Gerraty 4945447996SSimon J. Gerraty# turn a list into a set of :N modifiers 5045447996SSimon J. Gerraty# NskipFoo = ${Foo:${M_ListToSkip}} 5150d2e745SSimon J. GerratyM_ListToSkip= O:u:S,^,N,:ts: 5245447996SSimon J. Gerraty 5345447996SSimon J. Gerraty# type should be a builtin in any sh since about 1980, 5445447996SSimon J. Gerraty# but sadly there are exceptions! 5545447996SSimon J. Gerraty.if ${.MAKE.OS:Unknown:NBSD/OS} == "" 5645447996SSimon J. Gerraty_type_sh = which 5745447996SSimon J. Gerraty.endif 5845447996SSimon J. Gerraty 5945447996SSimon J. Gerraty# AUTOCONF := ${autoconf:L:${M_whence}} 6045447996SSimon J. GerratyM_type = @x@(${_type_sh:Utype} $$x) 2> /dev/null; echo;@:sh:[0]:N* found*:[@]:C,[()],,g 6145447996SSimon J. GerratyM_whence = ${M_type}:M/*:[1] 6245447996SSimon J. Gerraty 63a6f0e10bSSimon J. Gerraty# produce similar output to jot(1) or seq(1) 64956e45f6SSimon J. Gerraty# eg. ${LIST:[#]:${M_JOT}} 65956e45f6SSimon J. Gerraty# would be 1 2 3 4 5 if LIST has 5 words 66956e45f6SSimon J. Gerraty# ${9:L:${M_JOT}} 67956e45f6SSimon J. Gerraty# would be 1 2 3 4 5 6 7 8 9 68a6f0e10bSSimon J. Gerraty.if ${.MAKE.LEVEL} == 0 69a6f0e10bSSimon J. Gerraty.for x in jot seq 70a6f0e10bSSimon J. Gerraty.if empty(JOT_CMD) 71a6f0e10bSSimon J. GerratyJOT_CMD := ${$x:L:${M_whence}} 72a6f0e10bSSimon J. Gerraty.endif 73a6f0e10bSSimon J. Gerraty.endfor 74a6f0e10bSSimon J. Gerraty.if !empty(JOT_CMD) 75a6f0e10bSSimon J. Gerraty.export JOT_CMD 76a6f0e10bSSimon J. Gerraty.endif 77a6f0e10bSSimon J. Gerraty.endif 78a6f0e10bSSimon J. Gerraty.if !empty(JOT_CMD) 79a6f0e10bSSimon J. GerratyM_JOT = [1]:S,^,${JOT_CMD} ,:sh 80a6f0e10bSSimon J. Gerraty.else 81a6f0e10bSSimon J. GerratyM_JOT = [1]:@x@i=1;while [ $$$$i -le $$x ]; do echo $$$$i; i=$$$$((i + 1)); done;@:sh 82a6f0e10bSSimon J. Gerraty.endif 83956e45f6SSimon J. Gerraty 84956e45f6SSimon J. Gerraty# ${LIST:${M_RANGE}} is 1 2 3 4 5 if LIST has 5 words 854fde40d9SSimon J. Gerraty.if ${MAKE_VERSION} < 20170130 86956e45f6SSimon J. GerratyM_RANGE = [#]:${M_JOT} 874fde40d9SSimon J. Gerraty.else 884fde40d9SSimon J. GerratyM_RANGE = range 89956e45f6SSimon J. Gerraty.endif 90956e45f6SSimon J. Gerraty 9145447996SSimon J. Gerraty# convert a path to a valid shell variable 9245447996SSimon J. GerratyM_P2V = tu:C,[./-],_,g 9345447996SSimon J. Gerraty 9445447996SSimon J. Gerraty# convert path to absolute 954fde40d9SSimon J. Gerraty.if ${MAKE_VERSION} < 20100414 9645447996SSimon J. GerratyM_tA = C,.*,('cd' & \&\& 'pwd') 2> /dev/null || echo &,:sh 974fde40d9SSimon J. Gerraty.else 984fde40d9SSimon J. GerratyM_tA = tA 991ce939a7SSimon J. Gerraty.endif 1001ce939a7SSimon J. Gerraty 10145447996SSimon J. Gerraty# absoulte path to what we are reading. 10245447996SSimon J. Gerraty_PARSEDIR = ${.PARSEDIR:${M_tA}} 10349caa483SSimon J. Gerraty 1044fde40d9SSimon J. Gerraty.if ${MAKE_VERSION} >= 20170130 1054fde40d9SSimon J. Gerraty# M_cmpv allows comparing dotted versions like 3.1.2 1064fde40d9SSimon J. Gerraty# ${3.1.2:L:${M_cmpv}} -> 3001002 1074fde40d9SSimon J. Gerraty# we use big jumps to handle 3 digits per dot: 1084fde40d9SSimon J. Gerraty# ${123.456.789:L:${M_cmpv}} -> 123456789 1094fde40d9SSimon J. GerratyM_cmpv.units = 1 1000 1000000 1000000000 1000000000000 1104fde40d9SSimon J. GerratyM_cmpv = S,., ,g:C,^0*([0-9]),\1,:_:range:@i@+ $${_:[-$$i]} \* $${M_cmpv.units:[$$i]}@:S,^,expr 0 ,1:sh 1114fde40d9SSimon J. Gerraty.endif 1124fde40d9SSimon J. Gerraty 11349caa483SSimon J. Gerraty# many projects use MAJOR MINOR PATCH versioning 11449caa483SSimon J. Gerraty# ${OPENSSL:${M_M.M.P_VERSION}} is equivalent to 11549caa483SSimon J. Gerraty# ${OPENSSL_MAJOR_VERSION}.${OPENSSL_MINOR_VERSION}.${OPENSSL_PATCH_VERSION} 11649caa483SSimon J. GerratyM_M.M.P_VERSION = L:@v@$${MAJOR MINOR PATCH:L:@t@$${$$v_$$t_VERSION:U0}@}@:ts. 1174fde40d9SSimon J. Gerraty 1184fde40d9SSimon J. Gerraty# numeric sort 1194fde40d9SSimon J. Gerraty.if ${MAKE_VERSION} < 20210803 1204fde40d9SSimon J. GerratyM_On = O 1214fde40d9SSimon J. GerratyM_Onr = O 1224fde40d9SSimon J. Gerraty.else 1234fde40d9SSimon J. GerratyM_On = On 1244fde40d9SSimon J. GerratyM_Onr = Onr 1254fde40d9SSimon J. Gerraty.endif 1268c973ee2SSimon J. Gerraty 1278c973ee2SSimon J. Gerraty# Index of a word in a list. 1288c973ee2SSimon J. Gerraty# eg. ${LIST:${M_Index:S,K,key,}} is the index of 1298c973ee2SSimon J. Gerraty# the word "key" in ${LIST}, of course any pattern can be used. 1308c973ee2SSimon J. Gerraty# If "key" appears more than once, there will be multiple 1318c973ee2SSimon J. Gerraty# index values use ${M_Index:S,K,key,}:[1] to select only the first. 1328c973ee2SSimon J. GerratyM_Index = _:${M_RANGE}:@i@$${"$${_:[$$i]:MK}":?$$i:}@ 1338c973ee2SSimon J. Gerraty 134148ee845SSimon J. Gerraty# mtime of each word - assumed to be a valid pathname 135148ee845SSimon J. Gerraty.if ${.MAKE.LEVEL} < 20230510 136148ee845SSimon J. GerratyM_mtime = tW:S,^,${STAT:Ustat} -f %m ,:sh 137148ee845SSimon J. Gerraty.else 138148ee845SSimon J. Gerraty# M_mtime_fallback can be =error to throw an error 139148ee845SSimon J. Gerraty# or =0 to use 0, default is to use current time 140148ee845SSimon J. GerratyM_mtime = mtime${M_mtime_fallback:U} 141148ee845SSimon J. Gerraty.endif 142148ee845SSimon J. Gerraty 143*d9a65c5dSSimon J. Gerraty# This line noise allows doing .bel .space and .tab below 1446a7405f5SSimon J. Gerraty# don't expect sane results if input is more than a single word 1456a7405f5SSimon J. GerratyM_CharLiteral = L:@c@$${x x:L:$${:Uts$$c}:S/x//Wg}@ 1466a7405f5SSimon J. Gerraty.bel := ${\007:${M_CharLiteral}} 147*d9a65c5dSSimon J. Gerraty.space := ${\040:${M_CharLiteral}} 148*d9a65c5dSSimon J. Gerraty.tab := ${\t:${M_CharLiteral}} 149