1331246Ssjg# $Id: sys.vars.mk,v 1.3 2018/02/06 00:51:53 sjg Exp $
2310299Ssjg#
3310299Ssjg#	@(#) Copyright (c) 2003-2009, Simon J. Gerraty
4310299Ssjg#
5310299Ssjg#	This file is provided in the hope that it will
6310299Ssjg#	be of use.  There is absolutely NO WARRANTY.
7310299Ssjg#	Permission to copy, redistribute or otherwise
8310299Ssjg#	use this file is hereby granted provided that 
9310299Ssjg#	the above copyright notice and this notice are
10310299Ssjg#	left intact. 
11310299Ssjg#      
12310299Ssjg#	Please send copies of changes and bug-fixes to:
13310299Ssjg#	sjg@crufty.net
14310299Ssjg#
15310299Ssjg
16310299Ssjg# We use the following paradigm for preventing multiple inclusion.
17310299Ssjg# It relies on the fact that conditionals and dependencies are resolved 
18310299Ssjg# at the time they are read.
19310299Ssjg#
20310299Ssjg# _this ?= ${.PARSEFILE}
21310299Ssjg# .if !target(__${_this}__)
22310299Ssjg# __${_this}__:
23310299Ssjg#
24310299Ssjg.if ${MAKE_VERSION:U0} > 20100408
25310299Ssjg_this = ${.PARSEDIR:tA}/${.PARSEFILE}
26310299Ssjg.else
27310299Ssjg_this = ${.PARSEDIR}/${.PARSEFILE}
28310299Ssjg.endif
29310299Ssjg
30310299Ssjg# if this is an ancient version of bmake
31310299SsjgMAKE_VERSION ?= 0
32310299Ssjg.if ${MAKE_VERSION:M*make-*}
33310299Ssjg# turn it into what we want - just the date
34310299SsjgMAKE_VERSION := ${MAKE_VERSION:[1]:C,.*-,,}
35310299Ssjg.endif
36310299Ssjg
37310299Ssjg# some useful modifiers
38310299Ssjg
39310299Ssjg# A useful trick for testing multiple :M's against something
40310299Ssjg# :L says to use the variable's name as its value - ie. literal
41310299Ssjg# got = ${clean* destroy:${M_ListToMatch:S,V,.TARGETS,}}
42310299SsjgM_ListToMatch = L:@m@$${V:M$$m}@
43310299Ssjg# match against our initial targets (see above)
44310299SsjgM_L_TARGETS = ${M_ListToMatch:S,V,_TARGETS,}
45310299Ssjg
46310299Ssjg# turn a list into a set of :N modifiers
47310299Ssjg# NskipFoo = ${Foo:${M_ListToSkip}}
48331246SsjgM_ListToSkip= O:u:S,^,N,:ts:
49310299Ssjg
50310299Ssjg# type should be a builtin in any sh since about 1980,
51310299Ssjg# but sadly there are exceptions!
52310299Ssjg.if ${.MAKE.OS:Unknown:NBSD/OS} == ""
53310299Ssjg_type_sh = which
54310299Ssjg.endif
55310299Ssjg
56310299Ssjg# AUTOCONF := ${autoconf:L:${M_whence}}
57310299SsjgM_type = @x@(${_type_sh:Utype} $$x) 2> /dev/null; echo;@:sh:[0]:N* found*:[@]:C,[()],,g
58310299SsjgM_whence = ${M_type}:M/*:[1]
59310299Ssjg
60310299Ssjg# convert a path to a valid shell variable
61310299SsjgM_P2V = tu:C,[./-],_,g
62310299Ssjg
63310299Ssjg# convert path to absolute
64310299Ssjg.if ${MAKE_VERSION:U0} > 20100408
65310299SsjgM_tA = tA
66310299Ssjg.else
67310299SsjgM_tA = C,.*,('cd' & \&\& 'pwd') 2> /dev/null || echo &,:sh
68310299Ssjg.endif
69310299Ssjg
70319884Ssjg.if ${MAKE_VERSION:U0} >= 20170130
71319884Ssjg# M_cmpv allows comparing dotted versions like 3.1.2
72319884Ssjg# ${3.1.2:L:${M_cmpv}} -> 3001002
73319884Ssjg# we use big jumps to handle 3 digits per dot:
74319884Ssjg# ${123.456.789:L:${M_cmpv}} -> 123456789
75319884SsjgM_cmpv.units = 1 1000 1000000
76319884SsjgM_cmpv = S,., ,g:_:range:@i@+ $${_:[-$$i]} \* $${M_cmpv.units:[$$i]}@:S,^,expr 0 ,1:sh
77319884Ssjg.endif
78319884Ssjg
79310299Ssjg# absoulte path to what we are reading.
80310299Ssjg_PARSEDIR = ${.PARSEDIR:${M_tA}}
81