From 6c3ff1c438d4f8ee8eed534122e030027a0eea29 Mon Sep 17 00:00:00 2001
From: Jeff Squyres <jsquyres@cisco.com>
Date: Thu, 25 Jun 2009 16:50:53 +0000
Subject: [PATCH] Modify make_dist_tarball to conditionally allow it when
 ''higher'' than expected versions of tools are found.  make_dist_tarball will
 ''not'' accept lower or higher versions by default (since the goal is exact
 reproducability, after all), but you can specify the --highok command line
 switch to allow it.

I'm also removing make_tarball in this commit and will replace it with
a sym link to make_dist_tarball in the next commit.  The script will
default to allowing higher versions of the tools when invoked with an
argv[0] of "make tarball" (i.e., --highok is not necessary, but is
harmless).

This commit was SVN r21530.
---
 contrib/dist/make_dist_tarball | 115 ++++++++++++++++++-
 contrib/dist/make_tarball      | 204 ---------------------------------
 2 files changed, 109 insertions(+), 210 deletions(-)
 delete mode 100755 contrib/dist/make_tarball

diff --git a/contrib/dist/make_dist_tarball b/contrib/dist/make_dist_tarball
index 55630ad640..4d34c652f6 100755
--- a/contrib/dist/make_dist_tarball
+++ b/contrib/dist/make_dist_tarball
@@ -10,7 +10,7 @@
 #                         University of Stuttgart.  All rights reserved.
 # Copyright (c) 2004-2005 The Regents of the University of California.
 #                         All rights reserved.
-# Copyright (c) 2008      Cisco Systems, Inc.  All rights reserved.
+# Copyright (c) 2008-2009 Cisco Systems, Inc.  All rights reserved.
 # $COPYRIGHT$
 # 
 # Additional copyrights may follow
@@ -27,6 +27,32 @@ AM_TARGET_VERSION=1.10.1
 AC_TARGET_VERSION=2.63
 LT_TARGET_VERSION=2.2.6
 
+#
+# Check command line flags
+#
+
+# Default to requiring *exact* versions if we're making distribution
+# tarballs; but higher-than-expected versions are ok for
+# non-distribution tarballs.
+dist_target=distcheck
+if test "`basename $0`" = "make_tarball"; then
+    dist_target=dist
+    highok=1
+else
+    highok=0
+fi
+
+greekonly=0
+while test "$1" != ""; do
+    case $1 in
+        -greekonly) greekonly=1 ;;
+        --greekonly) greekonly=1 ;;
+        -highok) highok=1 ;;
+        --highok) highok=1 ;;
+    esac
+    shift
+done
+
 #
 # First things first -- check that the auto versions that we have are
 # the ones that we want.
@@ -37,10 +63,46 @@ check_gnu_version() {
     target="$2"
 
     ver="`$prog --version | head -n 1 | sed -e's/([^)]*)//g' -e's/[^0-9 .][^ ]* / /g' -e's/ //g'`"
+
+    ver_major=`echo $ver | cut -d. -f1`
+    ver_minor=`echo $ver | cut -d. -f2`
+    ver_release=`echo $ver | cut -d. -f3`
+    if test "$ver_release" = ""; then
+        ver_release=0
+    fi
+
+    target_major=`echo $target | cut -d. -f1`
+    target_minor=`echo $target | cut -d. -f2`
+    target_release=`echo $target | cut -d. -f3`
+    if test "$target_release" = ""; then
+        target_release=0
+    fi
+
+    result=same
     if test "$ver" != "$target"; then 
+        if test "$ver_major" -lt "$target_major"; then
+            result=low
+        elif test "$ver_major" = "$target_major" -a "$ver_minor" -lt "$target_minor"; then
+            result=low
+        elif test "$ver_major" = "$target_major" -a "$ver_minor" = "$target_minor" -a "$ver_release" -lt "$target_release"; then
+            result=low
+        elif test "$ver_major" -gt "$target_major"; then
+            result=high
+        elif test "$ver_major" = "$target_major" -a "$ver_minor" -gt "$target_minor"; then
+            result=high
+        elif test "$ver_major" = "$target_major" -a "$ver_minor" = "$target_minor" -a "$ver_release" -gt "$target_release"; then
+            result=high
+        else
+            result=unknown
+        fi
+    fi
+
+    if test "$result" = "low"; then
         cat <<EOF
-ERROR: Program "$prog" does not have the correct/expected version:
+----------------------------------------------------------------------
+ERROR: Program "$prog" does not have a high enough version:
        Found: $ver
+       Expected: $target
 
 Expected versions:
 m4: $M4_TARGET_VERSION
@@ -50,9 +112,50 @@ Libtool:  $LT_TARGET_VERSION
 
 Either change this script to match the found version, or install
 the correct version of the tools.
+----------------------------------------------------------------------
 EOF
         exit 1
     fi
+
+    if test "$result" = "high"; then
+        if test "$highok" = "0"; then
+            cat <<EOF
+----------------------------------------------------------------------
+ERROR: Program "$prog" has a higher version than expected:
+       Found: $ver
+       Expected: $target
+
+Expected versions:
+m4: $M4_TARGET_VERSION
+Automake: $AM_TARGET_VERSION
+Autoconf: $AC_TARGET_VERSION
+Libtool:  $LT_TARGET_VERSION
+
+Either change this script to match the found version, or install
+the correct version of the tools.
+----------------------------------------------------------------------
+EOF
+            exit 1
+        else
+            cat <<EOF
+----------------------------------------------------------------------
+WARNING: Program "$prog" has a higher version than expected:
+         Found: $ver
+         Expected: $target
+
+Expected versions:
+m4: $M4_TARGET_VERSION
+Automake: $AM_TARGET_VERSION
+Autoconf: $AC_TARGET_VERSION
+Libtool:  $LT_TARGET_VERSION
+
+This is *usually* ok, but this script is going to sleep for 5 seconds
+to give you the chance to quit before doing anything.
+----------------------------------------------------------------------
+EOF
+            sleep 5
+        fi
+    fi
 }
 
 #
@@ -85,13 +188,13 @@ make_tarball() {
     #
     # make tarball
     #
-    echo "*** Running make distcheck..."
+    echo "*** Running make $dist_target..."
     save_LD=$LD_LIBRARY_PATH
     LD_LIBRARY_PATH=
     rm -f success
-    (make distcheck 2>&1 && touch success) | tee dist.out
+    (make $dist_target 2>&1 && touch success) | tee dist.out
     if test ! -f success; then
-        echo "Make dist failed.  Aborting"
+        echo "Make $dist_target failed.  Aborting"
         exit 1
     fi
     rm -f success
@@ -190,7 +293,7 @@ make_tarball
 
 # Now if ! --greekonly, make the non-greek tarball
 
-if test "$1" != "-greekonly" -a "$1" != "--greekonly"; then
+if test "$greekonly" = "0"; then
     echo "*** REMOVING ALL GREEK FROM VERSION NUMBERS!!"
     for file in $version_files; do
         echo " - $file"
diff --git a/contrib/dist/make_tarball b/contrib/dist/make_tarball
deleted file mode 100755
index 5c832d4628..0000000000
--- a/contrib/dist/make_tarball
+++ /dev/null
@@ -1,204 +0,0 @@
-#!/bin/sh
-#
-# Copyright (c) 2004-2006 The Trustees of Indiana University and Indiana
-#                         University Research and Technology
-#                         Corporation.  All rights reserved.
-# Copyright (c) 2004-2005 The University of Tennessee and The University
-#                         of Tennessee Research Foundation.  All rights
-#                         reserved.
-# Copyright (c) 2004-2005 High Performance Computing Center Stuttgart, 
-#                         University of Stuttgart.  All rights reserved.
-# Copyright (c) 2004-2005 The Regents of the University of California.
-#                         All rights reserved.
-# Copyright (c) 2008      Cisco Systems, Inc.  All rights reserved.
-# $COPYRIGHT$
-# 
-# Additional copyrights may follow
-# 
-# $HEADER$
-#
-
-#
-# Version of auto tools that we want
-#
-
-M4_TARGET_VERSION=1.4.11
-AM_TARGET_VERSION=1.10.1
-AC_TARGET_VERSION=2.63
-LT_TARGET_VERSION=2.2.6
-
-#
-# First things first -- check that the auto versions that we have are
-# the ones that we want.
-#
-
-check_gnu_version() {
-    prog="$1"
-    target="$2"
-
-    ver="`$prog --version | head -n 1 | sed -e's/([^)]*)//g' -e's/[^0-9 .][^ ]* / /g' -e's/ //g'`"
-    if test "$ver" != "$target"; then 
-        cat <<EOF
-ERROR: Program "$prog" does not have the correct/expected version:
-       Found: $ver
-
-Expected versions:
-m4: $M4_TARGET_VERSION
-Automake: $AM_TARGET_VERSION
-Autoconf: $AC_TARGET_VERSION
-Libtool:  $LT_TARGET_VERSION
-
-Either change this script to match the found version, or install
-the correct version of the tools.
-EOF
-        exit 1
-    fi
-}
-
-#
-# Subroutine to actually make a tarball
-#
-
-make_tarball() {
-    #
-    # Autogen
-    #
-    echo "*** Running autogen.sh..."
-    rm -f success
-    (./autogen.sh 2>&1 && touch success) | tee auto.out
-    if test ! -f success; then
-        echo "Autogen failed.  Aborting"
-        exit 1
-    fi
-
-    #
-    # Configure
-    #
-    echo "*** Running configure..."
-    rm -f success
-    (./configure --enable-dist 2>&1 && touch success) | tee config.out
-    if test ! -f success; then
-        echo "Configure failed.  Aborting"
-        exit 1
-    fi
-
-    #
-    # make tarball
-    #
-    echo "*** Running make distcheck..."
-    save_LD=$LD_LIBRARY_PATH
-    LD_LIBRARY_PATH=
-    rm -f success
-    (make dist 2>&1 && touch success) | tee dist.out
-    if test ! -f success; then
-        echo "Make dist failed.  Aborting"
-        exit 1
-    fi
-    rm -f success
-    LD_LIBRARY_PATH=$save_LD
-
-    #
-    # move
-    #
-    echo "*** Moving tarballs..."
-    mv openmpi-* ..
-
-    echo "*** All done"
-}
-
-#########################################################################
-# main
-#########################################################################
-
-echo "*** Checking GNU tools versions..."
-check_gnu_version m4 $M4_TARGET_VERSION
-check_gnu_version automake $AM_TARGET_VERSION
-check_gnu_version autoconf $AC_TARGET_VERSION
-check_gnu_version libtool $LT_TARGET_VERSION
-
-#
-# Verify that we're in a top Open MPI dir
-#
-echo "*** Checking to ensure in top-level Open MPI directory..."
-if test -f VERSION -a -f configure.ac -a -f config/opal_setup_cc.m4; then
-    happy=1
-else
-    echo "Do not appear to be in an Open MPI top directory.  Abort!"
-    exit 1
-fi
-
-#
-# Do svn up and all that
-#
-echo "*** Removing old VERSION file..."
-rm -f VERSION
-
-if test -d .svn; then
-    echo "*** Running svn up..."
-    svn up
-    if test ! "$?" = "0"; then
-        echo "SVN update failed.  Aborting"
-        exit 1
-    fi
-elif test -d .hg; then
-    echo "*** Running hg up..."
-    hg revert VERSION
-    hg up
-    if test ! "$?" = "0"; then
-        echo "HG update failed.  Aborting"
-        exit 1
-    fi
-fi
-
-#
-# Ditch "svn/hg" from all version numbers
-#
-echo "*** Removing svn version numbers..."
-svn_r="r`svnversion .`"
-version_files=VERSION
-release_date=`date '+%b %d, %Y'`
-for file in $version_files; do
-    echo " - $file"
-    sed -e 's/^want_svn=.*/want_svn=0/' \
-        -e 's/^svn_r=.*/'svn_r=$svn_r/ \
-        -e "s/^date=.*/date=\"$release_date\"/" \
-        $file > $file.new
-    cp -f $file.new $file
-    rm $file.new
-done
-
-#
-# Make 2 tarballs:
-#
-# - one with the greek
-# - one without the greek
-#
-# unless the user specifically said --greekonly, then only make the
-# greek tarball.  Making both tarballs at once allows us to guarantee
-# to have two tarballs -- one greek and one not -- that have exactly
-# the same SVN r number (as opposed to, for example, running this
-# script to make a greek tarball, then running it again to make a
-# non-greek tarball -- there is a race condition that someone could
-# commit in the meantime and change the SVN r number in the 2nd
-# tarball)
-#
-
-# First, make greek tarball
-
-echo "*** Making greek tarball"
-make_tarball
-
-# Now if ! --greekonly, make the non-greek tarball
-
-if test "$1" != "-greekonly" -a "$1" != "--greekonly"; then
-    echo "*** REMOVING ALL GREEK FROM VERSION NUMBERS!!"
-    for file in $version_files; do
-        echo " - $file"
-        sed -e 's/^greek=.*/greek=/' $file > $file.new
-        cp -f $file.new $file
-        rm $file.new
-    done
-    echo "Making non-greek tarball"
-    make_tarball
-fi
-