varmod-order.mk revision 1.11       1 # $NetBSD: varmod-order.mk,v 1.11 2023/06/01 20:56:35 rillig Exp $
      2 #
      3 # Tests for the :O variable modifier and its variants, which either sort the
      4 # words of the value or shuffle them.
      5 
      6 WORDS=		one two three four five six seven eight nine ten
      7 NUMBERS=	8 5 4 9 1 7 6 10 3 2	# in English alphabetical order
      8 
      9 .if ${WORDS:O} != "eight five four nine one seven six ten three two"
     10 .  error ${WORDS:O}
     11 .endif
     12 
     13 # Unknown modifier "OX"
     14 # FIXME: The error message is wrong.
     15 # expect+1: Undefined variable "${WORDS:OX"
     16 _:=	${WORDS:OX}
     17 
     18 # Unknown modifier "OxXX"
     19 # FIXME: The error message is wrong.
     20 # expect+1: Undefined variable "${WORDS:Ox"
     21 _:=	${WORDS:OxXX}
     22 
     23 # Missing closing brace, to cover the error handling code.
     24 _:=	${WORDS:O
     25 _:=	${NUMBERS:On
     26 _:=	${NUMBERS:Onr
     27 
     28 # Shuffling numerically doesn't make sense, so don't allow 'x' and 'n' to be
     29 # combined.
     30 #
     31 # expect: make: Bad modifier ":Oxn" for variable "NUMBERS"
     32 # expect+1: Malformed conditional (${NUMBERS:Oxn})
     33 .if ${NUMBERS:Oxn}
     34 .  error
     35 .else
     36 .  error
     37 .endif
     38 
     39 # Extra characters after ':On' are detected and diagnosed.
     40 # TODO: Add line number information to the "Bad modifier" diagnostic.
     41 #
     42 # expect: make: Bad modifier ":On_typo" for variable "NUMBERS"
     43 # expect+1: Malformed conditional (${NUMBERS:On_typo})
     44 .if ${NUMBERS:On_typo}
     45 .  error
     46 .else
     47 .  error
     48 .endif
     49 
     50 # Extra characters after ':Onr' are detected and diagnosed.
     51 #
     52 # expect: make: Bad modifier ":Onr_typo" for variable "NUMBERS"
     53 # expect+1: Malformed conditional (${NUMBERS:Onr_typo})
     54 .if ${NUMBERS:Onr_typo}
     55 .  error
     56 .else
     57 .  error
     58 .endif
     59 
     60 # Extra characters after ':Orn' are detected and diagnosed.
     61 #
     62 # expect: make: Bad modifier ":Orn_typo" for variable "NUMBERS"
     63 # expect+1: Malformed conditional (${NUMBERS:Orn_typo})
     64 .if ${NUMBERS:Orn_typo}
     65 .  error
     66 .else
     67 .  error
     68 .endif
     69 
     70 # Repeating the 'n' is not supported.  In the typical use cases, the sorting
     71 # criteria are fixed, not computed, therefore allowing this redundancy does
     72 # not make sense.
     73 #
     74 # expect: make: Bad modifier ":Onn" for variable "NUMBERS"
     75 # expect+1: Malformed conditional (${NUMBERS:Onn})
     76 .if ${NUMBERS:Onn}
     77 .  error
     78 .else
     79 .  error
     80 .endif
     81 
     82 # Repeating the 'r' is not supported as well, for the same reasons as above.
     83 #
     84 # expect: make: Bad modifier ":Onrr" for variable "NUMBERS"
     85 # expect+1: Malformed conditional (${NUMBERS:Onrr})
     86 .if ${NUMBERS:Onrr}
     87 .  error
     88 .else
     89 .  error
     90 .endif
     91 
     92 # Repeating the 'r' is not supported as well, for the same reasons as above.
     93 #
     94 # expect: make: Bad modifier ":Orrn" for variable "NUMBERS"
     95 # expect+1: Malformed conditional (${NUMBERS:Orrn})
     96 .if ${NUMBERS:Orrn}
     97 .  error
     98 .else
     99 .  error
    100 .endif
    101 
    102 
    103 # If a modifier that starts with ':O' is not one of the known sort or shuffle
    104 # forms, it is a parse error.  Several other modifiers such as ':H' or ':u'
    105 # fall back to the SysV modifier, for example, ':H=new' is not the standard
    106 # ':H' modifier but instead replaces a trailing 'H' with 'new' in each word.
    107 # There is no such fallback for the ':O' modifiers.
    108 SWITCH=	On
    109 # expect: make: Bad modifier ":On=Off" for variable "SWITCH"
    110 # expect+1: Malformed conditional (${SWITCH:On=Off} != "Off")
    111 .if ${SWITCH:On=Off} != "Off"
    112 .  error
    113 .else
    114 .  error
    115 .endif
    116 
    117 all:
    118