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.
6 # BUILD_ROOT here the packages will be built
8 # (c) 1997-2008 SuSE GmbH Nuernberg, Germany
10 test -z "$BUILD_DIR" && BUILD_DIR=/usr/lib/build
11 test -z "$BUILD_ROOT" && BUILD_ROOT=/var/tmp/build-root
13 export BUILD_ARCH BUILD_ROOT BUILD_RPMS BUILD_DIR
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 #vm_img_mkfs='mkreiserfs -q -f'
23 #vm_img_mkfs='mkfs.ext2 -m 0 -q -F'
24 vm_img_mkfs='mkfs.ext3 -m 0 -q -F'
25 vm_img_tunefs='tune2fs -c 0'
26 qemu_kernel=/boot/vmlinuz
27 qemu_initrd=/boot/initrd
28 qemu_bin=/usr/bin/qemu
29 uml_kernel=/boot/vmlinux-um
30 uml_initrd=/boot/initrd-um
32 kvm_kernel=/boot/vmlinuz
33 kvm_initrd=/boot/initrd
34 kvm_bin=/usr/bin/qemu-kvm
35 mkinitrd_virtio_cmd=(env rootfstype=ext3 mkinitrd -d /dev/null -m "virtio_pci virtio_blk" -k $kvm_kernel -i $kvm_initrd-virtio)
36 # whether we have virtio support
66 export PATH=$BUILD_DIR:/sbin:/usr/sbin:$PATH
69 export YAST_IS_RUNNING=instsys
79 Some comments for build
80 -----------------------
82 With build you can create rpm packages. They will be built in a chroot
83 system. This chroot system will be setup automatically. Normally you can
84 simply call build with a spec file as parameter - nothing else has to be
87 If you want to set the directory were the chroot system will be setup
88 (at the moment it uses $BUILD_ROOT),
89 simply set the the environment variable BUILD_ROOT.
93 export BUILD_ROOT=/var/tmp/mybuildroot
96 Normally build builds the complete package including src.rpm (rpmbuild -ba).
97 If you want let build only make the binary package, simply set
99 export BUILD_RPM_BUILD_STAGE=-bb
101 (or -bc, -bp, -bi, ... see "Maximum RPM" for more details [*]).
103 When the build command succeeds, the rpm files can be found under
104 $BUILD_ROOT/usr/src/packages/RPMS/
109 --help You already got it :)
111 --clean Delete old build root before initializing it
113 --no-init Skip initialization of build root and start with build
116 --no-checks Do not run post-build checks
118 --rpms path1:path2:...
119 Specify path where to find the RPMs for the build system
121 --arch arch1:arch2:...
122 Specify what architectures to select from the RPMs
125 Do not expand dependencies but search the specfile for
128 --verify Run verify when initializing the build root
131 Also install package 'pack'
134 Use 'rootdir' to setup chroot environment
136 --oldpackages oldpackagesdir
137 Define a directory with a former build
139 --baselibs Create -32bit/-64bit/-x86 rpms for other architectures
142 List rpms that would be used to create a fresh build root.
143 Does not create the build root or perform a build.
146 enable feature X for build
149 disable feature X for build
152 define macro X with value Y
155 use ccache to speed up rebuilds
158 use N parallel build jobs with icecream
161 enable creation of a debuginfo package
163 Remember to have fun!
165 [*] Maximum RPM: http://www.rpm.org/max-rpm/
169 echo "Usage: `basename $0` [--no-init|--clean|--rpms path|--verify|--help] [dir-to-build|spec-to-build]"
175 # return values: 0 -> success, new packages built
176 # 1 -> error, build failed
177 # 2 -> successfull build, but no changes to former built packages
179 cleanup_and_exit () {
181 test -z "$1" && set 0
182 if test -n "$RUNNING_IN_VM" ; then
184 if test -n "$VM_SWAP" -a -e "$VM_SWAP" ; then
185 swapoff "$VM_SWAP" 2>/dev/null
186 echo -n "BUILDSTATUS$1" >"$VM_SWAP"
188 exec >&0 2>&0 # so that the logging tee finishes
189 sleep 1 # wait till tee terminates
190 kill -9 -1 # goodbye cruel world
191 exec /bin/bash -c 'mount -n -o remount,ro / ; halt -f -p'
194 umount -n $BUILD_ROOT/proc 2>/dev/null || true
195 umount -n $BUILD_ROOT/dev/pts 2>/dev/null || true
196 test "$VM_IMAGE" = 1 && VM_IMAGE=
197 [ -n "$VM_IMAGE" ] && umount $BUILD_ROOT 2>/dev/null || true
218 # create a shell script from command line. Used for preserving arguments
230 if [ "$ccache" = 1 ]; then
231 if mkdir -p $BUILD_ROOT/var/lib/build/ccache/bin; then
232 for i in gcc g++ cc c++; do
233 # ln -sf /usr/bin/ccache $BUILD_ROOT/var/lib/build/ccache/bin/$i
234 rm -f $BUILD_ROOT/var/lib/build/ccache/bin/$i
235 test -e $BUILD_ROOT/usr/bin/$i || continue
236 echo '#! /bin/sh' > $BUILD_ROOT/var/lib/build/ccache/bin/$i
237 echo "test -e /usr/bin/$i || exit 1" > $BUILD_ROOT/var/lib/build/ccache/bin/$i
238 echo 'export PATH=/opt/icecream/bin:/usr/bin:$PATH' >> $BUILD_ROOT/var/lib/build/ccache/bin/$i
239 echo "ccache $i \"\$@\"" >> $BUILD_ROOT/var/lib/build/ccache/bin/$i
240 chmod 755 $BUILD_ROOT/var/lib/build/ccache/bin/$i
241 echo "Installed ccache wrapper as $BUILD_ROOT/var/lib/build/ccache/bin/$i"
244 mkdir -p "$BUILD_ROOT"/.ccache
245 chroot "$BUILD_ROOT" chown -R "$BUILD_USER" "/.ccache"
246 echo "export CCACHE_DIR=/.ccache" > "$BUILD_ROOT"/etc/profile.d/build_ccache.sh
247 echo 'export PATH=/var/lib/build/ccache/bin:$PATH' >> "$BUILD_ROOT"/etc/profile.d/build_ccache.sh
249 rm -f "$BUILD_ROOT$builduserhome"/bin/{gcc,g++,cc,c++}
250 rm -f "$BUILD_ROOT"/var/lib/build/ccache/bin/{gcc,g++,cc,c++}
256 if [ "$icecream" -eq 0 ]; then
257 rm -rf "$BUILD_ROOT"/var/run/icecream
258 rm -f "$BUILD_ROOT"/etc/profile.d/build_icecream.sh
262 if ! chroot "$BUILD_ROOT" rpm -q icecream >/dev/null 2>/dev/null; then
263 echo "*** icecream package not installed ***"
268 echo "using icecream with $icecream jobs"
270 if [ "$ccache" -ne 1 ]; then
271 echo 'export PATH=/opt/icecream/bin:$PATH' > "$BUILD_ROOT"/etc/profile.d/build_icecream.sh
273 echo 'export CCACHE_PATH=/opt/icecream/bin' > "$BUILD_ROOT"/etc/profile.d/build_icecream.sh
276 local icecc_vers=(`shopt -s nullglob; echo $BUILD_ROOT/var/run/icecream/*.tar.{bz2,gz}`)
277 icecc_vers=${icecc_vers//$BUILD_ROOT/}
279 # XXX use changelog like autobuild does instead?
280 # only run create-env if compiler or glibc changed
281 if [ -z "$icecc_vers" \
282 -o ! -e "$BUILD_ROOT/$icecc_vers" \
283 -o "$BUILD_ROOT/usr/bin/gcc" -nt "$BUILD_ROOT/$icecc_vers" \
284 -o "$BUILD_ROOT/usr/bin/g++" -nt "$BUILD_ROOT/$icecc_vers" \
285 -o "$BUILD_ROOT/usr/bin/as" -nt "$BUILD_ROOT/$icecc_vers" \
286 -o "$BUILD_ROOT/lib/libc.so.6" -nt "$BUILD_ROOT/$icecc_vers" ]
288 rm -rf $BUILD_ROOT/var/run/icecream
289 mkdir -p $BUILD_ROOT/var/run/icecream
290 if [ -e "$BUILD_ROOT"/usr/bin/create-env ]; then
291 createenv=/usr/bin/create-env
292 elif [ -e "$BUILD_ROOT"/usr/lib/icecc/icecc-create-env ]; then
293 createenv="/usr/lib/icecc/icecc-create-env /usr/bin/gcc /usr/bin/g++" # XXX
294 elif [ -e "$BUILD_ROOT"/usr/lib64/icecc/icecc-create-env ]; then
295 createenv="/usr/lib64/icecc/icecc-create-env /usr/bin/gcc /usr/bin/g++" # XXX
297 echo "create-env not found"
301 chroot $BUILD_ROOT bash -c "cd /var/run/icecream; $createenv" || cleanup_and_exit 1
302 icecc_vers=(`shopt -s nullglob; echo $BUILD_ROOT/var/run/icecream/*.tar.{bz2,gz}`)
303 icecc_vers=${icecc_vers//$BUILD_ROOT/}
305 echo "reusing existing icecream environment $icecc_vers"
307 if [ -n "$icecc_vers" ]; then
308 echo "export ICECC_VERSION=$icecc_vers" >> "$BUILD_ROOT"/etc/profile.d/build_icecream.sh
314 if [ -n "$VM_IMAGE" -o -n "$RUNNING_IN_VM" ]; then
322 eval "mem=\$(($2/3*4))"
324 echo "Memory limit set to ${mem}KB"
328 done < <(cat /proc/meminfo) # cat for proc stuff
331 function create_baselibs {
332 echo "... creating baselibs"
334 for RPM in $BUILD_ROOT$TOPDIR/RPMS/*/*.rpm ; do
335 BRPMS="$BRPMS ${RPM#$BUILD_ROOT}"
338 if test -e $BUILD_ROOT$TOPDIR/SOURCES/baselibs.conf ; then
339 BASELIBS_CFG="-c $TOPDIR/SOURCES/baselibs.conf"
341 if test -f $BUILD_ROOT/usr/lib/build/mkbaselibs ; then
342 if test -z "$BASELIBS_CFG" -a -e $BUILD_ROOT/usr/lib/build/baselibs.conf ; then
343 BASELIBS_CFG="-c /usr/lib/build/baselibs.conf"
345 chroot $BUILD_ROOT /usr/lib/build/mkbaselibs -c /usr/lib/build/baselibs_global.conf $BASELIBS_CFG $BRPMS || cleanup_and_exit 1
347 # use external version
348 rm -rf $BUILD_ROOT/.mkbaselibs
349 mkdir -p $BUILD_ROOT/.mkbaselibs
350 cp -f $BUILD_DIR/mkbaselibs $BUILD_ROOT/.mkbaselibs
351 cp -f $BUILD_DIR/baselibs_global.conf $BUILD_ROOT/.mkbaselibs
352 if test -z "$BASELIBS_CFG" -a -e $BUILD_DIR/baselibs.conf ; then
353 cp -f $BUILD_DIR/baselibs.conf $BUILD_ROOT/.mkbaselibs/baselibs.conf
354 BASELIBS_CFG="-c /.mkbaselibs/baselibs.conf"
356 chroot $BUILD_ROOT /.mkbaselibs/mkbaselibs -c /.mkbaselibs/baselibs_global.conf $BASELIBS_CFG $BRPMS || cleanup_and_exit 1
357 rm -rf $BUILD_ROOT/.mkbaselibs
361 detect_vm_2nd_stage()
363 if ! test "$0" = "/.build/build" ; then
366 echo "2nd stage started in virtual machine"
369 . $BUILD_DIR/build.data
370 echo "machine type: `uname -m`"
371 if test "$PERSONALITY" != 0 -a -z "$PERSONALITY_SET" ; then
372 export PERSONALITY_SET=true
373 echo "switching personality to $PERSONALITY..."
374 # this is 32bit perl/glibc, thus the 32bit syscall number
375 exec perl -e 'syscall(136, '$PERSONALITY') == -1 && warn("personality: $!\n");exec "/.build/build" || die("/.build/build: $!\n")'
377 PATH=$BUILD_DIR:$PATH
379 mount -orw -n -tproc none /proc
380 mount -n -o remount,rw /
381 if [ -e /dev/kqemu ]; then
382 # allow abuild user to run qemu
383 chmod 0666 /dev/kqemu
385 if test -n "$VM_SWAP" ; then
386 for i in 1 2 3 4 5 6 7 8 9 10 ; do
387 test -e "$VM_SWAP" && break
388 test $i = 1 && echo "waiting for $VM_SWAP to appear"
393 # recreate the swap device manually if it didn't exist for some
394 # reason, hardcoded to hda2 atm
395 if ! test -b "$VM_SWAP" ; then
398 mknod "$VM_SWAP" b 3 2
401 swapon -v "$VM_SWAP" || exit 1
410 if [ -z "$BUILD_ARCH" ]; then
411 BUILD_ARCH=`uname -m`
412 test i686 = "$BUILD_ARCH" && BUILD_ARCH=i586 # XXX: why?
416 i686) BUILD_ARCH="i686:i586:i486:i386" ;;
417 i586) BUILD_ARCH="i586:i486:i386" ;;
418 i486) BUILD_ARCH="i486:i386" ;;
419 x86_64) BUILD_ARCH="x86_64:i686:i586:i486:i386" ;;
421 if test "$BUILD_ARCH" != "${BUILD_ARCH#i686}" ; then
422 cpuflags=`grep ^flags /proc/cpuinfo`
423 cpuflags="$cpuflags "
424 test "$cpuflags" = "${cpuflags/ cx8 /}" -o "$cpuflags" = "${cpuflags/ cmov /}" && {
425 echo "Your cpu doesn't support i686 rpms. Exit."
434 if [ -z "$SPECFILES" ]; then
437 set -- "${SPECFILES[@]}"
441 if [ "$spec" = "${spec#/}" ]; then
445 if [ -d "$spec" ]; then
446 specs=("$spec"/*.spec)
447 if [ -n "$specs" ]; then
448 SPECFILES=("${SPECFILES[@]}" "${specs[@]}")
450 specs=("$spec"/*.spec)
451 if [ -n "$specs" ]; then
452 SPECFILES=("${SPECFILES[@]}" "${specs[@]}")
456 SPECFILES[${#SPECFILES[@]}]="$spec";
460 if test -z "$SPECFILES"; then
461 echo no spec files or src rpms found in $@. exit...
466 become_root_or_fail()
468 if [ ! -w /root ]; then
469 echo "You have to be root to use $0" >&2
477 if [ -d "$BUILD_ROOT" ]; then
478 # check if it is owned by root
479 if [ -z "$RUNNING_IN_VM" -a \! -O "$BUILD_ROOT" -a "`stat -c %u $BUILD_ROOT`" -ne 0 ]; then
480 echo "BUILD_ROOT=$BUILD_ROOT must be owned by $USER. Exit..."
484 test "$BUILD_ROOT" != "${BUILD_ROOT%/*}" && mkdir -p "${BUILD_ROOT%/*}"
485 if ! mkdir $BUILD_ROOT; then
486 echo "can not create BUILD_ROOT=$BUILD_ROOT. Exit..."
491 rm -rf "$BUILD_ROOT"/.build.packages
496 perl -e 'syscall('$PERSONALITY_SYSCALL', 0); exec(@ARGV) || die("$ARGV[0]: $!\n")' "$@"
503 case `perl -V:archname` in
504 *x86_64*) PERSONALITY_SYSCALL=135 ;;
505 *i?86*) PERSONALITY_SYSCALL=136 ;;
510 if detect_vm_2nd_stage ; then
511 set "/.build-srcdir/$SPECFILE"
515 while test -n "$1"; do
523 set -- "----noarg=$PARAM" "$@"
537 CLEAN_BUILD='--clean'
544 if [ -z "$BUILD_RPMS" ] ; then
555 export VERIFY_BUILD_SYSTEM=true
558 ABUILD_TARGET_ARCH="$ARG"
566 BUILD_EXTRA_PACKS="$BUILD_EXTRA_PACKS $ARG"
576 CREATE_BASELIBS=internal
591 *-xen|*-kvm|--uml|--qemu)
593 if [ -n "$ARG" -a "$ARG" = "${ARG#-}" ]; then
604 *-xenmemory|*-memory)
609 RPMLIST="--rpmlist $ARG"
629 BUILD_RPM_BUILD_STAGE="$ARG"
633 USEUSEDFORBUILD="--useusedforbuild"
638 --define|--with|--without)
639 definesnstuff[${#definesnstuff[@]}]="$PARAM";
640 definesnstuff[${#definesnstuff[@]}]="$ARG";
644 if [ -z "$ARG" ] ; then
648 repos[${#repos[@]}]="$PARAM";
649 repos[${#repos[@]}]="$ARG";
653 if [ -z "$ARG" ] ; then
654 echo "--icecream needs an argument" >&2
659 if [ "$icecream" -gt 0 ]; then
679 echo "$ARG does not take an argument"
686 echo Unknown Option "$PARAM". Exit.
690 SPECFILES[${#SPECFILES[@]}]="$PARAM";
695 # XXX: doesn't kill vm if in prepare stage (because there is none)
696 if test -n "$KILL" ; then
697 test -z "$SRCDIR" || usage
698 if test -z "$VM_IMAGE" ; then
699 if ! $BUILD_DIR/killchroot -s 9 $BUILD_ROOT ; then
700 echo "could not kill build in $BUILD_ROOT"
703 elif test "$VM_TYPE" = 'xen'; then
704 XENID="${VM_IMAGE%/root}"
706 if xm list "build:$XENID" >/dev/null 2>&1 ; then
707 if ! xm destroy "build:$XENID" ; then
708 echo "could not kill xen build $XENID"
712 elif test -n "$VM_TYPE"; then
713 if ! fuser -k -TERM "$VM_IMAGE"; then
714 echo "could not kill build in $VM_IMAGE"
718 echo "don't know how to kill this build job"
724 if [ "$VM_TYPE" = 'kvm' ]; then
725 if [ ! -r /dev/kvm -o ! -x "$qemu_bin"-kvm ]; then
729 qemu_kernel="$kvm_kernel"
730 qemu_initrd="$kvm_initrd"
731 if [ ! -e $qemu_initrd-virtio -o $qemu_kernel -nt $qemu_initrd-virtio ]; then
732 if [ ! -w /root ]; then
733 echo "No initrd that provides virtio support found. virtio accelleration disabled."
734 echo "Run the following command as root to enable virtio:"
735 shellquote "${mkinitrd_virtio_cmd[@]}"
737 elif /sbin/modinfo virtio_pci >/dev/null 2>&1; then
738 echo "creating $qemu_initrd-virtio"
739 "${mkinitrd_virtio_cmd[@]}" || cleanup_and_exit 1
746 if [ "$kvm_virtio" = 1 ]; then
747 qemu_initrd="$qemu_initrd-virtio"
749 qemu_rootdev=/dev/vda
752 qemu_rootdev=/dev/sda
756 if [ "$VM_TYPE" = 'qemu' ]; then
758 qemu_rootdev=/dev/sda
761 if [ -z "$RPMLIST" ]; then
762 if [ -z "$repos" -a -z "$BUILD_RPMS" ]; then
763 BUILD_RPMS="/media/dvd/suse"
771 if [ -n "$CLEAN_BUILD" ]; then
777 if test -n "$LIST_STATE" ; then
778 BUILD_ROOT=`mktemp -d /var/tmp/build-list-state-XXXXXX`
779 test -d "$BUILD_ROOT" || cleanup_and_exit 1
780 SPECFILE=$SPECFILES # only one specified anyways
781 if test "$SPECFILE" != "${SPECFILE%.src.rpm}" ; then
782 rm -rf $BUILD_ROOT/usr/src/packages
783 mkdir -p $BUILD_ROOT/usr/src/packages/SOURCES $BUILD_ROOT/usr/src/packages/SPECS
784 rpm -i --nodigest --nosignature --root $BUILD_ROOT $SPECFILE || {
785 echo "could not install $SPECFILE." 2>&1
789 for SPECFILE in $BUILD_ROOT/usr/src/packages/SPECS/*.spec ; do : ; done
791 init_buildsystem --list-state "${definesnstuff[@]}" "${repos[@]}" $USEUSEDFORBUILD $SPECFILE $BUILD_EXTRA_PACKS
794 cleanup_and_exit $ERR
797 if test -z "$RUNNING_IN_VM" ; then
798 if test -n "$VM_IMAGE" ; then
799 if test "$VM_IMAGE" = 1 ; then
800 VM_IMAGE="$BUILD_ROOT.img"
802 if test ! -e "$VM_IMAGE" ; then
803 echo "you need to create a file system on $VM_IMAGE first"
807 if test -n "$VM_IMAGE" ; then
808 if test -n "$CLEAN_BUILD" ; then
809 echo "Creating filesystem on $VM_IMAGE"
810 $vm_img_mkfs $VM_IMAGE || become_root_or_fail
811 if test -n "$vm_img_tunefs" ; then
812 $vm_img_tunefs $VM_IMAGE || become_root_or_fail
816 if [ -w /root ]; then
817 mount -o loop $VM_IMAGE $BUILD_ROOT || cleanup_and_exit 1
819 mount $BUILD_ROOT || become_root_or_fail
822 test -w /root || become_root_or_fail
824 if test -n "$VM_SWAP" ; then
825 dd if=/dev/zero of="$VM_SWAP" bs=12 count=1 conv=notrunc 2>/dev/null
832 rm -f $BUILD_ROOT/exit
834 if [ -w /root ]; then
835 mkdir -p $BUILD_ROOT/proc
836 mkdir -p $BUILD_ROOT/dev/pts
837 mount -n -tproc none $BUILD_ROOT/proc || true
838 mount -n -tdevpts none $BUILD_ROOT/dev/pts
841 if test -z "$VM_IMAGE" -a -z "$LOGFILE"; then
842 LOGFILE="$BUILD_ROOT/.build.log"
845 if test -n "$LOGFILE" ; then
846 echo logging output to $LOGFILE...
849 if test -n "$VM_IMAGE" ; then
850 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
852 exec 1> >(exec -a 'build logging tee' tee -a $LOGFILE) 2>&1
861 test -z "$HOST" && HOST=`hostname`
863 if [ -z "$RUNNING_IN_VM" ]; then
864 echo Using BUILD_ROOT=$BUILD_ROOT
865 test -n "$BUILD_RPMS" && echo Using BUILD_RPMS=$BUILD_RPMS
866 echo Using BUILD_ARCH=$BUILD_ARCH
867 test -n "$VM_TYPE" && echo "Doing $VM_TYPE build in $VM_IMAGE"
871 test "$BUILD_ARCH" = all && BUILD_ARCH=
872 BUILD_USER_ABUILD_USED=
874 for SPECFILE in "${SPECFILES[@]}" ; do
876 SRCDIR="${SPECFILE%/*}"
877 SPECFILE="${SPECFILE##*/}"
881 *.spec|*.src.rpm) BUILDTYPE=spec ;;
882 *.dsc) BUILDTYPE=dsc ;;
883 *.kiwi) BUILDTYPE=kiwi ;;
885 if test -z "$BUILDTYPE" ; then
886 echo "don't know how to build $SPECFILE"
892 if [ -z "$RUNNING_IN_VM" ]; then
894 echo "$HOST started \"build $SPECFILE\" at `date`."
896 test -n "$REASON" && echo "$REASON"
901 # first setup building directory...
903 test -s "$SPECFILE" || {
904 echo "$SPECFILE" is empty. This should not happen...
908 if test "$SPECFILE" != "${SPECFILE%.src.rpm}" ; then
909 echo processing src rpm `pwd`/$SPECFILE...
910 TOPDIR=`rpm --eval '%_topdir'`
911 rm -rf $BUILD_ROOT$TOPDIR
912 mkdir -p $BUILD_ROOT$TOPDIR/SOURCES $BUILD_ROOT$TOPDIR/SPECS
913 rpm -i --nodigest --nosignature --root $BUILD_ROOT $SPECFILE || {
914 echo "could not install $SPECFILE."
917 rm -rf $BUILD_ROOT/.build-srcdir
918 mkdir -p $BUILD_ROOT/.build-srcdir
919 mv $BUILD_ROOT$TOPDIR/SOURCES/* $BUILD_ROOT/.build-srcdir
920 mv $BUILD_ROOT$TOPDIR/SPECS/* $BUILD_ROOT/.build-srcdir
921 MYSRCDIR=$BUILD_ROOT/.build-srcdir
922 cd $MYSRCDIR || cleanup_and_exit 1
923 for SPECFILE in *.spec ; do : ; done
925 echo processing specfile `pwd`/$SPECFILE...
930 test -n "$BUILD_EXTRA_PACKS" && ADDITIONAL_PACKS="$ADDITIONAL_PACKS $BUILD_EXTRA_PACKS"
931 test -n "$CREATE_BASELIBS" && ADDITIONAL_PACKS="$ADDITIONAL_PACKS build"
932 test "$ccache" = '1' && ADDITIONAL_PACKS="$ADDITIONAL_PACKS ccache"
933 test "$icecream" -gt 1 && ADDITIONAL_PACKS="$ADDITIONAL_PACKS icecream gcc-c++"
934 test -n "$DO_LINT" && ADDITIONAL_PACKS="$ADDITIONAL_PACKS rpmlint-Factory"
936 if test -n "$CHANGELOG" -a -z "$RUNNING_IN_VM" ; then
937 rm -f $BUILD_ROOT/.build-changelog
939 *.dsc) CFFORMAT=debian ;;
942 echo "running changelog2spec --target $CFFORMAT --file $MYSRCDIR/$SPECFILE"
943 if ! $BUILD_DIR/changelog2spec --target $CFFORMAT --file "$MYSRCDIR/$SPECFILE" > $BUILD_ROOT/.build-changelog ; then
944 rm -f $BUILD_ROOT/.build-changelog
948 if test -n "$VM_TYPE"; then
949 rm -rf $BUILD_ROOT/.build
950 mkdir -p $BUILD_ROOT/.build
951 if test "$DO_INIT" = true ; then
952 # do fist stage of init_buildsystem
953 rm -f $BUILD_ROOT/.build.success
954 set -- init_buildsystem --prepare "${definesnstuff[@]}" "${repos[@]}" $CLEAN_BUILD $USEUSEDFORBUILD $RPMLIST "$MYSRCDIR/$SPECFILE" $ADDITIONAL_PACKS
956 "$@" || cleanup_and_exit 1
957 if [ ! -w /root ]; then
958 # remove setuid bit if files belong to user to make e.g. mount work
959 find $BUILD_ROOT/{bin,sbin,usr/bin,usr/sbin} -type f -uid $UID -perm +4000 -print0 | xargs -0 --no-run-if-empty chmod -s
961 if [ -d "$OLD_PACKAGES" ]; then
962 rm -rf $BUILD_ROOT/.build.oldpackages
963 cp -a $OLD_PACKAGES $BUILD_ROOT/.build.oldpackages
966 # start up xen, rerun ourself
967 cp -a $BUILD_DIR/. $BUILD_ROOT/.build
968 if ! test "$MYSRCDIR" = $BUILD_ROOT/.build-srcdir ; then
969 rm -rf $BUILD_ROOT/.build-srcdir
970 mkdir $BUILD_ROOT/.build-srcdir
971 if test "$BUILDTYPE" = kiwi ; then
972 cp -pRL "$MYSRCDIR"/* $BUILD_ROOT/.build-srcdir
974 cp -p "$MYSRCDIR"/* $BUILD_ROOT/.build-srcdir
976 MYSRCDIR=$BUILD_ROOT/.build-srcdir
979 echo "SPECFILE='${SPECFILE//"'"/$Q}'" > $BUILD_ROOT/.build/build.data
980 echo "BUILD_JOBS='${BUILD_JOBS//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
981 echo "BUILD_ARCH='${BUILD_ARCH//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
982 echo "BUILD_RPMS='${BUILD_RPMS//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
985 cp $BUILD_DIST $BUILD_ROOT/.build/build.dist
986 BUILD_DIST=/.build/build.dist
989 echo "BUILD_DIST='${BUILD_DIST//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
990 echo "RELEASE='${RELEASE//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
991 echo "BUILD_DEBUG='${BUILD_DEBUG//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
992 echo "DO_LINT='${DO_LINT//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
993 echo "DO_CHECKS='${DO_CHECKS//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
994 echo "NOROOTFORBUILD='${NOROOTFORBUILD//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
995 echo "CREATE_BASELIBS='$CREATE_BASELIBS'" >> $BUILD_ROOT/.build/build.data
996 echo "REASON='${REASON//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
997 echo "CHANGELOG='${CHANGELOG//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
998 echo "INCARNATION='${INCARNATION//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
999 echo "DISTURL='${DISTURL//"'"/$Q}'" >> $BUILD_ROOT/.build/build.data
1000 # FIXME: this depends on the kernel and vm.
1001 # could be hda2, sda2 for xen or hdb/sdb for qemu
1002 test -n "$VM_SWAP" && echo "VM_SWAP='${VM_SWAPDEV:-/dev/hda2}'" >> $BUILD_ROOT/.build/build.data
1004 test -n "$PERSONALITY_SYSCALL" && PERSONALITY=`perl -e 'print syscall('$PERSONALITY_SYSCALL', 0)."\n"'`
1005 echo "OLD_PACKAGES='$OLD_PACKAGES'" >> $BUILD_ROOT/.build/build.data
1006 echo "PERSONALITY='$PERSONALITY'" >> $BUILD_ROOT/.build/build.data
1007 echo "MYHOSTNAME='`hostname`'" >> $BUILD_ROOT/.build/build.data
1008 echo -n "definesnstuff=(" >> $BUILD_ROOT/.build/build.data
1009 shellquote "${definesnstuff[@]}" >> $BUILD_ROOT/.build/build.data
1010 echo ")" >> $BUILD_ROOT/.build/build.data
1011 echo -n "repos=(" >> $BUILD_ROOT/.build/build.data
1012 shellquote "${repos[@]}" >> $BUILD_ROOT/.build/build.data
1013 echo ")" >> $BUILD_ROOT/.build/build.data
1014 umount -n $BUILD_ROOT/proc 2> /dev/null || true
1015 umount -n $BUILD_ROOT/dev/pts 2> /dev/null || true
1016 umount -n $BUILD_ROOT/mnt 2> /dev/null || true
1018 # needs to work otherwise we have a corrupted file system
1019 umount $BUILD_ROOT || cleanup_and_exit 1
1021 if [ "$VM_TYPE" = 'xen' ]; then
1022 XMROOT=file:$VM_IMAGE
1023 XMROOT=${XMROOT/#file:\/dev/phy:/dev}
1024 XMROOT="disk=$XMROOT,hda1,w"
1026 if test -n "$VM_SWAP" ; then
1027 XMSWAP=file:$VM_SWAP
1028 XMSWAP=${XMSWAP/#file:\/dev/phy:/dev}
1029 XMSWAP="disk=$XMSWAP,hda2,w"
1031 XENID="${VM_IMAGE%/root}"
1032 XENID="${XENID##*/}"
1033 CROSS_INIT_SCRIPT="/.build/build"
1034 # to run the qemu initialization in the XEN chroot, we need to register it with a statically build shell
1035 if [ x"$BUILD_ARCH" == xarmv4l -o x"$BUILD_ARCH" == xarmv5el -o x"$BUILD_ARCH" == xarmv7el -o x"$BUILD_ARCH" == xsh4 -o x"$BUILD_ARCH" == xppc ]; then
1036 if [ -n "$(uname -m | grep '[x3-6]86')" ]; then
1037 if [ -e /bin/bash-static -a -e /bin/mount-static ]; then
1038 CROSS_INIT_SCRIPT="/.build/initscript_qemu_vm"
1043 echo "booting XEN kernel ..."
1044 set -- xm create -c $BUILD_DIR/xen.conf name="build:$XENID" ${MEMSIZE:+memory=$MEMSIZE} $XMROOT $XMSWAP extra="quiet init="$CROSS_INIT_SCRIPT" panic=1 console=ttyS0"
1045 if test "$PERSONALITY" != 0 ; then
1046 # have to switch back to PER_LINUX to make xm work
1050 "$@" || true # somehow this is always false
1051 elif [ "$VM_TYPE" = 'uml' ]; then
1052 echo "booting UML kernel ..."
1053 set -- $uml_kernel initrd=$uml_initrd root=/ubda init=/.build/build panic=1 quiet ubd0=$VM_IMAGE ${MEMSIZE:+mem=$MEMSIZE}
1056 elif [ "$VM_TYPE" = 'qemu' -o "$VM_TYPE" = 'kvm' ]; then
1057 echo "booting $VM_TYPE ..."
1058 if [ "$kvm_virtio" = 1 ]; then
1059 qemu_disks=(-drive file="$VM_IMAGE",if=virtio -hda "$VM_IMAGE")
1060 if [ -n "$VM_SWAP" ]; then
1061 qemu_disks[${#qemu_disks[@]}]="-drive"
1062 qemu_disks[${#qemu_disks[@]}]="file=$VM_SWAP,if=virtio"
1065 qemu_disks=(-hda "$VM_IMAGE")
1066 if [ -n "$VM_SWAP" ]; then
1067 qemu_disks[${#qemu_disks[@]}]="-hdb"
1068 qemu_disks[${#qemu_disks[@]}]="$VM_SWAP"
1071 set -- $qemu_bin -no-reboot -nographic -net none -serial stdio \
1072 -kernel $qemu_kernel \
1073 -initrd $qemu_initrd \
1074 -append "root=$qemu_rootdev panic=1 quiet noapic rw console=ttyS0 init=/.build/build" \
1075 ${MEMSIZE:+-m $MEMSIZE} \
1078 if test "$PERSONALITY" != 0 ; then
1079 # have to switch back to PER_LINUX to make qemu work
1085 if test -n "$VM_SWAP" ; then
1086 BUILDSTATUS=`dd if="$VM_SWAP" bs=12 count=1 2>/dev/null`
1087 case $BUILDSTATUS in
1089 mkdir -p $BUILD_ROOT/.build.packages
1090 cd $BUILD_ROOT/.build.packages || cleanup_and_exit 1
1091 echo "build: extracting built packages..."
1092 extractbuild --disk "$VM_IMAGE" --input "$VM_SWAP" --skip 512 -v
1093 # create same layout as with plain chroot
1094 if test "$BUILDTYPE" = spec ; then
1096 for i in *src.rpm; do mv "$i" SRPMS/; done
1101 mv "$i" RPMS/$arch/;
1103 elif test "$BUILDTYPE" = dsc ; then
1105 find . -type f | while read i; do mv "$i" DEBS/; done
1108 find . -type f | while read i; do mv "$i" KIWI/; done
1110 cleanup_and_exit ${BUILDSTATUS#BUILDSTATUS}
1113 cleanup_and_exit ${BUILDSTATUS#BUILDSTATUS}
1121 if test "$DO_INIT" = true ; then
1123 # create legacy .buildenv file
1125 test -z "$INCARNATION" && INCARNATION=0
1126 echo "BUILD_INCARNATION=$INCARNATION" > $BUILD_ROOT/.buildenv
1127 CREATE_BUILD_BINARIES=
1128 egrep '^#[ ]*needsbinariesforbuild[ ]*$' >/dev/null <$MYSRCDIR/$SPECFILE && CREATE_BUILD_BINARIES=--create-build-binaries
1129 set -- init_buildsystem "${definesnstuff[@]}" "${repos[@]}" $CLEAN_BUILD $USEUSEDFORBUILD $CREATE_BUILD_BINARIES $RPMLIST "$MYSRCDIR/$SPECFILE" $ADDITIONAL_PACKS
1131 "$@" || cleanup_and_exit 1
1132 mount -n -tproc none $BUILD_ROOT/proc || true
1133 mount -n -tdevpts none $BUILD_ROOT/dev/pts
1134 if [ -d "$OLD_PACKAGES" ]; then
1135 [ -d "$BUILD_ROOT/.build.oldpackages" ] || cp -r $OLD_PACKAGES $BUILD_ROOT/.build.oldpackages
1139 if test -z "$BUILD_DIST" -a -e "$BUILD_ROOT/.guessed_dist" ; then
1140 BUILD_DIST=`cat $BUILD_ROOT/.guessed_dist`
1141 echo "assuming dist $BUILD_DIST"
1145 # fix rpmrc if we are compiling for i686
1147 test -f $BUILD_ROOT/usr/lib/rpm/rpmrc_i586 && mv $BUILD_ROOT/usr/lib/rpm/rpmrc_i586 $BUILD_ROOT/usr/lib/rpm/rpmrc
1148 if test -e $BUILD_ROOT/usr/lib/rpm/rpmrc -a "$BUILD_ARCH" != "${BUILD_ARCH#i686}" ; then
1149 mv $BUILD_ROOT/usr/lib/rpm/rpmrc $BUILD_ROOT/usr/lib/rpm/rpmrc_i586
1150 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
1154 # check if we want to build with the abuild user
1157 if test -x $BUILD_ROOT/bin/rpm ; then
1158 SUSE_VERSION=`chroot $BUILD_ROOT /bin/rpm --eval '%{?suse_version}' 2>/dev/null`
1159 if test -n "$SUSE_VERSION" && test "$SUSE_VERSION" -le 1020 ; then
1163 if test "$BUILD_USER" = abuild ; then
1164 egrep '^#[ ]*needsrootforbuild[ ]*$' >/dev/null <$SPECFILE && BUILD_USER=root
1166 egrep '^#[ ]*norootforbuild[ ]*$' >/dev/null <$SPECFILE && BUILD_USER=abuild
1168 test -n "$NOROOTFORBUILD" && BUILD_USER=abuild
1169 test "$BUILDTYPE" = kiwi && BUILD_USER=root
1171 if test $BUILD_USER = abuild ; then
1172 if ! egrep '^abuild:' >/dev/null <$BUILD_ROOT/etc/passwd ; then
1173 echo 'abuild::399:399:Autobuild:/home/abuild:/bin/bash' >>$BUILD_ROOT/etc/passwd
1174 echo 'abuild:*:::::::' >>$BUILD_ROOT/etc/shadow # This is needed on Mandriva 2009
1175 echo 'abuild:*:::::::' >>$BUILD_ROOT/etc/gshadow # This is needed on Ubuntu 8.10
1176 echo 'abuild::399:' >>$BUILD_ROOT/etc/group
1177 mkdir -p $BUILD_ROOT/home/abuild
1178 chown 399:399 $BUILD_ROOT/home/abuild
1180 if test -f $BUILD_ROOT/etc/shadow ; then
1181 sed -e "s@^root::@root:*:@" < $BUILD_ROOT/etc/shadow > $BUILD_ROOT/etc/shadow.t && mv $BUILD_ROOT/etc/shadow.t $BUILD_ROOT/etc/shadow
1183 if test -f $BUILD_ROOT/etc/gshadow ; then
1184 sed -e "s@^root::@root:*:@" < $BUILD_ROOT/etc/gshadow > $BUILD_ROOT/etc/gshadow.t && mv $BUILD_ROOT/etc/gshadow.t $BUILD_ROOT/etc/gshadow
1186 BUILD_USER_ABUILD_USED=true
1188 if egrep '^abuild:' >/dev/null <$BUILD_ROOT/etc/passwd ; then
1189 rm -rf $BUILD_ROOT/home/abuild
1190 egrep -v '^abuild:' <$BUILD_ROOT/etc/passwd >$BUILD_ROOT/etc/passwd.new
1191 mv $BUILD_ROOT/etc/passwd.new $BUILD_ROOT/etc/passwd
1192 egrep -v '^abuild:' <$BUILD_ROOT/etc/group >$BUILD_ROOT/etc/group.new
1193 mv $BUILD_ROOT/etc/group.new $BUILD_ROOT/etc/group
1194 if test -f $BUILD_ROOT/etc/shadow ; then
1195 egrep -v '^abuild:' <$BUILD_ROOT/etc/shadow >$BUILD_ROOT/etc/shadow.new
1196 mv $BUILD_ROOT/etc/shadow.new $BUILD_ROOT/etc/shadow
1198 if test -f $BUILD_ROOT/etc/gshadow ; then
1199 egrep -v '^abuild:' <$BUILD_ROOT/etc/gshadow >$BUILD_ROOT/etc/gshadow.new
1200 mv $BUILD_ROOT/etc/gshadow.new $BUILD_ROOT/etc/gshadow
1205 if test "$BUILDTYPE" = spec ; then
1206 TOPDIR=`chroot $BUILD_ROOT su -c "rpm --eval '%_topdir'" - $BUILD_USER`
1208 TOPDIR=/usr/src/packages
1209 mkdir -p $BUILD_ROOT$TOPDIR
1212 rm -f $BUILD_ROOT/.build.packages
1213 ln -s ${TOPDIR#/} $BUILD_ROOT/.build.packages
1215 mount -n -tproc none $BUILD_ROOT/proc 2> /dev/null
1216 mount -n -tdevpts none $BUILD_ROOT/dev/pts 2> /dev/null
1222 # nasty hack to prevent rpath on known paths
1223 # FIXME: do this only for suse
1224 if test -d "$BUILD_ROOT/etc/profile.d" ; then
1225 echo "export SUSE_IGNORED_RPATHS=/etc/ld.so.conf" > "$BUILD_ROOT/etc/profile.d/buildsystem.sh"
1229 # now clean up RPM building directories
1231 rm -rf $BUILD_ROOT$TOPDIR
1232 for i in BUILD RPMS/`uname -m` RPMS/i386 RPMS/noarch SOURCES SPECS SRPMS BUILDROOT; do
1233 mkdir -p $BUILD_ROOT$TOPDIR/$i
1234 test $BUILD_USER = abuild && chown 399:399 $BUILD_ROOT$TOPDIR/$i
1236 test -e $BUILD_ROOT/exit && cleanup_and_exit
1238 mkdir -p $BUILD_ROOT$TOPDIR/SOURCES
1239 if test "$BUILDTYPE" = kiwi ; then
1240 mkdir -p $BUILD_ROOT$TOPDIR/KIWI
1241 if test "$MYSRCDIR" = $BUILD_ROOT/.build-srcdir ; then
1242 mv "$MYSRCDIR"/* $BUILD_ROOT$TOPDIR/SOURCES/
1244 cp -dLR "$MYSRCDIR"/* $BUILD_ROOT$TOPDIR/SOURCES/
1247 cp -p "$MYSRCDIR"/* $BUILD_ROOT$TOPDIR/SOURCES/
1249 test "$MYSRCDIR" = $BUILD_ROOT/.build-srcdir && rm -rf "$MYSRCDIR"
1252 test -n "$CHANGELOG" -a -f "$BUILD_ROOT/.build-changelog" && CHANGELOGARGS="--changelog $BUILD_ROOT/.build-changelog"
1254 if test "$BUILDTYPE" = spec ; then
1255 # do buildrequires/release substitution
1257 if test -n "$RELEASE"; then
1258 args=(--release "$RELEASE")
1260 substitutedeps "${args[@]}" --dist "$BUILD_DIST" --archpath "$BUILD_ARCH" --configdir "$BUILD_DIR/configs" $CHANGELOGARGS "$BUILD_ROOT$TOPDIR/SOURCES/$SPECFILE" "$BUILD_ROOT/.spec.new" || cleanup_and_exit 1
1261 # extract macros from configuration
1262 getmacros --dist "$BUILD_DIST" --archpath "$BUILD_ARCH" --configdir "$BUILD_DIR/configs" > $BUILD_ROOT/root/.rpmmacros
1263 if test -n "$BUILD_DEBUG" ; then
1265 %prep %?_suse_insert_debug_package%%prep
1266 %package %?_suse_insert_debug_package%%package
1267 %suse_insert_debug_package \
1268 %global _suse_insert_debug_package \\\
1269 %%undefine _suse_insert_debug_package \\\
1272 ' >> $BUILD_ROOT/root/.rpmmacros
1274 test $BUILD_USER = abuild && cp -p $BUILD_ROOT/root/.rpmmacros $BUILD_ROOT/home/abuild/.rpmmacros
1275 # extract optflags from configuration
1276 getoptflags --dist "$BUILD_DIST" --configdir "$BUILD_DIR/configs" --archpath "$BUILD_ARCH" ${BUILD_DEBUG:+--debug} > $BUILD_ROOT/root/.rpmrc
1277 test $BUILD_USER = abuild && cp -p $BUILD_ROOT/root/.rpmrc $BUILD_ROOT/home/abuild/.rpmrc
1279 if test -f $BUILD_ROOT/.spec.new ; then
1280 if ! cmp -s $BUILD_ROOT$TOPDIR/SOURCES/$SPECFILE $BUILD_ROOT/.spec.new ; then
1281 echo -----------------------------------------------------------------
1282 echo I have the following modifications for $SPECFILE:
1283 diff $BUILD_ROOT$TOPDIR/SOURCES/$SPECFILE $BUILD_ROOT/.spec.new
1284 mv $BUILD_ROOT/.spec.new $BUILD_ROOT$TOPDIR/SOURCES/$SPECFILE
1286 rm -f $BUILD_ROOT/.spec.new
1290 if test "$BUILDTYPE" = dsc ; then
1291 rm -rf $BUILD_ROOT$TOPDIR/BUILD
1292 test $BUILD_USER = abuild && chown 399:399 $BUILD_ROOT$TOPDIR
1294 DEB_SOURCEDIR=$TOPDIR/SOURCES
1295 DEB_DSCFILE=$SPECFILE
1296 for f in $BUILD_ROOT$TOPDIR/SOURCES/debian.* ; do
1297 test -f $f && DEB_TRANSFORM=true
1299 if test -n "$DEB_TRANSFORM" ; then
1300 echo "running debian transformer..."
1301 mkdir -p $BUILD_ROOT$TOPDIR/SOURCES.DEB
1302 if ! debtransform $CHANGELOGARGS $BUILD_ROOT$TOPDIR/SOURCES $BUILD_ROOT$TOPDIR/SOURCES/$SPECFILE $BUILD_ROOT$TOPDIR/SOURCES.DEB ; then
1303 echo "debian transforming failed."
1306 DEB_SOURCEDIR=$TOPDIR/SOURCES.DEB
1307 for DEB_DSCFILE in $BUILD_ROOT/$DEB_SOURCEDIR/*.dsc ; do : ; done
1308 DEB_DSCFILE="${DEB_DSCFILE##*/}"
1310 chroot $BUILD_ROOT su -c "dpkg-source -x $DEB_SOURCEDIR/$DEB_DSCFILE $TOPDIR/BUILD" - $BUILD_USER
1313 if test $BUILD_USER = abuild ; then
1314 chown -R 399:399 $BUILD_ROOT$TOPDIR/*
1316 chown -R root:root $BUILD_ROOT$TOPDIR/*
1318 cd $BUILD_ROOT$TOPDIR/SOURCES || cleanup_and_exit 1
1320 echo -----------------------------------------------------------------
1321 if test "$BUILD_USER" = root ; then
1322 echo ----- building $SPECFILE
1324 echo ----- building $SPECFILE "(user $BUILD_USER)"
1326 echo -----------------------------------------------------------------
1327 echo -----------------------------------------------------------------
1328 test -n "$RUNNING_IN_VM" && ifconfig lo 127.0.0.1 up
1329 test -n "$RUNNING_IN_VM" -a -n "$MYHOSTNAME" && hostname "$MYHOSTNAME"
1331 BUILD_SUCCEEDED=false
1333 if test "$BUILDTYPE" = spec ; then
1334 test -z "$BUILD_RPM_BUILD_STAGE" && BUILD_RPM_BUILD_STAGE=-ba
1336 # XXX: move _srcdefattr to macro file?
1337 rpmbopts=("$BUILD_RPM_BUILD_STAGE" "--define" "_srcdefattr (-,root,root)")
1338 if [ -n "$ABUILD_TARGET_ARCH" ]; then
1339 rpmbopts[${#rpmbopts[@]}]="--target=$ABUILD_TARGET_ARCH"
1341 if [ -n "$BUILD_JOBS" ]; then
1342 rpmbopts[${#rpmbopts[@]}]='--define'
1343 rpmbopts[${#rpmbopts[@]}]="jobs $BUILD_JOBS"
1345 if [ -n "$DISTURL" ]; then
1346 rpmbopts[${#rpmbopts[@]}]='--define'
1347 rpmbopts[${#rpmbopts[@]}]="disturl $DISTURL"
1349 if test -s "$BUILD_ROOT/usr/lib/rpm/mandriva/macros" ; then
1350 rpmbopts[${#rpmbopts[@]}]='--eval'
1351 rpmbopts[${#rpmbopts[@]}]="%undefine _enable_debug_packages"
1353 if [ -n "$BUILD_DEBUG" ]; then
1354 rpmbopts[${#rpmbopts[@]}]='--eval'
1355 rpmbopts[${#rpmbopts[@]}]="%suse_insert_debug_package"
1359 test -x $BUILD_ROOT/usr/bin/rpmbuild || rpmbuild=rpm
1360 # su involves a shell which would require even more
1361 # complicated quoting to bypass than this
1362 toshellscript $rpmbuild \
1363 "${definesnstuff[@]}" \
1365 "$TOPDIR/SOURCES/$SPECFILE" \
1366 > $BUILD_ROOT/.build.command
1367 chmod 755 $BUILD_ROOT/.build.command
1368 chroot $BUILD_ROOT su -c /.build.command - $BUILD_USER < /dev/null && BUILD_SUCCEEDED=true
1371 if test "$BUILDTYPE" = dsc ; then
1372 chroot $BUILD_ROOT su -c "cd $TOPDIR/BUILD && dpkg-buildpackage -us -uc -rfakeroot-tcp" - $BUILD_USER < /dev/null && BUILD_SUCCEEDED=true
1373 mkdir -p $BUILD_ROOT/$TOPDIR/DEBS
1374 for DEB in $BUILD_ROOT/$TOPDIR/*.deb ; do
1375 test -e "$DEB" && mv "$DEB" "$BUILD_ROOT/$TOPDIR/DEBS"
1378 ln $BUILD_ROOT/$DEB_SOURCEDIR/$DEB_DSCFILE $BUILD_ROOT/$TOPDIR/DEBS/
1380 ln $BUILD_ROOT/$DEB_SOURCEDIR/$f $BUILD_ROOT/$TOPDIR/DEBS/
1381 done < <(sed -ne '/^Files:/,$s/^ ................................ [0-9][0-9]* //p' < $BUILD_ROOT/$DEB_SOURCEDIR/$DEB_DSCFILE)
1384 if test "$BUILDTYPE" = kiwi ; then
1385 # run createrepo on the repositories
1386 if test -d $BUILD_ROOT/$TOPDIR/SOURCES/repos ; then
1388 ln -sf $TOPDIR/SOURCES/repos $BUILD_ROOT/repos
1389 cd $BUILD_ROOT/$TOPDIR/SOURCES/repos
1391 test -L $r && continue
1392 test -d $r || continue
1393 repo="$TOPDIR/SOURCES/repos/$r/"
1394 # create compatibility link
1396 if test "$rc" != "$r" ; then
1400 ln -s $rl$r "${rc%/*}/${rc##*/}"
1401 repo="$TOPDIR/SOURCES/repos/${rc%/*}/${rc##*/}/"
1403 echo "creating repodata for $repo"
1404 chroot $BUILD_ROOT createrepo "$repo"
1409 for t in $BUILD_ROOT/$TOPDIR/SOURCES/root.tar* ; do
1410 test -f $t || continue
1411 mkdir -p $BUILD_ROOT/$TOPDIR/SOURCES/root
1412 chroot $BUILD_ROOT tar -C $TOPDIR/SOURCES/root -xf "$TOPDIR/SOURCES/${t##*/}"
1414 # fix script permissions
1415 chmod a+x $BUILD_ROOT/$TOPDIR/SOURCES/*.sh
1416 # unpack tar files in image directories
1417 if test -d $BUILD_ROOT/$TOPDIR/SOURCES/images ; then
1419 cd $BUILD_ROOT/$TOPDIR/SOURCES/images
1421 test -L $r && continue
1422 test -d $r || continue
1423 for t in $r/root.tar* ; do
1424 test -f $t || continue
1426 chroot $BUILD_ROOT tar -C $TOPDIR/SOURCES/images/$r/root -xf "$TOPDIR/SOURCES/images/$r/${t##*/}"
1428 # fix script permissions
1429 chmod a+x $BUILD_ROOT/$TOPDIR/SOURCES/images/$r/*.sh
1430 # create compatibility link
1432 if test "$rc" != "$r" ; then
1436 ln -s $rl$r "${rc%/*}/${rc##*/}"
1441 rm -f $BUILD_ROOT/$TOPDIR/SOURCES/config.xml
1442 ln -s $SPECFILE $BUILD_ROOT/$TOPDIR/SOURCES/config.xml
1443 imagetype=$(perl -I$BUILD_DIR -MBuild::Kiwi -e Build::Kiwi::show $BUILD_ROOT/$TOPDIR/SOURCES/$SPECFILE imagetype)
1444 imagename=$(perl -I$BUILD_DIR -MBuild::Kiwi -e Build::Kiwi::show $BUILD_ROOT/$TOPDIR/SOURCES/$SPECFILE filename)
1445 imageversion=$(perl -I$BUILD_DIR -MBuild::Kiwi -e Build::Kiwi::show $BUILD_ROOT/$TOPDIR/SOURCES/$SPECFILE version)
1446 chroot $BUILD_ROOT su -c "kiwi --version" -
1447 if test "$imagetype" = product ; then
1448 echo "running kiwi --create-instsource..."
1449 chroot $BUILD_ROOT su -c "kiwi --root $TOPDIR/KIWIROOT -v -v --instsource-local --logfile terminal -p $TOPDIR/SOURCES --create-instsource $TOPDIR/SOURCES" - $BUILD_USER < /dev/null && BUILD_SUCCEEDED=true
1450 for i in $BUILD_ROOT/$TOPDIR/KIWIROOT/main/* ; do
1451 test -d "$i" || continue
1453 test "$n" = scripts && continue
1454 test "$n" != "${n%0}" && continue
1455 chroot $BUILD_ROOT su -c "suse-isolinux $TOPDIR/KIWIROOT/main/$n $TOPDIR/KIWI/$n.iso" - $BUILD_USER
1458 BUILD_SUCCEEDED=true
1459 if [ -z "$RUNNING_IN_VM" ]; then
1460 # NOTE: this must be done with the outer system, because it loads the dm-mod kernel modules, which needs to fit to the kernel.
1461 echo "starting device mapper for kiwi..."
1462 [ -x /etc/init.d/boot.device-mapper ] && /etc/init.d/boot.device-mapper start
1464 for imgtype in $imagetype ; do
1465 echo "running kiwi --prepare for $imgtype..."
1466 if chroot $BUILD_ROOT su -c "cd $TOPDIR/SOURCES && kiwi --prepare $TOPDIR/SOURCES --logfile terminal --root $TOPDIR/KIWIROOT-$imgtype" - $BUILD_USER < /dev/null ; then
1467 echo "running kiwi --create for $imgtype..."
1468 mkdir -p $BUILD_ROOT/$TOPDIR/KIWI-$imgtype
1469 chroot $BUILD_ROOT su -c "cd $TOPDIR/SOURCES && kiwi --create $TOPDIR/KIWIROOT-$imgtype --logfile terminal --type $imgtype -d $TOPDIR/KIWI-$imgtype" - $BUILD_USER < /dev/null || cleanup_and_exit 1
1475 # create tar.gz of images, in case it makes sense
1476 imagearch=`uname -m`
1478 if test -n "$RELEASE"; then
1479 buildnum="-Build$RELEASE"
1481 for imgtype in $imagetype ; do
1484 pushd $BUILD_ROOT/$TOPDIR/KIWI-oem > /dev/null
1485 echo "compressing images... "
1486 tar cvzfS $BUILD_ROOT/$TOPDIR/KIWI/$imagename.$imagearch-$imageversion$buildnum-raw.tar.gz \
1487 --exclude=$imagename.$imagearch-$imageversion.iso *
1488 if [ -e $imagename.$imagearch-$imageversion.iso ]; then
1489 echo "Copy iso file and create md5..."
1490 mv $imagename.$imagearch-$imageversion.iso \
1491 $BUILD_ROOT/$TOPDIR/KIWI/$imagename.$imagearch-$imageversion$buildnum.iso
1492 pushd $BUILD_ROOT/$TOPDIR/KIWI > /dev/null
1493 md5sum $imagename.$imagearch-$imageversion$buildnum.iso \
1494 > "$imagename.$imagearch-$imageversion$buildnum.iso.md5"
1500 pushd $BUILD_ROOT/$TOPDIR/KIWI-vmx > /dev/null
1501 echo "compressing images... "
1502 tar cvzfS $BUILD_ROOT/$TOPDIR/KIWI/$imagename.$imagearch-$imageversion$buildnum-vmx.tar.gz \
1503 $imagename.$imagearch-$imageversion.vmx \
1504 $imagename.$imagearch-$imageversion.vmdk
1506 if [ -e $imagename.$imagearch-$imageversion.ovf ] ; then
1507 tar cvzfS $BUILD_ROOT/$TOPDIR/KIWI/$imagename.$imagearch-$imageversion$buildnum-ovf.tar.gz \
1508 $imagename.$imagearch-$imageversion.ovf \
1509 $imagename.$imagearch-$imageversion-disk*.vmdk
1514 pushd $BUILD_ROOT/$TOPDIR/KIWI-xen > /dev/null
1515 echo "compressing images... "
1516 tar cvzfS $BUILD_ROOT/$TOPDIR/KIWI/$imagename.$imagearch-$imageversion$buildnum-xen.tar.gz \
1517 `grep ^kernel $imagename.$imagearch-$imageversion.xenconfig | cut -d'"' -f2` \
1518 `grep ^ramdisk $imagename.$imagearch-$imageversion.xenconfig | cut -d'"' -f2` \
1519 $imagename.$imagearch-$imageversion.xenconfig \
1520 $imagename.$imagearch-$imageversion
1524 pushd $BUILD_ROOT/$TOPDIR/KIWI-pxe > /dev/null
1525 echo "compressing images... "
1526 tar cvzfS $BUILD_ROOT/$TOPDIR/KIWI/$imagename.$imagearch-$imageversion$buildnum-pxe.tar.gz \
1527 $imagename.$imagearch-$imageversion.config \
1528 $imagename.$imagearch-$imageversion.md5 \
1529 $imagename.$imagearch-$imageversion.gz \
1534 pushd $BUILD_ROOT/$TOPDIR/KIWI-iso > /dev/null
1535 echo "creating md5 sum for iso images... "
1537 pushd $BUILD_ROOT/$TOPDIR/KIWI/ > /dev/null
1538 mv $BUILD_ROOT/$TOPDIR/KIWI-iso/$i ${i%.iso}$buildnum.iso
1539 md5sum ${i%.iso}$buildnum.iso > ${i%.iso}$buildnum.iso.md5
1545 pushd $BUILD_ROOT/$TOPDIR/KIWI-$imgtype > /dev/null
1546 echo "compressing unkown images... "
1547 tar cvzfS $BUILD_ROOT/$TOPDIR/KIWI/$imagename.$imagearch-$imageversion$buildnum-$imgtype.tar.gz \
1556 test "$BUILD_SUCCEEDED" = true || cleanup_and_exit 1
1557 test -d "$SRCDIR" && cd "$SRCDIR"
1560 RPMS=`find $BUILD_ROOT/$TOPDIR/RPMS -type f -name "*.rpm"`
1562 if test -n "$RPMS" -a -n "$BUILD_USER_ABUILD_USED" ; then
1563 echo "... checking for files with abuild user/group"
1565 while read un gn fn ; do
1566 if test "$un" = abuild -o "$gn" = abuild -o "$un" = 399 -o "$gn" = 399 ; then
1570 done < <(rpm -qp --qf '[%{FILEUSERNAME} %{FILEGROUPNAME} %{FILENAMES}\n]' $RPMS)
1571 if test -n "$BADFILE" ; then
1572 echo "please fix your filelist (e.g. add defattr)"
1577 if test -n "$RPMS" -a -d "$BUILD_ROOT/usr/lib/build/checks" ; then
1578 mount -n -tproc none $BUILD_ROOT/proc 2> /dev/null
1580 export DO_RPM_REMOVE=true
1581 for SRPM in $BUILD_ROOT/$TOPDIR/SRPMS/*src.rpm ; do
1582 test -f "$SRPM" && PNAME=`rpm --nodigest --nosignature -qp --qf "%{NAME}" $SRPM`
1584 for CHECKSCRIPT in $BUILD_ROOT/usr/lib/build/checks/* ; do
1585 echo "... running `basename $CHECKSCRIPT`"
1586 $CHECKSCRIPT || cleanup_and_exit 1
1588 umount -n $BUILD_ROOT/proc 2> /dev/null
1591 if test -n "$RPMS" -a "$DO_CHECKS" != "false" -a -x "$BUILD_ROOT/opt/testing/bin/rpmlint" -a -d "$BUILD_ROOT/$TOPDIR/RPMS" ; then
1592 LINT_RPM_FILE_LIST=($(find $BUILD_ROOT/$TOPDIR/RPMS \
1593 \( -name "*-debuginfo-*" -o -name "*-debugsource-*" \
1594 -o -name "*-32bit-*" -o -name "*-64bit-*" \
1595 -o -name "*-x86-*" -o -name "*-ia32-*" \) -prune \
1596 -o -type f -name '*.rpm' -print))
1597 SRPM_FILE_LIST=($(find $BUILD_ROOT/$TOPDIR/SRPMS -type f -name "*.rpm"))
1599 echo "RPMLINT report:"
1600 echo "==============="
1601 chroot $BUILD_ROOT /opt/testing/bin/rpmlint --info ${LINT_RPM_FILE_LIST[*]#$BUILD_ROOT} ${SRPM_FILE_LIST[*]#$BUILD_ROOT} || cleanup_and_exit 1
1604 if test -n "$RPMS" -a -n "$CREATE_BASELIBS" -a -d "$BUILD_ROOT/$TOPDIR/RPMS" ; then
1605 if test -f $BUILD_ROOT/usr/lib/build/mkbaselibs -o "$CREATE_BASELIBS" != internal ; then
1606 mount -n -tproc none $BUILD_ROOT/proc 2> /dev/null
1608 umount -n $BUILD_ROOT/proc 2> /dev/null
1612 # IMPLEMENT ME: place code for creating binary package deltas here
1614 if test -n "$RUNNING_IN_VM" -a -n "$VM_SWAP"; then
1615 echo "... saving built packages"
1617 args="--padstart 512 --padend 512 -v"
1618 case "$BUILDTYPE" in
1620 computeblocklists $args $TOPDIR/RPMS/*/*.rpm $TOPDIR/SRPMS/*.rpm > "$VM_SWAP"
1623 computeblocklists $args $TOPDIR/DEBS/*.deb > "$VM_SWAP"
1626 computeblocklists $args $TOPDIR/KIWI/* > "$VM_SWAP"
1628 esac || cleanup_and_exit 1
1631 if test -n "$RPMS" -a -d "$BUILD_ROOT/$TOPDIR/RPMS" -a -d "$BUILD_ROOT/.build.oldpackages" -a -x "$BUILD_ROOT/usr/lib/build/same-build-result.sh" ; then
1632 echo "... comparing built packages with the former built"
1633 # exit with 2, if packages built successfull, but have no changes to former built packages.
1634 chroot $BUILD_ROOT /usr/lib/build/same-build-result.sh /.build.oldpackages "$TOPDIR/RPMS" "$TOPDIR/SRPMS" && cleanup_and_exit 2
1638 echo "$HOST finished \"build $SPECFILE\" at `date`."