1#!/bin/sh
2#
3# Copyright (c) 2004-2006 The Trustees of Indiana University and Indiana
4#                         University Research and Technology
5#                         Corporation.  All rights reserved.
6# Copyright (c) 2004-2005 The University of Tennessee and The University
7#                         of Tennessee Research Foundation.  All rights
8#                         reserved.
9# Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
10#                         University of Stuttgart.  All rights reserved.
11# Copyright (c) 2004-2005 The Regents of the University of California.
12#                         All rights reserved.
13# Copyright (c) 2008-2015 Cisco Systems, Inc.  All rights reserved.
14# Copyright (c) 2016      Intel, Inc. All rights reserved
15# $COPYRIGHT$
16#
17# Additional copyrights may follow
18#
19# $HEADER$
20#
21
22#
23# Version of auto tools that we want
24#
25
26M4_TARGET_VERSION=1.4.17
27AM_TARGET_VERSION=1.15
28AC_TARGET_VERSION=2.69
29LT_TARGET_VERSION=2.4.6
30FLEX_TARGET_VERSION=2.5.35
31
32#
33# When running "make distcheck", use these parallelization flags.  Can
34# significantly decrease the time required for "make distcheck" because
35# that target includes multiple builds of the entire code base.
36#
37
38DISTCHECK_MAKE_FLAGS=-j4
39
40#########################################################################
41
42#
43# Check command line flags
44#
45
46# Default to requiring *exact* versions if we're making distribution
47# tarballs; but higher-than-expected versions are ok for
48# non-distribution tarballs.
49want_ompi=1
50autogen_args=
51distdir=".."
52greekonly=0
53nogreek=0
54dirty_ok=0
55gnu_version_ignore=0
56dist_target=distcheck
57distcheck_flags="AM_MAKEFLAGS=$DISTCHECK_MAKE_FLAGS"
58git_update=1
59
60if test "`basename $0`" = "make_tarball"; then
61    dist_target=dist
62    distcheck_flags="AM_MAKEFLAGS=-j32"
63    highok=1
64    dirty_ok=1
65    greekonly=1
66else
67    highok=0
68fi
69
70while test "$1" != ""; do
71    case $1 in
72        --greekonly) greekonly=1 ;;
73        --no-greek) nogreek=1 ;;
74        --highok) highok=1 ;;
75        --no-ompi) want_ompi=0 ;;
76        --autogen-args) autogen_args=$2; shift ;;
77        --distdir) distdir=$2; shift ;;
78        --dirtyok) dirty_ok=1 ;;
79        --verok) gnu_version_ignore=1;;
80        --no-git-update) git_update=0;;
81        *)
82            cat <<EOF
83Unrecognized argument: $1
84
85Valid arguments:
86  --greekonly     Only build the greek tarball (vs. both tarballs)
87  --no-greek      Do not build the greek tarball
88  --highok        Ok if Autotools versions are too high
89  --no-ompi       Don't build the OMPI or OSHMEM layers
90  --autogen-args  Arguments to pass to autogen
91  --distdir       Move the tarball(s) to this directory when done
92  --dirtyok       Ok if the source tree is dirty
93  --verok         Ignore result of autotools version checking
94  --no-git-update Skip "git pull" part, assume local repo is updated already
95EOF
96            exit 1
97            ;;
98    esac
99    shift
100done
101
102#
103# First things first -- check that the auto versions that we have are
104# the ones that we want.
105#
106
107check_gnu_version() {
108    prog="$1"
109    target="$2"
110
111    ver="`$prog --version | head -n 1 | sed -e's/([^)]*)//g' -e's/[^0-9 .][^ ]* / /g' -e's/ //g'`"
112    echo $prog version is $ver
113
114    ver_major=`echo $ver | cut -d. -f1`
115    ver_minor=`echo $ver | cut -d. -f2`
116    ver_release=`echo $ver | cut -d. -f3`
117    if test "$ver_release" = ""; then
118        ver_release=0
119    fi
120
121    target_major=`echo $target | cut -d. -f1`
122    target_minor=`echo $target | cut -d. -f2`
123    target_release=`echo $target | cut -d. -f3`
124    if test "$target_release" = ""; then
125        target_release=0
126    fi
127
128    # Gah -- Libtool released version 2.2.6b, the "b" of which totally
129    # screws up the -lt and -gt comparisons, below.  So strip out any
130    # trailing letters in the target_release and ver_release variables
131    # -- if they don't match, we'll just get a "they don't match
132    # somehow" kind of message (because I'm not going to code up a
133    # complex/clever alphanumeric lower/higher comparison thingy).
134    # Sigh.
135    ver_release=`echo $ver_release | sed 's/[A-Za-z]//g'`
136    target_release=`echo $target_release | sed 's/[A-Za-z]//g'`
137
138    result=same
139    if test "$ver" != "$target"; then
140        if test "$ver_major" -lt "$target_major"; then
141            result=low
142        elif test "$ver_major" = "$target_major" -a "$ver_minor" -lt "$target_minor"; then
143            result=low
144        elif test "$ver_major" = "$target_major" -a "$ver_minor" = "$target_minor" -a "$ver_release" -lt "$target_release"; then
145            result=low
146        elif test "$ver_major" -gt "$target_major"; then
147            result=high
148        elif test "$ver_major" = "$target_major" -a "$ver_minor" -gt "$target_minor"; then
149            result=high
150        elif test "$ver_major" = "$target_major" -a "$ver_minor" = "$target_minor" -a "$ver_release" = "$target_release"; then
151            result=same
152        elif test "$ver_major" = "$target_major" -a "$ver_minor" = "$target_minor" -a "$ver_release" -gt "$target_release"; then
153            result=high
154        elif test "$ver_major" = "$target_major" -a "$ver_minor" = "$target_minor" -a "$ver_release" -lt "$target_release"; then
155            result=low
156        else
157            result=unknown
158        fi
159    fi
160
161    if test "$result" = "low"; then
162        cat <<EOF
163----------------------------------------------------------------------
164ERROR: Program "$prog" does not have a high enough version:
165       Found: $ver
166       Expected: $target
167
168Expected versions:
169m4: $M4_TARGET_VERSION
170Automake: $AM_TARGET_VERSION
171Autoconf: $AC_TARGET_VERSION
172Libtool:  $LT_TARGET_VERSION
173Flex:     $FLEX_TARGET_VERSION
174
175Either change this script to match the found version, or install
176the correct version of the tools.
177----------------------------------------------------------------------
178EOF
179        if test "$gnu_version_ignore" = "0"; then
180            exit 1
181        fi
182
183    elif test "$result" = "high"; then
184        if test "$highok" = "0"; then
185            cat <<EOF
186----------------------------------------------------------------------
187ERROR: Program "$prog" has a higher version than expected:
188       Found: $ver
189       Expected: $target
190
191Expected versions:
192m4: $M4_TARGET_VERSION
193Automake: $AM_TARGET_VERSION
194Autoconf: $AC_TARGET_VERSION
195Libtool:  $LT_TARGET_VERSION
196Flex:     $FLEX_TARGET_VERSION
197
198Either change this script to match the found version, or install
199the correct version of the tools.
200----------------------------------------------------------------------
201EOF
202        if test "$gnu_version_ignore" = "0"; then
203            exit 1
204        fi
205        else
206            cat <<EOF
207----------------------------------------------------------------------
208WARNING: Program "$prog" has a higher version than expected:
209         Found: $ver
210         Expected: $target
211
212Expected versions:
213m4: $M4_TARGET_VERSION
214Automake: $AM_TARGET_VERSION
215Autoconf: $AC_TARGET_VERSION
216Libtool:  $LT_TARGET_VERSION
217Flex:     $FLEX_TARGET_VERSION
218
219This is *usually* ok, but this script is going to sleep for 5 seconds
220to give you the chance to quit before doing anything.
221----------------------------------------------------------------------
222EOF
223            sleep 5
224        fi
225
226    elif test "$result" = "unknown"; then
227        cat <<EOF
228----------------------------------------------------------------------
229ERROR: Program "$prog" does not have the correct version:
230       Found: $ver
231       Expected: $target
232
233Expected versions:
234m4: $M4_TARGET_VERSION
235Automake: $AM_TARGET_VERSION
236Autoconf: $AC_TARGET_VERSION
237Libtool:  $LT_TARGET_VERSION
238Flex:     $FLEX_TARGET_VERSION
239
240Either change this script to match the found version, or install
241the correct version of the tools.
242----------------------------------------------------------------------
243EOF
244        if test "$gnu_version_ignore" = "0"; then
245            exit 1
246        fi
247    fi
248
249}
250
251#
252# Subroutine to actually make a tarball
253#
254
255make_tarball() {
256    #
257    # Autogen
258    #
259    echo "*** Running autogen $autogen_args..."
260    rm -f success
261    if test "$want_ompi" = "1" ; then
262        (./autogen.pl --force $autogen_args 2>&1 && touch success) | tee auto.out
263    else
264        (./autogen.pl --force --no-ompi $autogen_args 2>&1 && touch success) | tee auto.out
265    fi
266    if test ! -f success; then
267        echo "Autogen failed.  Aborting"
268        exit 1
269    fi
270
271    #
272    # Configure
273    #
274    echo "*** Running configure..."
275    rm -f success
276    (./configure 2>&1 && touch success) | tee config.out
277    if test ! -f success; then
278        echo "Configure failed.  Aborting"
279        exit 1
280    fi
281
282    #
283    # Remove all generated *_lex.c files so that we ensure to invoke
284    # flex from here in this script (to ensure that we're using a good
285    # version of flex, and not picking up random *_lex.c files that
286    # happened to be in the tree already).
287    #
288    echo "*** Removing old generated flex files..."
289    find . -name \*_lex.c -exec chmod ug+rw {} \; -exec rm -f {} \; -print
290
291    #
292    # make tarball
293    #
294    echo "*** Running make $dist_target..."
295    save_LD=$LD_LIBRARY_PATH
296    LD_LIBRARY_PATH=
297    rm -f success
298    (make $distcheck_flags $dist_target 2>&1 && touch success) | tee dist.out
299    if test ! -f success; then
300        echo "Make $dist_target failed.  Aborting"
301        exit 1
302    fi
303    rm -f success
304    LD_LIBRARY_PATH=$save_LD
305
306    #
307    # move
308    #
309    echo "*** Moving tarballs..."
310    mv openmpi-* $distdir
311
312    echo "*** All done"
313}
314
315#########################################################################
316# main
317#########################################################################
318
319start=`date`
320echo "*** Start time: $start"
321
322echo "*** Checking tools versions..."
323check_gnu_version m4 $M4_TARGET_VERSION
324check_gnu_version automake $AM_TARGET_VERSION
325check_gnu_version autoconf $AC_TARGET_VERSION
326check_gnu_version libtool $LT_TARGET_VERSION
327# Windows needs a recent version of flex; old versions don't generate
328# Windows-friendly *_lex.c files.
329check_gnu_version flex $FLEX_TARGET_VERSION
330
331#
332# Verify that we're in a top Open MPI dir
333#
334echo "*** Checking to ensure in top-level Open MPI directory..."
335if test -f VERSION -a -f configure.ac -a -f config/opal_get_version.m4 ; then
336    happy=1
337else
338    echo "Do not appear to be in an Open MPI top directory.  Abort!"
339    exit 1
340fi
341
342if test $git_update -eq 1; then
343
344    #
345    # Get the latest
346    #
347    echo "*** Git pull to get the latest..."
348    git pull --rebase
349    if test $? -ne 0; then
350        echo "*** Git pull failed.  Cannot continue."
351        exit 1
352    fi
353fi
354
355#
356# Ensure we have a clean repo
357#
358if test $dirty_ok -eq 0; then
359    echo "*** Checking if source tree is dirty..."
360    dirty=0
361    file=git-status.$$.out
362    git status > $file
363    if test "`grep 'Changes not staged for commit' $file`" != "" ||
364       test "`grep 'Changes staged for commit' $file`" != ""; then
365        dirty=1
366    fi
367    rm -f $file
368
369    if test $dirty -eq 1; then
370        echo "    Source tree is dirty.  Cannot continue."
371        exit 1
372    fi
373fi
374
375#
376# Get our repo_rev
377#
378echo "*** Removing old VERSION file..."
379rm -f VERSION
380echo "*** Restoring pristine VERSION file..."
381git checkout VERSION
382echo "*** Getting git version..."
383repo_rev=`git describe --tags --always`
384echo "    Repo rev number: $repo_rev"
385
386# Sanity checks
387if test "$repo_rev" = ""; then
388    echo "Somehow the repo rev number is empty.  Abort!"
389    exit 1
390elif test "`echo $repo_rev | grep ' '`" != ""; then
391    echo "Somehow the repo rev number has a space in it -- bad!"
392    exit 1
393fi
394
395#
396# Set final values in VERSION
397#
398echo "*** Removing version numbers from VERSION..."
399version_files=VERSION
400release_date=`date '+%b %d, %Y'`
401echo "    Release date: $release_date"
402for file in $version_files; do
403    echo " - $file"
404    sed -e 's/^repo_rev=.*/'repo_rev=$repo_rev/ \
405        -e "s/^date=.*/date=\"$release_date\"/" \
406        -e "s/^tarball_version=.*/tarball_version=/" \
407        $file > $file.new
408    cp -f $file.new $file
409    rm $file.new
410done
411
412#
413# Make 2 tarballs:
414#
415# - one with the greek
416# - one without the greek
417#
418# unless the user specifically said --greekonly, then only make the
419# greek tarball.  Making both tarballs at once allows us to guarantee
420# to have two tarballs -- one greek and one not -- that have exactly
421# the same SVN r number (as opposed to, for example, running this
422# script to make a greek tarball, then running it again to make a
423# non-greek tarball -- there is a race condition that someone could
424# commit in the meantime and change the SVN r number in the 2nd
425# tarball)
426#
427
428# First, if ! --no-greek, make greek tarball
429
430if test $nogreek -eq 0; then
431    echo "*** Making greek tarball"
432    make_tarball
433fi
434
435# Now if ! --greekonly, make the non-greek tarball
436
437if test $greekonly -eq 0; then
438    echo "*** REMOVING ALL GREEK FROM VERSION NUMBERS!!"
439    for file in $version_files; do
440        echo " - $file"
441        sed -e 's/^greek=.*/greek=/' $file > $file.new
442        cp -f $file.new $file
443        rm $file.new
444    done
445    echo "Making non-greek tarball"
446    make_tarball
447fi
448
449# Put the VERSION file back the way it was
450rm -f VERSION
451git checkout VERSION
452
453echo " "
454echo "*** Start time:  $start"
455echo "*** Finish time: `date`"
456