ignore buildnr
[pspp] / make-builder.as
1 AS_INIT[]dnl                                            -*- shell-script -*-
2 m4_divert_push([HEADER-COPYRIGHT])dnl
3 # @configure_input@
4 # make-builder -- create PSPP build scripts
5
6 # Copyright (C) 1992, 1993, 1994, 1996, 1999, 2000, 2001, 2002, 2003,
7 # 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation,
8 # Inc.
9
10 # This program is free software: you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation, either version 3 of the License, or
13 # (at your option) any later version.
14
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 # GNU General Public License for more details.
19
20 # You should have received a copy of the GNU General Public License
21 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
22
23 m4_divert_pop([HEADER-COPYRIGHT])dnl back to BODY
24 AS_ME_PREPARE[]dnl
25
26 usage=["\
27 Usage: $0 [OPTION]... REPOSITORY BRANCH
28 where REPO and BRANCH are a Git repository and branch to clone.
29
30 Options:
31   -h, --help                Print this usage message and exit
32   -b, --build=NUMBER        Set build number (default: next available)
33   -o, --output=DIRECTORY    Set build directory (default: build\$BUILDNR)
34   -f, --force               Overwrite files in existing directory
35
36 Report bugs to <bug-gnu-pspp@gnu.org>.
37 GNU PSPP: <http://www.gnu.org/software/pspp/>.
38 General help using GNU software: <http://www.gnu.org/gethelp/>."]
39
40 version=["\
41 make-builder (@PACKAGE_NAME@) @VERSION@
42 Copyright (C) 2010 Free Software Foundation, Inc.
43 License GPLv3+/Autoconf: GNU GPL version 3 or later
44 <http://gnu.org/licenses/gpl.html>, <http://gnu.org/licenses/exceptions.html>
45 This is free software: you are free to change and redistribute it.
46 There is NO WARRANTY, to the extent permitted by law.
47
48 Written by Ben Pfaff."]
49
50 help="\
51 Try \`$as_me --help' for more information."
52
53 exit_missing_arg='
54   m4_bpatsubst([AS_ERROR([option `$[1]' requires an argument$as_nl$help])],
55     ['], ['\\''])'
56 # restore font-lock: '
57
58 # Variables.
59 outdir=
60 overwrite=false
61 buildnr=
62
63 # Parse command line.
64 while test $# -gt 0 ; do
65   option=[`expr "x$1" : 'x\(--[^=]*\)' \| \
66                "x$1" : 'x\(-.\)'`]
67   optarg=[`expr "x$1" : 'x--[^=]*=\(.*\)' \| \
68                "x$1" : 'x-.\(.*\)'`]
69   case $1 in
70     --version | -V )
71        echo "$version" ; exit ;;
72     --help | -h )
73        AS_ECHO(["$usage"]); exit ;;
74
75     --verbose | -v )
76        verbose=:
77        autom4te_options="$autom4te_options $1"; shift ;;
78
79     --output=* | -o?* )
80        outdir=$optarg
81        shift ;;
82     --output | -o )
83        test $# = 1 && eval "$exit_missing_arg"
84        outdir=$2
85        shift; shift ;;
86
87     --build=* | -b?* )
88        buildnr=$optarg
89        shift ;;
90     --build | -b )
91        test $# = 1 && eval "$exit_missing_arg"
92        buildnr=$2
93        shift; shift ;;
94
95     --force | -f )
96        overwrite=true ;;
97
98     -- )     # Stop option processing
99        shift; break ;;
100     - ) # Use stdin as input.
101        break ;;
102     -* )
103        exec >&2
104        AS_ERROR([invalid option `$[1]'$as_nl$help]) ;; #`
105     * )
106        break ;;
107   esac
108 done
109
110 # Find the input file.
111 case $# in
112   2)
113     repository=$1
114     branch=$2
115     ;;
116   *) exec >&2
117      AS_ERROR([invalid number of arguments$as_nl$help]) ;;
118 esac
119
120 # Choose build number.
121 if test "x$buildnr" = x; then
122     lock_file () {
123         echo $$ > $[1].$$
124         if ln $[1].$$ $[1].lock; then
125             rm $[1].$$
126             return 0
127         fi
128         pid=`cat $[1].lock`
129         if kill -0 pid; then
130             :
131         else
132             rm -f $[1].lock
133         fi
134         return 1
135     }
136     until lock_file build_number; do
137         sleep 1
138     done
139
140     if test -e buildnr; then
141         buildnr=`cat buildnr`
142     else
143         buildnr=1
144     fi
145     echo `expr $buildnr + 1` > buildnr
146
147     rm build_number.lock
148 fi
149
150 # Check that build number is a number.
151 if expr "X$buildnr" : '[X[0-9][0-9]*$]' >/dev/null; then
152     :
153 else
154     exec >&2
155     AS_ERROR([invalid build number `$buildnr'$as_nl$help]) #`
156 fi
157
158 # Ensure that git repository exists.
159 GIT_DIR=$PWD/repo.git
160 export GIT_DIR
161 git init
162
163 # Fetch PSPP source.
164 git fetch $repository +$branch:refs/builds/$buildnr/pspp
165
166 # Get PSPP commit number.
167 pspp_commit=`git rev-parse refs/builds/$buildnr/pspp`
168
169 # Get gnulib commit number.
170 gnulib_commit=`\
171     git show refs/builds/$buildnr/pspp:README.Git | \
172     sed -n 's/^[[       ]]*commit \([[0-9a-fA-F]]\{8,\}\)$/\1/p' | \
173     head -1`
174
175 # Fetch Gnulib source.
176 if git rev-parse --verify --quiet $gnulib_commit^0 > /dev/null; then
177     :
178 else
179     # We don't have the right commit yet, update Gnulib.
180     git fetch git://git.sv.gnu.org/gnulib.git +refs/heads/*:refs/remotes/gnulib/*
181 fi
182 git update-ref refs/builds/$buildnr/gnulib $gnulib_commit
183
184 # Choose and create output directory.
185 test -z "$outdir" && outdir=build$buildnr
186 if test -e "$outdir" && test $overwrite = false; then
187     exec >&2
188     AS_ERROR([$outdir exists and --force not specified$as_nl$help])
189 fi
190 AS_MKDIR_P([$outdir])
191
192 # Make source tarballs.
193 git archive --format=tar --prefix=pspp-$pspp_commit/ $pspp_commit \
194     | gzip > $outdir/pspp-$pspp_commit.tar.gz
195 git archive --format=tar --prefix=gnulib-$gnulib_commit/ $gnulib_commit \
196     | gzip > $outdir/gnulib-$gnulib_commit.tar.gz
197
198 # Make build scripts.
199 sed < dist-pspp.in > "$outdir/dist-pspp" "
200 s,[@]PSPP_COMMIT[@],$pspp_commit,g
201 s,[@]GNULIB_COMMIT[@],$gnulib_commit,g
202 s,[@]BRANCH[@],$branch,g
203 s,[@]CONFIGUREFLAGS[@],,g
204 "
205 chmod +x "$outdir/dist-pspp"
206
207 # Copy in scripts.
208 cp gendocs.sh gendocs_template gendocs_template_min "$outdir/"