Home | History | Annotate | Line # | Download | only in unit-tests
modmisc.mk revision 1.7
      1 # $Id: modmisc.mk,v 1.7 2020/07/03 22:10:42 rillig Exp $
      2 #
      3 # miscellaneous modifier tests
      4 
      5 # do not put any dirs in this list which exist on some
      6 # but not all target systems - an exists() check is below.
      7 path=:/bin:/tmp::/:.:/no/such/dir:.
      8 # strip cwd from path.
      9 MOD_NODOT=S/:/ /g:N.:ts:
     10 # and decorate, note that $'s need to be doubled. Also note that 
     11 # the modifier_variable can be used with other modifiers.
     12 MOD_NODOTX=S/:/ /g:N.:@d@'$$d'@
     13 # another mod - pretend it is more interesting
     14 MOD_HOMES=S,/home/,/homes/,
     15 MOD_OPT=@d@$${exists($$d):?$$d:$${d:S,/usr,/opt,}}@
     16 MOD_SEP=S,:, ,g
     17 
     18 all:	modvar modvarloop modsysv mod-HTE emptyvar undefvar
     19 
     20 modsysv:
     21 	@echo "The answer is ${libfoo.a:L:libfoo.a=42}"
     22 
     23 modvar:
     24 	@echo "path='${path}'"
     25 	@echo "path='${path:${MOD_NODOT}}'"
     26 	@echo "path='${path:S,home,homes,:${MOD_NODOT}}'"
     27 	@echo "path=${path:${MOD_NODOTX}:ts:}"
     28 	@echo "path=${path:${MOD_HOMES}:${MOD_NODOTX}:ts:}"
     29 
     30 .for d in ${path:${MOD_SEP}:N.} /usr/xbin
     31 path_$d?= ${d:${MOD_OPT}:${MOD_HOMES}}/
     32 paths+= ${d:${MOD_OPT}:${MOD_HOMES}}
     33 .endfor
     34 
     35 modvarloop:
     36 	@echo "path_/usr/xbin=${path_/usr/xbin}"
     37 	@echo "paths=${paths}"
     38 	@echo "PATHS=${paths:tu}"
     39 
     40 PATHNAMES=	a/b/c def a.b.c a.b/c a a.a .gitignore a a.a
     41 mod-HTE:
     42 	@echo "dirname of '"${PATHNAMES:Q}"' is '"${PATHNAMES:H:Q}"'"
     43 	@echo "basename of '"${PATHNAMES:Q}"' is '"${PATHNAMES:T:Q}"'"
     44 	@echo "suffix of '"${PATHNAMES:Q}"' is '"${PATHNAMES:E:Q}"'"
     45 	@echo "root of '"${PATHNAMES:Q}"' is '"${PATHNAMES:R:Q}"'"
     46 
     47 # When a modifier is applied to the "" variable, the result is discarded.
     48 emptyvar:
     49 	@echo S:${:S,^$,empty,}
     50 	@echo C:${:C,^$,empty,}
     51 	@echo @:${:@var@${var}@}
     52 
     53 # The :U modifier turns even the "" variable into something that has a value.
     54 # The resulting variable is empty, but is still considered to contain a
     55 # single empty word. This word can be accessed by the :S and :C modifiers,
     56 # but not by the :@ modifier since it explicitly skips empty words.
     57 undefvar:
     58 	@echo S:${:U:S,^$,empty,}
     59 	@echo C:${:U:C,^$,empty,}
     60 	@echo @:${:U:@var@empty@}
     61