start rewrite
[pspp] / make-builder.as
diff --git a/make-builder.as b/make-builder.as
new file mode 100644 (file)
index 0000000..a30e437
--- /dev/null
@@ -0,0 +1,208 @@
+AS_INIT[]dnl                                            -*- shell-script -*-
+m4_divert_push([HEADER-COPYRIGHT])dnl
+# @configure_input@
+# make-builder -- create PSPP build scripts
+
+# Copyright (C) 1992, 1993, 1994, 1996, 1999, 2000, 2001, 2002, 2003,
+# 2004, 2005, 2006, 2007, 2008, 2009, 2010 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 3 of the License, 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, see <http://www.gnu.org/licenses/>.
+
+m4_divert_pop([HEADER-COPYRIGHT])dnl back to BODY
+AS_ME_PREPARE[]dnl
+
+usage=["\
+Usage: $0 [OPTION]... REPOSITORY BRANCH
+where REPO and BRANCH are a Git repository and branch to clone.
+
+Options:
+  -h, --help                Print this usage message and exit
+  -b, --build=NUMBER        Set build number (default: next available)
+  -o, --output=DIRECTORY    Set build directory (default: build\$BUILDNR)
+  -f, --force               Overwrite files in existing directory
+
+Report bugs to <bug-gnu-pspp@gnu.org>.
+GNU PSPP: <http://www.gnu.org/software/pspp/>.
+General help using GNU software: <http://www.gnu.org/gethelp/>."]
+
+version=["\
+make-builder (@PACKAGE_NAME@) @VERSION@
+Copyright (C) 2010 Free Software Foundation, Inc.
+License GPLv3+/Autoconf: GNU GPL version 3 or later
+<http://gnu.org/licenses/gpl.html>, <http://gnu.org/licenses/exceptions.html>
+This is free software: you are free to change and redistribute it.
+There is NO WARRANTY, to the extent permitted by law.
+
+Written by Ben Pfaff."]
+
+help="\
+Try \`$as_me --help' for more information."
+
+exit_missing_arg='
+  m4_bpatsubst([AS_ERROR([option `$[1]' requires an argument$as_nl$help])],
+    ['], ['\\''])'
+# restore font-lock: '
+
+# Variables.
+outdir=
+overwrite=false
+buildnr=
+
+# Parse command line.
+while test $# -gt 0 ; do
+  option=[`expr "x$1" : 'x\(--[^=]*\)' \| \
+              "x$1" : 'x\(-.\)'`]
+  optarg=[`expr "x$1" : 'x--[^=]*=\(.*\)' \| \
+              "x$1" : 'x-.\(.*\)'`]
+  case $1 in
+    --version | -V )
+       echo "$version" ; exit ;;
+    --help | -h )
+       AS_ECHO(["$usage"]); exit ;;
+
+    --verbose | -v )
+       verbose=:
+       autom4te_options="$autom4te_options $1"; shift ;;
+
+    --output=* | -o?* )
+       outdir=$optarg
+       shift ;;
+    --output | -o )
+       test $# = 1 && eval "$exit_missing_arg"
+       outdir=$2
+       shift; shift ;;
+
+    --build=* | -b?* )
+       buildnr=$optarg
+       shift ;;
+    --build | -b )
+       test $# = 1 && eval "$exit_missing_arg"
+       buildnr=$2
+       shift; shift ;;
+
+    --force | -f )
+       overwrite=true ;;
+
+    -- )     # Stop option processing
+       shift; break ;;
+    - )        # Use stdin as input.
+       break ;;
+    -* )
+       exec >&2
+       AS_ERROR([invalid option `$[1]'$as_nl$help]) ;; #`
+    * )
+       break ;;
+  esac
+done
+
+# Find the input file.
+case $# in
+  2)
+    repository=$1
+    branch=$2
+    ;;
+  *) exec >&2
+     AS_ERROR([invalid number of arguments$as_nl$help]) ;;
+esac
+
+# Choose build number.
+if test "x$buildnr" = x; then
+    lock_file () {
+       echo $$ > $[1].$$
+       if ln $[1].$$ $[1].lock; then
+           rm $[1].$$
+           return 0
+       fi
+       pid=`cat $[1].lock`
+       if kill -0 pid; then
+           :
+       else
+           rm -f $[1].lock
+       fi
+       return 1
+    }
+    until lock_file build_number; do
+       sleep 1
+    done
+
+    if test -e buildnr; then
+       buildnr=`cat buildnr`
+    else
+       buildnr=1
+    fi
+    echo `expr $buildnr + 1` > buildnr
+
+    rm build_number.lock
+fi
+
+# Check that build number is a number.
+if expr "X$buildnr" : '[X[0-9][0-9]*$]' >/dev/null; then
+    :
+else
+    exec >&2
+    AS_ERROR([invalid build number `$buildnr'$as_nl$help]) #`
+fi
+
+# Ensure that git repository exists.
+GIT_DIR=$PWD/repo.git
+export GIT_DIR
+git init
+
+# Fetch PSPP source.
+git fetch $repository +$branch:refs/builds/$buildnr/pspp
+
+# Get PSPP commit number.
+pspp_commit=`git rev-parse refs/builds/$buildnr/pspp`
+
+# Get gnulib commit number.
+gnulib_commit=`\
+    git show refs/builds/$buildnr/pspp:README.Git | \
+    sed -n 's/^[[      ]]*commit \([[0-9a-fA-F]]\{8,\}\)$/\1/p' | \
+    head -1`
+
+# Fetch Gnulib source.
+if git rev-parse --verify --quiet $gnulib_commit^0 > /dev/null; then
+    :
+else
+    # We don't have the right commit yet, update Gnulib.
+    git fetch git://git.sv.gnu.org/gnulib.git +refs/heads/*:refs/remotes/gnulib/*
+fi
+git update-ref refs/builds/$buildnr/gnulib $gnulib_commit
+
+# Choose and create output directory.
+test -z "$outdir" && outdir=build$buildnr
+if test -e "$outdir" && test $overwrite = false; then
+    exec >&2
+    AS_ERROR([$outdir exists and --force not specified$as_nl$help])
+fi
+AS_MKDIR_P([$outdir])
+
+# Make source tarballs.
+git archive --format=tar --prefix=pspp-$pspp_commit/ $pspp_commit \
+    | gzip > $outdir/pspp-$pspp_commit.tar.gz
+git archive --format=tar --prefix=gnulib-$gnulib_commit/ $gnulib_commit \
+    | gzip > $outdir/gnulib-$gnulib_commit.tar.gz
+
+# Make build scripts.
+sed < dist-pspp.in > "$outdir/dist-pspp" "
+s,[@]PSPP_COMMIT[@],$pspp_commit,g
+s,[@]GNULIB_COMMIT[@],$gnulib_commit,g
+s,[@]BRANCH[@],$branch,g
+s,[@]CONFIGUREFLAGS[@],,g
+"
+chmod +x "$outdir/dist-pspp"
+
+# Copy in scripts.
+cp gendocs.sh gendocs_template gendocs_template_min "$outdir/"