]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - crypto/heimdal/tools/heimdal-build.sh
- Copy stable/9 to releng/9.2 as part of the 9.2-RELEASE cycle.
[FreeBSD/releng/9.2.git] / crypto / heimdal / tools / heimdal-build.sh
1 #!/bin/sh
2 # Fetches, builds and store the result of a heimdal build
3 # Version: $Id: heimdal-build.sh 21653 2007-07-18 20:15:59Z lha $
4
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=
16
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"
21
22 # no more user configurabled part below (hopefully)
23
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]"
25
26 date=`date +%Y%m%d`
27 if [ "$?" != 0 ]; then
28     echo "have no sane date, punting"
29     exit 1
30 fi
31
32 hostname=`hostname`
33 if [ "$?" != 0 ]; then
34     echo "have no sane hostname, punting"
35     exit 1
36 fi
37
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
42 fi
43
44 dir=
45 hversion=
46 cvsroot=
47 cvsflags=
48 cvsbranch=
49 branch=
50 autotools=no
51 distcheck=no
52
53 while true
54 do
55         case $1 in
56         --autotools)
57                 autotools=yes
58                 shift
59                 ;;
60         --build-dir)
61                 builddir="$2"
62                 shift 2
63                 ;;
64         --current)
65                 dir="snapshots/"
66                 hversion="heimdal-${date}"
67                 shift
68                 ;;
69         --release)
70                 hversion="heimdal-$2"
71                 shift 2
72                 ;;
73         --cputime)
74                 cputimelimit="$2"
75                 shift 2
76                 ;;
77         --ccache-dir)
78                 ccachedir="$2"
79                 shift 2
80                 ;;
81         --svn)
82                 hversion="heimdal-svn-${date}"
83                 svnroot=$2
84                 fetchmethod=svn
85                 shift 2
86                 ;;
87         --distcheck)
88                 distcheck=yes
89                 shift
90                 ;;
91         --result-directory)
92                 resultdir="$2"
93                 if [ ! -d "$resultdir" ]; then
94                     echo "$resultdir doesn't exists"
95                     exit 1
96                 fi
97                 resultdir="`pwd`/${resultdir}"
98                 shift 2
99                 ;;
100         --fetch-method)
101                 fetchmethod="$2"
102                 shift 2
103                 ;;
104         --keep-tree)
105                 keeptree=yes
106                 shift
107                 ;;
108         --passphrase)
109                 passhrase="$2"
110                 shift 2
111                 ;;
112         --prepend-path)
113                 prependpath="$2"
114                 shift 2
115                 ;;
116         --test-environment)
117                 testenvironment="$2"
118                 shift 2
119                 ;;
120         --no-email)
121                 noemail="yes"
122                 shift
123                 ;;
124         --configure-flags)
125                 confflags="${confflags} $2"
126                 shift 2
127                 ;;
128         --version)
129                 echo "Version: $version"
130                 exit 0
131                 ;;
132         -*)
133                 echo "unknown option: $1"
134                 break
135                 ;;
136         *)
137                 break
138                 ;;
139         esac
140 done
141 if test $# -gt 0; then
142         echo $usage
143         exit 1
144 fi
145
146 if [ "X${hversion}" = X ]; then
147         echo "no version given"
148         exit 0
149 fi
150
151 hfile="${hversion}.tar.gz"
152 url="${baseurl}/${dir}${hfile}"
153 afsfile="${afsdir}/${dir}${hfile}"
154 unpack=yes
155
156 # extra paths for the user
157 if [ "X${prependpath}" != X ]; then
158         PATH="${prependpath}:${PATH}"
159 fi
160
161 # Limit cpu seconds this all can take
162 ulimit -t "$cputimelimit" > /dev/null 2>&1
163
164 if [ "X${builddir}" != X ]; then
165         echo "Changing build dir to ${builddir}"
166         cd "${builddir}"
167 fi
168
169 echo "Removing old source" 
170 rm -rf ${hversion}
171
172 echo "Fetching ${hversion} using $fetchmethod"
173 case "$fetchmethod" in
174 wget|ftp|fetch)
175         ${fetchmethod} $url > /dev/null
176         res=$?
177         ;;
178 curl)
179         ${fetchmethod} -o ${hfile} ${url} > /dev/null
180         res=$?
181         ;;
182 afs)
183         cp ${afsfile} ${hfile}
184         res=$?
185         ;;
186 svn)
187         svn co $svnroot ${hversion}
188         res=$?
189         unpack=no
190         autotools=yes
191         ;;
192 *)
193         echo "unknown fetch method"
194         ;;
195 esac
196
197 if [ "X$res" != X0 ]; then
198         echo "Failed to download the tar-ball"
199         exit 1
200 fi
201
202 if [ X"$unpack" = Xyes ]; then
203         echo Unpacking source
204         (gzip -dc ${hfile} | tar xf -) || exit 1
205 fi
206
207 if [ X"$autotools" = Xyes ]; then
208         echo "Autotooling"
209         (cd ${hversion} && sh ./autogen.sh) || exit 1
210 fi
211
212 if [ X"$ccachedir" != X ]; then
213         CCACHE_DIR="${ccachedir}"
214         export CCACHE_DIR
215 fi
216
217 cd ${hversion} || exit 1
218
219 makecheckenv=
220 if [ X"${testenvironment}" != X ] ; then
221     makecheckenv="${makecheckenv} TESTS_ENVIRONMENT=\"${testenvironment}\""
222 fi
223
224 mkdir socket_wrapper_dir
225 SOCKET_WRAPPER_DIR=`pwd`/socket_wrapper_dir
226 export SOCKET_WRAPPER_DIR
227
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}
234 fi
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}
240 fi
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}
246 fi
247
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}
253     fi
254 fi
255
256 status=${status:-ok}
257
258 echo "done: ${status}"
259
260 if [ "X${resultdir}" != X ] ; then
261         cp ab.txt "${resultdir}/ab-${hversion}-${hostname}-${date}.txt"
262 fi
263
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
270
271 Script-version: ${version}
272 Heimdal-version: ${hversion}
273 Machine: `uname -a`
274 Status: $status
275 EOF
276
277         if [ "X$passhrase" != X ] ; then
278                 cat >> email-header <<EOF
279 autobuild-passphrase: ${passhrase}
280 EOF
281         fi
282                 cat >> email-header <<EOF
283 ------L-O-G------------------------------------
284 EOF
285
286         cat email-header ab.txt | sendmail "${email}"
287 fi
288
289 cd ..
290 if [ X"$keeptree" != Xyes ] ; then
291     rm -rf ${hversion}
292 fi
293 rm -f ${hfile}
294
295 exit 0