havm 162: Use AS_VERSION_COMPARE to check GHC's version number.

https://svn.lrde.epita.fr/svn/havm/trunk Index: ChangeLog from Roland Levillain <roland@lrde.epita.fr> Use AS_VERSION_COMPARE to check GHC's version number. * build-aux/version-compare.m4: New file. * build-aux/prog.m4: New file. (HAVM_PROG): New macro. * configure.ac: Use it to check that GHC's version is at least 6.4. Catch "HAVM_*" macros that are not expanded. * Makefile.am: Add build-aux to the list of directories scanned by aclocal. Makefile.am | 2 + build-aux/prog.m4 | 36 +++++++++++++++++++ build-aux/version-compare.m4 | 80 +++++++++++++++++++++++++++++++++++++++++++ configure.ac | 7 +-- 4 files changed, 121 insertions, 4 deletions Index: configure.ac --- configure.ac (revision 161) +++ configure.ac (working copy) @@ -15,15 +15,14 @@ # the Free Software Foundation, 59 Temple Place - Suite 330, Boston, # MA 02111-1307, USA. +# Catch "HAVM_*" macros that are not expanded. +m4_pattern_forbid([^HAVM_]) AC_PREREQ([2.59]) AC_INIT([HAVM], [0.23a], [tiger-patches@lrde.epita.fr]) AC_CONFIG_AUX_DIR([build-aux]) AM_INIT_AUTOMAKE([1.9 dist-bzip2]) -AC_CHECK_TOOL([GHC], [ghc], [no]) -if test $GHC = no; then - AC_MSG_ERROR([GHC is required]) -fi +HAVM_PROG([ghc], [6.4], [GHC], [Glasgow Haskell Compiler]) AM_MISSING_PROG([HAPPY], [happy]) AC_CONFIG_FILES([ Index: Makefile.am --- Makefile.am (revision 161) +++ Makefile.am (working copy) @@ -15,6 +15,8 @@ # the Free Software Foundation, 59 Temple Place - Suite 330, Boston, # MA 02111-1307, USA. +ACLOCAL_AMFLAGS = -I build-aux + SUBDIRS = src doc debian install-epita: Index: build-aux/prog.m4 --- build-aux/prog.m4 (revision 0) +++ build-aux/prog.m4 (revision 0) @@ -0,0 +1,36 @@ +# -*- Autoconf -*- + +# HAVM_PROG(PROGRAM, REQUIRED-VERSION, VARIABLE, DESCRIPTION) +# ----------------------------------------------------------- +# Check whether PROGRAM version is greater or equal to REQUIRED-VERSION. +# Define VARIABLE as an Autoconf variable for this program, along with +# its DESCRIPTION. +AC_DEFUN([HAVM_PROG], + [AC_REQUIRE([AS_VERSION_COMPARE])dnl + AC_ARG_VAR([$3], [$4]) + AC_CHECK_PROGS([$3], [$1]) + [required_version="`echo \"$2\" | grep '^[0-9][0-9.]*$'`"] + if test -z "$required_version" ; then + AC_MSG_ERROR([[This macro requires a [0-9.]+ argument]]) + fi + if test -n "$$3" ; then + AC_CACHE_CHECK([for $1 >= $required_version], + [ac_cv_$1_version], + [[actual_version=`$$3 --version | \ + sed 's/^[^0-9]*\([0-9][0-9.]*[0-9]\).*$/\1/'`] + if test -z "$actual_version" ; then + ac_cv_$1_version=no + else + ac_cv_$1_version=yes + fi + if test x$ac_cv_$1_version = xyes ; then + AS_VERSION_COMPARE([$actual_version], [$required_version], + [ac_cv_$1_version=no], + [ac_cv_$1_version=yes], + [ac_cv_$1_version=yes])]) + fi + fi + if test x$ac_cv_$1_version != xyes; then + AC_MSG_ERROR([$1 $required_version or newer is required]) + fi +]) Index: build-aux/version-compare.m4 --- build-aux/version-compare.m4 (revision 0) +++ build-aux/version-compare.m4 (revision 0) @@ -0,0 +1,80 @@ +# Remove this as soon as Autoconf 2.60 airs. -*- Autoconf -*- + +# _AS_VERSION_COMPARE_PREPARE +# --------------------------- +# Output variables for comparing version numbers. +AC_DEFUN([_AS_VERSION_COMPARE_PREPARE], +[[as_awk_strverscmp=' + # Use only awk features that work with 7th edition Unix awk (1978). + # My, what an old awk you have, Mr. Solaris! + END { + while (length(v1) || length(v2)) { + # Set d1 to be the next thing to compare from v1, and likewise for d2. + # Normally this is a single character, but if v1 and v2 contain digits, + # compare them as integers and fractions as strverscmp does. + if (v1 ~ /^[0-9]/ && v2 ~ /^[0-9]/) { + # Split v1 and v2 into their leading digit string components d1 and d2, + # and advance v1 and v2 past the leading digit strings. + for (len1 = 1; substr(v1, len1 + 1) ~ /^[0-9]/; len1++) continue + for (len2 = 1; substr(v2, len2 + 1) ~ /^[0-9]/; len2++) continue + d1 = substr(v1, 1, len1); v1 = substr(v1, len1 + 1) + d2 = substr(v2, 1, len2); v2 = substr(v2, len2 + 1) + if (d1 ~ /^0/) { + if (d2 ~ /^0/) { + # Compare two fractions. + while (d1 ~ /^0/ && d2 ~ /^0/) { + d1 = substr(d1, 2); len1-- + d2 = substr(d2, 2); len2-- + } + if (len1 != len2 && ! (len1 && len2 && substr(d1, 1, 1) == substr(d2, 1, 1))) { + # The two components differ in length, and the common prefix + # contains only leading zeros. Consider the longer to be less. + d1 = -len1 + d2 = -len2 + } else { + # Otherwise, compare as strings. + d1 = "x" d1 + d2 = "x" d2 + } + } else { + # A fraction is less than an integer. + exit 1 + } + } else { + if (d2 ~ /^0/) { + # An integer is greater than a fraction. + exit 2 + } else { + # Compare two integers. + d1 += 0 + d2 += 0 + } + } + } else { + # The normal case, without worrying about digits. + if (v1 == "") d1 = v1; else { d1 = substr(v1, 1, 1); v1 = substr(v1,2) } + if (v2 == "") d2 = v2; else { d2 = substr(v2, 1, 1); v2 = substr(v2,2) } + } + if (d1 < d2) exit 1 + if (d1 > d2) exit 2 + } + } +']]) + +# AS_VERSION_COMPARE(VERSION-1, VERSION-2, +# [ACTION-IF-LESS], [ACTION-IF-EQUAL], [ACTION-IF-GREATER]) +# ----------------------------------------------------------------------------- +# Compare two strings possibly containing shell variables as version strings. +AC_DEFUN([AS_VERSION_COMPARE], +[AS_REQUIRE([_$0_PREPARE])dnl +as_arg_v1=$1 +as_arg_v2=$2 +dnl This usage is portable even to ancient awk, +dnl so don't worry about finding a "nice" awk version. +awk "$as_awk_strverscmp" v1="$as_arg_v1" v2="$as_arg_v2" /dev/null +case $? in +1) $3;; +0) $4;; +2) $5;; +esac[]dnl +])
participants (1)
-
Roland Levillain