From f03b6d77c4a2bcf7bdf4855a61ff6501e83021b6 Mon Sep 17 00:00:00 2001
From: Brian Tarricone <brian@tarricone.org>
Date: Tue, 28 Jul 2009 22:10:06 +0000
Subject: [PATCH] add --version and -V options, add required minimum version
 check.

users who wish to require a minimum version of xdt-autogen should
export XDT_AUTOGEN_REQUIRED_VERSION, set to the minimum required version
that is supported.

(Old svn revision: 30414)
---
 ChangeLog                                     |  7 ++
 NEWS                                          |  4 +
 configure.in.in                               | 16 +++-
 scripts/Makefile.am                           |  4 +-
 scripts/{xdt-autogen.in => xdt-autogen.in.in} | 83 +++++++++++++++++++
 5 files changed, 110 insertions(+), 4 deletions(-)
 rename scripts/{xdt-autogen.in => xdt-autogen.in.in} (81%)

diff --git a/ChangeLog b/ChangeLog
index ab841fe..f9e1047 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2009-07-28	Brian Tarricone <brian@tarricone.org>
+
+	* scripts/xdt-autogen.in: Renamed to xdt-autogen.in.in.
+	* scripts/xdt-autogen.in.in: Add --version and -V options.  Add a
+	  minimum required version check via the XDT_AUTOGEN_REQUIRED_VERSION
+	  env var.
+
 2009-07-27	Brian Tarricone <brian@tarricone.org>
 
 	* scripts/xdt-autogen.in: Also support newer IT_PROG_INTLTOOL
diff --git a/NEWS b/NEWS
index cce6e57..d280e43 100644
--- a/NEWS
+++ b/NEWS
@@ -1,6 +1,10 @@
 4.6.2
 =====
 - Also support the newer IT_PROG_INTLTOOL macro
+- Added --version and -V options to display the xdt-autogen version
+- Added ability for autogen.sh scripts to set an environment
+  variable XDT_AUTOGEN_REQUIRED_VERSION to depend on a particular version
+  of xdt-autogen.
 
 4.6.0
 =====
diff --git a/configure.in.in b/configure.in.in
index 52c10ec..746759a 100644
--- a/configure.in.in
+++ b/configure.in.in
@@ -11,10 +11,10 @@ dnl *** Version information ***
 dnl ***************************
 m4_define([xdt_version_major], [4])
 m4_define([xdt_version_minor], [6])
-m4_define([xdt_version_micro], [0])
+m4_define([xdt_version_micro], [1])
 m4_define([xdt_version_nano], [])
 m4_define([xdt_version_build], [r@REVISION@])
-m4_define([xdt_version_tag], [])
+m4_define([xdt_version_tag], [svn])
 m4_define([xdt_version], [xdt_version_major().xdt_version_minor().xdt_version_micro()ifelse(xdt_version_nano(), [], [], [.xdt_version_nano()])ifelse(xdt_version_tag(), [svn], [xdt_version_tag()-xdt_version_build()], [])])
 
 
@@ -25,13 +25,22 @@ dnl # YOU ARE DOING.
 dnl ***************************
 dnl *** Initialize autoconf ***
 dnl ***************************
-AC_INIT([xfce4-dev-tools], [xdt_version], [xfce4-dev@xfce.org])
+AC_INIT([xfce4-dev-tools], [xdt_version],
+        [http://bugzilla.xfce.org/enter_bug.cgi?product=Xfce4-dev-tools])
 AC_COPYRIGHT([Copyright (c) 2002-2008
         The Xfce development team. All rights reserved.
 
 Written for Xfce by Benedikt Meurer <benny@xfce.org>.])
 AC_REVISION([$Id$])
 
+dnl substitute version info
+AC_SUBST([VERSION_MAJOR], [xdt_version_major])
+AC_SUBST([VERSION_MINOR], [xdt_version_minor])
+AC_SUBST([VERSION_MICRO], [xdt_version_micro])
+AC_SUBST([VERSION_NANO], [xdt_version_nano])
+VERSION_REVISION=ifelse(xdt_version_tag(), [svn], [xdt_version_tag()-xdt_version_build()], [])
+AC_SUBST([VERSION_REVISION])
+
 dnl ***************************
 dnl *** Initialize automake ***
 dnl ***************************
@@ -51,6 +60,7 @@ Makefile
 xfce4-dev-tools.spec
 m4macros/Makefile
 scripts/Makefile
+scripts/xdt-autogen.in
 ])
 
 dnl vi:set ts=2 sw=2 et ai:
diff --git a/scripts/Makefile.am b/scripts/Makefile.am
index a3ecd01..28fe7e1 100644
--- a/scripts/Makefile.am
+++ b/scripts/Makefile.am
@@ -20,8 +20,10 @@ xdt-autogen: Makefile $(srcdir)/xdt-autogen.in
 CLEANFILES =								\
 	xdt-autogen
 
+DISTCLEANFILES = 							\
+	xdt-autogen.in
+
 EXTRA_DIST =								\
-	xdt-autogen.in							\
 	xdt-commit
 
 # vi:set ts=8 sw=8 noet ai:
diff --git a/scripts/xdt-autogen.in b/scripts/xdt-autogen.in.in
similarity index 81%
rename from scripts/xdt-autogen.in
rename to scripts/xdt-autogen.in.in
index d842a12..c3b9f77 100644
--- a/scripts/xdt-autogen.in
+++ b/scripts/xdt-autogen.in.in
@@ -24,6 +24,13 @@
 # xdt-autogen - Part of the Xfce developer tools.
 #
 
+VERSION="@VERSION@"
+
+XDT_AUTOGEN_VERSION_MAJOR="@VERSION_MAJOR@"
+XDT_AUTOGEN_VERSION_MINOR="@VERSION_MINOR@"
+XDT_AUTOGEN_VERSION_MICRO="@VERSION_MICRO@"
+XDT_AUTOGEN_VERSION_NANO="@VERSION_NANO@"
+XDT_AUTOGEN_VERSION_REVISION="@VERSION_REVISION@"
 
 ##
 ## Helper function to lookup configure.{in,ac} files recursively.
@@ -56,6 +63,82 @@ EOF
   done
 }
 
+##
+## check command-line args
+##
+if test "x$1" = "x--version" -o "x$1" = "x-V"; then
+  echo "`basename $0` $VERSION"
+  exit 0
+fi
+
+##
+## see if the caller is requesting a minimum version
+##
+do_version_check() {
+  test -z "$XDT_AUTOGEN_REQUIRED_VERSION" && return 0
+
+  major=`echo $XDT_AUTOGEN_REQUIRED_VERSION | cut -d. -f1`
+  test "$major" || return 1
+  test $major -le $XDT_AUTOGEN_VERSION_MAJOR || return 1
+  test $XDT_AUTOGEN_VERSION_MAJOR -gt $major && return 0
+
+  minor=`echo $XDT_AUTOGEN_REQUIRED_VERSION | cut -d. -f2`
+  test "$minor" || return 1
+  test $minor -le $XDT_AUTOGEN_VERSION_MINOR || return 1
+  test $XDT_AUTOGEN_VERSION_MINOR -gt $minor && return 0
+
+  micro=`echo $XDT_AUTOGEN_REQUIRED_VERSION | cut -d. -f3`
+  if echo "$micro" | grep -E -q "svn|git"; then
+    revision=`echo "$micro" | sed -e 's/[[:digit:].]\+\(.*\)/\1/'`
+    micro=`echo "$micro" | sed -e 's/\([[:digit:].]\+\).*/\1/'`
+  fi
+  if echo "$micro" | grep -q '\.'; then
+    nano=`echo "$micro" | cut -d. -f2`
+    micro=`echo "$micro" | cut -d. -f1`
+  fi
+
+  test "$micro" || return 1
+  test $micro -le $XDT_AUTOGEN_VERSION_MICRO || return 1
+  test $XDT_AUTOGEN_VERSION_MICRO -gt $micro && return 0
+
+  # the caller may or may not have specified a nano
+  if test "$nano"; then
+    # and we may or may not have a nano
+    test "$XDT_AUTOGEN_VERSION_NANO" || XDT_AUTOGEN_VERSION_NANO="0"
+
+    test $nano -le $XDT_AUTOGEN_VERSION_NANO || return 1
+    test $XDT_AUTOGEN_VERSION_NANO -gt $nano && return 0
+  fi
+
+  # the caller may or may not have specified a revision
+  if test "$revision"; then
+    # if we don't have a revision, then the check fails
+    test "$XDT_AUTOGEN_VERSION_REVISION" || return 1
+    
+    # version compares are handled differently between svn and git.
+    if echo "$revision" | grep -q "svn"; then
+      # if our revision includes "git", then we must be newer
+      echo "$XDT_AUTOGEN_VERSION_REVISION" | grep -q "git" && return 0
+
+      # figure out the revision numbers
+      rev_num=`echo "$revision" | sed -e 's/svn-r\([[:digit:]]\+\)/\1/'`
+      XDT_AUTOGEN_VERSION_REV_NUM=`echo "$XDT_AUTOGEN_VERSION_REVISION" | sed -e 's/svn-r\([[:digit:]]\+\)/\1/'`
+      test $rev_num -le $XDT_AUTOGEN_VERSION_REV_NUM || return 1
+    elif echo "$revision" | grep -q "git"; then
+      echo "Error: git revision comparison not yet implemented.  Please file a bug:"
+      echo "@PACKAGE_BUGREPORT@"
+      exit 1
+    fi
+  fi
+
+  return 0
+}
+
+if ! do_version_check; then
+  echo "This version of xdt-autogen ($VERSION) is too old.  Version" >&2
+  echo "$XDT_AUTOGEN_REQUIRED_VERSION or greater is required." >&2
+  exit 1
+fi
 
 ##
 ## Determine XDG data dirs
-- 
GitLab