Home | History | Annotate | Line # | Download | only in unit-tests
modmisc.mk revision 1.49
      1  1.49  rillig # $NetBSD: modmisc.mk,v 1.49 2020/10/24 08:50:17 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.49  rillig path=		:/bin:/tmp::/:.:/no/such/dir:.
      8   1.1     apb # strip cwd from path.
      9  1.49  rillig MOD_NODOT=	S/:/ /g:N.:ts:
     10  1.49  rillig # 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.49  rillig MOD_NODOTX=	S/:/ /g:N.:@d@'$$d'@
     13   1.1     apb # another mod - pretend it is more interesting
     14  1.49  rillig MOD_HOMES=	S,/home/,/homes/,
     15  1.49  rillig MOD_OPT=	@d@$${exists($$d):?$$d:$${d:S,/usr,/opt,}}@
     16  1.49  rillig MOD_SEP=	S,:, ,g
     17   1.1     apb 
     18  1.44  rillig all:	modvar modvarloop modsysv emptyvar undefvar
     19  1.23  rillig all:	mod-quote
     20  1.22  rillig all:	mod-break-many-words
     21   1.1     apb 
     22  1.23  rillig # See also sysv.mk.
     23   1.1     apb modsysv:
     24   1.1     apb 	@echo "The answer is ${libfoo.a:L:libfoo.a=42}"
     25   1.1     apb 
     26  1.23  rillig # Demonstrates modifiers that are given indirectly from a variable.
     27   1.1     apb modvar:
     28   1.1     apb 	@echo "path='${path}'"
     29   1.1     apb 	@echo "path='${path:${MOD_NODOT}}'"
     30   1.1     apb 	@echo "path='${path:S,home,homes,:${MOD_NODOT}}'"
     31   1.1     apb 	@echo "path=${path:${MOD_NODOTX}:ts:}"
     32   1.1     apb 	@echo "path=${path:${MOD_HOMES}:${MOD_NODOTX}:ts:}"
     33   1.1     apb 
     34   1.1     apb .for d in ${path:${MOD_SEP}:N.} /usr/xbin
     35  1.49  rillig path_$d?=	${d:${MOD_OPT}:${MOD_HOMES}}/
     36  1.49  rillig paths+=		${d:${MOD_OPT}:${MOD_HOMES}}
     37   1.1     apb .endfor
     38   1.1     apb 
     39   1.1     apb modvarloop:
     40   1.1     apb 	@echo "path_/usr/xbin=${path_/usr/xbin}"
     41   1.1     apb 	@echo "paths=${paths}"
     42   1.1     apb 	@echo "PATHS=${paths:tu}"
     43   1.2  rillig 
     44   1.7  rillig # When a modifier is applied to the "" variable, the result is discarded.
     45   1.7  rillig emptyvar:
     46   1.7  rillig 	@echo S:${:S,^$,empty,}
     47   1.7  rillig 	@echo C:${:C,^$,empty,}
     48   1.7  rillig 	@echo @:${:@var@${var}@}
     49   1.7  rillig 
     50   1.7  rillig # The :U modifier turns even the "" variable into something that has a value.
     51   1.7  rillig # The resulting variable is empty, but is still considered to contain a
     52   1.7  rillig # single empty word. This word can be accessed by the :S and :C modifiers,
     53   1.7  rillig # but not by the :@ modifier since it explicitly skips empty words.
     54   1.7  rillig undefvar:
     55   1.7  rillig 	@echo S:${:U:S,^$,empty,}
     56   1.7  rillig 	@echo C:${:U:C,^$,empty,}
     57   1.7  rillig 	@echo @:${:U:@var@empty@}
     58   1.8  rillig 
     59  1.19  rillig 
     60  1.23  rillig mod-quote:
     61  1.19  rillig 	@echo $@: new${.newline:Q}${.newline:Q}line
     62  1.22  rillig 
     63  1.22  rillig # Cover the bmake_realloc in brk_string.
     64  1.22  rillig mod-break-many-words:
     65  1.22  rillig 	@echo $@: ${UNDEF:U:range=500:[#]}
     66  1.27  rillig 
     67  1.31  rillig # To apply a modifier indirectly via another variable, the whole
     68  1.31  rillig # modifier must be put into a single variable.
     69  1.31  rillig .if ${value:L:${:US}${:U,value,replacement,}} != "S,value,replacement,}"
     70  1.48  rillig .  warning unexpected
     71  1.31  rillig .endif
     72  1.31  rillig 
     73  1.31  rillig # Adding another level of indirection (the 2 nested :U expressions) helps.
     74  1.31  rillig .if ${value:L:${:U${:US}${:U,value,replacement,}}} != "replacement"
     75  1.48  rillig .  warning unexpected
     76  1.31  rillig .endif
     77  1.31  rillig 
     78  1.31  rillig # Multiple indirect modifiers can be applied one after another as long as
     79  1.31  rillig # they are separated with colons.
     80  1.31  rillig .if ${value:L:${:US,a,A,}:${:US,e,E,}} != "vAluE"
     81  1.48  rillig .  warning unexpected
     82  1.31  rillig .endif
     83  1.32  rillig 
     84  1.32  rillig # An indirect variable that evaluates to the empty string is allowed though.
     85  1.32  rillig # This makes it possible to define conditional modifiers, like this:
     86  1.32  rillig #
     87  1.32  rillig # M.little-endian=	S,1234,4321,
     88  1.32  rillig # M.big-endian=		# none
     89  1.32  rillig .if ${value:L:${:Dempty}S,a,A,} != "vAlue"
     90  1.48  rillig .  warning unexpected
     91  1.32  rillig .endif
     92  1.40  rillig 
     93