From: Akim Demaille Date: Wed, 9 Feb 2000 11:59:24 +0000 (+0000) Subject: * libm4.m4 (m4_sign, m4_cmp, m4_list_cmp): New macros. X-Git-Tag: autoconf-2.50~1183 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ba05e822242ee3d32758df57e5335ed72ce4800f;p=thirdparty%2Fautoconf.git * libm4.m4 (m4_sign, m4_cmp, m4_list_cmp): New macros. * acgeneral.m4 (AC_UNGNITS): Renamed as... (_AC_VERSION_UNLETTER): this. All callers changed. Implement the scheme proposed by Alexandre Oliva: Nl -> (N+1).-1.(l#) (_AC_VERSION_COMPARE): New macro. (AC_PREREQ): Use it. --- diff --git a/ChangeLog b/ChangeLog index d32a9313e..e76548d25 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2000-02-09 Akim Demaille + + * libm4.m4 (m4_sign, m4_cmp, m4_list_cmp): New macros. + * acgeneral.m4 (AC_UNGNITS): Renamed as... + (_AC_VERSION_UNLETTER): this. All callers changed. + Implement the scheme proposed by Alexandre Oliva: + Nl -> (N+1).-1.(l#) + (_AC_VERSION_COMPARE): New macro. + (AC_PREREQ): Use it. + 2000-02-09 Akim Demaille * tests/base.m4: Really added to the CVS repository. diff --git a/acgeneral.m4 b/acgeneral.m4 index e75b3b2b1..6524ec86c 100644 --- a/acgeneral.m4 +++ b/acgeneral.m4 @@ -1303,51 +1303,41 @@ AC_DIVERT_POP()dnl to KILL # Subroutines of AC_PREREQ. -# m4_compare(VERSION-1, VERSION-2) -# -------------------------------- -# Compare the two version numbers and expand into -# -1 if VERSION-1 < VERSION-2 -# 0 if = -# 1 if > -# The handling of the special values [[]] is a pain, but seems necessary. -# This macro is a excellent tutorial on the order of evaluation of ifelse. -define(m4_compare, -[ifelse([$1],, [ifelse([$2],, 0, - [$2], [[]], 0, - 1)], - [$1], [[]], [ifelse([$2],, 0, - [$2], [[]], 0, - 1)], - [$2],, -1, - [$2], [[]], -1, - [ifelse(m4_eval(m4_car($1) < m4_car($2)), 1, 1, - [ifelse(m4_eval(m4_car($1) > m4_car($2)), 1, -1, - [m4_compare(m4_quote(m4_shift($1)), - m4_quote(m4_shift($2)))])])])]) - - -# AC_UNGNITS(VERSION) -# ------------------- -# Replace .a, .b etc. by .0.1, .0.2 in VERSION. For instance, version -# 2.14a is understood as 2.14.0.1 for version comparison. +# _AC_VERSION_UNLETTER(VERSION) +# ----------------------------- +# Normalize beta version numbers with letters to numbers only for comparison. +# +# Nl -> (N+1).-1.(l#) +# +#i.e., 2.14a -> 2.15.-1.1, 2.14b -> 2.15.-1.2, etc. # This macro is absolutely not robust to active macro, it expects -# reasonable version numbers. -# Warning: Valid up to `z', no double letters. -define(AC_UNGNITS, +# reasonable version numbers and is valid up to `z', no double letters. +define(_AC_VERSION_UNLETTER, [translit(patsubst(patsubst(patsubst([$1], - [\([abcdefghi]\)], [.0.\1]), - [\([jklmnopqrs]\)], [.0.1\1]), - [\([tuvwxyz]\)], [.0.2\1]), + [\([0-9]+\)\([abcdefghi]\)], + [m4_eval(\1 + 1).-1.\2]), + [\([0-9]+\)\([jklmnopqrs]\)], + [m4_eval(\1 + 1).-1.1\2]), + [\([0-9]+\)\([tuvwxyz]\)], + [m4_eval(\1 + 1).-1.2\2]), abcdefghijklmnopqrstuvwxyz, 12345678901234567890123456)]) +# _AC_VERSION_COMPARE(VERSION-1, VERSION-2) +# ----------------------------------------- +# Compare the two version numbers and expand into +# -1 if VERSION-1 < VERSION-2 +# 0 if = +# 1 if > +define(_AC_VERSION_COMPARE, +[m4_list_cmp((m4_split(_AC_VERSION_UNLETTER([$1]), [\.])), + (m4_split(_AC_VERSION_UNLETTER([$2]), [\.])))]) # AC_PREREQ(VERSION) # ------------------ # Complain and exit if the Autoconf version is less than VERSION. define(AC_PREREQ, -[ifelse(m4_compare(m4_split(AC_UNGNITS([$1]), [\.]), - m4_split(AC_UNGNITS(AC_ACVERSION), [\.])), -1, +[ifelse(_AC_VERSION_COMPARE([AC_ACVERSION], [$1]), -1, [AC_FATAL(Autoconf version $1 or higher is required for this script)])]) diff --git a/lib/autoconf/general.m4 b/lib/autoconf/general.m4 index e75b3b2b1..6524ec86c 100644 --- a/lib/autoconf/general.m4 +++ b/lib/autoconf/general.m4 @@ -1303,51 +1303,41 @@ AC_DIVERT_POP()dnl to KILL # Subroutines of AC_PREREQ. -# m4_compare(VERSION-1, VERSION-2) -# -------------------------------- -# Compare the two version numbers and expand into -# -1 if VERSION-1 < VERSION-2 -# 0 if = -# 1 if > -# The handling of the special values [[]] is a pain, but seems necessary. -# This macro is a excellent tutorial on the order of evaluation of ifelse. -define(m4_compare, -[ifelse([$1],, [ifelse([$2],, 0, - [$2], [[]], 0, - 1)], - [$1], [[]], [ifelse([$2],, 0, - [$2], [[]], 0, - 1)], - [$2],, -1, - [$2], [[]], -1, - [ifelse(m4_eval(m4_car($1) < m4_car($2)), 1, 1, - [ifelse(m4_eval(m4_car($1) > m4_car($2)), 1, -1, - [m4_compare(m4_quote(m4_shift($1)), - m4_quote(m4_shift($2)))])])])]) - - -# AC_UNGNITS(VERSION) -# ------------------- -# Replace .a, .b etc. by .0.1, .0.2 in VERSION. For instance, version -# 2.14a is understood as 2.14.0.1 for version comparison. +# _AC_VERSION_UNLETTER(VERSION) +# ----------------------------- +# Normalize beta version numbers with letters to numbers only for comparison. +# +# Nl -> (N+1).-1.(l#) +# +#i.e., 2.14a -> 2.15.-1.1, 2.14b -> 2.15.-1.2, etc. # This macro is absolutely not robust to active macro, it expects -# reasonable version numbers. -# Warning: Valid up to `z', no double letters. -define(AC_UNGNITS, +# reasonable version numbers and is valid up to `z', no double letters. +define(_AC_VERSION_UNLETTER, [translit(patsubst(patsubst(patsubst([$1], - [\([abcdefghi]\)], [.0.\1]), - [\([jklmnopqrs]\)], [.0.1\1]), - [\([tuvwxyz]\)], [.0.2\1]), + [\([0-9]+\)\([abcdefghi]\)], + [m4_eval(\1 + 1).-1.\2]), + [\([0-9]+\)\([jklmnopqrs]\)], + [m4_eval(\1 + 1).-1.1\2]), + [\([0-9]+\)\([tuvwxyz]\)], + [m4_eval(\1 + 1).-1.2\2]), abcdefghijklmnopqrstuvwxyz, 12345678901234567890123456)]) +# _AC_VERSION_COMPARE(VERSION-1, VERSION-2) +# ----------------------------------------- +# Compare the two version numbers and expand into +# -1 if VERSION-1 < VERSION-2 +# 0 if = +# 1 if > +define(_AC_VERSION_COMPARE, +[m4_list_cmp((m4_split(_AC_VERSION_UNLETTER([$1]), [\.])), + (m4_split(_AC_VERSION_UNLETTER([$2]), [\.])))]) # AC_PREREQ(VERSION) # ------------------ # Complain and exit if the Autoconf version is less than VERSION. define(AC_PREREQ, -[ifelse(m4_compare(m4_split(AC_UNGNITS([$1]), [\.]), - m4_split(AC_UNGNITS(AC_ACVERSION), [\.])), -1, +[ifelse(_AC_VERSION_COMPARE([AC_ACVERSION], [$1]), -1, [AC_FATAL(Autoconf version $1 or higher is required for this script)])]) diff --git a/libm4.m4 b/libm4.m4 index db15d7b28..df84ed367 100644 --- a/libm4.m4 +++ b/libm4.m4 @@ -458,9 +458,9 @@ define(_m4_foreach, [$3])])]) -## ----------------------- ## -## Text processing in m4. ## -## ----------------------- ## +## ----------------- ## +## Text processing. ## +## ----------------- ## # m4_quote(STRING) # ---------------- @@ -676,3 +676,50 @@ popdef([m4_Width])dnl popdef([m4_Prefix1])dnl popdef([m4_Prefix])dnl ]) + + + +## ------------------- ## +## Number processing. ## +## ------------------- ## + +# m4_sign(A) +# ---------- +# +# The sign of the integer A. +define(m4_sign, +[m4_match([$1], + [^-], -1, + [^0+], 0, + 1)]) + +# m4_cmp(A, B) +# ------------ +# +# Compare two integers. +# A < B -> -1 +# A = B -> 0 +# A > B -> 1 +define(m4_cmp, +[m4_sign(m4_eval([$1 - $2]))]) + + +# m4_list_cmp(A, B) +# ----------------- +# +# Compare the two lists of integers A and B. For instance: +# m4_list_cmp((1, 0), (1)) -> 0 +# m4_list_cmp((1, 0), (1, 0)) -> 0 +# m4_list_cmp((1, 2), (1, 0)) -> 1 +# m4_list_cmp((1, 2, 3), (1, 2)) -> 1 +# m4_list_cmp((1, 2, -3), (1, 2)) -> -1 +# m4_list_cmp((1, 0), (1, 2)) -> -1 +# m4_list_cmp((1), (1, 2)) -> -1 +define(m4_list_cmp, +[ifelse([$1$2], [()()], 0, + [$1], [()], [m4_list_cmp((0), [$2])], + [$2], [()], [m4_list_cmp([$1], (0))], + [m4_case(m4_cmp(m4_car$1, m4_car$2), + -1, -1, + 1, 1, + 0, [m4_list_cmp((m4_shift$1), (m4_shift$2))])])])