]> git.ipfire.org Git - thirdparty/automake.git/commitdiff
* lib/Automake/Version.pm: New file.
authorAlexandre Duret-Lutz <adl@gnu.org>
Fri, 11 Apr 2003 22:11:43 +0000 (22:11 +0000)
committerAlexandre Duret-Lutz <adl@gnu.org>
Fri, 11 Apr 2003 22:11:43 +0000 (22:11 +0000)
* lib/Automake/Makefile.am (dist_perllib_DATA): Add Version.pm.
* lib/Automake/tests/Version.pl: New file.
* lib/Automake/tests/Makefile.am (TESTS): Add Version.pl.
* tests/Makefile.am (TESTS): Remove version5.test.
* tests/version5.test: Delete.  Move the tests to Version.pl.
* automake.in (version_split, version_compare, version_check): Move ...
* lib/Automake/Version.pm (split, compare, check): ... here.

ChangeLog
automake.in
lib/Automake/Makefile.am
lib/Automake/Makefile.in
lib/Automake/Version.pm [new file with mode: 0644]
lib/Automake/tests/Makefile.am
lib/Automake/tests/Makefile.in
lib/Automake/tests/Version.pl [moved from tests/version5.test with 61% similarity, mode: 0644]
tests/Makefile.am
tests/Makefile.in

index 6c19021d22a9e7a9e29e1a53a0b90ce177e972f2..e5c188bf18bcf1ad0689ec94e8825416f380b4b5 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2003-04-12  Alexandre Duret-Lutz  <adl@gnu.org>
+
+       * lib/Automake/Version.pm: New file.
+       * lib/Automake/Makefile.am (dist_perllib_DATA): Add Version.pm.
+       * lib/Automake/tests/Version.pl: New file.
+       * lib/Automake/tests/Makefile.am (TESTS): Add Version.pl.
+       * tests/Makefile.am (TESTS): Remove version5.test.
+       * tests/version5.test: Delete.  Move the tests to Version.pl.
+       * automake.in (version_split, version_compare, version_check): Move ...
+       * lib/Automake/Version.pm (split, compare, check): ... here.
+
 2003-04-11  Alexandre Duret-Lutz  <adl@gnu.org>
 
        * lib/Automake/tests/Condition.pl (test_reduce_and)
index c0b899b2ac902e07391a425058c73775fa85ae8d..ac582c595ef569d9e8f8b2001a540d8b41ee011f 100755 (executable)
@@ -128,6 +128,7 @@ use Automake::ChannelDefs;
 use Automake::Location;
 use Automake::Condition qw/TRUE FALSE/;
 use Automake::DisjConditions;
+use Automake::Version;
 use File::Basename;
 use Tie::RefHash;
 use Carp;
@@ -1634,92 +1635,6 @@ sub generate_makefile
 
 ################################################################
 
-# A version is a string that looks like
-#   MAJOR.MINOR[.MICRO][ALPHA][-FORK]
-# where
-#   MAJOR, MINOR, and MICRO are digits, ALPHA is a character, and
-# FORK any alphanumeric word.
-# Usually, ALPHA is used to label alpha releases or intermediate snapshots,
-# FORK is used for CVS branches or patched releases, and MICRO is used
-# for bug fixes releases on the MAJOR.MINOR branch.
-#
-# For the purpose of ordering, 1.4 is the same as 1.4.0, but 1.4g is
-# the same as 1.4.99g.  The FORK identifier is ignored in the
-# ordering, except when it looks like -pMINOR[ALPHA]: some versions
-# were labeled like 1.4-p3a, this is the same as an alpha release
-# labeled 1.4.3a.  Yes, it's horrible, but Automake did not support
-# two-dot versions in the past.
-
-# version_split (VERSION)
-# -----------------------
-# Split a version string into the corresponding (MAJOR, MINOR, MICRO,
-# ALPHA, FORK) tuple.  For instance "1.4g" would be split into
-# (1, 4, 99, 'g', '').
-# Return () on error.
-sub version_split ($)
-{
-    my ($ver) = @_;
-
-    # Special case for versions like 1.4-p2a.
-    if ($ver =~ /^(\d+)\.(\d+)(?:-p(\d+)([a-z]+)?)$/)
-    {
-       return ($1, $2, $3, $4 || '', '');
-    }
-    # Common case.
-    elsif ($ver =~ /^(\d+)\.(\d+)(?:\.(\d+))?([a-z])?(?:-([A-Za-z0-9]+))?$/)
-    {
-       return ($1, $2, $3 || (defined $4 ? 99 : 0), $4 || '', $5 || '');
-    }
-    return ();
-}
-
-# version_compare (\@LVERSION, \@RVERSION)
-# ----------------------------------------
-# Return 1 if LVERSION > RVERSION,
-#       -1 if LVERSION < RVERSION,
-#        0 if LVERSION = RVERSION.
-sub version_compare (\@\@)
-{
-    my @l = @{$_[0]};
-    my @r = @{$_[1]};
-
-    for my $i (0, 1, 2)
-    {
-       return 1  if ($l[$i] > $r[$i]);
-       return -1 if ($l[$i] < $r[$i]);
-    }
-    for my $i (3, 4)
-    {
-       return 1  if ($l[$i] gt $r[$i]);
-       return -1 if ($l[$i] lt $r[$i]);
-    }
-    return 0;
-}
-
-# Handles the logic of requiring a version number in AUTOMAKE_OPTIONS.
-# Return 0 if the required version is satisfied, 1 otherwise.
-sub version_check ($)
-{
-  my ($required) = @_;
-  my @version = version_split $VERSION;
-  my @required = version_split $required;
-
-  prog_error "version is incorrect: $VERSION"
-    if $#version == -1;
-
-  # This should not happen, because process_option_list and split_version
-  # use similar regexes.
-  prog_error "required version is incorrect: $required"
-    if $#required == -1;
-
-  # If we require 3.4n-foo then we require something
-  # >= 3.4n, with the `foo' fork identifier.
-  return 1
-    if ($required[4] ne '' && $required[4] ne $version[4]);
-
-  return 0 > version_compare @version, @required;
-}
-
 # $BOOL
 # process_option_list ($CONFIG, @OPTIONS)
 # ------------------------------
@@ -1771,7 +1686,7 @@ sub process_option_list
       elsif (/^\d+\.\d+(?:\.\d+)?[a-z]?(?:-[A-Za-z0-9]+)?$/)
        {
          # Got a version number.
-         if (version_check $&)
+         if (Automake::Version::check ($VERSION, $&))
            {
              error ($where, "require Automake $_, but have $VERSION",
                     uniq_scope => US_GLOBAL);
index c724c874ed4eee061c1a3e2824b03dae2c53a91c..c51546f78145f035771ff08ee876b71613ffdb3c 100644 (file)
@@ -28,4 +28,5 @@ dist_perllib_DATA = \
   General.pm \
   Location.pm \
   Struct.pm \
+  Version.pm \
   XFile.pm
index d45051cd86ce76e57c973afd53b51abb9a2bdacb..d6d04e4daa918b8a611dcca77b630e479bf57424 100644 (file)
@@ -128,6 +128,7 @@ dist_perllib_DATA = \
   General.pm \
   Location.pm \
   Struct.pm \
+  Version.pm \
   XFile.pm
 
 all: all-recursive
diff --git a/lib/Automake/Version.pm b/lib/Automake/Version.pm
new file mode 100644 (file)
index 0000000..5a874f8
--- /dev/null
@@ -0,0 +1,159 @@
+# Copyright (C) 2001, 2002, 2003  Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+# 02111-1307, USA.
+
+package Automake::Version;
+use strict;
+use Automake::ChannelDefs;
+
+=head1 NAME
+
+Automake::Version - version comparison
+
+=head1 SYNOPSIS
+
+  use Automake::Version;
+
+  print "Version $version is older than required version $required\n"
+    if Automake::Version::check ($version, $required);
+
+=head1 DESCRIPTION
+
+This module provides support for comparing versions string
+as they are used in Automake.
+
+A version is a string that looks like
+C<MAJOR.MINOR[.MICRO][ALPHA][-FORK]> where C<MAJOR>, C<MINOR>, and
+C<MICRO> are digits, C<ALPHA> is a character, and C<FORK> any
+alphanumeric word.
+
+Usually, C<ALPHA> is used to label alpha releases or intermediate
+snapshots, C<FORK> is used for CVS branches or patched releases, and
+C<MICRO> is used for bug fixes releases on the C<MAJOR.MINOR> branch.
+
+For the purpose of ordering, C<1.4> is the same as C<1.4.0>, but
+C<1.4g> is the same as C<1.4.99g>.  The C<FORK> identifier is ignored
+in the ordering, except when it looks like C<-pMINOR[ALPHA]>: some
+versions were labeled like C<1.4-p3a>, this is the same as an alpha
+release labeled C<1.4.3a>.  Yes, it's horrible, but Automake did not
+support two-dot versions in the past.
+
+=head2 FUNCTIONS
+
+=over 4
+
+=item C<split ($version)>
+
+Split the string C<$version> into the corresponding C<(MAJOR, MINOR,
+MICRO, ALPHA, FORK)> tuple.  For instance C<'1.4g'> would be split
+into C<(1, 4, 99, 'g', '')>.  Return C<()> on error.
+
+=cut
+
+sub split ($)
+{
+  my ($ver) = @_;
+
+  # Special case for versions like 1.4-p2a.
+  if ($ver =~ /^(\d+)\.(\d+)(?:-p(\d+)([a-z]+)?)$/)
+  {
+    return ($1, $2, $3, $4 || '', '');
+  }
+  # Common case.
+  elsif ($ver =~ /^(\d+)\.(\d+)(?:\.(\d+))?([a-z])?(?:-([A-Za-z0-9]+))?$/)
+  {
+    return ($1, $2, $3 || (defined $4 ? 99 : 0), $4 || '', $5 || '');
+  }
+  return ();
+}
+
+=item C<compare (\@LVERSION, \@RVERSION)>
+
+Compare two version tuples, as returned by C<split>.
+
+Return 1, 0, or -1, if C<LVERSION> is found to be respectively
+greater than, equal to, or less than C<RVERSION>.
+
+=cut
+
+sub compare (\@\@)
+{
+  my @l = @{$_[0]};
+  my @r = @{$_[1]};
+
+  for my $i (0, 1, 2)
+  {
+    return 1  if ($l[$i] > $r[$i]);
+    return -1 if ($l[$i] < $r[$i]);
+  }
+  for my $i (3, 4)
+  {
+    return 1  if ($l[$i] gt $r[$i]);
+    return -1 if ($l[$i] lt $r[$i]);
+  }
+  return 0;
+}
+
+=item C<check($VERSION, $REQUIRED)>
+
+Handles the logic of requiring a version number in Automake.
+C<$VERSION> should be Automake's version, while C<$REQUIRED>
+is the version required by the user input.
+
+Return 0 if the required version is satisfied, 1 otherwise.
+
+=cut
+
+sub check ($$)
+{
+  my ($version, $required) = @_;
+  my @version = Automake::Version::split ($version);
+  my @required = Automake::Version::split ($required);
+
+  prog_error "version is incorrect: $version"
+    if $#version == -1;
+
+  # This should not happen, because process_option_list and split_version
+  # use similar regexes.
+  prog_error "required version is incorrect: $required"
+    if $#required == -1;
+
+  # If we require 3.4n-foo then we require something
+  # >= 3.4n, with the `foo' fork identifier.
+  return 1
+    if ($required[4] ne '' && $required[4] ne $version[4]);
+
+  return 0 > compare (@version, @required);
+}
+
+1;
+
+### Setup "GNU" style for perl-mode and cperl-mode.
+## Local Variables:
+## perl-indent-level: 2
+## perl-continued-statement-offset: 2
+## perl-continued-brace-offset: 0
+## perl-brace-offset: 0
+## perl-brace-imaginary-offset: 0
+## perl-label-offset: -2
+## cperl-indent-level: 2
+## cperl-brace-offset: 0
+## cperl-continued-brace-offset: 0
+## cperl-label-offset: -2
+## cperl-extra-newline-before-brace: t
+## cperl-merge-trailing-else: nil
+## cperl-continued-statement-offset: 2
+## End:
index 1fefa71575e9705c228fc558e1d40aa73fb7318d..22127660eb1a8d09b9649d0b242ae2934bd6dc08 100644 (file)
@@ -20,6 +20,7 @@
 TESTS_ENVIRONMENT = $(PERL) -Mstrict -I $(top_srcdir)/lib -w
 TESTS = \
 Condition.pl \
-DisjConditions.pl
+DisjConditions.pl \
+Version.pl
 
 EXTRA_DIST = $(TESTS)
index 9050a37e6668ba784bea938544a68a7e6c10a351..822c081709386ce2c9506f0a191226a26ffa7fa5 100644 (file)
@@ -107,7 +107,8 @@ target_alias = @target_alias@
 TESTS_ENVIRONMENT = $(PERL) -Mstrict -I $(top_srcdir)/lib -w
 TESTS = \
 Condition.pl \
-DisjConditions.pl
+DisjConditions.pl \
+Version.pl
 
 EXTRA_DIST = $(TESTS)
 all: all-am
old mode 100755 (executable)
new mode 100644 (file)
similarity index 61%
rename from tests/version5.test
rename to lib/Automake/tests/Version.pl
index 2995dcc..f8e2a40
@@ -1,5 +1,4 @@
-#! /bin/sh
-# Copyright (C) 2002  Free Software Foundation, Inc.
+# Copyright (C) 2002, 2003  Free Software Foundation, Inc.
 #
 # This file is part of GNU Automake.
 #
 # GNU General Public License for more details.
 #
 # You should have received a copy of the GNU General Public License
-# along with autoconf; see the file COPYING.  If not, write to
+# along with Automake; see the file COPYING.  If not, write to
 # the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 # Boston, MA 02111-1307, USA.
 
-# Exercise &version_compare.
-
-. ./defs || exit 1
-
-set -e
-
-# FIXME: probably ought to let users override this like we do in `defs'.
-amfile=../../automake
-
-sed 1q $amfile >>automake_tmp
-cat << 'END' >> automake_tmp
+use Automake::Version;
 
 my $failed = 0;
 
 sub test_version_compare
 {
   my ($left, $right, $result) = @_;
-  my @leftver = Automake::version_split ($left);
-  my @rightver = Automake::version_split ($right);
+  my @leftver = Automake::Version::split ($left);
+  my @rightver = Automake::Version::split ($right);
   if ($#leftver == -1)
   {
-     print "can't grok \"$left\"\n";
-     $failed = 1;
-     return;
+    print "can't grok \"$left\"\n";
+    $failed = 1;
+    return;
   }
   if ($#rightver == -1)
   {
-     print "can't grok \"$right\"\n";
-     $failed = 1;
-     return;
+    print "can't grok \"$right\"\n";
+    $failed = 1;
+    return;
   }
-  my $res = Automake::version_compare (\@leftver, \@rightver);
+  my $res = Automake::Version::compare (@leftver, @rightver);
   if ($res != $result)
   {
-     print "version_compare (\"$left\", \"$right\") = $res! (not $result?)\n";
-     $failed = 1;
+    print "compare (\"$left\", \"$right\") = $res! (not $result?)\n";
+    $failed = 1;
   }
 }
 
@@ -93,8 +82,20 @@ my @tests = (
 test_version_compare (@{$_}) foreach @tests;
 
 exit $failed;
-END
-
-cat $amfile >>automake_tmp
 
-$PERL ./automake_tmp
+### Setup "GNU" style for perl-mode and cperl-mode.
+## Local Variables:
+## perl-indent-level: 2
+## perl-continued-statement-offset: 2
+## perl-continued-brace-offset: 0
+## perl-brace-offset: 0
+## perl-brace-imaginary-offset: 0
+## perl-label-offset: -2
+## cperl-indent-level: 2
+## cperl-brace-offset: 0
+## cperl-continued-brace-offset: 0
+## cperl-label-offset: -2
+## cperl-extra-newline-before-brace: t
+## cperl-merge-trailing-else: nil
+## cperl-continued-statement-offset: 2
+## End:
index 3f70ff58f40a9cbaa90fe736d9cd9ff241f9cee7..e0c9ae65c454322ee6b6075b10e868ad084a08b4 100644 (file)
@@ -440,7 +440,6 @@ version.test \
 version2.test \
 version3.test \
 version4.test \
-version5.test \
 version6.test \
 version7.test \
 vpath.test \
index 65f4a8bd46bcb0113be297c53a793e13302f24d8..9a19ca9c3a923fca4f55036c8ac52041e4387706 100644 (file)
@@ -543,7 +543,6 @@ version.test \
 version2.test \
 version3.test \
 version4.test \
-version5.test \
 version6.test \
 version7.test \
 vpath.test \