1*4fde40d9SSimon J. Gerraty# $NetBSD: varmod-order-numeric.mk,v 1.8 2022/09/27 19:18:45 rillig Exp $ 212904384SSimon J. Gerraty# 312904384SSimon J. Gerraty# Tests for the variable modifiers ':On', which returns the words, sorted in 412904384SSimon J. Gerraty# ascending numeric order, and for ':Orn' and ':Onr', which additionally 512904384SSimon J. Gerraty# reverse the order. 612904384SSimon J. Gerraty# 712904384SSimon J. Gerraty# The variable modifiers ':On', ':Onr' and ':Orn' were added in var.c 1.939 812904384SSimon J. Gerraty# from 2021-07-30. 912904384SSimon J. Gerraty 1012904384SSimon J. Gerraty# This list contains only 32-bit numbers since the make code needs to conform 119f45a3c8SSimon J. Gerraty# to C90, which does not necessarily provide integer types larger than 32 bit. 129f45a3c8SSimon J. Gerraty# Make uses 'long long' for C99 or later, and 'long' for older C versions. 1312904384SSimon J. Gerraty# 1412904384SSimon J. Gerraty# To get 53-bit integers even in C90, it would be possible to switch to 1512904384SSimon J. Gerraty# 'double' instead, but that would allow floating-point numbers as well, which 1612904384SSimon J. Gerraty# is out of scope for this variable modifier. 1712904384SSimon J. GerratyNUMBERS= 3 5 7 1 42 -42 5K -3m 1M 1k -2G 1812904384SSimon J. Gerraty 1912904384SSimon J. Gerraty.if ${NUMBERS:On} != "-2G -3m -42 1 3 5 7 42 1k 5K 1M" 2012904384SSimon J. Gerraty. error ${NUMBERS:On} 2112904384SSimon J. Gerraty.endif 2212904384SSimon J. Gerraty 2312904384SSimon J. Gerraty.if ${NUMBERS:Orn} != "1M 5K 1k 42 7 5 3 1 -42 -3m -2G" 2412904384SSimon J. Gerraty. error ${NUMBERS:Orn} 2512904384SSimon J. Gerraty.endif 2612904384SSimon J. Gerraty 2712904384SSimon J. Gerraty# Both ':Onr' and ':Orn' have the same effect. 2812904384SSimon J. Gerraty.if ${NUMBERS:Onr} != "1M 5K 1k 42 7 5 3 1 -42 -3m -2G" 2912904384SSimon J. Gerraty. error ${NUMBERS:Onr} 3012904384SSimon J. Gerraty.endif 3112904384SSimon J. Gerraty 3212904384SSimon J. Gerraty# Duplicate numbers are preserved in the output. In this case the 3312904384SSimon J. Gerraty# equal-valued numbers are spelled the same, so they are indistinguishable in 3412904384SSimon J. Gerraty# the output. 351d3f2ddcSSimon J. GerratyDUPLICATES= 3 1 2 2 1 1 # subsequence of https://oeis.org/A034002 3612904384SSimon J. Gerraty.if ${DUPLICATES:On} != "1 1 1 2 2 3" 3712904384SSimon J. Gerraty. error ${DUPLICATES:On} 3812904384SSimon J. Gerraty.endif 3912904384SSimon J. Gerraty 4012904384SSimon J. Gerraty# If there are several numbers that have the same integer value, they are 4112904384SSimon J. Gerraty# returned in unspecified order. 4212904384SSimon J. GerratySAME_VALUE:= ${:U 79 80 0x0050 81 :On} 4312904384SSimon J. Gerraty.if ${SAME_VALUE} != "79 80 0x0050 81" && ${SAME_VALUE} != "79 0x0050 80 81" 4412904384SSimon J. Gerraty. error ${SAME_VALUE} 4512904384SSimon J. Gerraty.endif 4612904384SSimon J. Gerraty 471d3f2ddcSSimon J. Gerraty# Hexadecimal and octal numbers can be sorted as well. 4812904384SSimon J. GerratyMIXED_BASE= 0 010 0x7 9 4912904384SSimon J. Gerraty.if ${MIXED_BASE:On} != "0 0x7 010 9" 5012904384SSimon J. Gerraty. error ${MIXED_BASE:On} 5112904384SSimon J. Gerraty.endif 5212904384SSimon J. Gerraty 53*4fde40d9SSimon J. Gerraty# The measurement units for suffixes are k, M, G, but not T. 54*4fde40d9SSimon J. Gerraty# The string '3T' evaluates to 3, the string 'x' evaluates as '0'. 55*4fde40d9SSimon J. Gerraty.if ${4 3T 2M x:L:On} != "x 3T 4 2M" 56*4fde40d9SSimon J. Gerraty. error 57*4fde40d9SSimon J. Gerraty.endif 58*4fde40d9SSimon J. Gerraty 5912904384SSimon J. Gerratyall: 60