Home | History | Annotate | Line # | Download | only in unit-tests
modmisc.mk revision 1.7
      1  1.7  rillig # $Id: modmisc.mk,v 1.7 2020/07/03 22:10:42 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.1     apb 
     20  1.1     apb modsysv:
     21  1.1     apb 	@echo "The answer is ${libfoo.a:L:libfoo.a=42}"
     22  1.1     apb 
     23  1.1     apb modvar:
     24  1.1     apb 	@echo "path='${path}'"
     25  1.1     apb 	@echo "path='${path:${MOD_NODOT}}'"
     26  1.1     apb 	@echo "path='${path:S,home,homes,:${MOD_NODOT}}'"
     27  1.1     apb 	@echo "path=${path:${MOD_NODOTX}:ts:}"
     28  1.1     apb 	@echo "path=${path:${MOD_HOMES}:${MOD_NODOTX}:ts:}"
     29  1.1     apb 
     30  1.1     apb .for d in ${path:${MOD_SEP}:N.} /usr/xbin
     31  1.1     apb path_$d?= ${d:${MOD_OPT}:${MOD_HOMES}}/
     32  1.1     apb paths+= ${d:${MOD_OPT}:${MOD_HOMES}}
     33  1.1     apb .endfor
     34  1.1     apb 
     35  1.1     apb modvarloop:
     36  1.1     apb 	@echo "path_/usr/xbin=${path_/usr/xbin}"
     37  1.1     apb 	@echo "paths=${paths}"
     38  1.1     apb 	@echo "PATHS=${paths:tu}"
     39  1.2  rillig 
     40  1.6  rillig PATHNAMES=	a/b/c def a.b.c a.b/c a a.a .gitignore a a.a
     41  1.4  rillig mod-HTE:
     42  1.6  rillig 	@echo "dirname of '"${PATHNAMES:Q}"' is '"${PATHNAMES:H:Q}"'"
     43  1.6  rillig 	@echo "basename of '"${PATHNAMES:Q}"' is '"${PATHNAMES:T:Q}"'"
     44  1.6  rillig 	@echo "suffix of '"${PATHNAMES:Q}"' is '"${PATHNAMES:E:Q}"'"
     45  1.6  rillig 	@echo "root of '"${PATHNAMES:Q}"' is '"${PATHNAMES:R:Q}"'"
     46  1.7  rillig 
     47  1.7  rillig # When a modifier is applied to the "" variable, the result is discarded.
     48  1.7  rillig emptyvar:
     49  1.7  rillig 	@echo S:${:S,^$,empty,}
     50  1.7  rillig 	@echo C:${:C,^$,empty,}
     51  1.7  rillig 	@echo @:${:@var@${var}@}
     52  1.7  rillig 
     53  1.7  rillig # The :U modifier turns even the "" variable into something that has a value.
     54  1.7  rillig # The resulting variable is empty, but is still considered to contain a
     55  1.7  rillig # single empty word. This word can be accessed by the :S and :C modifiers,
     56  1.7  rillig # but not by the :@ modifier since it explicitly skips empty words.
     57  1.7  rillig undefvar:
     58  1.7  rillig 	@echo S:${:U:S,^$,empty,}
     59  1.7  rillig 	@echo C:${:U:C,^$,empty,}
     60  1.7  rillig 	@echo @:${:U:@var@empty@}
     61