Home | History | Annotate | Line # | Download | only in unit-tests
modmisc.mk revision 1.10
      1  1.10  rillig # $Id: modmisc.mk,v 1.10 2020/07/04 17:10:33 rillig Exp $
      2   1.1     apb #
      3   1.1     apb # miscellaneous modifier tests
      4   1.1     apb 
      5   1.1     apb # do not put any dirs in this list which exist on some
      6   1.1     apb # but not all target systems - an exists() check is below.
      7   1.1     apb path=:/bin:/tmp::/:.:/no/such/dir:.
      8   1.1     apb # strip cwd from path.
      9   1.1     apb MOD_NODOT=S/:/ /g:N.:ts:
     10   1.1     apb # and decorate, note that $'s need to be doubled. Also note that 
     11   1.1     apb # the modifier_variable can be used with other modifiers.
     12   1.1     apb MOD_NODOTX=S/:/ /g:N.:@d@'$$d'@
     13   1.1     apb # another mod - pretend it is more interesting
     14   1.1     apb MOD_HOMES=S,/home/,/homes/,
     15   1.1     apb MOD_OPT=@d@$${exists($$d):?$$d:$${d:S,/usr,/opt,}}@
     16   1.1     apb MOD_SEP=S,:, ,g
     17   1.1     apb 
     18   1.7  rillig all:	modvar modvarloop modsysv mod-HTE emptyvar undefvar
     19  1.10  rillig all:	mod-S mod-C mod-at-varname mod-at-resolve
     20   1.1     apb 
     21   1.1     apb modsysv:
     22   1.1     apb 	@echo "The answer is ${libfoo.a:L:libfoo.a=42}"
     23   1.1     apb 
     24   1.1     apb modvar:
     25   1.1     apb 	@echo "path='${path}'"
     26   1.1     apb 	@echo "path='${path:${MOD_NODOT}}'"
     27   1.1     apb 	@echo "path='${path:S,home,homes,:${MOD_NODOT}}'"
     28   1.1     apb 	@echo "path=${path:${MOD_NODOTX}:ts:}"
     29   1.1     apb 	@echo "path=${path:${MOD_HOMES}:${MOD_NODOTX}:ts:}"
     30   1.1     apb 
     31   1.1     apb .for d in ${path:${MOD_SEP}:N.} /usr/xbin
     32   1.1     apb path_$d?= ${d:${MOD_OPT}:${MOD_HOMES}}/
     33   1.1     apb paths+= ${d:${MOD_OPT}:${MOD_HOMES}}
     34   1.1     apb .endfor
     35   1.1     apb 
     36   1.1     apb modvarloop:
     37   1.1     apb 	@echo "path_/usr/xbin=${path_/usr/xbin}"
     38   1.1     apb 	@echo "paths=${paths}"
     39   1.1     apb 	@echo "PATHS=${paths:tu}"
     40   1.2  rillig 
     41   1.6  rillig PATHNAMES=	a/b/c def a.b.c a.b/c a a.a .gitignore a a.a
     42   1.4  rillig mod-HTE:
     43   1.6  rillig 	@echo "dirname of '"${PATHNAMES:Q}"' is '"${PATHNAMES:H:Q}"'"
     44   1.6  rillig 	@echo "basename of '"${PATHNAMES:Q}"' is '"${PATHNAMES:T:Q}"'"
     45   1.6  rillig 	@echo "suffix of '"${PATHNAMES:Q}"' is '"${PATHNAMES:E:Q}"'"
     46   1.6  rillig 	@echo "root of '"${PATHNAMES:Q}"' is '"${PATHNAMES:R:Q}"'"
     47   1.7  rillig 
     48   1.7  rillig # When a modifier is applied to the "" variable, the result is discarded.
     49   1.7  rillig emptyvar:
     50   1.7  rillig 	@echo S:${:S,^$,empty,}
     51   1.7  rillig 	@echo C:${:C,^$,empty,}
     52   1.7  rillig 	@echo @:${:@var@${var}@}
     53   1.7  rillig 
     54   1.7  rillig # The :U modifier turns even the "" variable into something that has a value.
     55   1.7  rillig # The resulting variable is empty, but is still considered to contain a
     56   1.7  rillig # single empty word. This word can be accessed by the :S and :C modifiers,
     57   1.7  rillig # but not by the :@ modifier since it explicitly skips empty words.
     58   1.7  rillig undefvar:
     59   1.7  rillig 	@echo S:${:U:S,^$,empty,}
     60   1.7  rillig 	@echo C:${:U:C,^$,empty,}
     61   1.7  rillig 	@echo @:${:U:@var@empty@}
     62   1.8  rillig 
     63   1.8  rillig mod-S:
     64   1.8  rillig 	@echo :${:Ua b b c:S,a b,,:Q}:
     65   1.8  rillig 	@echo :${:Ua b b c:S,a b,,1:Q}:
     66   1.8  rillig 	@echo :${:Ua b b c:S,a b,,W:Q}:
     67   1.8  rillig 	@echo :${:Ua b b c:S,b,,g:Q}:
     68   1.8  rillig 	@echo :${:U1 2 3 1 2 3:S,1 2,___,Wg:S,_,x,:Q}:
     69   1.8  rillig 
     70   1.8  rillig mod-C:
     71   1.8  rillig 	@echo :${:Ua b b c:C,a b,,:Q}:
     72   1.8  rillig 	@echo :${:Ua b b c:C,a b,,1:Q}:
     73   1.8  rillig 	@echo :${:Ua b b c:C,a b,,W:Q}:
     74   1.8  rillig 	@echo :${:Uword1 word2:C,****,____,g:C,word,____,:Q}:
     75   1.8  rillig 	@echo :${:Ua b b c:C,b,,g:Q}:
     76   1.8  rillig 	@echo :${:U1 2 3 1 2 3:C,1 2,___,Wg:C,_,x,:Q}:
     77   1.9  rillig 
     78   1.9  rillig # In the :@ modifier, the name of the loop variable can even be generated
     79   1.9  rillig # dynamically.  There's no practical use-case for this, and hopefully nobody
     80   1.9  rillig # will ever depend on this, but technically it's possible.
     81   1.9  rillig mod-at-varname:
     82   1.9  rillig 	@echo :${:Uone two three:@${:Ubar:S,b,v,}@+${var}+@:Q}:
     83  1.10  rillig 
     84  1.10  rillig # The :@ modifier resolves the variables a little more often than expected.
     85  1.10  rillig # In particular, it resolves _all_ variables from the context, and not only
     86  1.10  rillig # the loop variable (in this case v).
     87  1.10  rillig RESOLVE=	${RES1} $${RES1}
     88  1.10  rillig RES1=		1a${RES2} 1b$${RES2}
     89  1.10  rillig RES2=		2
     90  1.10  rillig 
     91  1.10  rillig mod-at-resolve:
     92  1.10  rillig 	@echo $@:${RESOLVE:@v@w${v}w@:Q}:
     93