xref: /dragonfly/contrib/bmake/mk/sys.vars.mk (revision f9993810)
1# $Id: sys.vars.mk,v 1.10 2022/09/03 17:52:48 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# 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 ?= ${.PARSEFILE}
21# .if !target(__${_this}__)
22# __${_this}__: .NOTMAIN
23#
24.if ${MAKE_VERSION:U0} > 20100408
25_this = ${.PARSEDIR:tA}/${.PARSEFILE}
26.else
27_this = ${.PARSEDIR}/${.PARSEFILE}
28.endif
29
30# if this is an ancient version of bmake
31MAKE_VERSION ?= 0
32.if ${MAKE_VERSION:M*make-*}
33# turn it into what we want - just the date
34MAKE_VERSION := ${MAKE_VERSION:[1]:C,.*-,,}
35.endif
36
37# some useful modifiers
38
39# A useful trick for testing multiple :M's against something
40# :L says to use the variable's name as its value - ie. literal
41# got = ${clean* destroy:${M_ListToMatch:S,V,.TARGETS,}}
42M_ListToMatch = L:@m@$${V:M$$m}@
43# match against our initial targets (see above)
44M_L_TARGETS = ${M_ListToMatch:S,V,_TARGETS,}
45
46# turn a list into a set of :N modifiers
47# NskipFoo = ${Foo:${M_ListToSkip}}
48M_ListToSkip= O:u:S,^,N,:ts:
49
50# type should be a builtin in any sh since about 1980,
51# but sadly there are exceptions!
52.if ${.MAKE.OS:Unknown:NBSD/OS} == ""
53_type_sh = which
54.endif
55
56# AUTOCONF := ${autoconf:L:${M_whence}}
57M_type = @x@(${_type_sh:Utype} $$x) 2> /dev/null; echo;@:sh:[0]:N* found*:[@]:C,[()],,g
58M_whence = ${M_type}:M/*:[1]
59
60# produce similar output to jot(1) or seq(1)
61# eg. ${LIST:[#]:${M_JOT}}
62# would be 1 2 3 4 5 if LIST has 5 words
63# ${9:L:${M_JOT}}
64# would be 1 2 3 4 5 6 7 8 9
65.if ${.MAKE.LEVEL} == 0
66.for x in jot seq
67.if empty(JOT_CMD)
68JOT_CMD := ${$x:L:${M_whence}}
69.endif
70.endfor
71.if !empty(JOT_CMD)
72.export JOT_CMD
73.endif
74.endif
75.if !empty(JOT_CMD)
76M_JOT = [1]:S,^,${JOT_CMD} ,:sh
77.else
78M_JOT = [1]:@x@i=1;while [ $$$$i -le $$x ]; do echo $$$$i; i=$$$$((i + 1)); done;@:sh
79.endif
80
81# ${LIST:${M_RANGE}} is 1 2 3 4 5 if LIST has 5 words
82.if ${MAKE_VERSION} >= 20170130
83M_RANGE = range
84.else
85M_RANGE = [#]:${M_JOT}
86.endif
87
88# convert a path to a valid shell variable
89M_P2V = tu:C,[./-],_,g
90
91# convert path to absolute
92.if ${MAKE_VERSION:U0} > 20100408
93M_tA = tA
94.else
95M_tA = C,.*,('cd' & \&\& 'pwd') 2> /dev/null || echo &,:sh
96.endif
97
98.if ${MAKE_VERSION:U0} >= 20170130
99# M_cmpv allows comparing dotted versions like 3.1.2
100# ${3.1.2:L:${M_cmpv}} -> 3001002
101# we use big jumps to handle 3 digits per dot:
102# ${123.456.789:L:${M_cmpv}} -> 123456789
103M_cmpv.units = 1 1000 1000000 1000000000 1000000000000
104M_cmpv = S,., ,g:C,^0*([0-9]),\1,:_:range:@i@+ $${_:[-$$i]} \* $${M_cmpv.units:[$$i]}@:S,^,expr 0 ,1:sh
105.endif
106
107# absoulte path to what we are reading.
108_PARSEDIR = ${.PARSEDIR:${M_tA}}
109
110# many projects use MAJOR MINOR PATCH versioning
111# ${OPENSSL:${M_M.M.P_VERSION}} is equivalent to
112# ${OPENSSL_MAJOR_VERSION}.${OPENSSL_MINOR_VERSION}.${OPENSSL_PATCH_VERSION}
113M_M.M.P_VERSION = L:@v@$${MAJOR MINOR PATCH:L:@t@$${$$v_$$t_VERSION:U0}@}@:ts.
114