x
[heimdal.git] / tools / heimdal-build.sh
blob55703a0c81398c04a386ca9a4287db1fd0d07e90
1 #!/bin/sh
2 # Fetches, builds and store the result of a heimdal build
3 # Version: $Id$
5 fetchmethod=wget #options are: wget, curl, ftp, afs
6 resultdir=
7 email=heimdal-build-log@it.su.se
8 baseurl=ftp://ftp.pdc.kth.se/pub/heimdal/src
9 afsdir=/afs/pdc.kth.se/public/ftp/pub/heimdal/src
10 keeptree=no
11 passhrase=
12 builddir=
13 noemail=
14 cputimelimit=3600
15 confflags=
17 # Add some bonus paths, to find sendmail and other tools
18 # on interesting platforms.
19 PATH="${PATH}:/usr/sbin:/usr/bin:/usr/libexec:/usr/lib"
20 PATH="${PATH}:/usr/local/bin:/usr/local/sbin"
22 # no more user configurabled part below (hopefully)
24 usage="[--current] [--svn SourceRepository] [--cvs-flags] [--result-directory dir] [--fetch-method wget|ftp|curl|cvs|fetch|afs] --keep-tree] [--autotools] [--passhrase string] [--no-email] [--build-dir dir] [--cputime] [--distcheck] [--test-environment env] [--configure-flags flags]"
26 date=`date +%Y%m%d`
27 if [ "$?" != 0 ]; then
28 echo "have no sane date, punting"
29 exit 1
32 hostname=`hostname`
33 if [ "$?" != 0 ]; then
34 echo "have no sane hostname, punting"
35 exit 1
38 version=`grep "^# Version: " "$0" | cut -f2- -d:`
39 if [ "X${version}" = X ]; then
40 echo "Can not figure out what version I am"
41 exit 1
44 dir=
45 hversion=
46 cvsroot=
47 cvsflags=
48 cvsbranch=
49 branch=
50 autotools=no
51 distcheck=no
53 while true
55 case $1 in
56 --autotools)
57 autotools=yes
58 shift
60 --build-dir)
61 builddir="$2"
62 shift 2
64 --current)
65 dir="snapshots/"
66 hversion="heimdal-${date}"
67 shift
69 --release)
70 hversion="heimdal-$2"
71 shift 2
73 --cputime)
74 cputimelimit="$2"
75 shift 2
77 --ccache-dir)
78 ccachedir="$2"
79 shift 2
81 --svn)
82 hversion="heimdal-svn-${date}"
83 svnroot=$2
84 fetchmethod=svn
85 shift 2
87 --distcheck)
88 distcheck=yes
89 shift
91 --result-directory)
92 resultdir="$2"
93 if [ ! -d "$resultdir" ]; then
94 echo "$resultdir doesn't exists"
95 exit 1
97 resultdir="`pwd`/${resultdir}"
98 shift 2
100 --fetch-method)
101 fetchmethod="$2"
102 shift 2
104 --keep-tree)
105 keeptree=yes
106 shift
108 --passphrase)
109 passhrase="$2"
110 shift 2
112 --prepend-path)
113 prependpath="$2"
114 shift 2
116 --test-environment)
117 testenvironment="$2"
118 shift 2
120 --no-email)
121 noemail="yes"
122 shift
124 --configure-flags)
125 confflags="${confflags} $2"
126 shift 2
128 --version)
129 echo "Version: $version"
130 exit 0
133 echo "unknown option: $1"
134 break
137 break
139 esac
140 done
141 if test $# -gt 0; then
142 echo $usage
143 exit 1
146 if [ "X${hversion}" = X ]; then
147 echo "no version given"
148 exit 0
151 hfile="${hversion}.tar.gz"
152 url="${baseurl}/${dir}${hfile}"
153 afsfile="${afsdir}/${dir}${hfile}"
154 unpack=yes
156 # extra paths for the user
157 if [ "X${prependpath}" != X ]; then
158 PATH="${prependpath}:${PATH}"
161 # Limit cpu seconds this all can take
162 ulimit -t "$cputimelimit" > /dev/null 2>&1
164 if [ "X${builddir}" != X ]; then
165 echo "Changing build dir to ${builddir}"
166 cd "${builddir}"
169 echo "Removing old source"
170 rm -rf ${hversion}
172 echo "Fetching ${hversion} using $fetchmethod"
173 case "$fetchmethod" in
174 wget|ftp|fetch)
175 ${fetchmethod} $url > /dev/null
176 res=$?
178 curl)
179 ${fetchmethod} -o ${hfile} ${url} > /dev/null
180 res=$?
182 afs)
183 cp ${afsfile} ${hfile}
184 res=$?
186 svn)
187 svn co $svnroot ${hversion}
188 res=$?
189 unpack=no
190 autotools=yes
193 echo "unknown fetch method"
195 esac
197 if [ "X$res" != X0 ]; then
198 echo "Failed to download the tar-ball"
199 exit 1
202 if [ X"$unpack" = Xyes ]; then
203 echo Unpacking source
204 (gzip -dc ${hfile} | tar xf -) || exit 1
207 if [ X"$autotools" = Xyes ]; then
208 echo "Autotooling"
209 (cd ${hversion} && sh ./autogen.sh) || exit 1
212 if [ X"$ccachedir" != X ]; then
213 CCACHE_DIR="${ccachedir}"
214 export CCACHE_DIR
217 cd ${hversion} || exit 1
219 makecheckenv=
220 if [ X"${testenvironment}" != X ] ; then
221 makecheckenv="${makecheckenv} TESTS_ENVIRONMENT=\"${testenvironment}\""
224 mkdir socket_wrapper_dir
225 SOCKET_WRAPPER_DIR=`pwd`/socket_wrapper_dir
226 export SOCKET_WRAPPER_DIR
228 echo "Configuring and building ($hversion)"
229 echo "./configure --enable-socket-wrapper ${confflags}" > ab.txt
230 ./configure --enable-socket-wrapper ${confflags} >> ab.txt 2>&1
231 if [ $? != 0 ] ; then
232 echo Configure failed
233 status=${status:-configure}
235 echo make all >> ab.txt
236 make all >> ab.txt 2>&1
237 if [ $? != 0 ] ; then
238 echo Make all failed
239 status=${status:-make all}
241 echo make check >> ab.txt
242 eval env $makecheckenv make check >> ab.txt 2>&1
243 if [ $? != 0 ] ; then
244 echo Make check failed
245 status=${status:-make check}
248 if [ "$distcheck" = yes ] ; then
249 echo make distcheck >> ab.txt
250 if [ $? != 0 ] ; then
251 echo Make check failed
252 status=${status:-make distcheck}
256 status=${status:-ok}
258 echo "done: ${status}"
260 if [ "X${resultdir}" != X ] ; then
261 cp ab.txt "${resultdir}/ab-${hversion}-${hostname}-${date}.txt"
264 if [ "X${noemail}" = X ] ; then
265 cat > email-header <<EOF
266 From: ${USER:-unknown-user}@${hostname}
267 To: <heimdal-build-log@it.su.se>
268 Subject: heimdal-build-log SPAM COOKIE
269 X-heimdal-build: kaka-till-love
271 Script-version: ${version}
272 Heimdal-version: ${hversion}
273 Machine: `uname -a`
274 Status: $status
277 if [ "X$passhrase" != X ] ; then
278 cat >> email-header <<EOF
279 autobuild-passphrase: ${passhrase}
282 cat >> email-header <<EOF
283 ------L-O-G------------------------------------
286 cat email-header ab.txt | sendmail "${email}"
289 cd ..
290 if [ X"$keeptree" != Xyes ] ; then
291 rm -rf ${hversion}
293 rm -f ${hfile}
295 exit 0