1*6eef5f0cSAntonio Huete Jimenez# $Id: sys.vars.mk,v 1.10 2022/09/03 17:52:48 sjg Exp $ 2ca58f742SDaniel Fojt# 3ca58f742SDaniel Fojt# @(#) Copyright (c) 2003-2009, Simon J. Gerraty 4ca58f742SDaniel Fojt# 5ca58f742SDaniel Fojt# This file is provided in the hope that it will 6ca58f742SDaniel Fojt# be of use. There is absolutely NO WARRANTY. 7ca58f742SDaniel Fojt# Permission to copy, redistribute or otherwise 8ca58f742SDaniel Fojt# use this file is hereby granted provided that 9ca58f742SDaniel Fojt# the above copyright notice and this notice are 10ca58f742SDaniel Fojt# left intact. 11ca58f742SDaniel Fojt# 12ca58f742SDaniel Fojt# Please send copies of changes and bug-fixes to: 13ca58f742SDaniel Fojt# sjg@crufty.net 14ca58f742SDaniel Fojt# 15ca58f742SDaniel Fojt 16ca58f742SDaniel Fojt# We use the following paradigm for preventing multiple inclusion. 17ca58f742SDaniel Fojt# It relies on the fact that conditionals and dependencies are resolved 18ca58f742SDaniel Fojt# at the time they are read. 19ca58f742SDaniel Fojt# 20ca58f742SDaniel Fojt# _this ?= ${.PARSEFILE} 21ca58f742SDaniel Fojt# .if !target(__${_this}__) 22*6eef5f0cSAntonio Huete Jimenez# __${_this}__: .NOTMAIN 23ca58f742SDaniel Fojt# 24ca58f742SDaniel Fojt.if ${MAKE_VERSION:U0} > 20100408 25ca58f742SDaniel Fojt_this = ${.PARSEDIR:tA}/${.PARSEFILE} 26ca58f742SDaniel Fojt.else 27ca58f742SDaniel Fojt_this = ${.PARSEDIR}/${.PARSEFILE} 28ca58f742SDaniel Fojt.endif 29ca58f742SDaniel Fojt 30ca58f742SDaniel Fojt# if this is an ancient version of bmake 31ca58f742SDaniel FojtMAKE_VERSION ?= 0 32ca58f742SDaniel Fojt.if ${MAKE_VERSION:M*make-*} 33ca58f742SDaniel Fojt# turn it into what we want - just the date 34ca58f742SDaniel FojtMAKE_VERSION := ${MAKE_VERSION:[1]:C,.*-,,} 35ca58f742SDaniel Fojt.endif 36ca58f742SDaniel Fojt 37ca58f742SDaniel Fojt# some useful modifiers 38ca58f742SDaniel Fojt 39ca58f742SDaniel Fojt# A useful trick for testing multiple :M's against something 40ca58f742SDaniel Fojt# :L says to use the variable's name as its value - ie. literal 41ca58f742SDaniel Fojt# got = ${clean* destroy:${M_ListToMatch:S,V,.TARGETS,}} 42ca58f742SDaniel FojtM_ListToMatch = L:@m@$${V:M$$m}@ 43ca58f742SDaniel Fojt# match against our initial targets (see above) 44ca58f742SDaniel FojtM_L_TARGETS = ${M_ListToMatch:S,V,_TARGETS,} 45ca58f742SDaniel Fojt 46ca58f742SDaniel Fojt# turn a list into a set of :N modifiers 47ca58f742SDaniel Fojt# NskipFoo = ${Foo:${M_ListToSkip}} 48ca58f742SDaniel FojtM_ListToSkip= O:u:S,^,N,:ts: 49ca58f742SDaniel Fojt 50ca58f742SDaniel Fojt# type should be a builtin in any sh since about 1980, 51ca58f742SDaniel Fojt# but sadly there are exceptions! 52ca58f742SDaniel Fojt.if ${.MAKE.OS:Unknown:NBSD/OS} == "" 53ca58f742SDaniel Fojt_type_sh = which 54ca58f742SDaniel Fojt.endif 55ca58f742SDaniel Fojt 56ca58f742SDaniel Fojt# AUTOCONF := ${autoconf:L:${M_whence}} 57ca58f742SDaniel FojtM_type = @x@(${_type_sh:Utype} $$x) 2> /dev/null; echo;@:sh:[0]:N* found*:[@]:C,[()],,g 58ca58f742SDaniel FojtM_whence = ${M_type}:M/*:[1] 59ca58f742SDaniel Fojt 60*6eef5f0cSAntonio Huete Jimenez# produce similar output to jot(1) or seq(1) 61a34d5fb1SAntonio Huete Jimenez# eg. ${LIST:[#]:${M_JOT}} 62a34d5fb1SAntonio Huete Jimenez# would be 1 2 3 4 5 if LIST has 5 words 63a34d5fb1SAntonio Huete Jimenez# ${9:L:${M_JOT}} 64a34d5fb1SAntonio Huete Jimenez# would be 1 2 3 4 5 6 7 8 9 65*6eef5f0cSAntonio Huete Jimenez.if ${.MAKE.LEVEL} == 0 66*6eef5f0cSAntonio Huete Jimenez.for x in jot seq 67*6eef5f0cSAntonio Huete Jimenez.if empty(JOT_CMD) 68*6eef5f0cSAntonio Huete JimenezJOT_CMD := ${$x:L:${M_whence}} 69*6eef5f0cSAntonio Huete Jimenez.endif 70*6eef5f0cSAntonio Huete Jimenez.endfor 71*6eef5f0cSAntonio Huete Jimenez.if !empty(JOT_CMD) 72*6eef5f0cSAntonio Huete Jimenez.export JOT_CMD 73*6eef5f0cSAntonio Huete Jimenez.endif 74*6eef5f0cSAntonio Huete Jimenez.endif 75*6eef5f0cSAntonio Huete Jimenez.if !empty(JOT_CMD) 76*6eef5f0cSAntonio Huete JimenezM_JOT = [1]:S,^,${JOT_CMD} ,:sh 77*6eef5f0cSAntonio Huete Jimenez.else 78*6eef5f0cSAntonio Huete JimenezM_JOT = [1]:@x@i=1;while [ $$$$i -le $$x ]; do echo $$$$i; i=$$$$((i + 1)); done;@:sh 79*6eef5f0cSAntonio Huete Jimenez.endif 80a34d5fb1SAntonio Huete Jimenez 81a34d5fb1SAntonio Huete Jimenez# ${LIST:${M_RANGE}} is 1 2 3 4 5 if LIST has 5 words 82a34d5fb1SAntonio Huete Jimenez.if ${MAKE_VERSION} >= 20170130 83a34d5fb1SAntonio Huete JimenezM_RANGE = range 84a34d5fb1SAntonio Huete Jimenez.else 85a34d5fb1SAntonio Huete JimenezM_RANGE = [#]:${M_JOT} 86a34d5fb1SAntonio Huete Jimenez.endif 87a34d5fb1SAntonio Huete Jimenez 88ca58f742SDaniel Fojt# convert a path to a valid shell variable 89ca58f742SDaniel FojtM_P2V = tu:C,[./-],_,g 90ca58f742SDaniel Fojt 91ca58f742SDaniel Fojt# convert path to absolute 92ca58f742SDaniel Fojt.if ${MAKE_VERSION:U0} > 20100408 93ca58f742SDaniel FojtM_tA = tA 94ca58f742SDaniel Fojt.else 95ca58f742SDaniel FojtM_tA = C,.*,('cd' & \&\& 'pwd') 2> /dev/null || echo &,:sh 96ca58f742SDaniel Fojt.endif 97ca58f742SDaniel Fojt 98ca58f742SDaniel Fojt.if ${MAKE_VERSION:U0} >= 20170130 99ca58f742SDaniel Fojt# M_cmpv allows comparing dotted versions like 3.1.2 100ca58f742SDaniel Fojt# ${3.1.2:L:${M_cmpv}} -> 3001002 101ca58f742SDaniel Fojt# we use big jumps to handle 3 digits per dot: 102ca58f742SDaniel Fojt# ${123.456.789:L:${M_cmpv}} -> 123456789 103*6eef5f0cSAntonio Huete JimenezM_cmpv.units = 1 1000 1000000 1000000000 1000000000000 104*6eef5f0cSAntonio Huete JimenezM_cmpv = S,., ,g:C,^0*([0-9]),\1,:_:range:@i@+ $${_:[-$$i]} \* $${M_cmpv.units:[$$i]}@:S,^,expr 0 ,1:sh 105ca58f742SDaniel Fojt.endif 106ca58f742SDaniel Fojt 107ca58f742SDaniel Fojt# absoulte path to what we are reading. 108ca58f742SDaniel Fojt_PARSEDIR = ${.PARSEDIR:${M_tA}} 109ca58f742SDaniel Fojt 110ca58f742SDaniel Fojt# many projects use MAJOR MINOR PATCH versioning 111ca58f742SDaniel Fojt# ${OPENSSL:${M_M.M.P_VERSION}} is equivalent to 112ca58f742SDaniel Fojt# ${OPENSSL_MAJOR_VERSION}.${OPENSSL_MINOR_VERSION}.${OPENSSL_PATCH_VERSION} 113ca58f742SDaniel FojtM_M.M.P_VERSION = L:@v@$${MAJOR MINOR PATCH:L:@t@$${$$v_$$t_VERSION:U0}@}@:ts. 114