do not fail on Kiwi:parse, even though it is not yet implemented.
[opensuse:build.git] / build
1 #!/bin/bash
2 # Script to build a package.  It uses init_buildsystem to setup a chroot
3 # building tree.  This script needs a directory as parameter.  This directory
4 # has to include sources and a spec file.
5 #
6 # BUILD_ROOT        here the packages will be built
7 #
8 # (c) 1997-2008 SuSE GmbH Nuernberg, Germany
9
10 test -z "$BUILD_DIR" && BUILD_DIR=/usr/lib/build
11 test -z "$BUILD_ROOT" && BUILD_ROOT=/var/tmp/build-root
12
13 export BUILD_ARCH BUILD_ROOT BUILD_RPMS BUILD_DIR
14
15 ccache=0
16 icecream=0
17 definesnstuff=()
18 repos=()
19
20 # mkreiserfs only works with qemu/uml if it is able to create a file
21 # system that is owned by the calling user (bnc#369006)
22 #xen_img_mkfs='mkreiserfs -q -f'
23 xen_img_mkfs='mkfs.ext2 -m 0 -q -F'
24 #xen_img_mkfs='mkfs.ext3 -j -m 0 -q -F'
25 qemu_kernel=/boot/vmlinuz
26 qemu_initrd=/boot/initrd
27 qemu_bin=/usr/bin/qemu
28 uml_kernel=/boot/vmlinux-um
29 uml_initrd=/boot/initrd-um
30
31 DO_INIT=true
32 DO_LINT=
33 CLEAN_BUILD=
34 SPECFILES=()
35 SRCDIR=
36 BUILD_JOBS=
37 ABUILD_TARGET_ARCH=
38 CREATE_BASELIBS=
39 USEUSEDFORBUILD=
40 LIST_STATE=
41 USE_UML=
42 USE_QEMU=
43 USE_XEN=
44 VM_IMAGE=
45 XENSWAP=
46 XENMEMORY=
47 RUNNING_IN_XEN=
48 RPMLIST=
49 RELEASE=
50 REASON=
51 NOROOTFORBUILD=
52 LOGFILE=
53 KILL=
54 CHANGELOG=
55
56 export PATH=$BUILD_DIR:$PATH
57
58 # This is for insserv
59 export YAST_IS_RUNNING=instsys
60
61 unset LANGUAGE
62 unset LANG
63 export LC_ALL=POSIX
64 umask 022
65
66 echo_help () {
67     cat << EOT
68
69 Some comments for build
70 -----------------------
71
72 With build you can create rpm packages.  They will be built in a chroot
73 system.  This chroot system will be setup automatically.  Normally you can
74 simply call build with a spec file as parameter - nothing else has to be
75 set.
76
77 If you want to set the directory were the chroot system will be setup
78 (at the moment it uses $BUILD_ROOT),
79 simply set the the environment variable BUILD_ROOT.
80
81 Example:
82
83   export BUILD_ROOT=/var/tmp/mybuildroot
84
85
86 Normally build builds the complete package including src.rpm (rpmbuild -ba).
87 If you want let build only make the binary package, simply set
88
89    export BUILD_RPM_BUILD_STAGE=-bb
90
91 (or -bc, -bp, -bi, ...  see "Maximum RPM" for more details [*]).
92
93 When the build command succeeds, the rpm files can be found under
94 $BUILD_ROOT/usr/src/packages/RPMS/
95
96
97 Known Parameters:
98
99   --help      You already got it :)
100
101   --clean     Delete old build root before initializing it
102
103   --no-init   Skip initialization of build root and start with build
104               immediately.
105
106   --rpms path1:path2:...
107               Specify path where to find the RPMs for the build system
108
109   --arch arch1:arch2:...
110               Specify what architectures to select from the RPMs
111
112   --useusedforbuild
113               Do not expand dependencies but search the specfile for
114               usedforbuild lines.
115
116   --verify    Run verify when initializing the build root
117
118   --extra-packs pack
119               Also install package 'pack'
120
121   --root rootdir
122               Use 'rootdir' to setup chroot environment
123
124   --baselibs  Create -32bit/-64bit/-x86 rpms for other architectures
125
126   --list-state
127               List rpms that would be used to create a fresh build root.
128               Does not create the build root or perform a build.
129
130   --with X
131               enable feature X for build
132
133   --without X
134               disable feature X for build
135
136   --define 'X Y'
137               define macro X with value Y
138
139   --ccache
140               use ccache to speed up rebuilds
141
142   --icecream N
143               use N parallel build jobs with icecream
144
145 Remember to have fun!
146
147 [*] Maximum RPM: http://www.rpm.org/max-rpm/
148 EOT
149 }
150 usage () {
151     echo "Usage: `basename $0` [--no-init|--clean|--rpms path|--verify|--help] [dir-to-build|spec-to-build]"
152     cleanup_and_exit 1
153 }
154
155 #
156 #  cleanup_and_exit
157 #
158 cleanup_and_exit () {
159     test -z "$1" && set 0
160     if test -n "$RUNNING_IN_XEN" ; then
161         cd /
162         if test -n "$XENSWAP" -a -e "$XENSWAP" ; then
163             swapoff "$XENSWAP"
164             echo -n "BUILDSTATUS$1" >"$XENSWAP"
165         fi
166         exec >&0 2>&0   # so that the logging tee finishes
167         sleep 1         # wait till tee terminates
168         kill -9 -1      # goodbye cruel world
169         exec /bin/bash -c 'mount -n -o remount,ro / ; halt -f'
170         halt -f
171     else
172         umount -n $BUILD_ROOT/proc 2>/dev/null || true
173         umount -n $BUILD_ROOT/dev/pts 2>/dev/null || true
174         [ -n "$VM_IMAGE" ] && umount "$VM_IMAGE" 2>/dev/null || true
175     fi
176     exit $1
177 }
178
179 shellquote()
180 {
181     for arg; do
182         arg=${arg/\\/\\\\}
183         arg=${arg/\$/\\\$}
184         arg=${arg/\"/\\\"}
185         arg=${arg/\`/\\\`}
186         echo -n " \"$arg\""
187     done
188 }
189
190 # create a shell script from command line. Used for preserving arguments
191 # through /bin/su -c
192 toshellscript()
193 {
194         echo "#!/bin/sh -x"
195         echo -n exec
196         shellquote "$@"
197         echo
198 }
199
200 setupccache()
201 {
202     if [ "$ccache" = 1 ]; then
203         if mkdir -p $BUILD_ROOT/var/lib/build/ccache/bin; then
204             for i in gcc g++ cc c++; do
205 #               ln -sf /usr/bin/ccache $BUILD_ROOT/var/lib/build/ccache/bin/$i
206                 rm -f $BUILD_ROOT/var/lib/build/ccache/bin/$i
207                 test -e $BUILD_ROOT/usr/bin/$i || continue
208                 echo '#! /bin/sh' > $BUILD_ROOT/var/lib/build/ccache/bin/$i
209                 echo "test -e /usr/bin/$i || exit 1" > $BUILD_ROOT/var/lib/build/ccache/bin/$i
210                 echo 'export PATH=/opt/icecream/bin:/usr/bin:$PATH' >> $BUILD_ROOT/var/lib/build/ccache/bin/$i
211                 echo "ccache $i \"\$@\"" >> $BUILD_ROOT/var/lib/build/ccache/bin/$i
212                 chmod 755 $BUILD_ROOT/var/lib/build/ccache/bin/$i
213                 echo "Installed ccache wrapper as $BUILD_ROOT/var/lib/build/ccache/bin/$i"
214             done
215         fi
216         mkdir -p "$BUILD_ROOT"/.ccache
217         chroot "$BUILD_ROOT" chown -R "$BUILD_USER" "/.ccache"
218         echo "export CCACHE_DIR=/.ccache" > "$BUILD_ROOT"/etc/profile.d/build_ccache.sh
219         echo 'export PATH=/var/lib/build/ccache/bin:$PATH' >> "$BUILD_ROOT"/etc/profile.d/build_ccache.sh
220     else
221         rm -f "$BUILD_ROOT$builduserhome"/bin/{gcc,g++,cc,c++}
222         rm -f "$BUILD_ROOT"/var/lib/build/ccache/bin/{gcc,g++,cc,c++}
223     fi
224 }
225
226 setupicecream()
227 {
228     if [ "$icecream" -eq 0 ]; then
229         rm -rf "$BUILD_ROOT"/var/run/icecream
230         rm -f "$BUILD_ROOT"/etc/profile.d/build_icecream.sh
231         return
232     fi
233
234     if ! chroot "$BUILD_ROOT" rpm -q icecream >/dev/null 2>/dev/null; then
235         echo "*** icecream package not installed ***"
236         false
237         return
238     fi
239
240     echo "using icecream with $icecream jobs"
241
242     if [ "$ccache" -ne 1 ]; then
243         echo 'export PATH=/opt/icecream/bin:$PATH' > "$BUILD_ROOT"/etc/profile.d/build_icecream.sh
244     else
245         echo 'export CCACHE_PATH=/opt/icecream/bin' > "$BUILD_ROOT"/etc/profile.d/build_icecream.sh
246     fi
247
248     local icecc_vers=(`shopt -s nullglob; echo $BUILD_ROOT/var/run/icecream/*.tar.{bz2,gz}`)
249     icecc_vers=${icecc_vers//$BUILD_ROOT/}
250
251     # XXX use changelog like autobuild does instead?
252     # only run create-env if compiler or glibc changed
253     if [ -z "$icecc_vers" \
254         -o ! -e "$BUILD_ROOT/$icecc_vers" \
255         -o "$BUILD_ROOT/usr/bin/gcc" -nt "$BUILD_ROOT/$icecc_vers" \
256         -o "$BUILD_ROOT/usr/bin/g++" -nt "$BUILD_ROOT/$icecc_vers" \
257         -o "$BUILD_ROOT/usr/bin/as" -nt "$BUILD_ROOT/$icecc_vers" \
258         -o "$BUILD_ROOT/lib/libc.so.6" -nt "$BUILD_ROOT/$icecc_vers" ]
259     then
260         rm -rf $BUILD_ROOT/var/run/icecream
261         mkdir -p $BUILD_ROOT/var/run/icecream
262         if [ -e "$BUILD_ROOT"/usr/bin/create-env ]; then
263           createenv=/usr/bin/create-env
264         elif [ -e "$BUILD_ROOT"/usr/lib/icecc/icecc-create-env ]; then
265           createenv="/usr/lib/icecc/icecc-create-env /usr/bin/gcc /usr/bin/g++" # XXX
266         else
267           echo "create-env not found"
268           false
269           return
270         fi
271         chroot $BUILD_ROOT bash -c "cd /var/run/icecream; $createenv"
272         icecc_vers=(`shopt -s nullglob; echo $BUILD_ROOT/var/run/icecream/*.tar.{bz2,gz}`)
273         icecc_vers=${icecc_vers//$BUILD_ROOT/}
274     else
275         echo "reusing existing icecream environment $icecc_vers"
276     fi
277     if [ -n "$icecc_vers" ]; then
278       echo "export ICECC_VERSION=$icecc_vers" >> "$BUILD_ROOT"/etc/profile.d/build_icecream.sh
279     fi
280 }
281
282 setmemorylimit()
283 {
284     if [ -n "$VM_IMAGE" -o -n "$RUNNING_IN_XEN" ]; then
285         return
286     fi
287     local mem
288     while read mem; do
289         case "$mem" in
290             MemTotal:*)
291                 set -- $mem
292                 eval "mem=\$(($2/3*2))"
293                 ulimit -v $mem
294                 echo "Memory limit set to ${mem}KB"
295                 break;
296             ;;
297         esac
298     done < <(cat /proc/meminfo) # cat for proc stuff
299 }
300
301 function create_baselibs {
302     echo "... creating baselibs"
303     BRPMS=
304     for RPM in $BUILD_ROOT$TOPDIR/RPMS/*/*.rpm ; do
305         BRPMS="$BRPMS ${RPM#$BUILD_ROOT}"
306     done
307     BASELIBS_CFG=
308     if test -e $BUILD_ROOT$TOPDIR/SOURCES/baselibs.conf ; then
309         BASELIBS_CFG="-c $TOPDIR/SOURCES/baselibs.conf"
310     fi
311     if test -f $BUILD_ROOT/usr/lib/build/mkbaselibs ; then
312         if test -z "$BASELIBS_CFG" -a -e $BUILD_ROOT/usr/lib/build/baselibs.conf ; then
313             BASELIBS_CFG="-c /usr/lib/build/baselibs.conf"
314         fi
315         chroot $BUILD_ROOT /usr/lib/build/mkbaselibs -c /usr/lib/build/baselibs_global.conf $BASELIBS_CFG $BRPMS || cleanup_and_exit 1
316     else
317         # use external version
318         rm -rf $BUILD_ROOT/.mkbaselibs
319         mkdir -p $BUILD_ROOT/.mkbaselibs
320         cp -f $BUILD_DIR/mkbaselibs $BUILD_ROOT/.mkbaselibs
321         cp -f $BUILD_DIR/baselibs_global.conf $BUILD_ROOT/.mkbaselibs
322         if test -z "$BASELIBS_CFG" -a -e $BUILD_DIR/baselibs.conf ; then
323             cp -f $BUILD_DIR/baselibs.conf $BUILD_ROOT/.mkbaselibs/baselibs.conf
324             BASELIBS_CFG="-c /.mkbaselibs/baselibs.conf"
325         fi
326         chroot $BUILD_ROOT /.mkbaselibs/mkbaselibs -c /.mkbaselibs/baselibs_global.conf $BASELIBS_CFG $BRPMS || cleanup_and_exit 1
327         rm -rf $BUILD_ROOT/.mkbaselibs
328     fi
329 }
330
331 detect_xen_2nd_stage()
332 {
333     if ! test "$0" = "/.build/build" ; then
334         return 1
335     fi
336     echo "XEN 2nd stage started"
337     BUILD_ROOT=/
338     BUILD_DIR=/.build
339     . $BUILD_DIR/build.data
340     echo "machine type: `uname -m`"
341     if test "$PERSONALITY" != 0 -a -z "$PERSONALITY_SET" ; then
342         export PERSONALITY_SET=true
343         echo "switching personality to $PERSONALITY..."
344         # this is 32bit perl/glibc, thus the 32bit syscall number
345         exec perl -e 'syscall(136, '$PERSONALITY') == -1 && warn("personality: $!\n");exec "/.build/build" || die("/.build/build: $!\n")'
346     fi
347     PATH=$BUILD_DIR:$PATH
348     RUNNING_IN_XEN=true
349     mount -orw -n -tproc none /proc
350     mount -n -o remount,rw /
351     if test -n "$XENSWAP" ; then
352         for i in 1 2 3 4 5 6 7 8 9 10 ; do
353             test -e "$XENSWAP" && break
354             test $i = 1 && echo "waiting for $XENSWAP to appear"
355             echo -n .
356             sleep 1
357         done
358         test $i = 1 || echo
359     fi
360 #why would one want to do that?? Breaks all kinds of things
361 # XXX: why wait for it and then recreate?
362     umount -l /dev 2>/dev/null
363     if test -n "$XENSWAP" ; then
364         rm -f "$XENSWAP"
365         umask 027
366         mknod "$XENSWAP" b 3 2
367         umask 022
368         swapon -v "$XENSWAP" || exit 1
369     fi
370     HOST="$MYHOSTNAME"
371
372     return 0
373 }
374
375 set_build_arch()
376 {
377     if [ -z "$BUILD_ARCH" ]; then
378         BUILD_ARCH=`uname -m`
379         test i686 = "$BUILD_ARCH" && BUILD_ARCH=i586 # XXX: why?
380     fi
381
382     case $BUILD_ARCH in
383       i686) BUILD_ARCH="i686:i586:i486:i386" ;;
384       i586) BUILD_ARCH="i586:i486:i386" ;;
385       i486) BUILD_ARCH="i486:i386" ;;
386       x86_64) BUILD_ARCH="x86_64:i686:i586:i486:i386" ;;
387     esac
388     if test "$BUILD_ARCH" != "${BUILD_ARCH#i686}" ; then
389         cpuflags=`grep ^flags /proc/cpuinfo`
390         cpuflags="$cpuflags "
391         test "$cpuflags" = "${cpuflags/ cx8 /}" -o "$cpuflags" = "${cpuflags/ cmov /}" && {
392             echo "Your cpu doesn't support i686 rpms. Exit."
393             exit 1
394         }
395     fi
396 }
397
398 find_spec_files()
399 {
400     local spec files
401     if [ -z "$SPECFILES" ]; then
402         set -- "`pwd`"
403     else
404         set -- "${SPECFILES[@]}"
405     fi
406     SPECFILES=()
407     for spec in "$@"; do
408         if [ "$spec" = "${spec#/}" ]; then
409             spec="`pwd`/$spec"
410         fi
411
412         if [ -d "$spec" ]; then
413             specs=("$spec"/*.spec)
414             if [ -n "$specs" ]; then
415                 SPECFILES=("${SPECFILES[@]}" "${specs[@]}")
416             else
417                 specs=("$spec"/*.spec)
418                 if [ -n "$specs" ]; then
419                     SPECFILES=("${SPECFILES[@]}" "${specs[@]}")
420                 fi
421             fi
422         else
423             SPECFILES[${#SPECFILES[@]}]="$spec";
424         fi
425     done
426
427     if test -z "$SPECFILES"; then
428         echo no spec files or src rpms found in $@. exit...
429         cleanup_and_exit 1
430     fi
431 }
432
433 become_root_or_fail()
434 {
435     if [ ! -w /root ]; then
436         echo "You have to be root to use $0" >&2
437         exit 1
438     fi
439     cleanup_and_exit 1
440 }
441
442 mkdir_build_root()
443 {
444     if [ -d "$BUILD_ROOT" ]; then
445         # check if it is owned by root
446         if [ -z "$RUNNING_IN_XEN" -a \! -O "$BUILD_ROOT" ]; then
447             echo "BUILD_ROOT=$BUILD_ROOT must be owned by $USER. Exit..."
448             cleanup_and_exit 1
449         fi
450     else
451         test "$BUILD_ROOT" != "${BUILD_ROOT%/*}" && mkdir -p "${BUILD_ROOT%/*}"
452         if ! mkdir $BUILD_ROOT; then
453             echo "can not create BUILD_ROOT=$BUILD_ROOT. Exit..."
454             cleanup_and_exit 1
455         fi
456     fi
457 }
458
459 shopt -s nullglob
460
461 if detect_xen_2nd_stage; then
462     set "/.build-srcdir/$SPECFILE"
463 else
464     export HOST
465 fi
466
467 while test -n "$1"; do
468   PARAM="$1"
469   ARG="$2"
470   shift
471   case $PARAM in
472     *-*=*)
473       ARG=${PARAM#*=}
474       PARAM=${PARAM%%=*}
475       set -- "----noarg=$PARAM" "$@"
476   esac
477   case $PARAM in
478       *-help|-h)
479         echo_help
480         cleanup_and_exit
481       ;;
482       *-no*init)
483         DO_INIT=false
484       ;;
485       *-clean)
486         CLEAN_BUILD='--clean'
487       ;;
488       *-kill)
489         KILL=true
490       ;;
491       *-rpms)
492         BUILD_RPMS="$ARG"
493         if [ -z "$BUILD_RPMS" ] ; then
494           echo_help
495           cleanup_and_exit
496         fi
497         shift
498       ;;
499       *-arch)
500         BUILD_ARCH="$ARG"
501         shift
502       ;;
503       *-verify)
504         export VERIFY_BUILD_SYSTEM=true
505       ;;
506       *-target)
507         ABUILD_TARGET_ARCH="$ARG"
508         shift
509       ;;
510       *-jobs) 
511         BUILD_JOBS="$ARG"
512         shift
513       ;;
514       *-extra*packs|-X)
515         BUILD_EXTRA_PACKS="$BUILD_EXTRA_PACKS $ARG"
516         shift
517       ;;
518       *-lint)
519         DO_LINT=true
520         ;;
521       *-baselibs)
522         CREATE_BASELIBS=true
523         ;;
524       *-baselibs-internal)
525         CREATE_BASELIBS=internal
526         ;;
527       *-root)
528         BUILD_ROOT="$ARG"
529         shift
530       ;;
531       *-dist) 
532         BUILD_DIST="$ARG"
533         export BUILD_DIST
534         shift
535       ;;
536       *-xen)
537         USE_XEN=1
538         if [ -n "$ARG" -a "$ARG" = "${ARG#-}" ]; then
539             VM_IMAGE="$ARG"
540             shift
541         else
542             VM_IMAGE=1
543         fi
544       ;;
545       --uml)
546         USE_UML=1
547         if [ -n "$ARG" -a "$ARG" = "${ARG#-}" ]; then
548             VM_IMAGE="$ARG"
549             shift
550         else
551             VM_IMAGE=1
552         fi
553       ;;
554       --qemu)
555         USE_QEMU=1
556         if [ -n "$ARG" -a "$ARG" = "${ARG#-}" ]; then
557             VM_IMAGE="$ARG"
558             shift
559         else
560             VM_IMAGE=1
561         fi
562       ;;
563       *-xenswap)
564         XENSWAP="$ARG"
565         shift
566       ;;
567       *-xenmemory)
568         VM_MEMORY="$ARG"
569         shift
570       ;;
571       *-rpmlist)
572         RPMLIST="--rpmlist $ARG"
573         BUILD_RPMS=
574         shift
575       ;;
576       *-release)
577         RELEASE="--release $ARG"
578         shift
579       ;;
580       *-logfile)
581         LOGFILE="$ARG"
582         shift
583       ;;
584       *-reason)
585         REASON="$ARG"
586         shift
587       ;;
588       *-norootforbuild)
589         NOROOTFORBUILD=true
590       ;;
591       *-stage)
592         BUILD_RPM_BUILD_STAGE="$ARG"
593         shift
594       ;;
595       *-useusedforbuild)
596         USEUSEDFORBUILD="--useusedforbuild"
597       ;;
598       *-list*state)
599         LIST_STATE=true
600       ;;
601       --define|--with|--without)
602         definesnstuff[${#definesnstuff[@]}]="$PARAM";
603         definesnstuff[${#definesnstuff[@]}]="$ARG";
604         shift
605       ;;
606       --repository)
607         if [ -z "$ARG" ] ; then
608           echo_help
609           cleanup_and_exit
610         fi
611         repos[${#repos[@]}]="$PARAM";
612         repos[${#repos[@]}]="$ARG";
613         shift
614       ;;
615       --icecream)
616         if [ -z "$ARG" ] ; then
617           echo "--icecream needs an argument" >&2
618           echo_help
619           cleanup_and_exit 1
620         fi
621         icecream="$ARG"
622         BUILD_JOBS="$ARG"
623         shift
624       ;;
625       --ccache)
626         ccache=1
627       ;;
628       ----noarg)
629         echo "$ARG does not take an argument"
630         cleanup_and_exit
631       ;;
632       *-changelog)
633         CHANGELOG=true
634       ;;
635       -*)
636         echo Unknown Option "$PARAM". Exit.
637         cleanup_and_exit 1
638       ;;
639       *)
640         SPECFILES[${#SPECFILES[@]}]="$PARAM";
641       ;;
642     esac
643 done
644
645 if test -n "$KILL" ; then
646     test -z "$SRCDIR" || usage
647     if test -z "$VM_IMAGE" ; then
648         if ! $BUILD_DIR/killchroot -s 9 $BUILD_ROOT ; then
649             echo "could not kill build in $BUILD_ROOT"
650             exit 1
651         fi
652     else
653         XENID="${VM_IMAGE%/root}"
654         XENID="${XENID##*/}"
655         if xm list "build:$XENID" >/dev/null 2>&1 ; then
656             if ! xm destroy "build:$XENID" ; then
657                 echo "could not kill xen build $XENID"
658                 exit 1
659             fi
660         fi
661     fi
662     exit 0
663 fi
664
665 if [ -z "$RPMLIST" ]; then
666     if [ -z "$repos" -a -z "$BUILD_RPMS" ]; then
667         BUILD_RPMS="/media/dvd/suse"
668     fi
669 else
670     repos=()
671 fi
672
673 set_build_arch
674
675 if [ -n "$CLEAN_BUILD" ]; then
676     DO_INIT=true
677 fi
678
679 find_spec_files
680
681 if test -n "$LIST_STATE" ; then
682     BUILD_ROOT=`mktemp -d /var/tmp/build-list-state-XXXXXX`
683     test -d "$BUILD_ROOT" || exit 1
684     SPECFILE=$SPECFILES # only one specified anyways
685     if test "$SPECFILE" != "${SPECFILE%.src.rpm}" ; then
686        rm -rf $BUILD_ROOT/usr/src/packages
687        mkdir -p $BUILD_ROOT/usr/src/packages/SOURCES $BUILD_ROOT/usr/src/packages/SPECS
688        rpm -i --nodigest --nosignature --root $BUILD_ROOT $SPECFILE || {
689            echo "could not install $SPECFILE." 2>&1
690            rm -rf $BUILD_ROOT
691            cleanup_and_exit 1
692        }
693        for SPECFILE in $BUILD_ROOT/usr/src/packages/SPECS/*.spec ; do : ; done
694     fi
695     init_buildsystem --list-state "${definesnstuff[@]}" "${repos[@]}" $USEUSEDFORBUILD $SPECFILE $BUILD_EXTRA_PACKS
696     ERR=$?
697     rm -rf $BUILD_ROOT
698     cleanup_and_exit $ERR
699 fi
700
701 if test -z "$RUNNING_IN_XEN" ; then
702     if test -n "$VM_IMAGE" ; then
703         if test "$VM_IMAGE" = 1 ; then
704             VM_IMAGE="$BUILD_ROOT.img"
705         fi
706         if test ! -f "$VM_IMAGE" ; then
707             echo "you need to create a file system on $VM_IMAGE first"
708             cleanup_and_exit 1
709         fi
710     fi
711     if test -n "$VM_IMAGE" ; then
712         if test -n "$CLEAN_BUILD" ; then
713             echo "Creating filesystem on $VM_IMAGE"
714             $xen_img_mkfs $VM_IMAGE || become_root_or_fail
715         fi
716         mkdir_build_root
717         if [ -w /root ]; then
718             mount -o loop $VM_IMAGE $BUILD_ROOT || cleanup_and_exit 1
719         else
720             mount $BUILD_ROOT || become_root_or_fail
721         fi
722     else
723         test -w /root || become_root_or_fail
724     fi
725     if test -n "$XENSWAP" ; then
726         dd if=/dev/zero of="$XENSWAP" bs=12 count=1 conv=notrunc 2>/dev/null
727         mkswap "$XENSWAP"
728     fi
729 fi
730
731 mkdir_build_root
732
733 rm -f $BUILD_ROOT/exit
734
735 if [ -w /root ]; then
736     mkdir -p $BUILD_ROOT/proc
737     mkdir -p $BUILD_ROOT/dev/pts
738     mount -n -tproc none $BUILD_ROOT/proc || true
739     mount -n -tdevpts none $BUILD_ROOT/dev/pts
740 fi
741
742 if test -z "$VM_IMAGE" -a -z "$LOGFILE"; then
743     LOGFILE="$BUILD_ROOT/.build.log"
744 fi
745
746 if test -n "$LOGFILE" ; then
747     echo  logging output to $LOGFILE...
748     rm -f $LOGFILE
749     touch $LOGFILE
750     if test -n "$VM_IMAGE" ; then
751         exec 1> >(exec -a 'build logging tee' perl -e 'open(F,">>",$ARGV[0])||die("$ARGV[0]: $!\n");$|=1;select(F);$|=1;while(<STDIN>){print STDOUT;s/^\r//s;s/\r\n/\n/gs;print F}' $LOGFILE) 2>&1
752     else
753         exec 1> >(exec -a 'build logging tee' tee -a $LOGFILE) 2>&1
754     fi
755 fi
756
757 setmemorylimit
758
759 #
760 # say hello
761 #
762 test -z "$HOST" && HOST=`hostname`
763 echo Using BUILD_ROOT=$BUILD_ROOT
764 test -n "$BUILD_RPMS" && echo Using BUILD_RPMS=$BUILD_RPMS
765 echo Using BUILD_ARCH=$BUILD_ARCH
766 test -n "$USE_XEN" && echo "Doing XEN build in $VM_IMAGE"
767 echo
768
769 test "$BUILD_ARCH" = all && BUILD_ARCH=
770
771 for SPECFILE in "${SPECFILES[@]}" ; do
772
773     SRCDIR="${SPECFILE%/*}"
774     SPECFILE="${SPECFILE##*/}"
775
776     cd "$SRCDIR"
777
778     echo
779     echo "$HOST started \"build $SPECFILE\" at `date`."
780     echo
781     test -n "$REASON" && echo "$REASON"
782     echo
783
784     #
785     # first setup building directory...
786     #
787     test -s "$SPECFILE" || {
788        echo "$SPECFILE" is empty.  This should not happen...
789        cleanup_and_exit 1
790     }
791
792     if test "$SPECFILE" != "${SPECFILE%.src.rpm}" ; then
793         echo processing src rpm `pwd`/$SPECFILE...
794         TOPDIR=`rpm --eval '%_topdir'`
795         rm -rf $BUILD_ROOT$TOPDIR
796         mkdir -p $BUILD_ROOT$TOPDIR/SOURCES $BUILD_ROOT$TOPDIR/SPECS
797         rpm -i --nodigest --nosignature --root $BUILD_ROOT $SPECFILE || {
798             echo "could not install $SPECFILE."
799             cleanup_and_exit 1
800         }
801         rm -rf $BUILD_ROOT/.build-srcdir
802         mkdir -p $BUILD_ROOT/.build-srcdir
803         mv $BUILD_ROOT$TOPDIR/SOURCES/* $BUILD_ROOT/.build-srcdir
804         mv $BUILD_ROOT$TOPDIR/SPECS/* $BUILD_ROOT/.build-srcdir
805         MYSRCDIR=$BUILD_ROOT/.build-srcdir
806         cd $MYSRCDIR || cleanup_and_exit 1
807         for SPECFILE in *.spec ; do : ; done
808     else
809         echo processing specfile `pwd`/$SPECFILE...
810         MYSRCDIR="$SRCDIR"
811     fi
812
813     ADDITIONAL_PACKS=""
814     test -n "$BUILD_EXTRA_PACKS" && ADDITIONAL_PACKS="$ADDITIONAL_PACKS $BUILD_EXTRA_PACKS"
815     test -n "$CREATE_BASELIBS" && ADDITIONAL_PACKS="$ADDITIONAL_PACKS build"
816     test "$ccache" = '1' && ADDITIONAL_PACKS="$ADDITIONAL_PACKS ccache"
817     test "$icecream" -gt 1 && ADDITIONAL_PACKS="$ADDITIONAL_PACKS icecream gcc-c++"
818     test -n "$DO_LINT" && ADDITIONAL_PACKS="$ADDITIONAL_PACKS rpmlint-mini"
819
820     if test -n "$CHANGELOG" -a -z "$RUNNING_IN_XEN" ; then
821         rm -f $BUILD_ROOT/.build-changelog
822         case $SPECFILE in
823           *.dsc) CFFORMAT=debian ;;
824           *) CFFORMAT=rpm ;;
825         esac
826         echo "running changelog2spec --target $CFFORMAT --file $MYSRCDIR/$SPECFILE"
827         if ! $BUILD_DIR/changelog2spec --target $CFFORMAT --file "$MYSRCDIR/$SPECFILE" > $BUILD_ROOT/.build-changelog ; then
828             rm -f $BUILD_ROOT/.build-changelog
829         fi
830     fi
831
832     if test -n "$USE_XEN" -o -n "$USE_UML" -o -n "$USE_QEMU"; then
833         rm -rf $BUILD_ROOT/.build
834         mkdir -p $BUILD_ROOT/.build
835         if test "$DO_INIT" = true ; then
836             # do fist stage of init_buildsystem
837             rm -f $BUILD_ROOT/.build.success
838             set -- init_buildsystem --prepare "${definesnstuff[@]}" "${repos[@]}" $CLEAN_BUILD $USEUSEDFORBUILD $RPMLIST "$MYSRCDIR/$SPECFILE" $ADDITIONAL_PACKS
839             echo "$* ..."
840             "$@" || cleanup_and_exit 1
841             if [ ! -w /root ]; then
842                 # remove setuid bit if files belong to user to make e.g. mount work
843                 find $BUILD_ROOT/{bin,sbin,usr/bin,usr/sbin} -type f -uid $UID -perm +4000 -print0 | xargs -0 --no-run-if-empty chmod -s
844             fi
845         fi
846         # start up xen, rerun ourself
847         cp -a $BUILD_DIR/. $BUILD_ROOT/.build
848         if ! test "$MYSRCDIR" = $BUILD_ROOT/.build-srcdir ; then
849             rm -rf $BUILD_ROOT/.build-srcdir
850             mkdir $BUILD_ROOT/.build-srcdir
851             cp -p "$MYSRCDIR"/* $BUILD_ROOT/.build-srcdir
852             MYSRCDIR=$BUILD_ROOT/.build-srcdir
853         fi
854         Q="'\''"
855         echo "SPECFILE='${SPECFILE//"'"/$Q}'" > $BUILD_ROOT/.build/build.data
856         echo "BUILD_JOBS='${BUILD_JOBS//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
857         echo "BUILD_ARCH='${BUILD_ARCH//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
858         echo "BUILD_RPMS='${BUILD_RPMS//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
859         case $BUILD_DIST in
860             */*)
861                 cp $BUILD_DIST $BUILD_ROOT/.build/build.dist
862                 BUILD_DIST=/.build/build.dist
863                 ;;
864         esac
865         echo "BUILD_DIST='${BUILD_DIST//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
866         echo "RELEASE='${RELEASE//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
867         echo "NOROOTFORBUILD='${NOROOTFORBUILD//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
868         echo "CREATE_BASELIBS='$CREATE_BASELIBS'" >> $BUILD_ROOT/.build/build.data
869         echo "REASON='${REASON//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
870         echo "CHANGELOG='${CHANGELOG//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
871         test -n "$XENSWAP" && echo "XENSWAP='/dev/hda2'" >> $BUILD_ROOT/.build/build.data
872         PERSONALITY_SYSCALL=
873         PERSONALITY=0
874         case `perl -V:archname` in
875             *x86_64*) PERSONALITY_SYSCALL=135 ;;
876             *i?86*)   PERSONALITY_SYSCALL=136 ;;
877         esac
878         test -n "$PERSONALITY_SYSCALL" && PERSONALITY=`perl -e 'print syscall('$PERSONALITY_SYSCALL', 0)."\n"'`
879         echo "PERSONALITY='$PERSONALITY'" >> $BUILD_ROOT/.build/build.data
880         echo "MYHOSTNAME='`hostname`'" >> $BUILD_ROOT/.build/build.data
881         echo -n "definesnstuff=(" >> $BUILD_ROOT/.build/build.data
882         shellquote "${definesnstuff[@]}" >> $BUILD_ROOT/.build/build.data
883         echo ")" >> $BUILD_ROOT/.build/build.data
884         echo -n "repos=(" >> $BUILD_ROOT/.build/build.data
885         shellquote "${repos[@]}" >> $BUILD_ROOT/.build/build.data
886         echo ")" >> $BUILD_ROOT/.build/build.data
887         umount -n $BUILD_ROOT/proc 2> /dev/null || true
888         umount -n $BUILD_ROOT/dev/pts 2> /dev/null || true
889         umount -n $BUILD_ROOT/mnt 2> /dev/null || true
890         umount $VM_IMAGE
891
892         if [ -n "$USE_XEN" ]; then
893                 XMROOT=file:$VM_IMAGE
894                 XMROOT=${XMROOT/#file:\/dev/phy:}
895                 XMROOT="disk=$XMROOT,hda1,w"
896                 XMSWAP=
897                 if test -n "$XENSWAP" ; then
898                     XMSWAP=file:$XENSWAP
899                     XMSWAP=${XMSWAP/#file:\/dev/phy:}
900                     XMSWAP="disk=$XMSWAP,hda2,w"
901                 fi
902                 XENID="${VM_IMAGE%/root}"
903                 XENID="${XENID##*/}"
904                 echo "booting XEN kernel ..."
905                 set -- xm create -c $BUILD_DIR/xen.conf name="build:$XENID" ${VM_MEMORY:+memory=$VM_MEMORY} $XMROOT $XMSWAP extra="init=/.build/build panic=1 console=ttyS0"
906                 if test "$PERSONALITY" != 0 ; then
907                     # have to switch back to PER_LINUX to make xm work
908                     set -- perl -e 'syscall('$PERSONALITY_SYSCALL', 0); exec(@ARGV) || die("$ARGV[0]: $!\n")' "$@"
909                 fi
910                 echo "$@"
911                 "$@" || true # somehow this is always false
912         elif [ -n "$USE_UML" ]; then
913                 echo "booting UML kernel ..."
914                 set -- $uml_kernel initrd=$uml_initrd root=/ubda init=/.build/build panic=1 quiet ubd0=$VM_IMAGE ${VM_MEMORY:+mem=$VM_MEMORY}
915                 echo "$@"
916                 "$@"
917         elif [ -n "$USE_QEMU" ]; then
918                 echo "booting QEMU ..."
919                 set -- $qemu_bin -no-reboot -nographic -net none -kernel $qemu_kernel -initrd $qemu_initrd -append "init=/.build/build panic=1 quiet root=/dev/sda rw console=ttyS0,115200" -serial stdio -hda $VM_IMAGE ${VM_MEMORY:+-m $VM_MEMORY}
920                 echo "$@"
921                 "$@"
922         fi
923         if test -n "$XENSWAP" ; then
924             BUILDSTATUS=`dd if="$XENSWAP" bs=12 count=1 2>/dev/null`
925             case $BUILDSTATUS in
926               BUILDSTATUS[0-9])
927                 exit ${BUILDSTATUS#BUILDSTATUS}
928                 ;;
929             esac
930             exit 1
931         fi
932         exit 0
933     fi
934
935     if test "$DO_INIT" = true ; then
936         set -- init_buildsystem "${definesnstuff[@]}" "${repos[@]}" $CLEAN_BUILD $USEUSEDFORBUILD $RPMLIST "$MYSRCDIR/$SPECFILE" $ADDITIONAL_PACKS
937         echo "$* ..."
938         "$@" || cleanup_and_exit 1
939         mount -n -tproc none $BUILD_ROOT/proc || true
940         mount -n -tdevpts none $BUILD_ROOT/dev/pts
941     fi
942
943     if test -z "$BUILD_DIST" -a -e "$BUILD_ROOT/.guessed_dist" ; then
944         BUILD_DIST=`cat $BUILD_ROOT/.guessed_dist`
945     fi
946
947     if test "$SPECFILE" = "${SPECFILE%.dsc}" ; then
948         TOPDIR=`chroot $BUILD_ROOT rpm --eval '%_topdir'`
949     else
950         TOPDIR=/usr/src/packages
951         mkdir -p $BUILD_ROOT$TOPDIR
952     fi
953
954     rm -f $BUILD_ROOT/.build.packages
955     ln -s ${TOPDIR#/} $BUILD_ROOT/.build.packages
956
957     #
958     # fix rpmrc if we are compiling for i686
959     #
960     test -f $BUILD_ROOT/usr/lib/rpm/rpmrc_i586 && mv $BUILD_ROOT/usr/lib/rpm/rpmrc_i586 $BUILD_ROOT/usr/lib/rpm/rpmrc
961     if test -e $BUILD_ROOT/usr/lib/rpm/rpmrc -a "$BUILD_ARCH" != "${BUILD_ARCH#i686}" ; then
962         mv $BUILD_ROOT/usr/lib/rpm/rpmrc $BUILD_ROOT/usr/lib/rpm/rpmrc_i586
963         sed -e 's/^buildarchtranslate: athlon.*/buildarchtranslate: athlon: i686/' -e 's/^buildarchtranslate: i686.*/buildarchtranslate: i686: i686/' < $BUILD_ROOT/usr/lib/rpm/rpmrc_i586 > $BUILD_ROOT/usr/lib/rpm/rpmrc
964     fi
965
966     #
967     # check if we want to build with the abuild user
968     #
969     BUILD_USER=root
970     if test "$BUILD_USER" = abuild ; then
971         egrep '^#[       ]*needsrootforbuild[       ]*$' >/dev/null <$SPECFILE && BUILD_USER=root
972     else
973         egrep '^#[       ]*norootforbuild[       ]*$' >/dev/null <$SPECFILE && BUILD_USER=abuild
974     fi
975     test -n "$NOROOTFORBUILD" && BUILD_USER=abuild
976     if test $BUILD_USER = abuild ; then
977         if ! egrep '^abuild:' >/dev/null <$BUILD_ROOT/etc/passwd ; then
978             echo 'abuild::99:99:Autobuild:/home/abuild:/bin/bash' >>$BUILD_ROOT/etc/passwd
979             echo 'abuild::99:' >>$BUILD_ROOT/etc/group
980             mkdir -p $BUILD_ROOT/home/abuild
981             chown 99:99 $BUILD_ROOT/home/abuild
982         fi
983         if test -f $BUILD_ROOT/etc/shadow ; then
984             sed -e "s@^root::@root:*:@" < $BUILD_ROOT/etc/shadow > $BUILD_ROOT/etc/shadow.t && mv $BUILD_ROOT/etc/shadow.t $BUILD_ROOT/etc/shadow
985         fi
986     else
987         if egrep '^abuild:' >/dev/null <$BUILD_ROOT/etc/passwd ; then
988             egrep -v '^abuild:' <$BUILD_ROOT/etc/passwd >$BUILD_ROOT/etc/passwd.new
989             mv $BUILD_ROOT/etc/passwd.new $BUILD_ROOT/etc/passwd
990             egrep -v '^abuild:' <$BUILD_ROOT/etc/group >$BUILD_ROOT/etc/group.new
991             mv $BUILD_ROOT/etc/group.new $BUILD_ROOT/etc/group
992             rm -rf $BUILD_ROOT/home/abuild
993         fi
994     fi
995
996     mount -n -tproc none $BUILD_ROOT/proc 2> /dev/null
997     mount -n -tdevpts none $BUILD_ROOT/dev/pts 2> /dev/null
998  
999     setupicecream
1000
1001     setupccache
1002     #
1003     # now clean up RPM building directories
1004     #
1005     rm -rf $BUILD_ROOT$TOPDIR
1006     for i in BUILD RPMS/`arch` RPMS/i386 RPMS/noarch SOURCES SPECS SRPMS ; do
1007         mkdir -p $BUILD_ROOT$TOPDIR/$i
1008         test $BUILD_USER = abuild && chown 99:99 $BUILD_ROOT$TOPDIR/$i
1009     done
1010     test -e $BUILD_ROOT/exit && cleanup_and_exit
1011     mkdir -p $BUILD_ROOT$TOPDIR/SOURCES
1012     cp -p "$MYSRCDIR"/* $BUILD_ROOT$TOPDIR/SOURCES/
1013     test "$MYSRCDIR" = $BUILD_ROOT/.build-srcdir && rm -rf "$MYSRCDIR"
1014
1015     CHANGELOGARGS=
1016     test -n "$CHANGELOG" -a -f "$BUILD_ROOT/.build-changelog" && CHANGELOGARGS="--changelog $BUILD_ROOT/.build-changelog"
1017
1018     if test "$SPECFILE" = "${SPECFILE%.dsc}" ; then
1019         # do buildrequires/release substitution
1020         substitutedeps $RELEASE --dist "$BUILD_DIST" --archpath "$BUILD_ARCH" --configdir "$BUILD_DIR/configs" $CHANGELOGARGS "$BUILD_ROOT$TOPDIR/SOURCES/$SPECFILE" "$BUILD_ROOT/.spec.new" || cleanup_and_exit 1
1021         # extract macros from configuration
1022         getmacros --dist "$BUILD_DIST" --archpath "$BUILD_ARCH" --configdir "$BUILD_DIR/configs" > $BUILD_ROOT/root/.rpmmacros
1023         test $BUILD_USER = abuild && cp -p $BUILD_ROOT/root/.rpmmacros $BUILD_ROOT/home/abuild/.rpmmacros
1024         # extract optflags from configuration
1025         getoptflags --dist "$BUILD_DIST" --configdir "$BUILD_DIR/configs" --archpath "$BUILD_ARCH" > $BUILD_ROOT/root/.rpmrc
1026         test $BUILD_USER = abuild && cp -p $BUILD_ROOT/root/.rpmrc $BUILD_ROOT/home/abuild/.rpmrc
1027     fi
1028     if test -f $BUILD_ROOT/.spec.new ; then
1029         if ! cmp -s $BUILD_ROOT$TOPDIR/SOURCES/$SPECFILE $BUILD_ROOT/.spec.new ; then
1030             echo -----------------------------------------------------------------
1031             echo I have the following modifications for $SPECFILE:
1032             diff $BUILD_ROOT$TOPDIR/SOURCES/$SPECFILE $BUILD_ROOT/.spec.new
1033             mv $BUILD_ROOT/.spec.new $BUILD_ROOT$TOPDIR/SOURCES/$SPECFILE
1034         else
1035             rm -f $BUILD_ROOT/.spec.new
1036         fi
1037     fi
1038
1039     if test "$SPECFILE" != "${SPECFILE%.dsc}" ; then
1040         rm -rf $BUILD_ROOT$TOPDIR/BUILD
1041         test $BUILD_USER = abuild && chown 99:99 $BUILD_ROOT$TOPDIR
1042         DEB_TRANSFORM=
1043         for f in $BUILD_ROOT$TOPDIR/SOURCES/debian.* ; do
1044             test -f $f && DEB_TRANSFORM=true
1045         done
1046         if test -n "$DEB_TRANSFORM" ; then
1047             echo "running debian transformer..."
1048             mkdir -p $BUILD_ROOT$TOPDIR/SOURCES.DEB
1049             if ! debtransform $CHANGELOGARGS $BUILD_ROOT$TOPDIR/SOURCES $BUILD_ROOT$TOPDIR/SOURCES/$SPECFILE $BUILD_ROOT$TOPDIR/SOURCES.DEB ; then
1050                 echo "debian transforming failed."
1051                 cleanup_and_exit 1
1052             fi
1053             chroot $BUILD_ROOT su -c "dpkg-source -x $TOPDIR/SOURCES.DEB/*.dsc $TOPDIR/BUILD" - $BUILD_USER
1054         else
1055             chroot $BUILD_ROOT su -c "dpkg-source -x $TOPDIR/SOURCES/$SPECFILE $TOPDIR/BUILD" - $BUILD_USER
1056         fi
1057     fi
1058     if test $BUILD_USER = abuild ; then
1059         chown -R 99:99 $BUILD_ROOT$TOPDIR/*
1060     else
1061         chown -R root:root $BUILD_ROOT$TOPDIR/*
1062     fi
1063     cd $BUILD_ROOT$TOPDIR/SOURCES || cleanup_and_exit 1
1064
1065     echo -----------------------------------------------------------------
1066     if test "$BUILD_USER" = root ; then
1067         echo ----- building $SPECFILE
1068     else
1069         echo ----- building $SPECFILE "(user $BUILD_USER)"
1070     fi
1071     echo -----------------------------------------------------------------
1072     echo -----------------------------------------------------------------
1073     test -n "$RUNNING_IN_XEN" && ifconfig lo 127.0.0.1 up
1074     test -n "$RUNNING_IN_XEN" -a -n "$MYHOSTNAME" && hostname "$MYHOSTNAME"
1075
1076     BUILD_SUCCEDED=false
1077
1078     if test "$SPECFILE" = "${SPECFILE%.dsc}" ; then
1079         test -z "$BUILD_RPM_BUILD_STAGE" && BUILD_RPM_BUILD_STAGE=-ba
1080
1081         # XXX: move _srcdefattr to macro file?
1082         rpmbopts=("$BUILD_RPM_BUILD_STAGE" "--eval" "%define _srcdefattr (-,root,root)")
1083         if [ -n "$ABUILD_TARGET_ARCH" ]; then
1084                 rpmbopts[${#rpmbopts[@]}]="--target=$ABUILD_TARGET_ARCH"
1085         fi
1086         if [ -n "$BUILD_JOBS" ]; then
1087                 rpmbopts[${#rpmbopts[@]}]='--eval'
1088                 rpmbopts[${#rpmbopts[@]}]="%define jobs $BUILD_JOBS"
1089         fi
1090         rpmbuild=rpmbuild
1091
1092         test -x $BUILD_ROOT/usr/lib/rpm/rpmi || rpmbuild=rpm
1093         # su involves a shell which would require even more
1094         # complicated quoting to bypass than this
1095         toshellscript $rpmbuild \
1096                 "${definesnstuff[@]}" \
1097                 "${rpmbopts[@]}" \
1098                 "$TOPDIR/SOURCES/$SPECFILE" \
1099                 > $BUILD_ROOT/.build.command
1100         chmod 755 $BUILD_ROOT/.build.command
1101         chroot $BUILD_ROOT su -c /.build.command - $BUILD_USER < /dev/null && BUILD_SUCCEDED=true
1102     else
1103         chroot $BUILD_ROOT su -c "cd $TOPDIR/BUILD && dpkg-buildpackage -us -uc -rfakeroot" - $BUILD_USER < /dev/null && BUILD_SUCCEDED=true
1104         mkdir -p $BUILD_ROOT/$TOPDIR/DEBS
1105         for DEB in $BUILD_ROOT/$TOPDIR/*.deb ; do
1106             test -e "$DEB" && mv "$DEB" "$BUILD_ROOT/$TOPDIR/DEBS"
1107         done
1108     fi
1109
1110     test "$BUILD_SUCCEDED" = true || cleanup_and_exit 1
1111     test -d "$SRCDIR" && cd "$SRCDIR"
1112 done
1113
1114 if test -n "$DO_LINT" -a -x $BUILD_ROOT/opt/testing/bin/rpmlint -a -d "$BUILD_ROOT/$TOPDIR/RPMS" ; then
1115     LINT_RPM_FILE_LIST=($(find $BUILD_ROOT/$TOPDIR/RPMS -name "*-debuginfo-*" -prune \
1116                           -o -name "*-32bit-*" -prune -o -name "*-64bit-*" -prune \
1117                           -o -name "*-x86-*" -prune -o -name "*-ia32-*" -prune \
1118                           -o -type f -name '*.rpm' -print))
1119     SRPM_FILE_LIST=($(find $BUILD_ROOT/$TOPDIR/SRPMS -type f -name "*.rpm"))
1120     echo
1121     echo "RPMLINT report:"
1122     echo "==============="
1123     chroot $BUILD_ROOT /opt/testing/bin/rpmlint --info ${LINT_RPM_FILE_LIST[*]#$BUILD_ROOT} ${SRPM_FILE_LIST[*]#$BUILD_ROOT} || cleanup_and_exit 1
1124 fi
1125
1126 if test -n "$CREATE_BASELIBS" -a -d "$BUILD_ROOT/$TOPDIR/RPMS" ; then
1127     if test -f $BUILD_ROOT/usr/lib/build/mkbaselibs -o "$CREATE_BASELIBS" != internal ; then
1128         mount -n -tproc none $BUILD_ROOT/proc 2> /dev/null
1129         create_baselibs
1130         umount -n $BUILD_ROOT/proc 2> /dev/null
1131     fi
1132 fi
1133
1134 cleanup_and_exit 0