|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +######################################################################## |
| 4 | +# Regenerate auto-generated files (e.g. configure) |
| 5 | +# |
| 6 | +# If the -s option is given, save the autogenerated scripts in |
| 7 | +# $SAGE_ROOT/upstream/configure-$CONFVERSION.tar.gz where CONFVERSION |
| 8 | +# is the version number stored in |
| 9 | +# build/pkgs/configure/package-version.txt |
| 10 | +# |
| 11 | +# If optional argument -i is given, then automatically increment the |
| 12 | +# version number. |
| 13 | +# |
| 14 | +# If optional argument -d is given and bootstrapping failed, instead |
| 15 | +# extract the files from a local configure tarball, downloading it if |
| 16 | +# needed. If -D is given, don't try to bootstrap and always extract or |
| 17 | +# donwload. |
| 18 | +######################################################################## |
| 19 | + |
| 20 | +# Either run this script from SAGE_ROOT or make sure that SAGE_ROOT |
| 21 | +# is set |
| 22 | +test -z "$SAGE_ROOT" || cd "$SAGE_ROOT" |
| 23 | + |
| 24 | +PKG=build/pkgs/configure |
| 25 | +MAKE="${MAKE:-make}" |
| 26 | +CONFVERSION=`cat $PKG/package-version.txt` |
| 27 | + |
| 28 | +bootstrap () { |
| 29 | + aclocal -I m4 && \ |
| 30 | + automake --add-missing --copy build/Makefile-auto && \ |
| 31 | + autoconf |
| 32 | + |
| 33 | + st=$? |
| 34 | + case $st in |
| 35 | + 0) true;; # Success |
| 36 | + |
| 37 | + 63|127) # Autotools not installed or version too old |
| 38 | + if [ $DOWNLOAD = yes ]; then |
| 39 | + echo >&2 "Bootstrap failed, downloading required files instead." |
| 40 | + bootstrap-download || exit $? |
| 41 | + else |
| 42 | + if [ $st -eq 127 ]; then |
| 43 | + verb="install" |
| 44 | + else |
| 45 | + verb="upgrade" |
| 46 | + fi |
| 47 | + echo >&2 "Bootstrap failed. Either $verb autotools or run bootstrap with" |
| 48 | + echo >&2 "the -d option to download the auto-generated files instead." |
| 49 | + exit $st |
| 50 | + fi;; |
| 51 | + |
| 52 | + *) exit $st;; # Failure |
| 53 | + esac |
| 54 | +} |
| 55 | + |
| 56 | +# Bootstrap by downloading the auto-generated files |
| 57 | +bootstrap-download () { |
| 58 | + source src/bin/sage-env |
| 59 | + |
| 60 | + mkdir upstream 2>/dev/null |
| 61 | + if [ ! -f $CONFBALL ]; then |
| 62 | + sage-download-file $SAGE_UPSTREAM/configure/configure-$CONFVERSION.tar.gz >$CONFBALL |
| 63 | + if [ $? -ne 0 ]; then |
| 64 | + rm -f "$CONFBALL" |
| 65 | + echo >&2 "Error: downloading configure-$CONFVERSION.tar.gz failed" |
| 66 | + exit 1 |
| 67 | + fi |
| 68 | + fi |
| 69 | + |
| 70 | + # The "m" option to tar ensures that timestamps are set to the |
| 71 | + # current time, not taken from the tarball. |
| 72 | + # We need these files to be more recent than the input files |
| 73 | + # like configure.ac, otherwise "make" gets confused. |
| 74 | + tar xzmf $CONFBALL || exit $? |
| 75 | +} |
| 76 | + |
| 77 | +save () { |
| 78 | + set -e |
| 79 | + |
| 80 | + # Create configure tarball |
| 81 | + echo "Creating $CONFBALL..." |
| 82 | + mkdir -p upstream |
| 83 | + tar zcf "$CONFBALL" configure config/* build/Makefile-auto.in |
| 84 | + |
| 85 | + # Update version number |
| 86 | + echo "$CONFVERSION" >$PKG/package-version.txt |
| 87 | + |
| 88 | + # Compute checksum |
| 89 | + SAGE_ROOT=. src/bin/sage-fix-pkg-checksums "$CONFBALL" |
| 90 | +} |
| 91 | + |
| 92 | + |
| 93 | +usage () { |
| 94 | + echo >&2 "Usage: $0 [-d|-D|-s] [-i] [-h]" |
| 95 | +} |
| 96 | + |
| 97 | + |
| 98 | +# Parse options |
| 99 | +SAVE=no |
| 100 | +DOWNLOAD=no |
| 101 | +ALWAYSDOWNLOAD=no |
| 102 | +while getopts "Ddsih" OPTION |
| 103 | +do |
| 104 | + case "$OPTION" in |
| 105 | + D) ALWAYSDOWNLOAD=yes; DOWNLOAD=yes;; |
| 106 | + d) DOWNLOAD=yes;; |
| 107 | + s) SAVE=yes;; |
| 108 | + i) CONFVERSION=$(( CONFVERSION + 1 ));; |
| 109 | + h) usage; exit 0;; |
| 110 | + ?) usage; exit 2;; |
| 111 | + esac |
| 112 | +done |
| 113 | +CONFBALL="upstream/configure-$CONFVERSION.tar.gz" |
| 114 | + |
| 115 | +if [ $DOWNLOAD$SAVE = yesyes ]; then |
| 116 | + echo >&2 "$0: refusing to download and save." |
| 117 | + usage |
| 118 | + exit 2 |
| 119 | +fi |
| 120 | + |
| 121 | +# Start cleanly (it's not a problem if this fails) |
| 122 | +$MAKE bootstrap-clean 2>/dev/null |
| 123 | +mkdir config 2>/dev/null |
| 124 | + |
| 125 | +if [ $ALWAYSDOWNLOAD = yes ]; then |
| 126 | + bootstrap-download || exit $? |
| 127 | +else |
| 128 | + bootstrap |
| 129 | +fi |
| 130 | + |
| 131 | +if [ $SAVE = yes ]; then |
| 132 | + save |
| 133 | +fi |
0 commit comments