[meego-commits] 6805: Changes to Tools:Building/build

Jian-feng Ding jian-feng.ding at intel.com
Wed Aug 18 10:48:51 UTC 2010


Hi,
I have made the following changes to build in project Tools:Building. Please review and accept ASAP.

Thank You,
Jian-feng Ding

[This message was auto-generated]

---

Request #6805:

  submit:   devel:tools:building/build(r10) -> Tools:Building/build


Message:
    Update to 2010.08.04 snapshot

State:   new          2010-08-17T22:39:27 jfding
Comment: None



changes files:
--------------
--- build.changes
+++ build.changes
@@ -0,0 +1,3 @@
+* Tue Aug 10 2010 Jian-feng Ding <jian-feng.ding at intel.com> 2010.08.04
+- Update to 2010.08.04 snapshot
+

old:
----
  build-2010.04.15.tar.gz

new:
----
  build-2010.08.04.tar.gz

spec files:
-----------
--- build.spec
+++ build.spec
@@ -23,7 +23,7 @@
 Group:          Development/Tools/Building
 AutoReqProv:    on
 Summary:        A Script to Build SUSE Linux RPMs
-Version:        2010.04.15
+Version:        2010.08.04
 Release:        1
 # osc rm build-*tar.bz2
 # REVISION=$(svn info https://forgesvn1.novell.com/svn/opensuse/trunk/buildservice/src/build | sed -ne "/Revision: /s///p")
@@ -77,4 +77,3 @@
 /usr/lib/build
 %{_mandir}/man1/build.1*
 
-%changelog

dsc files:
----------
--- build.dsc
+++ build.dsc
@@ -1,6 +1,6 @@
 Format: 1.0
 Source: build
-Version: 2010.04.15
+Version: 2010.08.04
 Binary: build
 Maintainer: Adrian Schroeter <adrian at suse.de>
 Architecture: all

other changes:
--------------

++++++ build-2010.04.15.tar.gz -> build-2010.08.04.tar.gz
--- Build.pm
+++ Build.pm
@@ -132,6 +132,8 @@
   delete $config->{'save_expanded'};
   $config->{'preinstall'} = [];
   $config->{'vminstall'} = [];
+  $config->{'cbpreinstall'} = [];
+  $config->{'cbinstall'} = [];
   $config->{'runscripts'} = [];
   $config->{'required'} = [];
   $config->{'support'} = [];
@@ -149,6 +151,7 @@
   $config->{'release'} = '<CI_CNT>.<B_CNT>';
   $config->{'repotype'} = [];
   $config->{'patterntype'} = [];
+  $config->{'fileprovides'} = {};
   for my $l (@spec) {
     $l = $l->[1] if ref $l;
     next unless defined $l;
@@ -165,7 +168,7 @@
       }
       next;
     }
-    if ($l0 eq 'preinstall:' || $l0 eq 'vminstall:' || $l0 eq 'required:' || $l0 eq 'support:' || $l0 eq 'keep:' || $l0 eq 'prefer:' || $l0 eq 'ignore:' || $l0 eq 'conflict:' || $l0 eq 'runscripts:') {
+    if ($l0 eq 'preinstall:' || $l0 eq 'vminstall:' || $l0 eq 'cbpreinstall:' || $l0 eq 'cbinstall:' || $l0 eq 'required:' || $l0 eq 'support:' || $l0 eq 'keep:' || $l0 eq 'prefer:' || $l0 eq 'ignore:' || $l0 eq 'conflict:' || $l0 eq 'runscripts:') {
       my $t = substr($l0, 0, -1);
       for my $l (@l) {
 	if ($l eq '!*') {
@@ -186,6 +189,16 @@
       } else {
 	$config->{'substitute'}->{$ll} = [ @l ];
       }
+    } elsif ($l0 eq 'fileprovides:') {
+      next unless @l;
+      $ll = shift @l;
+      if ($ll eq '!*') {
+	$config->{'fileprovides'} = {};
+      } elsif ($ll =~ /^!(.*)$/) {
+	delete $config->{'fileprovides'}->{$1};
+      } else {
+	$config->{'fileprovides'}->{$ll} = [ @l ];
+      }
     } elsif ($l0 eq 'exportfilter:') {
       next unless @l;
       $ll = shift @l;
@@ -216,13 +229,13 @@
       $config->{'release'} = $l[0];
     } elsif ($l0 eq 'releaseprg:') {
       $config->{'releaseprg'} = $l[0];
-    } elsif ($l0 eq 'changetarget:') {
-      $config->{'changetarget'} = join(' ', @l);
+    } elsif ($l0 eq 'changetarget:' || $l0 eq 'target:') {
+      $config->{'target'} = join(' ', @l);
     } elsif ($l0 !~ /^[#%]/) {
       warn("unknown keyword in config: $l0\n");
     }
   }
-  for my $l (qw{preinstall vminstall required support keep runscripts repotype patterntype}) {
+  for my $l (qw{preinstall vminstall cbpreinstall cbinstall required support keep runscripts repotype patterntype}) {
     $config->{$l} = [ unify(@{$config->{$l}}) ];
   }
   for my $l (keys %{$config->{'substitute'}}) {
@@ -353,6 +366,16 @@
   return @{$config->{'vminstall'}};
 }
 
+sub get_cbpreinstalls {
+  my ($config) = @_;
+  return @{$config->{'cbpreinstall'}};
+}
+
+sub get_cbinstalls {
+  my ($config) = @_;
+  return @{$config->{'cbinstall'}};
+}
+
 sub get_runscripts {
   my ($config) = @_;
   return @{$config->{'runscripts'}};
@@ -363,10 +386,10 @@
 sub readdeps {
   my ($config, $pkginfo, @depfiles) = @_;
 
-  my %whatprovides = ();
   my %requires = ();
   local *F;
   my %provides;
+  my $dofileprovides = %{$config->{'fileprovides'}};
   for my $depfile (@depfiles) {
     if (ref($depfile) eq 'HASH') {
       for my $rr (keys %$depfile) {
@@ -382,7 +405,7 @@
       my $s = shift @s;
       my @ss;
       while (@s) {
-	if ($s[0] =~ /^\//) {
+	if (!$dofileprovides && $s[0] =~ /^\//) {
 	  shift @s;
 	  next;
 	}
@@ -428,14 +451,27 @@
     }
     close F;
   }
-  for my $p (keys %provides) {
-    my @pp = @{$provides{$p}};
+  $config->{'providesh'} = \%provides;
+  $config->{'requiresh'} = \%requires;
+  makewhatprovidesh($config);
+}
+
+sub makewhatprovidesh {
+  my ($config) = @_;
+
+  my %whatprovides;
+  my $provides = $config->{'providesh'};
+
+  for my $p (keys %$provides) {
+    my @pp = @{$provides->{$p}};
     s/[ <=>].*// for @pp;
     push @{$whatprovides{$_}}, $p for unify(@pp);
   }
-  $config->{'providesh'} = \%provides;
+  for my $p (keys %{$config->{'fileprovides'}}) {
+    my @pp = map {@{$whatprovides{$_} || []}} @{$config->{'fileprovides'}->{$p}};
+    @{$whatprovides{$p}} = unify(@{$whatprovides{$p} || []}, @pp) if @pp;
+  }
   $config->{'whatprovidesh'} = \%whatprovides;
-  $config->{'requiresh'} = \%requires;
 }
 
 sub setdeps {
@@ -576,6 +612,7 @@
 	  if ($r eq $p) {
 	    push @rerror, "nothing provides $r";
 	  } else {
+	    next if $r =~ /^\//;
 	    push @rerror, "nothing provides $r needed by $p";
 	  }
 	  next;
--- Build/Kiwi.pm
+++ Build/Kiwi.pm
@@ -203,7 +203,11 @@
     }
 
     # not nice, but optimizes our build dependencies
-    next if $package->{'onlyarch'} && $package->{'onlyarch'} eq "skipit";
+    # FIXME: design a real blacklist option in kiwi
+    if ($package->{'onlyarch'} && $package->{'onlyarch'} eq "skipit") {
+       push @packages, "-".$package->{'name'};
+       next;
+    }
 
     # we need this package
     push @packages, $package->{'name'};
@@ -264,11 +268,13 @@
   print "@$x\n";
 }
 
-sub query {
+# not implemented yet.
+sub queryiso {
   my ($handle, %opts) = @_;
   return {};
 }
 
+
 sub queryhdrmd5 {
   my ($bin) = @_;
   die("Build::Kiwi::queryhdrmd5 unimplemented.\n");
--- Build/Rpm.pm
+++ Build/Rpm.pm
@@ -184,6 +184,7 @@
     my $expandedline = '';
     if (!$skip) {
       my $tries = 0;
+      # newer perls: \{((?:(?>[^{}]+)|(?2))*)\}
       while ($line =~ /^(.*?)%(\{([^\}]+)\}|[\?\!]*[0-9a-zA-Z_]+|%|\()(.*?)$/) {
 	if ($tries++ > 1000) {
 	  print STDERR "Warning: spec file parser ",($lineno?" line $lineno":''),": macro too deeply nested\n" if $config->{'warnings'};
@@ -194,6 +195,14 @@
 	$line = $4;
 	my $macname = defined($3) ? $3 : $2;
 	my $macorig = $2;
+        if (defined($3) && $macname =~ /{/) {
+	  while (($macname =~ y/{/{/) > ($macname =~ y/}/}/)) {
+	    last unless $line =~ /^([^}]*)}(.*)$/;
+	    $macname .= "}$1";
+	    $macorig .= "$1}";
+	    $line = $2;
+	  }
+	}
 	my $mactest = 0;
 	if ($macname =~ /^\!\?/ || $macname =~ /^\?\!/) {
 	  $mactest = -1;
@@ -536,12 +545,12 @@
   if (@sigtags && !$dosigs) {
     %res = &rpmq(["$head$index$data"], @sigtags);
   }
-  if (ref($rpm) eq 'ARRAY' && !$dosigs && @stags && @$rpm > 1) {
+  if (ref($rpm) eq 'ARRAY' && !$dosigs && @$rpm > 1) {
     my %res2 = &rpmq([ $rpm->[1] ], @stags);
     %res = (%res, %res2);
     return %res;
   }
-  if (ref($rpm) ne 'ARRAY' && !$dosigs && @stags) {
+  if (ref($rpm) ne 'ARRAY' && !$dosigs) {
     if (read(RPM, $head, 16) != 16) {
       warn("Bad rpm $rpm\n");
       close RPM unless ref($rpm);
@@ -566,14 +575,14 @@
   }
   close RPM unless ref($rpm);
 
-  return %res unless @stags;
+#  return %res unless @stags;
 
   while($cnt-- > 0) {
     ($tag, $type, $offset, $count, $index) = unpack('N4a*', $index);
     $tag = 0+$tag;
-    if ($stags{$tag}) {
+    if ($stags{$tag} || !@stags) {
       eval {
-	my $otag = $stags{$tag};
+	my $otag = $stags{$tag} || $tag;
 	if ($type == 0) {
 	  $res{$otag} = [ '' ];
 	} elsif ($type == 1) {
--- Build/Susetags.pm
+++ Build/Susetags.pm
@@ -33,7 +33,7 @@
   my $r = '(' . join('|', @needed) . '|Pkg):\s*(.*)';
 
   if (!open(F, '<', $file)) {
-    if (!open(F, '-|', "gzip -dc $file".'.gz')) {
+    if (!open(F, '-|', "gzip", "-dc", $file.'.gz')) {
       die "$file: $!";
     }
   }
--- build
+++ build
@@ -10,19 +10,21 @@
 test -z "$BUILD_DIR" && BUILD_DIR=/usr/lib/build
 test -z "$BUILD_ROOT" && BUILD_ROOT=/var/tmp/build-root
 
-export BUILD_ARCH BUILD_HOST_ARCH BUILD_ROOT BUILD_RPMS BUILD_DIR
+export BUILD_ARCH BUILD_HOST_ARCH BUILD_ROOT BUILD_RPMS BUILD_DIR BUILD_DEBUG
+export BUILD_DIST
 
 ccache=0
 icecream=0
 shell=
 definesnstuff=()
 repos=()
+old_packages=()
 
 # defaults for vm_img_mkfs
 vm_img_mkfs_ext4='mkfs.ext4 -m 0 -q -F'
-vm_img_tunefs_ext4='tune2fs -c 0'
+vm_img_tunefs_ext4='tune2fs -c 0 -o journal_data_writeback'
 vm_img_mkfs_ext3='mkfs.ext3 -m 0 -q -F'
-vm_img_tunefs_ext3='tune2fs -c 0'
+vm_img_tunefs_ext3='tune2fs -c 0 -o journal_data_writeback'
 vm_img_mkfs_ext2='mkfs.ext2 -m 0 -q -F'
 vm_img_tunefs_ext2='tune2fs -c 0'
 vm_img_mkfs_reiserfs='mkreiserfs -q -f'
@@ -51,7 +53,7 @@
 SPECFILES=()
 SRCDIR=
 BUILD_JOBS=
-ABUILD_TARGET_ARCH=
+ABUILD_TARGET=
 CREATE_BASELIBS=
 USEUSEDFORBUILD=
 LIST_STATE=
@@ -76,12 +78,12 @@
 INCARNATION=
 DISTURL=
 LINKSOURCES=
-CHANGETARGET=
 OVERLAY=
 RSYNCSRC=
 RSYNCDEST=
 RSYNCDONE=
 : ${EMULATOR_ARCHS:="armv4l armv5el armv6el armv7el sh4 ppc ppc64 mips mipsel"}
+: ${CACHE_DIR:=/var/cache/build}
 
 export EMULATOR_ARCHS
 
@@ -213,14 +215,27 @@
               This is useful if you are hacking in the buildroot.
               This must be set to the same value if the buildroot is re-used.
 
-  --vmdisk-rootsize   <size in MB>
-  --vmdisk-swapsize   <size in MB>
-  --vmdisk-filesystem <ext3|ext4>  
+  --vm-type TYPE
+              Use virtual machine instead of chroot
+              TYPE is one of xen|kvm|uml|qemu|lxc
+
+  --vm-disk FILE
+              Use FILE as disk for virtual machine.
+              Defaults to \$BUILD_ROOT.img if unset
+
+  --vm-swap FILE
+              Use FILE as swap space for virtual machine. The swap space is
+              also used for retrieving packages from the VM so it's size must be
+              sufficiently large
+
+  --vm-disk-size SIZEINMB
+  --vm-swap-size SIZEINMB
+  --vm-disk-filesystem TYPE
               Defaults for automatic setup of VM root/swap files
 
-  --vm-kernel 
-  --vm-initrd
-              Kernel and initrd to use for VM build.
+  --vm-kernel FILE
+  --vm-initrd FILE
+              Kernel and initrd to use for VM (kvm and qemu only)
 
   --debug
               enable creation of a debuginfo package
@@ -325,7 +340,7 @@
 	    done
 	fi
 	mkdir -p "$BUILD_ROOT"/.ccache
-	chroot "$BUILD_ROOT" chown -R "$BUILD_USER" "/.ccache"
+	chown -R "$ABUILD_UID:$ABUILD_GID" "$BUILD_ROOT/.ccache"
 	echo "export CCACHE_DIR=/.ccache" > "$BUILD_ROOT"/etc/profile.d/build_ccache.sh
 	echo 'export PATH=/var/lib/build/ccache/bin:$PATH' >> "$BUILD_ROOT"/etc/profile.d/build_ccache.sh
     else
@@ -411,27 +426,14 @@
     done < <(cat /proc/meminfo) # cat for proc stuff
 }
 
-function create_baselibs {
-    echo "... creating baselibs"
-    BRPMS=
-    for RPM in $BUILD_ROOT$TOPDIR/RPMS/*/*.rpm ; do
-	BRPMS="$BRPMS ${RPM#$BUILD_ROOT}"
-    done
-    BDEBS=
-    for DEB in $BUILD_ROOT$TOPDIR/DEBS/*.deb ; do
-	BDEBS="$BDEBS ${DEB#$BUILD_ROOT}"
-    done
+create_baselibs()
+{
+    local pkgs=()
+
     BASELIBS_CFG=
-## Nb REPO is the name of the project instance
-## DISTRO is the underlying (remote?) distro
-#    if test -e $BUILD_ROOT$TOPDIR/SOURCES/baselibs_${REPO}.conf ; then
-#        BASELIBS_CFG="-c $TOPDIR/SOURCES/baselibs_${REPO}.conf"
-#    elif test -e $BUILD_ROOT$TOPDIR/SOURCES/baselibs_${DISTRO}.conf ; then
-#        BASELIBS_CFG="-c $TOPDIR/SOURCES/baselibs_${DISTRO}.conf"
-#    elif test -e $BUILD_ROOT$TOPDIR/SOURCES/baselibs.conf ; then
 
     if test "$BUILDTYPE" == "dsc" ; then
-	BPKGS=$BDEBS
+	pkgs=($DEBS)
     else # spec and kiwi
 	if test -e $BUILD_ROOT$TOPDIR/SOURCES/baselibs.conf ; then
 	    BASELIBS_CFG="-c $TOPDIR/SOURCES/baselibs.conf"
@@ -439,16 +441,30 @@
 	if test -e $BUILD_ROOT/usr/lib/build/baselibs_global.conf; then
 	    BASELIBS_GLOBAL="-c /usr/lib/build/baselibs_global.conf"
 	fi
-	BPKGS=$BRPMS
+	pkgs=($RPMS)
     fi
-    if test -f $BUILD_ROOT/usr/lib/build/mkbaselibs ; then
+
+    mount -n -tproc none $BUILD_ROOT/proc 2> /dev/null
+    # don't use -R as extracted sources, build root etc might be below $TOPDIR
+    chown "$ABUILD_UID:$ABUILD_GID" "$BUILD_ROOT$TOPDIR"/* "$BUILD_ROOT$TOPDIR"/RPMS/* || true
+
+    local mkbaselibs="/usr/lib/build/mkbaselibs"
+    local whichone=''
+    # $BUILD_DIR is set to /.build when using a vm. So we need to
+    # hardcode /usr/lib/build instead of $BUILD_DIR to prefer
+    # mkbaselibs from the distro.
+    if test -f $BUILD_ROOT$mkbaselibs; then
 	if test -z "$BASELIBS_CFG" -a -e $BUILD_ROOT/usr/lib/build/baselibs.conf ; then
 	    BASELIBS_CFG="-c /usr/lib/build/baselibs.conf"
 	fi
-	echo "RUNNING internal mkbaselibs ... "
-	chroot $BUILD_ROOT su -c "/usr/lib/build/mkbaselibs -v $BASELIBS_GLOBAL $BASELIBS_CFG $BPKGS" - $BUILD_USER || cleanup_and_exit 1
     else
+	if test "$CREATE_BASELIBS" = 'internal'; then
+	    echo "Warning: mkbaselibs missing in build root, skipping baselibs"
+	    return
+	fi
 	# use external version
+	whichone=" (external)"
+	mkbaselibs="/.mkbaselibs/mkbaselibs"
 	rm -rf $BUILD_ROOT/.mkbaselibs
 	mkdir -p $BUILD_ROOT/.mkbaselibs
 	cp -f $BUILD_DIR/mkbaselibs $BUILD_ROOT/.mkbaselibs/
@@ -466,9 +482,27 @@
 	if test -e $BUILD_ROOT/.mkbaselibs/baselibs_g.conf; then
 	    BASELIBS_GLOBAL="-c /.mkbaselibs/baselibs_g.conf"
 	fi
-	chroot $BUILD_ROOT su -c "/.mkbaselibs/mkbaselibs $BASELIBS_GLOBAL $BASELIBS_CFG $BPKGS" - $BUILD_USER || cleanup_and_exit 1
-	rm -rf $BUILD_ROOT/.mkbaselibs
     fi
+    echo "... creating baselibs$whichone"
+    chroot $BUILD_ROOT su -c "$mkbaselibs $BASELIBS_GLOBAL $BASELIBS_CFG ${pkgs[*]#$BUILD_ROOT}" - $BUILD_USER || cleanup_and_exit 1
+    rm -rf $BUILD_ROOT/.mkbaselibs
+}
+
+copy_oldpackages()
+{
+    local i=0
+    local d
+    local dest
+    for d in "${old_packages[@]}"; do
+	dest="$BUILD_ROOT/.build.oldpackages"
+	test "$i" = 0 || dest="$dest$i"
+	if [ -d "$d" -a "$d" != "$dest" ] ; then
+	    rm -rf "$dest"
+	    mkdir -p "$dest"
+	    cp -L $d/* "$dest"
+	    : $((++i))
+	fi
+    done
 }
 
 vm_img_mkfs()
@@ -520,7 +554,7 @@
     RUNNING_IN_VM=true
     mount -orw -n -tproc none /proc
     if test "$VM_TYPE" != 'lxc'; then
-	mount -n -o remount,rw /
+	mount -n -o remount,noatime,rw /
     fi
 # qemu inside of xen does not work, check again with kvm later before enabling this
 #    if [ -e /dev/kqemu ]; then
@@ -616,9 +650,10 @@
     fi
 
     rm -rf "$BUILD_ROOT"/.build.packages
-    if [ -z "$RUNNING_IN_VM" ]; then
+    if [ -z "$VM_TYPE" -a -z "$RUNNING_IN_VM" ]; then
        # don't touch this in VM
        rm -rf "$BUILD_ROOT"/.build
+       mkdir -p "$BUILD_ROOT"/.build
     fi
 }
 
@@ -649,9 +684,18 @@
 
 export HOST
 
+needarg()
+{
+  if [ -z "$ARG" ]; then
+    echo "$PARAM needs an agrument" >&2
+    cleanup_and_exit 1
+  fi
+}
+
 while test -n "$1"; do
   PARAM="$1"
   ARG="$2"
+  [ "$ARG" = "${ARG#-}" ] || ARG=""
   shift
   case $PARAM in
     *-*=*)
@@ -677,14 +721,12 @@
 	KILL=true
       ;;
       *-rpms)
+	needarg
 	BUILD_RPMS="$ARG"
-	if [ -z "$BUILD_RPMS" ] ; then
-	  echo_help
-	  cleanup_and_exit
-	fi
 	shift
       ;;
       *-arch)
+	needarg
 	BUILD_ARCH="$ARG"
 	shift
       ;;
@@ -692,14 +734,17 @@
 	export VERIFY_BUILD_SYSTEM=true
       ;;
       *-target)
-	ABUILD_TARGET_ARCH="$ARG"
+	needarg
+	ABUILD_TARGET="$ARG"
 	shift
       ;;
       *-jobs)
+	needarg
 	BUILD_JOBS="$ARG"
 	shift
       ;;
       *-extra*packs|-X)
+	needarg
 	BUILD_EXTRA_PACKS="$BUILD_EXTRA_PACKS $ARG"
 	shift
       ;;
@@ -713,25 +758,28 @@
 	CREATE_BASELIBS=internal
 	;;
       *-root)
+	needarg
 	BUILD_ROOT="$ARG"
 	shift
       ;;
       *-cachedir)
+	needarg
 	CACHE_DIR="$ARG"
 	shift
       ;;
       *-oldpackages)
-	OLD_PACKAGES="$ARG"
+	needarg
+	old_packages=("${old_packages[@]}" "$ARG")
 	shift
       ;;
       *-dist)
+	needarg
 	BUILD_DIST="$ARG"
-	export BUILD_DIST
 	shift
       ;;
       *-xen|*-kvm|--uml|--qemu)
 	VM_TYPE=${PARAM##*-}
-	if [ -n "$ARG" -a "$ARG" = "${ARG#-}" ]; then
+	if [ -n "$ARG" ]; then
 	    VM_IMAGE="$ARG"
 	    shift
 	else
@@ -741,48 +789,77 @@
       --lxc)
 	VM_TYPE=${PARAM##*-}
       ;;
+      --vm-type)
+	needarg
+	VM_TYPE="$ARG"
+	case "$VM_TYPE" in
+	    xen|kvm|uml|qemu|lxc) ;;
+	    none|chroot) VM_TYPE='' ;;
+	    *)
+		echo "VM $VM_TYPE not supported"
+		cleanup_and_exit
+	    ;;
+	esac
+	shift
+      ;;
+      --vm-disk)
+	needarg
+	VM_IMAGE="$ARG"
+	shift
+      ;;
       *-xenswap|*-swap)
+	needarg
 	VM_SWAP="$ARG"
 	shift
       ;;
       *-xenmemory|*-memory)
+	needarg
 	MEMSIZE="$ARG"
 	shift
       ;;
       *-vm-kernel)
+	needarg
 	VM_KERNEL="$ARG"
 	shift
       ;;
       *-vm-initrd)
+	needarg
 	VM_INITRD="$ARG"
 	shift
       ;;
-      *-vmdisk-rootsize)
+      *-vmdisk-rootsize|--vm-disk-size)
+	needarg
 	VMDISK_ROOTSIZE="$ARG"
 	shift
       ;;
-      *-vmdisk-swapsize)
+      *-vmdisk-swapsize|--vm-swap-size)
+	needarg
 	VMDISK_SWAPSIZE="$ARG"
 	shift
       ;;
-      *-vmdisk-filesystem)
+      *-vmdisk-filesystem|--vm-disk-filesystem)
+	needarg
 	VMDISK_FILESYSTEM="$ARG"
 	shift
       ;;
       *-rpmlist)
+	needarg
 	RPMLIST="--rpmlist $ARG"
 	BUILD_RPMS=
 	shift
       ;;
       *-release)
+	needarg
 	RELEASE="$ARG"
 	shift
       ;;
       *-logfile)
+	needarg
 	LOGFILE="$ARG"
 	shift
       ;;
       *-reason)
+	needarg
 	REASON="$ARG"
 	shift
       ;;
@@ -790,6 +867,7 @@
 	NOROOTFORBUILD=true
       ;;
       *-stage)
+	needarg
 	BUILD_RPM_BUILD_STAGE="$ARG"
 	shift
       ;;
@@ -800,25 +878,19 @@
 	LIST_STATE=true
       ;;
       --define|--with|--without)
+	needarg
 	definesnstuff[${#definesnstuff[@]}]="$PARAM";
 	definesnstuff[${#definesnstuff[@]}]="$ARG";
 	shift
       ;;
       --repository|--repo)
-	if [ -z "$ARG" ] ; then
-	  echo_help
-	  cleanup_and_exit
-	fi
+	needarg
 	repos[${#repos[@]}]="$PARAM";
 	repos[${#repos[@]}]="$ARG";
 	shift
       ;;
       --icecream)
-	if [ -z "$ARG" ] ; then
-	  echo "--icecream needs an argument" >&2
-	  echo_help
-	  cleanup_and_exit 1
-	fi
+	needarg
 	icecream="$ARG"
 	if [ "$icecream" -gt 0 ]; then
 		BUILD_JOBS="$ARG"
@@ -832,10 +904,12 @@
 	BUILD_DEBUG=1
       ;;
       --incarnation)
+	needarg
 	INCARNATION=$ARG
 	shift
       ;;
       --disturl)
+	needarg
 	DISTURL=$ARG
 	shift
       ;;
@@ -850,18 +924,22 @@
 	CHANGELOG=true
       ;;
       --overlay)
+	needarg
 	OVERLAY=$ARG
 	shift
       ;;
       --rsync-src)
+	needarg
 	RSYNCSRC=$ARG
 	shift
       ;;
       --rsync-dest)
+	needarg
 	RSYNCDEST=$ARG
 	shift
       ;;
       --uid)
+	needarg
 	ABUILD_ID="$ARG"
 	if test -n "${ABUILD_ID//[0-9:]/}"; then
 	    echo "--uid argument must be uid:gid"
@@ -885,7 +963,10 @@
     esac
 done
 
-test -n "$CACHE_DIR" ||  CACHE_DIR=/var/cache/build
+if test "$VM_TYPE" = "lxc"; then
+    VM_IMAGE=''
+    VM_SWAP=''
+fi
 
 if test -n "$KILL" ; then
     test -z "$SRCDIR" || usage
@@ -935,6 +1016,18 @@
 	qemu_kernel="$VM_KERNEL"
     fi
 
+    # check if a SUSE system with virtio initrd is running
+    if [ -z "$VM_INITRD" -a -e /etc/sysconfig/kernel ]; then
+       a=$( source /etc/sysconfig/kernel; echo $INITRD_MODULES )
+       have_virtio_pci=""
+       have_virtio_blk=""
+       for i in $a; do
+          [ "$i" == "virtio_pci" ] && have_virtio_pci="1"
+          [ "$i" == "virtio_blk" ] && have_virtio_blk="1"
+       done
+       [ -n "$have_virtio_pci" -a -n "$have_virtio_blk" ] && VM_INITRD="/boot/initrd"
+    fi
+
     if [ -n "$VM_INITRD" ]; then
 	qemu_initrd="$VM_INITRD"
 	kvm_virtio=1
@@ -984,7 +1077,7 @@
     qemu_rootdev=/dev/sda
 fi
 
-if [ -z "$RPMLIST" ]; then
+if [ -z "$RPMLIST" -a -z "$RUNNING_IN_VM" ]; then
     if [ -z "$repos" -a -z "$BUILD_RPMS" ]; then
 	repos=(--repository 'zypp://')
     fi
@@ -1030,8 +1123,16 @@
 		echo "using $VM_SWAP as vm swap"
 	    fi
 	fi
+	if [ "$VM_TYPE" = 'xen' ]; then
+	    # this should not be needed, but sometimes a xen instance got lost
+	    XENID="${VM_IMAGE%/root}"
+	    XENID="${XENID%/tmpfs}"
+	    XENID="${XENID##*/}"
+	    xm destroy "build:$XENID" >/dev/null 2>&1
+	fi
 	if test ! -e "$VM_IMAGE"; then
 	    echo "Creating $VM_IMAGE (${VMDISK_ROOTSIZE}M)"
+	    mkdir -p "${VM_IMAGE%/*}"
 	    dd if=/dev/zero of="$VM_IMAGE" bs=1 count=1 seek=$(( ${VMDISK_ROOTSIZE} * 1024 * 1024 )) || cleanup_and_exit 3
 	    if test -z "$CLEAN_BUILD" ; then
 		vm_img_mkfs "$VMDISK_FILESYSTEM" "$VM_IMAGE" || cleanup_and_exit 3
@@ -1040,6 +1141,7 @@
 	if test ! -e "$VM_SWAP"; then
 	    # setup VM_SWAP
 	    echo "Creating $VM_SWAP (${VMDISK_SWAPSIZE}M)"
+	    mkdir -p "${VM_SWAP%/*}"
 	    dd if=/dev/zero of="$VM_SWAP" bs=1 count=1 seek=$(( ${VMDISK_SWAPSIZE} * 1024 * 1024 )) || cleanup_and_exit 3
 	fi
 	if test ! -e "$VM_IMAGE" ; then
@@ -1138,7 +1240,7 @@
 
     if [ -z "$RUNNING_IN_VM" ]; then
 	echo
-	echo "$HOST started \"build $SPECFILE\" at `date`."
+	echo "$HOST started \"build $SPECFILE\" at `date --utc`."
 	echo
 	test -n "$REASON" && echo "$REASON"
 	echo
@@ -1165,11 +1267,6 @@
 	for SPECFILE in *.spec ; do : ; done
     else
 	MYSRCDIR="$SRCDIR"
-	# strip prefix from autogenerated files from OBS.
-	for i in $MYSRCDIR/_service\:*; do
-	  mv "$i" "${i##*:}"
-	done
-	SPECFILE="${SPECFILE##*:}"
     fi
 
     # FIX to work with baselibs_$PROJ etc
@@ -1192,12 +1289,11 @@
     echo processing specfile $MYSRCDIR/$SPECFILE ...
 
     ADDITIONAL_PACKS=""
-    test -n "$BUILD_EXTRA_PACKS" && ADDITIONAL_PACKS="$ADDITIONAL_PACKS $BUILD_EXTRA_PACKS"
-    test -n "$CREATE_BASELIBS" && ADDITIONAL_PACKS="$ADDITIONAL_PACKS build"
-    test "$ccache" = '1' && ADDITIONAL_PACKS="$ADDITIONAL_PACKS ccache"
-    test "$icecream" -gt 1 && ADDITIONAL_PACKS="$ADDITIONAL_PACKS icecream gcc-c++"
-    test -n "$DO_LINT" && ADDITIONAL_PACKS="$ADDITIONAL_PACKS rpmlint-Factory"
-    test -n "$OLD_PACKAGES" && ADDITIONAL_PACKS="$ADDITIONAL_PACKS build-compare"
+    test -z "$BUILD_EXTRA_PACKS" || ADDITIONAL_PACKS="$ADDITIONAL_PACKS $BUILD_EXTRA_PACKS"
+    test -z "$CREATE_BASELIBS" || ADDITIONAL_PACKS="$ADDITIONAL_PACKS build"
+    test "$ccache" = '0' || ADDITIONAL_PACKS="$ADDITIONAL_PACKS ccache"
+    test "$icecream" = 0 || ADDITIONAL_PACKS="$ADDITIONAL_PACKS icecream gcc-c++"
+    test -z "$DO_LINT" || ADDITIONAL_PACKS="$ADDITIONAL_PACKS rpmlint-Factory"
 
     if test -n "$CHANGELOG" -a -z "$RUNNING_IN_VM" ; then
 	rm -f $BUILD_ROOT/.build-changelog
@@ -1225,10 +1321,7 @@
 		# remove setuid bit if files belong to user to make e.g. mount work
 		find $BUILD_ROOT/{bin,sbin,usr/bin,usr/sbin} -type f -uid $UID -perm +4000 -print0 | xargs -0 --no-run-if-empty chmod -s
 	    fi
-	    if [ -d "$OLD_PACKAGES" ]; then
-	       rm -rf $BUILD_ROOT/.build.oldpackages
-	       cp -a $OLD_PACKAGES $BUILD_ROOT/.build.oldpackages
-	    fi
+	    copy_oldpackages
 	fi
 	# start up xen, rerun ourself
 	cp -a $BUILD_DIR/. $BUILD_ROOT/.build
@@ -1277,7 +1370,6 @@
 	    test -n "$PERSONALITY_SYSCALL" && PERSONALITY=`perl -e 'print syscall('$PERSONALITY_SYSCALL', 0)."\n"'`
 	fi
 	echo "PERSONALITY='$PERSONALITY'" >> $BUILD_ROOT/.build/build.data
-	echo "OLD_PACKAGES='$OLD_PACKAGES'" >> $BUILD_ROOT/.build/build.data
 	echo "MYHOSTNAME='`hostname`'" >> $BUILD_ROOT/.build/build.data
 	echo -n "definesnstuff=(" >> $BUILD_ROOT/.build/build.data
 	shellquote "${definesnstuff[@]}" >> $BUILD_ROOT/.build/build.data
@@ -1305,12 +1397,12 @@
 	fi
 
 	if [ "$VM_TYPE" = 'xen' ]; then
-		XMROOT=file:$VM_IMAGE
+		XMROOT="file:$(readlink -f $VM_IMAGE)"
 		XMROOT=${XMROOT/#file:\/dev/phy:/dev}
 		XMROOT="disk=$XMROOT,hda1,w"
 		XMSWAP=
 		if test -n "$VM_SWAP" ; then
-		    XMSWAP=file:$VM_SWAP
+		    XMSWAP="file:$(readlink -f $VM_SWAP)"
 		    XMSWAP=${XMSWAP/#file:\/dev/phy:/dev}
 		    XMSWAP="disk=$XMSWAP,hda2,w"
 		fi
@@ -1324,7 +1416,7 @@
 		   echo "Please report to your server admin, there might be multiple services running for same domain"
 		   cleanup_and_exit 3
 		fi
-		set -- xm create -c $BUILD_DIR/xen.conf name="build:$XENID" ${MEMSIZE:+memory=$MEMSIZE} $XMROOT $XMSWAP extra="quiet init="$vm_init_script" panic=1 console=ttyS0"
+		set -- xm create -c $BUILD_DIR/xen.conf name="build:$XENID" ${MEMSIZE:+memory=$MEMSIZE} $XMROOT $XMSWAP extra="quiet init="$vm_init_script" elevator=noop panic=1 console=ttyS0"
 		if test "$PERSONALITY" != 0 ; then
 		    # have to switch back to PER_LINUX to make xm work
 		    set -- linux64 "$@"
@@ -1333,30 +1425,34 @@
 		"$@" || cleanup_and_exit 3
 	elif [ "$VM_TYPE" = 'uml' ]; then
 		echo "booting UML kernel ..."
-		set -- $uml_kernel initrd=$uml_initrd root=/ubda init="$vm_init_script" panic=1 quiet ubd0=$VM_IMAGE ${MEMSIZE:+mem=$MEMSIZE}
+		set -- $uml_kernel initrd=$uml_initrd root=/ubda init="$vm_init_script" panic=1 elevator=noop quiet ubd0=$VM_IMAGE ${MEMSIZE:+mem=$MEMSIZE}
 		echo "$@"
 		"$@"
 	elif [ "$VM_TYPE" = 'qemu' -o "$VM_TYPE" = 'kvm' ]; then
 		echo "booting $VM_TYPE ..."
 		if [ "$kvm_virtio" = 1 ]; then
-		    qemu_disks=(-drive file="$VM_IMAGE",if=virtio -hda "$VM_IMAGE")
+		    qemu_args=(-drive file="$VM_IMAGE",if=virtio -hda "$VM_IMAGE")
 		    if [ -n "$VM_SWAP" ]; then
-			qemu_disks[${#qemu_disks[@]}]="-drive"
-			qemu_disks[${#qemu_disks[@]}]="file=$VM_SWAP,if=virtio"
+			qemu_args=("${qemu_args[@]}" "-drive")
+			qemu_args=("${qemu_args[@]}" "file=$VM_SWAP,if=virtio")
 		    fi
 		else
-		    qemu_disks=(-hda "$VM_IMAGE")
+		    qemu_args=(-hda "$VM_IMAGE")
 		    if [ -n "$VM_SWAP" ]; then
-			qemu_disks[${#qemu_disks[@]}]="-hdb"
-			qemu_disks[${#qemu_disks[@]}]="$VM_SWAP"
+			qemu_args=("${qemu_args[@]}" "-hdb")
+			qemu_args=("${qemu_args[@]}" "$VM_SWAP")
 		    fi
 		fi
-		set -- $qemu_bin -no-reboot -nographic -net none -serial stdio \
+		if [ -n "$BUILD_JOBS" -a "$icecream" = 0 ]; then
+		    qemu_args=("${qemu_args[@]}" "-smp" "$BUILD_JOBS")
+		fi
+
+		set -- $qemu_bin -no-reboot -nographic -net none \
 		    -kernel $qemu_kernel \
 		    -initrd $qemu_initrd \
-		    -append "root=$qemu_rootdev panic=1 quiet noapic rw console=ttyS0 init=$vm_init_script" \
+		    -append "root=$qemu_rootdev panic=1 quiet noapic rw elevator=noop console=ttyS0 init=$vm_init_script" \
 		    ${MEMSIZE:+-m $MEMSIZE} \
-		    "${qemu_disks[@]}"
+		    "${qemu_args[@]}"
 
 		if test "$PERSONALITY" != 0 ; then
 		    # have to switch back to PER_LINUX to make qemu work
@@ -1400,6 +1496,7 @@
 		    for i in *.rpm ; do
 			test -e "$i" || continue
 			arch=${i%.rpm}
+			arch=${i%.delta}
 			arch=${arch##*\.}
 			mkdir -p RPMS/$arch
 			mv "$i" RPMS/$arch/
@@ -1417,7 +1514,7 @@
 		cleanup_and_exit ${BUILDSTATUS#BUILDSTATUS}
 		;;
 	      *)
-		echo "No buildstatus set, packager broke either the base system (glibc/bash) or the build host has a problem, server will retry..."
+		echo "No buildstatus set, either the packager broke the base system (glibc/bash/perl) or the build host has a kernel or hardware problem, OBS server will retry..."
 		cleanup_and_exit 3
 		;;
 	    esac
@@ -1445,10 +1542,8 @@
 	fi
 	mount -n -tproc none $BUILD_ROOT/proc || true
 	mount -n -tdevpts none $BUILD_ROOT/dev/pts
-	if [ -d "$OLD_PACKAGES" ]; then
-	   rm -rf "$BUILD_ROOT/.build.oldpackages"
-	   cp -r $OLD_PACKAGES $BUILD_ROOT/.build.oldpackages
-	fi
+
+	copy_oldpackages
     fi
 
     if test -z "$BUILD_DIST" -a -e "$BUILD_ROOT/.guessed_dist" ; then
@@ -1488,7 +1583,7 @@
 	    echo 'abuild:*::' >>$BUILD_ROOT/etc/gshadow # This is needed on Ubuntu
 	    echo "abuild::${ABUILD_GID}:" >>$BUILD_ROOT/etc/group
 	    mkdir -p $BUILD_ROOT/home/abuild
-	    chown ${ABUILD_UID}:${ABUILD_GID} $BUILD_ROOT/home/abuild
+	    chown "$ABUILD_UID:$ABUILD_GID" $BUILD_ROOT/home/abuild
 	else
 	    if ! egrep "^abuild::${ABUILD_UID}:${ABUILD_GID}" >/dev/null <$BUILD_ROOT/etc/passwd ; then
 		echo "abuild user present in the buildroot ($BUILD_ROOT) but uid:gid does not match"
@@ -1508,6 +1603,9 @@
 	fi
 	BUILD_USER_ABUILD_USED=true
     else
+	# building as root
+	ABUILD_UID=0
+	ABUILD_GID=0
 	if egrep '^abuild:' >/dev/null <$BUILD_ROOT/etc/passwd ; then
 	    rm -rf $BUILD_ROOT/home/abuild
 	    egrep -v '^abuild:' <$BUILD_ROOT/etc/passwd >$BUILD_ROOT/etc/passwd.new
@@ -1558,8 +1656,8 @@
     rm -rf $BUILD_ROOT$TOPDIR
     for i in BUILD RPMS/`uname -m` RPMS/i386 RPMS/noarch SOURCES SPECS SRPMS BUILDROOT; do
 	mkdir -p $BUILD_ROOT$TOPDIR/$i
-	test $BUILD_USER = abuild && chown ${ABUILD_UID}:${ABUILD_GID} $BUILD_ROOT$TOPDIR/$i
     done
+    chown -R "$ABUILD_UID:$ABUILD_GID" "$BUILD_ROOT$TOPDIR"
     check_exit
 
     mkdir -p $BUILD_ROOT$TOPDIR/SOURCES
@@ -1581,6 +1679,12 @@
     else
 	cp -p "$MYSRCDIR"/* $BUILD_ROOT$TOPDIR/SOURCES/
     fi
+    # strip prefix from autogenerated files of source services.
+    for i in $BUILD_ROOT$TOPDIR/SOURCES/_service\:*; do
+      mv "$i" "${i%/*}/${i##*:}"
+    done
+    SPECFILE="${SPECFILE##*:}"
+
     test "$MYSRCDIR" = $BUILD_ROOT/.build-srcdir && rm -rf "$MYSRCDIR"
     CHANGELOGARGS=
     test -n "$CHANGELOG" -a -f "$BUILD_ROOT/.build-changelog" && CHANGELOGARGS="--changelog $BUILD_ROOT/.build-changelog"
@@ -1616,13 +1720,9 @@
 	# extract optflags from configuration
 	getoptflags --dist "$BUILD_DIST" --configdir "$BUILD_DIR/configs" --archpath "$BUILD_ARCH" ${BUILD_DEBUG:+--debug} > $BUILD_ROOT/root/.rpmrc
 	test $BUILD_USER = abuild && cp -p $BUILD_ROOT/root/.rpmrc $BUILD_ROOT/home/abuild/.rpmrc
-	# case arm, extract changetarget
-	# this is restricted to arm to make sure it doesn't interfere with x86
-	if [ "$BUILD_ARCH" != "${BUILD_ARCH#arm}" ]; then
-	    echo "changing targetarch"
-	    chmod a+x $BUILD_DIR/getchangetarget || cleanup_and_exit 1
-	    CHANGETARGET=$(getchangetarget --dist "$BUILD_DIST" --configdir "$BUILD_DIR/configs" --archpath "$BUILD_ARCH" )
-	    echo "NEW TARGET: $CHANGETARGET"
+	if test -z "$ABUILD_TARGET"; then
+	    ABUILD_TARGET=$(getchangetarget --dist "$BUILD_DIST" --configdir "$BUILD_DIR/configs" --archpath "$BUILD_ARCH" )
+	    test -z "$ABUILD_TARGET" || echo "build target is $ABUILD_TARGET"
 	fi
     fi
     if test -f $BUILD_ROOT/.spec.new ; then
@@ -1642,7 +1742,7 @@
     if test "$BUILDTYPE" = dsc ; then
 	rm -rf $BUILD_ROOT$TOPDIR/BUILD
 	mkdir -p $BUILD_ROOT$TOPDIR/SOURCES.DEB
-	test $BUILD_USER = abuild && chown -R ${ABUILD_UID}:${ABUILD_GID} $BUILD_ROOT$TOPDIR
+	chown -R "$ABUILD_UID:$ABUILD_GID" "$BUILD_ROOT$TOPDIR"
 	DEB_TRANSFORM=
 	DEB_SOURCEDIR=$TOPDIR/SOURCES
 	DEB_DSCFILE=$SPECFILE
@@ -1662,11 +1762,7 @@
 	chroot $BUILD_ROOT su -c "dpkg-source -x $DEB_SOURCEDIR/$DEB_DSCFILE $TOPDIR/BUILD" - $BUILD_USER
     fi
 
-    if test $BUILD_USER = abuild ; then
-	chown -R ${ABUILD_UID}:${ABUILD_GID} $BUILD_ROOT$TOPDIR/*
-    else
-	chown -R root:root $BUILD_ROOT$TOPDIR/*
-    fi
+    chown -R "$ABUILD_UID:$ABUILD_GID" "$BUILD_ROOT$TOPDIR"
     cd $BUILD_ROOT$TOPDIR/SOURCES || cleanup_and_exit 1
 
     echo -----------------------------------------------------------------
@@ -1711,7 +1807,7 @@
 		fi
 		echo "Running rsync ..."
 		rsync -av $RSYNCSRC/* $BUILD_ROOT/$RSYNCDEST/
-		chown -R ${ABUILD_UID}:${ABUILD_GID} $BUILD_ROOT/$RSYNCDEST
+		chown -R "$ABUILD_UID:$ABUILD_GID" "$BUILD_ROOT/$RSYNCDEST"
 		RSYNCDONE=true
 		echo "... done"
 	    else
@@ -1727,8 +1823,8 @@
 
 	# XXX: move _srcdefattr to macro file?
 	rpmbopts=("$BUILD_RPM_BUILD_STAGE" "--define" "_srcdefattr (-,root,root)")
-	if [ -n "$ABUILD_TARGET_ARCH" ]; then
-		rpmbopts[${#rpmbopts[@]}]="--target=$ABUILD_TARGET_ARCH"
+	if [ -n "$ABUILD_TARGET" ]; then
+		rpmbopts[${#rpmbopts[@]}]="--target=$ABUILD_TARGET"
 	fi
 	if [ -n "$DISTURL" ]; then
 		rpmbopts[${#rpmbopts[@]}]='--define'
@@ -1742,10 +1838,6 @@
 		rpmbopts[${#rpmbopts[@]}]='--eval'
 		rpmbopts[${#rpmbopts[@]}]="%suse_insert_debug_package"
 	fi
-	if [ -n "$CHANGETARGET" ]; then
-		rpmbopts[${#rpmbopts[@]}]='--target'
-		rpmbopts[${#rpmbopts[@]}]="$CHANGETARGET"
-	fi
 	if [ -n "$RSYNCDONE" ] ; then
 		rpmbopts[${#rpmbopts[@]}]='--define'
 		rpmbopts[${#rpmbopts[@]}]="RSYNCDONE 1"
@@ -1848,22 +1940,40 @@
     echo "RPMLINT report:"
     echo "==============="
     chroot $BUILD_ROOT /opt/testing/bin/rpmlint --info ${LINT_RPM_FILE_LIST[*]#$BUILD_ROOT} ${SRPM_FILE_LIST[*]#$BUILD_ROOT} || cleanup_and_exit 1
+    echo
 fi
 
-if test \( -n "$RPMS" -o -n "$DEBS" \) -a -n "$CREATE_BASELIBS" -a \( -d "$BUILD_ROOT/$TOPDIR/RPMS" -o -d "$BUILD_ROOT/$TOPDIR/DEBS" \)  ; then
-    # $BUILD_DIR is set to /.build when using a vm. So we need to
-    # hardcode /usr/lib/build instead of $BUILD_DIR to prefer
-    # mkbaselibs from the distro.
-    # (and force distro version if CREATE_BASELIBS=internal)
-    if test -f $BUILD_ROOT/usr/lib/build/mkbaselibs -o "$CREATE_BASELIBS" != internal ; then
+if test \( -n "$RPMS" -o -n "$DEBS" \) -a -n "$CREATE_BASELIBS"; then
+    create_baselibs
+fi
+
+exitcode=0
+# post build scripts
+# TODO: don't hardcode. instead run scripts in a directory as it's done for the checks
+if test -n "$RPMS" \
+	-a -d "$BUILD_ROOT/$TOPDIR/RPMS" \
+	-a -d "$BUILD_ROOT/.build.oldpackages" \
+	; then
+    if test -x "$BUILD_ROOT/usr/lib/build/same-build-result.sh" ; then
+	echo "... comparing built packages with the former built"
 	mount -n -tproc none $BUILD_ROOT/proc 2> /dev/null
-	test $BUILD_USER = abuild && chown ${ABUILD_UID}:${ABUILD_GID} $BUILD_ROOT$TOPDIR/*
-	create_baselibs
+	if chroot $BUILD_ROOT /usr/lib/build/same-build-result.sh /.build.oldpackages "$TOPDIR/RPMS" "$TOPDIR/SRPMS"; then
+	    > $BUILD_ROOT/.build/.same_result_marker
+	    # XXX: dirty build service hack. fix bs_worker. Search for
+	    # 'same_result_marker' for traces of a first try to get rid of this
+	    if test -n "$REASON" -a -n "$DISTURL"; then
+		exitcode=2
+	    fi
+	fi
+    fi
+    if test -x "$BUILD_ROOT/usr/bin/makedeltarpm" \
+	-a -x $BUILD_ROOT/usr/lib/build/makedeltarpms; then
+	echo "... creating delta rpms"
+	ds=("$BUILD_ROOT/$TOPDIR"/RPMS/* "$BUILD_ROOT$TOPDIR/SRPMS")
+	chroot $BUILD_ROOT /usr/lib/build/makedeltarpms /.build.oldpackages "${ds[@]#$BUILD_ROOT}"
     fi
 fi
 
-# IMPLEMENT ME: place code for creating binary package deltas here
-
 if test -n "$RUNNING_IN_VM" -a -n "$VM_SWAP"; then
     echo "... saving built packages"
     swapoff "$VM_SWAP"
@@ -1881,17 +1991,8 @@
     esac || cleanup_and_exit 1
 fi
 
-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
-    echo "... comparing built packages with the former built"
-    mount -n -tproc none $BUILD_ROOT/proc 2> /dev/null
-    # exit with 2, if packages built successfull, but have no changes to former built packages.
-    if chroot $BUILD_ROOT /usr/lib/build/same-build-result.sh /.build.oldpackages "$TOPDIR/RPMS" "$TOPDIR/SRPMS"; then
-	cleanup_and_exit 2
-    fi
-fi
-
 echo
-echo "$HOST finished \"build $SPECFILE\" at `date`."
+echo "$HOST finished \"build $SPECFILE\" at `date --utc`."
 echo
 
-cleanup_and_exit 0
+cleanup_and_exit "$exitcode"
--- build.1
+++ build.1
@@ -73,6 +73,15 @@
 automatically sets this to a sensible value for your host if you
 don't specify this option.
 .TP
+.BI "\-\-repo " url_or_dir
+Also use the specified repository to create the build system.
+The repositories may be either of type rpmmd, yast2 (susetags),
+or a simple directory. Multiple --repo options may be given.
+As a special form, 'zypp://reponame' can be used to specify
+a system repository. 'zypp://' selects all enabled system
+repositories. This is also the default if BUILD_RPMS is not
+set and no --rpms or --repo option is used.
+.TP
 .BI "\-\-root " buildroot
 Specifies where the build system is set up. Overrides the
 BUILD_ROOT enviroment variable.
@@ -92,6 +101,14 @@
 .TP
 .B --verify
 verify the files in an existing build system.
+.TP
+.BI "\-\--dist " distribution
+Set the distribution. If this option is not given, build tries to
+calculate the distribution by looking at the rpm package used in the
+build.
+The specified distribution can either be a string
+like "11.2" or "sles9", or the pathname of the build configuration to
+use.
 
 .SH .spec FILE OPTIONS
 The
@@ -131,8 +148,7 @@
 .TP
 .B BUILD_RPMS
 Where build can find the SuSE Linux RPMs.  build needs them to create the
-build system.  "/media/dvd/suse" is the default value which will do
-the trick if you have the SuSE Linux DVD mounted.
+build system.
 .TP
 .B BUILD_RPM_BUILD_STAGE
 The rpm build stage (-ba, -bb, ...).  This is just passed through to
@@ -147,7 +163,7 @@
 .I http://www.rpm.org/max-rpm/
 .TP
 .BR "cross distribution packaging":
-.I http://en.opensuse.org/Build_Service/cross_distribution_package_how_to
+.I http://en.opensuse.org/openSUSE:Build_Service_cross_distribution_howto
 .TP
-.BR "SUSE packaging standards and guidelines":
-.I http://en.opensuse.org/Packaging
+.BR "openSUSE packaging standards and guidelines":
+.I http://en.opensuse.org/Portal:Packaging
--- build_kiwi.sh
+++ build_kiwi.sh
@@ -5,30 +5,26 @@
     imagename=$(perl -I$BUILD_DIR -MBuild::Kiwi -e Build::Kiwi::show $BUILD_ROOT/$TOPDIR/SOURCES/$SPECFILE filename)
     imageversion=$(perl -I$BUILD_DIR -MBuild::Kiwi -e Build::Kiwi::show $BUILD_ROOT/$TOPDIR/SOURCES/$SPECFILE version)
     # prepare rpms as source and createrepo on the repositories
-    if test -d $BUILD_ROOT/$TOPDIR/SOURCES/repos -a "$DO_INIT" != false ; then
-	(
-	ln -sf $TOPDIR/SOURCES/repos $BUILD_ROOT/repos
-	cd $BUILD_ROOT/$TOPDIR/SOURCES/repos
-	for r in */* ; do
-	    test -L $r && continue
-	    test -d $r || continue
-	    repo="$TOPDIR/SOURCES/repos/$r/"
-	    # create compatibility link for old kiwi versions
-	    rc="${r//:/:/}"
-	    if test "$rc" != "$r" ; then
-		rl="${rc//[^\/]}"
-		rl="${rl//?/../}"
-		mkdir -p "${rc%/*}"
-		ln -s $rl$r "${rc%/*}/${rc##*/}"
-		repo="$TOPDIR/SOURCES/repos/${rc%/*}/${rc##*/}/"
-	    fi
-	    if test "$imagetype" != product ; then
-		echo "creating repodata for $repo"
-		chroot $BUILD_ROOT createrepo "$repo"
-	    fi
-	done
-	)
-    fi
+    ln -sf $TOPDIR/SOURCES/repos $BUILD_ROOT/repos
+    cd $BUILD_ROOT/$TOPDIR/SOURCES/repos
+    for r in */* ; do
+        test -L $r && continue
+        test -d $r || continue
+        repo="$TOPDIR/SOURCES/repos/$r/"
+        # create compatibility link for old kiwi versions
+        rc="${r//:/:/}"
+        if test "$rc" != "$r" ; then
+    	rl="${rc//[^\/]}"
+    	rl="${rl//?/../}"
+    	mkdir -p "${rc%/*}"
+    	ln -s $rl$r "${rc%/*}/${rc##*/}"
+    	repo="$TOPDIR/SOURCES/repos/${rc%/*}/${rc##*/}/"
+        fi
+        if test "$imagetype" != product ; then
+    	echo "creating repodata for $repo"
+    	chroot $BUILD_ROOT createrepo "$repo"
+        fi
+    done
     # unpack root tar
     for t in $BUILD_ROOT/$TOPDIR/SOURCES/root.tar* ; do
 	test -f $t || continue
@@ -128,7 +124,9 @@
 	echo "take iso file and create sha256..."
 	mv "$imageout.iso" "/$TOPDIR/KIWI/$imageout$buildnum.iso"
 	pushd /$TOPDIR/KIWI
-	sha256sum "$imageout$buildnum.iso" > "$imageout$buildnum.iso.sha256"
+	if [ -x /usr/bin/sha256sum ]; then
+           /usr/bin/sha256sum "$imageout$buildnum.iso" > "$imageout$buildnum.iso.sha256"
+        fi
 	popd
 fi
 if [ -e "$imageout.raw" ]; then
@@ -136,15 +134,19 @@
 	pushd /$TOPDIR/KIWI
 	echo "bzip2 raw file..."
 	bzip2 "$imageout$buildnum.raw"
-	echo "Create sha256 file..."
-	sha256sum "$imageout$buildnum.raw.bz2" > "$imageout$buildnum.raw.bz2.sha256"
+	if [ -x /usr/bin/sha256sum ]; then
+	    echo "Create sha256 file..."
+	    /usr/bin/sha256sum "$imageout$buildnum.raw.bz2" > "$imageout$buildnum.raw.bz2.sha256"
+        fi
 	popd
 fi
 
 tar cvjfS "/$TOPDIR/KIWI/$imageout$buildnum-raw.tar.bz2" \
 	--exclude="$imageout.iso" --exclude="$imageout.raw" *
 cd /$TOPDIR/KIWI
-sha256sum "$imageout$buildnum-raw.tar.bz2" > "$imageout$buildnum-raw.tar.bz2.sha256"
+if [ -x /usr/bin/sha256sum ]; then
+   /usr/bin/sha256sum "$imageout$buildnum-raw.tar.bz2" > "$imageout$buildnum-raw.tar.bz2.sha256"
+fi
 EOF
 		    ;;
 		vmx)
@@ -154,7 +156,7 @@
 # This option has a number of format parameters
 VMXFILES=""
 SHAFILES=""
-for i in "$imageout.vmx" "$imageout.vmdk" "$imageout-disk*.vmdk"; do
+for i in "$imageout.vmx" "$imageout.vmdk" "$imageout-disk*.vmdk" "$imageout.ovf"; do
 	ls \$i >& /dev/null && VMXFILES="\$VMXFILES \$i"
 done
 if [ -n "\$VMXFILES" ]; then
@@ -166,16 +168,13 @@
 	tar cvjfS "/$TOPDIR/KIWI/$imageout$buildnum-vmx.tar.bz2" $imageout.xenconfig $imageout.raw initrd-*
 	SHAFILES="\$SHAFILES $imageout$buildnum-vmx.tar.bz2"
 fi
-for i in "$imageout.ovf"; do
-	[ -e \$i ] && SHAFILES="\$SHAFILES \$i"
-done
 # FIXME: do we need a single .raw file in any case ?
 
 cd /$TOPDIR/KIWI
-if [ -n "\$SHAFILES" ]; then
+if [ -n "\$SHAFILES" -a -x /usr/bin/sha256sum ]; then
 	for i in \$SHAFILES; do
 		echo "Create sha256 file..."
-		sha256sum "\$i" > "\$i.sha256"
+		/usr/bin/sha256sum "\$i" > "\$i.sha256"
 	done
 fi
 EOF
@@ -190,9 +189,11 @@
 	initrd-* \
 	"$imageout.xenconfig" \
 	"$imageout"
-echo "Create sha256 file..."
-cd $TOPDIR/KIWI
-sha256sum "$imageout$buildnum-xen.tar.bz2" > "$imageout$buildnum-xen.tar.bz2.sha256"
+if [ -x /usr/bin/sha256sum ]; then
+   echo "Create sha256 file..."
+   cd $TOPDIR/KIWI
+   /usr/bin/sha256sum "$imageout$buildnum-xen.tar.bz2" > "$imageout$buildnum-xen.tar.bz2.sha256"
+fi
 EOF
 		    ;;
 		pxe)
@@ -200,9 +201,11 @@
 echo "compressing pxe images... "
 cd /$TOPDIR/KIWI-pxe
 tar cvjfS "/$TOPDIR/KIWI/$imageout$buildnum-pxe.tar.bz2" ${imageout}* initrd-*
-echo "Create sha256 file..."
-cd $TOPDIR/KIWI
-sha256sum "$imageout$buildnum-pxe.tar.bz2" > "$imageout$buildnum-pxe.tar.bz2.sha256"
+if [ -x /usr/bin/sha256sum ]; then
+   echo "Create sha256 file..."
+   cd $TOPDIR/KIWI
+   /usr/bin/sha256sum "$imageout$buildnum-pxe.tar.bz2" > "$imageout$buildnum-pxe.tar.bz2.sha256"
+fi
 EOF
 		    ;;
 		iso)
@@ -211,11 +214,13 @@
 for i in *.iso; do
 	mv "\$i" "/$TOPDIR/KIWI/\${i%.iso}$buildnum.iso"
 done
-echo "creating sha256 sum for iso images... "
-cd $TOPDIR/KIWI
-for i in *.iso; do
-	sha256sum "\$i" > "\$i.sha256"
-done
+if [ -x /usr/bin/sha256sum ]; then
+   echo "creating sha256 sum for iso images... "
+   cd $TOPDIR/KIWI
+   for i in *.iso; do
+	/usr/bin/sha256sum "\$i" > "\$i.sha256"
+   done
+fi
 EOF
 		    ;;
 		*)
@@ -223,13 +228,15 @@
 echo "compressing unkown images... "
 cd /$TOPDIR/KIWI-$imgtype
 tar cvjfS "/$TOPDIR/KIWI/$imageout$buildnum-$imgtype.tar.bz2" *
-echo "Create sha256 file..."
-cd /$TOPDIR/KIWI
-sha256sum "$imageout$buildnum-$imgtype.tar.bz2" > "$imageout$buildnum-$imgtype.tar.bz2.sha256"
+if [ -x /usr/bin/sha256sum ]; then
+   echo "Create sha256 file..."
+   cd /$TOPDIR/KIWI
+   /usr/bin/sha256sum "$imageout$buildnum-$imgtype.tar.bz2" > "$imageout$buildnum-$imgtype.tar.bz2.sha256"
+fi
 EOF
 		    ;;
 	    esac
-	    chroot $BUILD_ROOT su -c "sh -e -x /kiwi_post.sh" || cleanup_and_exit 1
+	    chroot $BUILD_ROOT su -c "sh -x -e /kiwi_post.sh" || cleanup_and_exit 1
 	    rm -f $BUILD_ROOT/kiwi_post.sh
 	done
     fi
--- common_functions
+++ common_functions
@@ -55,6 +55,10 @@
 {
     is_emulator_arch || return
 
+    if [ -z "$VM_TYPE" ]; then
+	return 0
+    fi
+
     # to run the qemu initialization in the XEN chroot, we need to register it with a statically build shell
     case "$BUILD_HOST_ARCH" in
 	i?86|x86_64)
--- configs/sl11.3.conf
+++ configs/sl11.3.conf
+%define gcc_version 45
+
+Substitute: kiwi-packagemanager:zypper zypper
+Substitute: kiwi-packagemanager:smart smart
+Substitute: kiwi-packagemanager:instsource kiwi-instsource cdrkit-cdrtools-compat syslinux kiwi-instsource-plugins-openSUSE-11-3
+Substitute: kiwi-filesystem:ext3 e2fsprogs procps psmisc reiserfs
+Substitute: kiwi-filesystem:squashfs squashfs
+Substitute: kiwi-boot:isoboot kiwi-desc-isoboot module-init-tools elfutils squashfs clicfs e2fsprogs fribidi gfxboot-devel gawk gfxboot gfxboot-devel grub hdparm hwinfo iproute2 kiwi-tools lvm2 make memtest86+ netcfg psmisc
+Substitute: kiwi-boot:netboot kiwi-desc-netboot kiwi-desc-xenboot ncurses-utils curl dhcpcd iputils nbd net-tools netcfg nfs-client parted grub mdadm
+Substitute: kiwi-boot:oemboot kiwi-desc-oemboot
+Substitute: kiwi-boot:usbboot kiwi-desc-usbboot
+Substitute: kiwi-boot:vmxboot kiwi-desc-vmxboot
+Substitute: kiwi-boot:xenboot kiwi-desc-xenboot
+
+Substitute: build:debug vim strace gdb
+
+Preinstall: aaa_base acl attr bash coreutils diffutils
+Preinstall: filesystem fillup glibc grep insserv libacl libattr
+Preinstall: libbz2-1 libgcc%{gcc_version} libxcrypt m4 libncurses5 pam
+Preinstall: permissions libreadline6 rpm sed tar zlib libselinux1
+Preinstall: liblzma0 libcap2 libpcre0
+Preinstall: libpopt0 libelf1 liblua5_1
+
+Runscripts: aaa_base
+
+Order: libopenssl0_9_8:openssl-certs
+
+VMinstall: util-linux perl-base libdb-4_5 libsepol1 libblkid1 libuuid1
+
+Required: autoconf automake binutils bzip2 gcc gcc%{gcc_version}
+Required: gettext-runtime glibc libtool perl rpm zlib libmpfr1
+Required: libncurses5 libgmp3 libgmpxx4
+
+Support: libaudit1
+Support: cpio cpp cpp%{gcc_version} cracklib cvs
+Support: file findutils gawk gdbm gettext-tools
+Support: glibc-devel glibc-locale groff gzip info less
+Support: libbz2-devel libdb-4_5
+Support: libstdc++%{gcc_version}
+Support: libxcrypt libzio
+Support: make man netcfg
+Support: linux-glibc-devel
+Support: net-tools pam-modules patch perl-base sysvinit-tools
+Support: texinfo timezone util-linux login
+Support: libgomp%{gcc_version} libuuid1 psmisc
+Support: terminfo-base update-alternatives pwdutils build-mkbaselibs
+Support: brp-check-suse post-build-checks rpmlint-Factory
+Keep: brp-check-suse
+# remove build-compare support to disable "same result" package dropping
+Support: build-compare
+
+%ifarch ia64
+Support: libunwind libunwind-devel
+%endif
+
+Keep: libaudit1 binutils bzip2 cpio cpp cracklib file findutils gawk gcc gcc-ada gcc-c++
+Keep: gdbm glibc-devel glibc-locale gzip libada libpcre0
+Keep: libunwind libunwind-devel libzio make pam-devel pam-modules
+Keep: patch perl-base perl rcs timezone libmpfr1 libcap2
+Keep: gmp libgmp3 libgmpxx4 libmpc2
+Keep: cpp45 gcc45 gcc45-ada libstdc++45
+Keep: cpp44 gcc44 gcc44-ada libstdc++44
+Keep: cpp43 gcc43 gcc43-ada libstdc++43
+Keep: cpp42 gcc42 gcc42-ada libstdc++42
+Keep: cpp41 gcc41 gcc41-ada libstdc++41
+Keep: java-1_6_0-openjdk java-1_6_0-openjdk-devel libcloog0 libppl7 libppl_c2
+Keep: libpopt0 pkg-config
+
+Prefer: -suse-build-key
+Prefer: krb5 krb5-devel
+Prefer: krb5-mini-devel:krb5-mini
+Prefer: libreadline5
+Prefer: libdb_java-4_5 libicu
+Prefer: cracklib-dict-small postfix
+Prefer: jta libpng fam mozilla mozilla-nss
+Prefer: unixODBC libsoup glitz
+Prefer: gnome-panel desktop-data-openSUSE gnome2-SuSE
+Prefer: mono-nunit gecko-sharp2
+Prefer: apache2-prefork Mesa openmotif-libs ghostscript-mini ghostscript-library
+Prefer: gtk-sharp2 glib-sharp2 glade-sharp2
+Prefer: libzypp-zmd-backend novell-NLDAPsdk zaptel-kmp-default
+Prefer: hbedv-dazuko-kmp-default dazuko-kmp-default vmware-wkstnmods-kmp-default
+Prefer: virtualbox-kmp-default preload-kmp-default
+Prefer: libstdc++%{gcc_version} libgcc%{gcc_version}
+Prefer: libstdc++%{gcc_version}-32bit libstdc++%{gcc_version}-64bit
+%ifarch s390x
+Prefer: -libstdc++41
+%endif
+Prefer: libstroke
+Prefer: gnome-sharp2:art-sharp2 gnome-sharp:art-sharp
+Prefer: ifolder3:gnome-sharp2 ifolder3:gconf-sharp2
+Prefer: nautilus-ifolder3:gnome-sharp2 inkscape:gtkmm24
+Prefer: gconf-sharp2:glade-sharp2 gconf-sharp:glade-sharp
+Prefer: gjdoc:antlr-bootstrap
+Prefer: tomboy:gconf-sharp2 tomboy:gnome-sharp2
+Prefer: zmd:libzypp-zmd-backend
+Prefer: yast2-packagemanager-devel:yast2-packagemanager
+Prefer: glitz-32bit:Mesa-32bit
+Prefer: poppler-tools
+Prefer: banshee:banshee-engine-gst helix-banshee:helix-banshee-engine-gst
+Prefer: banshee-1:banshee-1-client-classic
+Prefer: java-1_5_0-ibm:java-1_5_0-ibm-alsa
+Prefer: java-1_5_0-ibm:java-1_5_0-ibm-fonts
+Prefer: java-1_6_0-ibm:java-1_6_0-ibm-fonts
+Prefer: microcode_ctl:kernel-default
+Prefer: notification-daemon
+Prefer: pkg-config gtk-doc wlan-kmp-default lua-libs
+Prefer: gnu-jaf classpathx-mail avahi-compat-mDNSResponder yast2-control-center-qt
+Prefer: vim-normal myspell-american wine
+Prefer: eclipse-platform eclipse-scripts
+Prefer: yast2-theme-openSUSE
+Prefer: amarok:amarok-xine
+Prefer: kdenetwork3-vnc:tightvnc
+Prefer: libgweather0 jessie ndesk-dbus ndesk-dbus-glib tomcat6-jsp-2_1-api tomcat6-servlet-2_5-api
+Prefer: icewm-lite
+Prefer: patterns-openSUSE-GNOME-cd:banshee
+Prefer: yast2-ncurses-pkg
+Prefer: monodevelop: mono-addins
+Prefer: ant-trax:saxon
+Prefer: gnome-session:gnome-session-branding-openSUSE
+Prefer: gnome-session:gconf2-branding-openSUSE
+Prefer: bundle-lang-gnome:gnome-session-branding-openSUSE
+Prefer: texlive-xmltex texlive-tools texlive-jadetex
+Prefer: mono-web:mono-data-sqlite
+Prefer: gnome-games:gnuchess
+Prefer: glchess:gnuchess
+Prefer: OpenOffice_org:OpenOffice_org-branding-upstream
+Prefer: gimp:gimp-branding-upstream
+Prefer: libesd-devel:esound
+Prefer: libesd0:esound-daemon
+Prefer: package-lists-openSUSE-KDE-cd: esound-daemon
+Prefer: glib2:glib2-branding-upstream
+Prefer: kdelibs4:kdelibs4-branding-upstream
+Prefer: kdebase4-workspace:kdebase4-workspace-branding-upstream
+Prefer: kdelibs4-branding:kdelibs4-branding-upstream
+Prefer: PackageKit:PackageKit-branding-upstream
+Prefer: mysql-connector-java:java-1_5_0-gcj-compat
+Prefer: -geronimo-jta-1_0_1B-api -geronimo-jms-1_1-api -geronimo-el-1_0-api
+Prefer: rhino:xmlbeans-mini
+Prefer: ghostscript-devel:ghostscript-library
+Prefer: gdm:gdm-branding-upstream
+Prefer: rpcbind log4j-mini eclipse-source
+Prefer: mx4j:log4j-mini
+Prefer: podsleuth:sg3_utils
+Prefer: libcdio_cdda0 libcdio_paranoia0
+Prefer: mozilla-xulrunner191
+Prefer: mozilla-xulrunner191-32bit
+Prefer: boo tog-pegasus
+Prefer: kde4-kupdateapplet:kde4-kupdateapplet-zypp
+Prefer: ant:xerces-j2
+Prefer: dhcp-client:dhcp
+Prefer: beagle-index:preload-kmp-default
+Prefer: dummy-release
+Prefer: -bundle-lang-kde-de -bundle-lang-kde-en -bundle-lang-kde-es
+Prefer: -bundle-lang-kde-fr -bundle-lang-kde-pt
+Prefer: -bundle-lang-kde-zh -bundle-lang-kde-ja -bundle-lang-kde-ru -bundle-lang-kde-pl
+Prefer: -bundle-lang-kde-sv -bundle-lang-kde-ko -bundle-lang-kde-fi -bundle-lang-kde-da
+Prefer: -bundle-lang-kde-cs -bundle-lang-kde-nl -bundle-lang-kde-hu -bundle-lang-kde-nb
+Prefer: -bundle-lang-kde-it -bundle-lang-kde-ca -bundle-lang-kde-ar
+Prefer: -bundle-lang-gnome-es -bundle-lang-gnome-de -bundle-lang-gnome-fr
+Prefer: -bundle-lang-gnome-pt -bundle-lang-gnome-en
+Prefer: -bundle-lang-gnome-zh -bundle-lang-gnome-ja -bundle-lang-gnome-ru -bundle-lang-gnome-cs
+Prefer: -bundle-lang-gnome-ko -bundle-lang-gnome-da -bundle-lang-gnome-nl -bundle-lang-gnome-hu
+Prefer: -bundle-lang-gnome-pl -bundle-lang-gnome-fi -bundle-lang-gnome-nb -bundle-lang-gnome-sv
+Prefer: -bundle-lang-gnome-it -bundle-lang-gnome-ca -bundle-lang-gnome-ar
+Prefer: -bundle-lang-gnome-extras-es -bundle-lang-gnome-extras-de -bundle-lang-gnome-extras-fr
+Prefer: -bundle-lang-gnome-extras-pt -bundle-lang-gnome-extras-en
+Prefer: -bundle-lang-gnome-extras-zh -bundle-lang-gnome-extras-ja -bundle-lang-gnome-extras-ru -bundle-lang-gnome-extras-cs
+Prefer: -bundle-lang-gnome-extras-ko -bundle-lang-gnome-extras-da -bundle-lang-gnome-extras-nl -bundle-lang-gnome-extras-hu
+Prefer: -bundle-lang-gnome-extras-pl -bundle-lang-gnome-extras-fi -bundle-lang-gnome-extras-nb -bundle-lang-gnome-extras-sv
+Prefer: -bundle-lang-gnome-extras-it -bundle-lang-gnome-extras-ca -bundle-lang-gnome-extras-ar
+Prefer: -bundle-lang-common-es -bundle-lang-common-de -bundle-lang-common-fr
+Prefer: -bundle-lang-common-pt -bundle-lang-common-en
+Prefer: -bundle-lang-common-ja -bundle-lang-common-zh -bundle-lang-common-cs -bundle-lang-common-ru
+Prefer: -bundle-lang-common-nl -bundle-lang-common-hu -bundle-lang-common-pl -bundle-lang-common-da
+Prefer: -bundle-lang-common-ko -bundle-lang-common-nb -bundle-lang-common-fi -bundle-lang-common-sv
+Prefer: -bundle-lang-common-it -bundle-lang-common-ca -bundle-lang-common-ar
+Prefer: -libgcc-mainline -libstdc++-mainline -gcc-mainline-c++
+Prefer: -libgcj-mainline -viewperf -compat -compat-openssl097g
+Prefer: -zmd -OpenOffice_org -pam-laus -libgcc-tree-ssa -busybox-links
+
+Prefer: -NX -xaw3dd -db43
+Prefer: -xerces-j2-xml-resolver -xerces-j2-xml-apis
+Prefer: -vmware-player
+Prefer: libgcc%{gcc_version} libgcc%{gcc_version}-32bit libgcc%{gcc_version}-64bit
+Prefer: libgcc%{gcc_version}-x86 libffi%{gcc_version} libffi%{gcc_version}-devel libgcj_bc%{gcc_version}
+Prefer: libgomp%{gcc_version} libgomp%{gcc_version}-32bit libgomp%{gcc_version}-64bit
+Prefer: libmudflap%{gcc_version} libmudflap%{gcc_version}-32bit libmudflap%{gcc_version}-64bit
+Prefer: libobjc%{gcc_version} libgfortran%{gcc_version}
+Prefer: -libnetpbm -libcdio7-mini -libiso9660-5-mini -libiso9660-7-mini -libcdio10-mini
+Prefer: -libcdio-mini -faac-mini
+Prefer: -seamonkey
+Prefer: -libdb-4_4-devel -libevoldap-2_4-2
+Conflict: ghostscript-library:ghostscript-mini
+Conflict: ghostscript-fonts-std:ghostscript-mini
+Prefer: libopenal0-soft openal-soft -lsb-buildenv
+Prefer: -libevent
+Prefer: gnu-crypto libusb-compat-devel
+Prefer: libusb-0_1-4
+Prefer: CASA_auth_token_svc:xerces-j2
+Prefer: OpenOffice_org:xerces-j2
+Prefer: k3b:libdvdread4
+Prefer: glibc-devel
+Prefer: -libpcap -java-1_7_0-icedtea-devel -libiniparser -loudmouth -libkonq4 -libnetcdf-4
+Prefer: NetworkManager:dhcp-client
+Prefer: kdebase3-SuSE:kdebase3
+Prefer: kde4-kdm:kde4-kdm-branding-upstream
+Prefer: kdm:kdm-branding-upstream
+Prefer: pcre-tools
+Prefer: libpopt0
+Prefer: -apache2-mod_perl -otrs -qa_apache_testsuite -ctcs2
+Prefer: libgnome-keyring-devel
+Prefer: linux-glibc-devel
+Prefer: squid sysvinit
+Prefer: libpng14-compat-devel
+Prefer: -python3 -x11-video-fglrxG02 -libpng12-0
+Prefer: perl-Mail-SPF:perl-Error libldb0 -audit-libs mysql-community-server mysql-community-server-client
+
+#Temporary hack to solve #442202
+Ignore: yast2-all-packages:yast2-boot-server,yast2-heartbeat,yast2-issleconfig,yast2-linux-user-mgmt,yast2-trans-am,yast2-trans-be,yast2-trans-he,yast2-trans-ms,yast2-trans-my,yast2-trans-tk
+
+Ignore: openSUSE-release:openSUSE-release-ftp,openSUSE-release-dvd5,openSUSE-release-biarch,openSUSE-release-livecdkde,openSUSE-release-livecdgnome
+Ignore: cracklib:cracklib-dict
+Ignore: aaa_base:aaa_skel,suse-release,logrotate,ash,mingetty,distribution-release,udev
+Ignore: gettext-tools:libgcj,libstdc++-devel,libgcj41,libstdc++41-devel,libgcj42,libstdc++42-devel
+Ignore: libgcj43,libstdc++43-devel
+Ignore: libgcj44,libstdc++44-devel
+Ignore: libgcj45,libstdc++45-devel
+Ignore: pwdutils:openslp
+Ignore: pam-modules:resmgr
+Ignore: rpm:suse-build-key,build-key
+Ignore: bind-utils:bind-libs
+Ignore: alsa:dialog,pciutils
+Ignore: portmap:syslogd
+Ignore: xorg-x11:x11-tools,resmgr,xkeyboard-config,xorg-x11-Mesa,libusb,freetype2,libjpeg,libpng
+Ignore: xorg-x11-server:xorg-x11-driver-input,xorg-x11-driver-video
+Ignore: apache2:logrotate
+Ignore: arts:alsa,audiofile,resmgr,libogg,libvorbis
+Ignore: kdelibs3:alsa,arts,OpenEXR,aspell,cups-libs,mDNSResponder-lib,krb5,libjasper
+Ignore: kdelibs3-devel:libvorbis-devel
+Ignore: kdebase3:kdebase3-ksysguardd,OpenEXR,dbus-1,dbus-1-qt,hal,powersave,openslp,libusb
+Ignore: kdebase3-SuSE:release-notes
+Ignore: jack:alsa,libsndfile
+Ignore: libxml2-devel:readline-devel
+Ignore: gnome-vfs2:gnome-mime-data,desktop-file-utils,cdparanoia,dbus-1,dbus-1-glib,hal,libsmbclient,fam,file_alteration
+Ignore: libgda:file_alteration
+Ignore: gnutls:lzo,libopencdk
+Ignore: gnutls-devel:lzo-devel,libopencdk-devel
+Ignore: pango:cairo,glitz,libpixman,libpng
+Ignore: pango-devel:cairo-devel
+Ignore: cairo-devel:libpixman-devel
+Ignore: libgnomeprint:libgnomecups
+Ignore: libgnomeprintui:libgnomecups
+Ignore: orbit2-devel:indent
+Ignore: qt3:libmng
+Ignore: qt-sql:qt_database_plugin
+Ignore: gtk2:libpng,libtiff
+Ignore: libgnomecanvas-devel:glib-devel
+Ignore: libgnomeui:gnome-icon-theme,shared-mime-info
+Ignore: scrollkeeper:docbook_4
+Ignore: gnome-desktop:libgnomesu,startup-notification
+Ignore: python-devel:python-tk
+Ignore: gnome-pilot:gnome-panel
+Ignore: gnome-panel:control-center2
+Ignore: gnome-menus:kdebase3
+Ignore: gnome-main-menu:rug
+Ignore: libbonoboui:gnome-desktop
+Ignore: postfix:pcre,libpcre0
+Ignore: docbook_4:iso_ent,xmlcharent
+Ignore: control-center2:nautilus,evolution-data-server,gnome-menus,gstreamer-plugins,gstreamer,metacity,mozilla-nspr,mozilla,libxklavier,gnome-desktop,startup-notification
+Ignore: docbook-xsl-stylesheets:xmlcharent
+Ignore: liby2util-devel:libstdc++-devel,openssl-devel
+Ignore: yast2:yast2-ncurses,yast2_theme,perl-Config-Crontab,yast2-xml,SuSEfirewall2
+Ignore: yast2-core:netcat,hwinfo,wireless-tools,sysfsutils
+Ignore: yast2-core-devel:libxcrypt-devel,hwinfo-devel,blocxx-devel,sysfsutils,libstdc++-devel
+Ignore: yast2-packagemanager-devel:rpm-devel,curl-devel,openssl-devel
+Ignore: yast2-devtools:libxslt
+Ignore: yast2-installation:yast2-update,yast2-mouse,yast2-country,yast2-bootloader,yast2-packager,yast2-network,yast2-online-update,yast2-users,release-notes,autoyast2-installation
+Ignore: yast2-bootloader:bootloader-theme
+Ignore: yast2-packager:yast2-x11
+Ignore: yast2-x11:sax2-libsax-perl
+Ignore: yast2-network:yast2-inetd
+Ignore: openslp-devel:openssl-devel
+Ignore: java-1_4_2-sun:xorg-x11-libs
+Ignore: java-1_4_2-sun-devel:xorg-x11-libs
+Ignore: tetex:xorg-x11-libs,expat,fontconfig,freetype2,libjpeg,ghostscript-x11,xaw3d,gd,dialog,ed
+Ignore: texlive-bin:ghostscript-x11
+Ignore: texlive-bin-omega:ghostscript-x11
+Ignore: yast2-country:yast2-trans-stats
+Ignore: tpb:tpctl-kmp
+Ignore: tpctl:tpctl-kmp
+Ignore: zaptel:zaptel-kmp
+Ignore: mkinitrd:pciutils
+Ignore: pciutils:pciutils-ids
+
+Ignore: libgcc:glibc-32bit
+Ignore: libgcc41:glibc-32bit
+Ignore: libgcc42:glibc-32bit
+Ignore: libgcc43:glibc-32bit
+Ignore: libgcc44:glibc-32bit
+Ignore: libgcc45:glibc-32bit
+Ignore: libstdc++:glibc-32bit
+Ignore: libstdc41++:glibc-32bit
+Ignore: libstdc42++:glibc-32bit
+Ignore: libstdc43++:glibc-32bit
+Ignore: libstdc44++:glibc-32bit
+Ignore: libstdc45++:glibc-32bit
+Ignore: ncurses-32bit
+
+Ignore: susehelp:susehelp_lang,suse_help_viewer
+Ignore: mailx:smtp_daemon
+Ignore: cron:smtp_daemon
+Ignore: hotplug:syslog
+Ignore: pcmcia:syslog
+Ignore: openct:syslog
+Ignore: avalon-logkit:servlet
+Ignore: jython:servlet
+Ignore: ispell:ispell_dictionary,ispell_english_dictionary
+Ignore: aspell:aspel_dictionary,aspell_dictionary
+Ignore: smartlink-softmodem:kernel,kernel-nongpl
+Ignore: OpenOffice_org-de:myspell-german-dictionary
+Ignore: OpenOffice_org:OpenOffice_org-i18n
+Ignore: OpenOffice_org:OpenOffice_org-icon-themes
+Ignore: mediawiki:php-session,php-gettext,php-zlib,php-mysql,mod_php_any
+Ignore: squirrelmail:mod_php_any,php-session,php-gettext,php-iconv,php-mbstring,php-openssl
+
+Ignore: simias:mono(log4net)
+Ignore: zmd:mono(log4net)
+Ignore: horde:mod_php_any,php-gettext,php-mcrypt,php-imap,php-pear-log,php-pear,php-session,php
+
+Ignore: xerces-j2:xml-commons-apis,xml-commons-resolver
+Ignore: xdg-menu:desktop-data
+Ignore: nessus-libraries:nessus-core
+Ignore: evolution:yelp
+
+Ignore: mono-tools:mono(gconf-sharp),mono(glade-sharp),mono(gnome-sharp),mono(gtkhtml-sharp),mono(atk-sharp),mono(gdk-sharp),mono(glib-sharp),mono(gtk-sharp),mono(pango-sharp)
+Ignore: gecko-sharp2:mono(glib-sharp),mono(gtk-sharp)
+
+Ignore: vcdimager:libcdio.so.6,libcdio.so.6(CDIO_6),libiso9660.so.4,libiso9660.so.4(ISO9660_4)
+Ignore: libcdio:libcddb.so.2
+
+Ignore: gnome-libs:libgnomeui
+Ignore: nautilus:gnome-themes
+Ignore: gnome-panel:gnome-themes
+Ignore: gnome-panel:tomboy
+Ignore: NetworkManager:NetworkManager-client
+Ignore: libbeagle:beagle
+Ignore: coreutils:coreutils-lang
+Ignore: cpio:cpio-lang
+Ignore: glib2:glib2-lang
+Ignore: gtk2:gtk2-lang
+Ignore: gtk:gtk-lang
+Ignore: atk:atk-lang
+Ignore: hal:pm-utils
+Ignore: MozillaThunderbird:pinentry-dialog
+Ignore: seamonkey:pinentry-dialog
+Ignore: pinentry:pinentry-dialog
+Ignore: gpg2:gpg2-lang
+Ignore: util-linux:util-linux-lang
+Ignore: suseRegister:distribution-release
+Ignore: compiz:compiz-decorator
+Ignore: icecream:gcc-c++
+Ignore: no
+Ignore: package
+Ignore: provides
+Ignore: j9vm/libjvm.so()(64bit)
+Ignore: kdepim3:suse_help_viewer
+Ignore: kdebase3-SuSE:kdebase3-SuSE-branding
+Ignore: kio_sysinfo:kdebase3-SuSE-branding
+Ignore: gnome-menus:gnome-menus-branding
+Ignore: epiphany:epiphany-branding
+Ignore: phonon:phonon-backend
+Ignore: openwbem-devel
+Ignore: MozillaFirefox:MozillaFirefox-branding
+Ignore: yast2:yast2-branding
+Ignore: yast2-theme-SLE:yast2-branding
+Ignore: yast2-registration:yast2-registration-branding
+Ignore: compiz:compiz-branding
+Ignore: texlive:perl-Tk texlive-bin:perl-Tk
+Ignore: xfce4-desktop:xfce4-desktop-branding
+Ignore: xfce4-panel:xfce4-panel-branding
+Ignore: xfce4-session:xfce4-session-branding
+Ignore: kdebase4-runtime:kdebase4-runtime-branding
+Ignore: pulseaudio:kernel
+Ignore: transmission-common:transmission-ui
+Ignore: mutter-moblin:moblin-branding
+Ignore: sysvinit-tools:mkinitrd cifs-utils:mkinitrd
+Ignore: opensc:pinentry
+Ignore: gpg2:pinentry
+Ignore: NetworkManager:dhcp
+# sysconfig requires it at runtime, not buildtime
+Ignore: sysconfig:dbus-1
+Ignore: sysconfig:procps
+Ignore: sysconfig:iproute2
+# no build dependencies
+Ignore: libksuseinstall1:yast2-packager
+Ignore: libksuseinstall1:zypper
+Ignore: libqca2:gpg2
+Ignore: NetworkManager:wpa_supplicant
+Ignore: NetworkManager:dhcp-client
+
+%ifnarch ia64 s390 s390x
+Prefer: java-1_6_0-openjdk java-1_6_0-openjdk-devel
+%endif
+%ifarch s390 s390x
+Prefer: java-1_6_0-ibm java-1_6_0-ibm-devel
+%endif
+%ifarch ia64
+Prefer: java-1_6_0-bea java-1_6_0-bea-devel
+%endif
+
+Prefer: -java-1_5_0-gcj-compat-devel
+%ifarch %ix86 x86_64
+Prefer: -java-1_5_0-ibm-devel
+%endif
+# We use always openjdk on openSUSE !
+#%ifnarch ia64 s390 s390x
+Substitute: java2-devel-packages java-1_6_0-openjdk-devel
+#%else
+# %ifarch s390 s390x
+#Substitute: java2-devel-packages java-1_6_0-ibm-devel unzip update-alternatives
+# %endif
+# %ifarch ia64
+#Substitute: java2-devel-packages java-1_6_0-bea-devel unzip update-alternatives
+# %endif
+#%endif
+
+%ifarch x86_64 ppc64 s390x sparc64
+Substitute: glibc-devel-32bit glibc-devel-32bit glibc-32bit
+%else
+ %ifarch ppc
+Substitute: glibc-devel-32bit glibc-devel-64bit
+ %else
+Substitute: glibc-devel-32bit
+ %endif
+%endif
+
+%ifarch %ix86
+Substitute: kernel-binary-packages kernel-default kernel-smp kernel-bigsmp kernel-debug kernel-xen
+%endif
+%ifarch ia64
+Substitute: kernel-binary-packages kernel-default kernel-debug
+%endif
+%ifarch x86_64
+Substitute: kernel-binary-packages kernel-default kernel-smp kernel-xen
+%endif
+%ifarch ppc
+Substitute: kernel-binary-packages kernel-default kernel-ppc64 kernel-ps3
+%endif
+%ifarch ppc64
+Substitute: kernel-binary-packages kernel-default kernel-ppc64
+%endif
+%ifarch s390
+Substitute: kernel-binary-packages kernel-s390
+%endif
+%ifarch s390x
+Substitute: kernel-binary-packages kernel-default
+%endif
+
+# until the builds of the packages are fixed...
+Substitute: yast2-theme-SLED
+Substitute: yast2-theme-SLE
+
+Optflags: i586 -fomit-frame-pointer -fmessage-length=0
+Optflags: i686 -march=i686 -mtune=generic -fomit-frame-pointer -fmessage-length=0
+Optflags: x86_64 -fmessage-length=0
+Optflags: ppc -fmessage-length=0
+Optflags: ppc64 -fmessage-length=0
+Optflags: ia64 -fmessage-length=0
+Optflags: s390 -fmessage-length=0
+Optflags: s390x -fmessage-length=0
+
+Optflags: * -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector -funwind-tables -fasynchronous-unwind-tables
+
+%define suse_version 1130
+
+Macros:
+%insserv_prereq insserv sed
+%fillup_prereq fillup coreutils grep diffutils
+%suseconfig_fonts_prereq perl aaa_base
+%install_info_prereq info
+%kernel_module_package_buildreq module-init-tools kernel-syms
+%kernel_module_package_buildreqs module-init-tools kernel-syms
+
+%suse_version 1130
+%sles_version 0
+%ul_version 0
+%do_profiling 1
+%_vendor suse
--- createrepomddeps
+++ createrepomddeps
@@ -57,11 +57,12 @@
 	'rpm:obsoletes' => { 'rpm:entry' => { _start => \&primary_handle_package_obsoletes }, },
 	'rpm:buildhost' => { _text => \&primary_collect_text, _end => \&primary_store_text },
 	'rpm:sourcerpm' => { _text => \&primary_collect_text, _end => \&primary_store_text },
-	file => {
-	  _start => \&primary_handle_file_start,
-	  _text => \&primary_collect_text,
-	  _end => \&primary_handle_file_end
-	},
+### currently commented out, as we ignore file provides in createrpmdeps
+#	file => {
+#	  _start => \&primary_handle_file_start,
+#	  _text => \&primary_collect_text,
+#	  _end => \&primary_handle_file_end
+#	},
       },
       location => { _start => \&primary_handle_package_location },
     },
@@ -398,8 +399,9 @@
   } elsif ($url =~ /^http:\/\/([^\/]*)\/?/) {
     my $repoid = md5_hex($url);
     $dir = "$cachedir/$repoid/";
-    getmetadata($url, $dir);
     $baseurl = $url;
+    $baseurl .= '/' unless $baseurl =~ /\/$/;
+    getmetadata($baseurl, $dir);
   } else {
     $dir = $url;
     $dir .= '/' unless $dir =~ /\/$/;
@@ -418,12 +420,20 @@
 
     my $u = $dir . $f->{'location'};
     if ($url =~ /^http:\/\/([^\/]*)\/?/) {
-        system($INC[0].'/download', $dir . "repodata/", $baseurl . "repodata/" . basename($u));
+        if (system($INC[0].'/download', $dir . "repodata/", $baseurl . "repodata/" . basename($u))) {
+	  die("download failed\n");
+	}
+    }
+    if ($] > 5.007) {
+	require Encode;
+	utf8::downgrade($u);
     }
-    $u = 'gzip -cd ' . $u . '|' if ($u =~ /\.gz$/); # XXX
-
     my $fh;
-    open($fh, $u) or next;
+    open($fh, '<', $u) or die "Error opening $u: $!\n";
+    if ($u =~ /\.gz$/) {
+	use IO::Uncompress::Gunzip qw($GunzipError);
+	$fh = new IO::Uncompress::Gunzip $fh or die "Error opening $u: $GunzipError\n";
+    }
     $p->parse($fh);
     close($fh);
   }
--- download
+++ download
@@ -21,7 +21,6 @@
   timeout => 42);
 
 for my $url (@ARGV) {
-  my $dest = $dir;
   if ($url =~ /^zypp:\/\/([^\/]*)\/?/) {
     use Build::Zypp;
     my $repo = Build::Zypp::parsecfg($1);
@@ -34,8 +33,16 @@
   } else {
     $url = URI->new($url);
   }
-  my $res = $ua->mirror($url, $dest.'/'.basename($url->path));
-  die "reqesting $url failed: ".$res->status_line."\n" unless $res->is_success;
+  my $dest = "$dir/".basename($url->path);
+  unlink($dest);	# just in case
+  my $retry = 3;
+  while ($retry--) {
+    my $res = $ua->mirror($url, $dest);
+    last if $res->is_success;
+    # if it's a redirect we probably got a bad mirror and should just retry
+    die "reqesting $url failed: ".$res->status_line."\n" unless $retry && $res->previous;
+    warn "retrying $url\n";
+  }
 }
 
 # vim:sw=2
--- expanddeps
+++ expanddeps
@@ -101,42 +101,17 @@
   $packs{$_} ||= "$_.$arch" for @{$packs_arch{$arch} || []};
 }
 
-for my $pack (keys %packs) {
-  my $r = {};
-  my (@s, $s, @pr, @re);
-  @s = split(' ', $prov{$packs{$pack}});
-  while (@s) {
-    $s = shift @s;
-    next if $s =~ /^\//;
-    if ($s =~ /^rpmlib\(/) {
-      splice(@s, 0, 2);
-      next;
-    }
-    push @pr, $s;
-    splice(@s, 0, 2) if @s && $s[0] =~ /^[<=>]/;
-  }
-  @s = split(' ', $req{$packs{$pack}});
-  while (@s) {
-    $s = shift @s;
-    next if $s =~ /^\//;
-    if ($s =~ /^rpmlib\(/) {
-      splice(@s, 0, 2);
-      next;
-    }
-    push @re, $s;
-    splice(@s, 0, 2) if @s && $s[0] =~ /^[<=>]/;
-  }
-  $r->{'provides'} = \@pr;
-  $r->{'requires'} = \@re;
-  $repo{$pack} = $r;
-}
-
 if (!defined($dist) || $dist eq '') {
   my $rpmarch = (grep {$fn{"rpm.$_"}} @archs)[0];
   if (!$rpmarch) {
     $dist = 'default';
   } else {
     my $rpmfn = $fn{"rpm.$rpmarch"};
+    if ($rpmfn =~ /^[a-z]+:\/\//) {
+      require File::Temp;
+      my $tmpdir = File::Temp::tempdir('CLEANUP' => 1);
+      $rpmfn =~ s/.*\//$tmpdir\// unless system("$INC[0]/download", $tmpdir, $rpmfn);
+    }
     my $rpmdist = '';
     if ($rpmfn =~ /^\// && -e $rpmfn) {
       my %res = Build::Rpm::rpmq($rpmfn, 1010);
@@ -145,9 +120,14 @@
     $rpmdist = lc($rpmdist);
     $rpmdist =~ s/-/_/g;
     $rpmdist =~ s/opensuse/suse linux/;
-    my $rpmdista = $rpmdist;
-    $rpmdista =~ s/.*\(//;
-    $rpmdista =~ s/\).*//;
+    my $rpmdista;
+    if ($rpmdist =~ /\(/) {
+      $rpmdista = $rpmdist;
+      $rpmdista =~ s/.*\(//;
+      $rpmdista =~ s/\).*//;
+    } else {
+      $rpmdista = $archs[0];
+    }
     $rpmdista =~ s/i[456]86/i386/;
     $rpmdist = '' unless $rpmdista =~ /^(i386|x86_64|ia64|ppc|ppc64|s390|s390x)$/;
     if ($rpmdist =~ /unitedlinux 1\.0.*/) {
@@ -171,6 +151,39 @@
 my $cf = Build::read_config_dist($dist, $archs[0], $configdir);
 $cf->{'warnings'} = 1;
 
+my $dofileprovides = %{$cf->{'fileprovides'}};
+
+for my $pack (keys %packs) {
+  my $r = {};
+  my (@s, $s, @pr, @re);
+  @s = split(' ', $prov{$packs{$pack}});
+  while (@s) {
+    $s = shift @s;
+    next if !$dofileprovides && $s =~ /^\//;
+    if ($s =~ /^rpmlib\(/) {
+      splice(@s, 0, 2);
+      next;
+    }
+    push @pr, $s;
+    splice(@s, 0, 2) if @s && $s[0] =~ /^[<=>]/;
+  }
+  @s = split(' ', $req{$packs{$pack}});
+  while (@s) {
+    $s = shift @s;
+    next if !$dofileprovides && $s =~ /^\//;
+    if ($s =~ /^rpmlib\(/) {
+      splice(@s, 0, 2);
+      next;
+    }
+    push @re, $s;
+    splice(@s, 0, 2) if @s && $s[0] =~ /^[<=>]/;
+  }
+  $r->{'provides'} = \@pr;
+  $r->{'requires'} = \@re;
+  $repo{$pack} = $r;
+}
+
+
 #######################################################################
 
 sub print_rpmlist
@@ -181,6 +194,8 @@
   }
   print "preinstall: @{$cf->{'preinstall'} || []}\n";
   print "vminstall: @{$cf->{'vminstall'} || []}\n";
+  print "cbpreinstall: @{$cf->{'cbpreinstall'} || []}\n"; # preinstall if is_emulator_arch
+  print "cbinstall: @{$cf->{'cbinstall'} || []}\n";       # install if is_emulator_arch
   print "runscripts: @{$cf->{'runscripts'} || []}\n";
   print "dist: $dist\n" if defined $dist;
 }
--- getchangetarget
+++ getchangetarget
@@ -8,7 +8,7 @@
 
 use Build;
 
-my ($dist, $archs, $configdir, $debug);
+my ($dist, $archs, $configdir);
 
 while (@ARGV)  {
   if ($ARGV[0] eq '--dist') {
@@ -26,18 +26,10 @@
     $configdir = shift @ARGV;
     next;
   }
-  if ($ARGV[0] eq '--debug') {
-    shift @ARGV;
-    $debug = 1;
-    next;
-  }
   last;
 }
 
-die("Usage: getchangetargetarch --dist <dist> --archpath <archpath> [--configdir <configdir>]\n") if @ARGV;
+die("Usage: getchangetarget --dist <dist> --archpath <archpath> [--configdir <configdir>]\n") if @ARGV;
 
 my $cf = Build::read_config_dist($dist, $archs, $configdir);
-exit 0 unless $cf->{'changetarget'};
-my $target = $cf->{'changetarget'};
-$target = defined($target) && $target ne '' ? "$target" : '';
-print "$target";
+print "$cf->{'target'}\n" if $cf->{'target'};
--- init_buildsystem
+++ init_buildsystem
@@ -91,7 +91,8 @@
 # needed functions
 #
 
-function cleanup_and_exit {
+cleanup_and_exit()
+{
     trap EXIT
     [ "$BUILD_ROOT" != / ] || chown $browner $BUILD_ROOT
     # umount so init_buildsystem can be used standalone
@@ -103,7 +104,8 @@
     exit ${1:-0}
 }
 
-function clean_build_root () {
+clean_build_root()
+{
 	test -n "$BUILD_ROOT" && {
 	    umount -n $BUILD_ROOT/proc/sys/fs/binfmt_misc 2> /dev/null || true
 	    umount -n $BUILD_ROOT/proc 2> /dev/null || true
@@ -122,76 +124,84 @@
 	}
 }
 
-function preinstall {
+preinstall()
+{
     check_exit
-    if test -n "$1" ; then
-	echo "preinstalling $1..."
-	cd $BUILD_ROOT || cleanup_and_exit 1
-	CPIO="cpio --extract --unconditional --preserve-modification-time --make-directories --no-absolute-filenames --quiet"
-	if test -e "$BUILD_ROOT/.init_b_cache/rpms/$1.rpm" ; then
-	    PAYLOADDECOMPRESS=cat
-	    case `rpm -qp --nodigest --nosignature --qf "%{PAYLOADCOMPRESSOR}\n" "$BUILD_ROOT/.init_b_cache/rpms/$1.rpm"` in
-		lzma) rpm --showrc | grep PayloadIsLzma > /dev/null || PAYLOADDECOMPRESS="lzma -d" ;;
-		xz) rpm --showrc | grep PayloadIsXz > /dev/null || PAYLOADDECOMPRESS="xz -d" ;;
-	    esac
-	    if test "$PAYLOADDECOMPRESS" = "lzma -d" ; then
-		if ! lzma </dev/null >/dev/null 2>&1 ; then
-		    test -f "$BUILD_DIR/lzmadec.sh" && PAYLOADDECOMPRESS="bash $BUILD_DIR/lzmadec.sh"
-		fi
-	    fi
-	    if test "$PAYLOADDECOMPRESS" = cat ; then
-		rpm2cpio "$BUILD_ROOT/.init_b_cache/rpms/$1.rpm" | $CPIO
-	    else
-		rpm2cpio "$BUILD_ROOT/.init_b_cache/rpms/$1.rpm" | $PAYLOADDECOMPRESS | $CPIO
+    echo "preinstalling $1..."
+    cd $BUILD_ROOT || cleanup_and_exit 1
+    CPIO="cpio --extract --unconditional --preserve-modification-time --make-directories --no-absolute-filenames --quiet"
+    if test -e "$BUILD_ROOT/.init_b_cache/rpms/$1.rpm" ; then
+	PAYLOADDECOMPRESS=cat
+	case `rpm -qp --nodigest --nosignature --qf "%{PAYLOADCOMPRESSOR}\n" "$BUILD_ROOT/.init_b_cache/rpms/$1.rpm"` in
+	    lzma) rpm --showrc | grep PayloadIsLzma > /dev/null || PAYLOADDECOMPRESS="lzma -d" ;;
+	    xz) rpm --showrc | grep PayloadIsXz > /dev/null || PAYLOADDECOMPRESS="xz -d" ;;
+	esac
+	if test "$PAYLOADDECOMPRESS" = "lzma -d" ; then
+	    if ! lzma </dev/null >/dev/null 2>&1 ; then
+		test -f "$BUILD_DIR/lzmadec.sh" && PAYLOADDECOMPRESS="bash $BUILD_DIR/lzmadec.sh"
 	    fi
-	    if test -e .init_b_cache/scripts/$1.run ; then
-		rpm -qp --nodigest --nosignature --qf "%{PREIN}" "$BUILD_ROOT/.init_b_cache/rpms/$1.rpm" > .init_b_cache/scripts/$1.pre
-		rpm -qp --nodigest --nosignature --qf "%{POSTIN}" "$BUILD_ROOT/.init_b_cache/rpms/$1.rpm" > .init_b_cache/scripts/$1.post
-		echo -n '(none)' > .init_b_cache/scripts/.none
-		cmp -s .init_b_cache/scripts/$1.pre .init_b_cache/scripts/.none && rm -f .init_b_cache/scripts/$1.pre
-		cmp -s .init_b_cache/scripts/$1.post .init_b_cache/scripts/.none && rm -f .init_b_cache/scripts/$1.post
-		rm -f .init_b_cache/scripts/.none
-	    fi
-	elif test -e "$BUILD_ROOT/.init_b_cache/rpms/$1.deb" ; then
-	    ar x "$BUILD_ROOT/.init_b_cache/rpms/$1.deb" control.tar.gz data.tar.gz
-	    mkdir -p .init_b_cache/scripts/control
-	    tar -C .init_b_cache/scripts/control -xzf control.tar.gz
-	    tar xzf data.tar.gz
-	    if test -e .init_b_cache/scripts/$1.run ; then
-		test -e .init_b_cache/scripts/control/preinst && mv .init_b_cache/scripts/control/preinst .init_b_cache/scripts/$1.pre
-		test -e .init_b_cache/scripts/control/postinst && mv .init_b_cache/scripts/control/postinst .init_b_cache/scripts/$1.post
+	fi
+	if test "$PAYLOADDECOMPRESS" = "xz -d" ; then
+	    if ! xz </dev/null >/dev/null 2>&1 ; then
+		test -f "$BUILD_DIR/xzdec.sh" && PAYLOADDECOMPRESS="bash $BUILD_DIR/xzdec.sh"
 	    fi
-	    rm -rf .init_b_cache/scripts/control control.tar.gz data.tar.gz
+	fi
+	if test "$PAYLOADDECOMPRESS" = cat ; then
+	    rpm2cpio "$BUILD_ROOT/.init_b_cache/rpms/$1.rpm" | $CPIO
 	else
-	    echo "warning: package $1 does not exist"
+	    rpm2cpio "$BUILD_ROOT/.init_b_cache/rpms/$1.rpm" | $PAYLOADDECOMPRESS | $CPIO
 	fi
+	if test -e .init_b_cache/scripts/$1.run ; then
+	    rpm -qp --nodigest --nosignature --qf "%{PREIN}" "$BUILD_ROOT/.init_b_cache/rpms/$1.rpm" > .init_b_cache/scripts/$1.pre
+	    rpm -qp --nodigest --nosignature --qf "%{POSTIN}" "$BUILD_ROOT/.init_b_cache/rpms/$1.rpm" > .init_b_cache/scripts/$1.post
+	    echo -n '(none)' > .init_b_cache/scripts/.none
+	    cmp -s .init_b_cache/scripts/$1.pre .init_b_cache/scripts/.none && rm -f .init_b_cache/scripts/$1.pre
+	    cmp -s .init_b_cache/scripts/$1.post .init_b_cache/scripts/.none && rm -f .init_b_cache/scripts/$1.post
+	    rm -f .init_b_cache/scripts/.none
+	fi
+    elif test -e "$BUILD_ROOT/.init_b_cache/rpms/$1.deb" ; then
+	ar x "$BUILD_ROOT/.init_b_cache/rpms/$1.deb" control.tar.gz data.tar.gz
+	mkdir -p .init_b_cache/scripts/control
+	tar -C .init_b_cache/scripts/control -xzf control.tar.gz
+	tar xzf data.tar.gz
+	if test -e .init_b_cache/scripts/$1.run ; then
+	    test -e .init_b_cache/scripts/control/preinst && mv .init_b_cache/scripts/control/preinst .init_b_cache/scripts/$1.pre
+	    test -e .init_b_cache/scripts/control/postinst && mv .init_b_cache/scripts/control/postinst .init_b_cache/scripts/$1.post
+	fi
+	rm -rf .init_b_cache/scripts/control control.tar.gz data.tar.gz
+    else
+	echo "warning: package $1 does not exist"
     fi
-    if test -n "$2" ; then
-	chroot $BUILD_ROOT /sbin/ldconfig 2>/dev/null
-	for PKG in $PACKAGES_TO_RUNSCRIPTS ; do
-	    if test -e "$BUILD_ROOT/.init_b_cache/scripts/$PKG.pre" ; then
-		echo "running $PKG preinstall script"
-		if test -e "$BUILD_ROOT/.init_b_cache/rpms/$PKG.rpm" ; then
-		    chroot $BUILD_ROOT sh ".init_b_cache/scripts/$PKG.pre" 0
-		else
-		    chroot $BUILD_ROOT ".init_b_cache/scripts/$PKG.pre" install < /dev/null
-		fi
-		rm -f "$BUILD_ROOT/.init_b_cache/scripts/$PKG.pre"
-	    fi
-	    if test -e "$BUILD_ROOT/.init_b_cache/scripts/$PKG.post" ; then
-		echo "running $PKG postinstall script"
-		if test -e "$BUILD_ROOT/.init_b_cache/rpms/$PKG.rpm" ; then
-		    chroot $BUILD_ROOT sh ".init_b_cache/scripts/$PKG.post" 1
-		else
-		    chroot $BUILD_ROOT ".init_b_cache/scripts/$PKG.post" configure '' < /dev/null
-		fi
-		rm -f "$BUILD_ROOT/.init_b_cache/scripts/$PKG.post"
+}
+
+run_pkg_scripts()
+{
+    chroot $BUILD_ROOT /sbin/ldconfig 2>/dev/null
+    for PKG in $PACKAGES_TO_RUNSCRIPTS ; do
+	if test -e "$BUILD_ROOT/.init_b_cache/scripts/$PKG.pre" ; then
+	    echo "running $PKG preinstall script"
+	    if test -e "$BUILD_ROOT/.init_b_cache/rpms/$PKG.rpm" ; then
+		chroot $BUILD_ROOT sh ".init_b_cache/scripts/$PKG.pre" 0
+	    else
+		chroot $BUILD_ROOT ".init_b_cache/scripts/$PKG.pre" install < /dev/null
 	    fi
-	done
-    fi
+	    rm -f "$BUILD_ROOT/.init_b_cache/scripts/$PKG.pre"
+	fi
+	if test -e "$BUILD_ROOT/.init_b_cache/scripts/$PKG.post" ; then
+	    echo "running $PKG postinstall script"
+	    if test -e "$BUILD_ROOT/.init_b_cache/rpms/$PKG.rpm" ; then
+		chroot $BUILD_ROOT sh ".init_b_cache/scripts/$PKG.post" 1
+	    else
+		chroot $BUILD_ROOT ".init_b_cache/scripts/$PKG.post" configure '' < /dev/null
+	    fi
+	    rm -f "$BUILD_ROOT/.init_b_cache/scripts/$PKG.post"
+	fi
+	check_exit
+    done
 }
 
-function init_db {
+init_db()
+{
     if test $PSUF = rpm ; then
 	echo initializing rpm db...
 	chroot $BUILD_ROOT rpm --initdb || cleanup_and_exit 1
@@ -209,7 +219,8 @@
     fi
 }
 
-function reorder {
+reorder()
+{
     test -z "$*" && return
     rm -f $BUILD_ROOT/.init_b_cache/order.manifest
     for PKG in "$@" ; do
@@ -219,7 +230,8 @@
     rm -f $BUILD_ROOT/.init_b_cache/order.manifest
 }
 
-function create_devs {
+create_devs()
+{
     local com file mode arg
 
     mkdir -m 755 -p $BUILD_ROOT/dev/pts
@@ -259,10 +271,10 @@
     r=()
     for i in "${repos[@]}"; do
 	if [ "$i" = "zypp://" ]; then
-	    for j in `grep -l enabled=1 /etc/zypp/repos.d/*.repo`; do
+	    while read j; do
 		j="${j#/etc/zypp/repos.d/}"
 		r=("${r[@]}" "zypp://${j%.repo}")
-	    done
+	    done < <(grep -l enabled=1 /etc/zypp/repos.d/*.repo)
 	else
 	    r=("${r[@]}" "$i")
 	fi
@@ -270,15 +282,25 @@
     repos=("${r[@]}")
 }
 
-function validate_cache_file {
+validate_cache_file()
+{
     local findonly=''
     maybe_add_all_zypp_repos
-    test "${repos[*]} ${BUILD_RPMS//:/ /}" != "$(cat $CACHE_FILE.id 2>/dev/null)" && rm -f $CACHE_FILE.id
-    test -f $CACHE_FILE || rm -f $CACHE_FILE.id
-    for SRC in "${repos[@]}" ${BUILD_RPMS//:/ /}; do
-	test -z "$SRC" && SRC=.
-	test "$SRC" -nt $CACHE_FILE && rm -f $CACHE_FILE.id
-    done
+    if ! test -f $CACHE_FILE || ! test -f $CACHE_FILE.id || \
+	test "${repos[*]} ${BUILD_RPMS//:/ /}" != "$(cat $CACHE_FILE.id 2>/dev/null)"; then
+	rm -f $CACHE_FILE.id
+    else
+	for SRC in "${repos[@]}" ${BUILD_RPMS//:/ /}; do
+	    test -n "$SRC" || SRC=.
+	    if [ "${SRC#zypp://}" != "$SRC" ]; then
+		SRC="/var/cache/zypp/raw" # XXX can't use name here as we'd need to parse the file
+	    fi
+	    if test "$SRC" -nt $CACHE_FILE; then
+		rm -f $CACHE_FILE.id
+		break
+	    fi
+	done
+    fi
     if ! test -f $CACHE_FILE.id ; then
 	test -z "$LIST_STATE" && echo initializing $CACHE_FILE ...
 	for SRC in "${repos[@]}" -- ${BUILD_RPMS//:/ /}; do
@@ -324,9 +346,11 @@
     # To initially run the init script, there needs to be also a
     # static bash to register qemu in this chroot and to start up
     # /.build/build
-    mkdir -p  $BUILD_ROOT/bin
-    install -m755 /bin/bash-static $BUILD_ROOT/bin
-    install -m755 /bin/mount-static $BUILD_ROOT/bin
+    if [ -n "$PREPARE_VM" ]; then
+	mkdir -p  $BUILD_ROOT/bin
+	install -m755 /bin/bash-static $BUILD_ROOT/bin
+	install -m755 /bin/mount-static $BUILD_ROOT/bin
+    fi
 }
 
 check_binfmt_registered()
@@ -354,7 +378,7 @@
     if [ "${url:0:7}" == "zypp://" ] ; then
 	cachedir="/var/cache/zypp/packages/"
 	SRC="$cachedir${url#zypp://}"
-	mkdir -p "$(dirname $SRC)"
+	mkdir -p "${SRC%/*}" || cleanup_and_exit 1
     elif [ "${url:0:7}" == "http://" -o "${url:0:8}" == "https://" -o "${url:0:6}" == "ftp://" -o "${url:0:7}" == "ftps://" ] ; then
 	cachedir="$(getcachedir "$url")"
 	local name="$(basename "$url")"
@@ -457,7 +481,7 @@
     . $BUILD_ROOT/.build/init_buildsystem.data
     if ! test -e $BUILD_ROOT/.init_b_cache/preinstall_finished ; then
 	# finish preinstall
-	preinstall '' true
+	run_pkg_scripts
 	init_db
 	touch $BUILD_ROOT/.init_b_cache/preinstall_finished
     fi
@@ -491,6 +515,7 @@
 	while read PKG SRC ; do
 	   test "$PKG" = "preinstall:" && continue
 	   test "$PKG" = "runscripts:" && continue
+	   test "$PKG" = "cbpreinstall:" && continue
 	   test "$PKG" = "vminstall:" && continue
 	   test "$PKG" = "dist:" && continue
 	   test "$PKG" = "rpmid:" && continue
@@ -521,6 +546,8 @@
     PACKAGES_TO_PREINSTALL=
     PACKAGES_TO_RUNSCRIPTS=
     PACKAGES_TO_VMINSTALL=
+    PACKAGES_TO_CBPREINSTALL=
+    PACKAGES_TO_CBINSTALL=
     RUNSCRIPTS_SEEN=
     GUESSED_DIST=unknown
     mkdir -p $BUILD_ROOT/.init_b_cache/rpms
@@ -533,6 +560,20 @@
 	    PACKAGES_TO_VMINSTALL=$SRC
 	    continue
 	fi
+	# these additional preinstall / install values are only set for 
+	# emulated "CrossBuild" setups - thus CB(pre)install
+	if test "$PKG" = "cbpreinstall:" ; then
+	    if is_emulator_arch ; then
+		PACKAGES_TO_CBPREINSTALL=$SRC
+	    fi
+	    continue
+	fi
+	if test "$PKG" = "cbinstall:" ; then
+	    if is_emulator_arch ; then
+		PACKAGES_TO_CBINSTALL=$SRC
+	    fi
+	    continue
+	fi
 	if test "$PKG" = "runscripts:" ; then
 	    RUNSCRIPTS_SEEN=true
 	    PACKAGES_TO_RUNSCRIPTS=$SRC
@@ -546,6 +587,10 @@
 	    echo "${SRC#*:}" > $BUILD_ROOT/.init_b_cache/rpms/${SRC%%:*}.id
 	    continue
 	fi
+	if test "$PKG" != "${PKG%:}"; then
+	    echo "Warning: ignoring unsupported tag '$PKG'" >&2
+	    continue
+	fi
 	if [ "${SRC#/}" = "$SRC" ]; then
 	    url="$SRC"
 	    case "$url" in
@@ -553,7 +598,7 @@
 		    downloadpkg "$url"
 		    ;;
 		*)
-		    echo "unsupported url: $url" >&2
+		    echo "unsupported url for '$PKG': $url" >&2
 		    cleanup_and_exit 1
 		    ;;
 	    esac
@@ -563,10 +608,13 @@
 	PACKAGES_TO_INSTALL="$PACKAGES_TO_INSTALL $PKG"
     done < $RPMLIST
 
+    test -n "$PACKAGES_TO_CBPREINSTALL" && echo "cbpreinstall: $PACKAGES_TO_CBPREINSTALL"
+    test -n "$PACKAGES_TO_CBINSTALL" && echo "cbinstall   : $PACKAGES_TO_CBINSTALL"
     # compatibility...
     test -z "$RUNSCRIPTS_SEEN" && PACKAGES_TO_RUNSCRIPTS="$PACKAGES_TO_PREINSTALL"
 
     echo "$GUESSED_DIST" > $BUILD_ROOT/.guessed_dist
+    test -n "$BUILD_DIST" || BUILD_DIST="$GUESSED_DIST"
     PSUF=rpm
     test -L $BUILD_ROOT/.init_b_cache/rpms/rpm.rpm || PSUF=deb
 fi
@@ -601,13 +649,17 @@
 	    preinstall ${PKG##*/}
 	done
     fi
+    # add cbpreinstall if cross HOST != TARGET
+    for PKG in $PACKAGES_TO_CBPREINSTALL ; do
+        preinstall ${PKG##*/}
+    done
     if [ -w /root ]; then
 	    test -c $BUILD_ROOT/dev/null || create_devs
     fi
     test -e $BUILD_ROOT/etc/fstab || touch $BUILD_ROOT/etc/fstab
     test -e $BUILD_ROOT/etc/ld.so.conf || cp $BUILD_ROOT/etc/ld.so.conf.in $BUILD_ROOT/etc/ld.so.conf
     if test -z "$PREPARE_VM" ; then
-	preinstall '' true
+	run_pkg_scripts
 	init_db
 	touch $BUILD_ROOT/.init_b_cache/preinstall_finished
     fi
@@ -706,7 +758,7 @@
     test "$PKG" = "*" && continue
     ln $BUILD_ROOT/.init_b_cache/alreadyinstalled/$PKG $BUILD_ROOT/.init_b_cache/todelete/$PKG
 done
-for PKG in $PACKAGES_TO_INSTALL_FIRST $PACKAGES_TO_INSTALL ; do
+for PKG in $PACKAGES_TO_INSTALL_FIRST $PACKAGES_TO_INSTALL $PACKAGES_TO_CBINSTALL ; do
     rm -f $BUILD_ROOT/.init_b_cache/todelete/$PKG
 done
 for PKG in $BUILD_ROOT/.init_b_cache/todelete/* ; do
@@ -720,7 +772,7 @@
 
 rm -rf $BUILD_ROOT/.init_b_cache/preinstalls
 mkdir -p $BUILD_ROOT/.init_b_cache/preinstalls
-for PKG in $PACKAGES_TO_PREINSTALL ; do
+for PKG in $PACKAGES_TO_PREINSTALL $PACKAGES_TO_CBPREINSTALL; do
     touch "$BUILD_ROOT/.init_b_cache/preinstalls/$PKG"
 done
 
@@ -734,7 +786,7 @@
 test -x $BUILD_ROOT/usr/bin/rpmsign && RPMCHECKOPTS="--nodigest --nosignature"
 test -x /usr/bin/rpmsign && RPMCHECKOPTS_HOST="--nodigest --nosignature"
 
-for PKG in $PACKAGES_TO_INSTALL_FIRST RUN_LDCONFIG $PACKAGES_TO_INSTALL ; do
+for PKG in $PACKAGES_TO_INSTALL_FIRST RUN_LDCONFIG $PACKAGES_TO_INSTALL $PACKAGES_TO_CBINSTALL; do
 
     case $PKG in
       RUN_LDCONFIG)
@@ -799,7 +851,10 @@
 	fi
 	if test -e "$BUILD_ROOT/.init_b_cache/preinstalls/$PKG" ; then
 	    preinstall "$PKG"
-	    test rpm = "$PKG" && chroot $BUILD_ROOT rpm --rebuilddb
+	    # call for rpm-4.x and not rpm-devel
+	    test -z "${PKG##rpm-[0-9]*}" && chroot $BUILD_ROOT rpm --rebuilddb
+	    # also exec for exchanged rpm !  naming is rpm-x86-<target>-<ver>
+	    test -z "${PKG##rpm-x86-*[0-9]*}" && chroot $BUILD_ROOT rpm --rebuilddb
 	fi
     fi
     export ADDITIONAL_PARAMS=
--- makedeltarpms
+++ makedeltarpms
+#!/usr/bin/perl -w
+
+BEGIN {
+  unshift @INC, ($::ENV{'BUILD_DIR'} || '/usr/lib/build');
+}
+
+use Build;
+use strict;
+
+my %oldpkgs;
+
+sub query
+{
+    my $file = shift;
+    return undef if $file =~ /\.(?:patch|delta)\.rpm$/; # XXX: rpmtags?
+    my %res = Build::Rpm::rpmq($file, qw/NAME VERSION RELEASE ARCH SOURCERPM NOSOURCE NOPATCH 1124/);
+    return undef unless %res;
+    return undef if $res{'1124'}->[0] && $res{'1124'}->[0] eq 'drpm';
+    my $arch;
+    if ($res{'SOURCERPM'}->[0]) {
+	$arch = $res{'ARCH'}->[0];
+    } else {
+#	if ($res{'NOSOURCE'}->[0] || $res{'NOPATCH'}->[0]) {
+#	    $arch = 'nosrc';
+#	} else {
+#	    $arch = 'src';
+#	}
+	return undef;
+    }
+    return { name => $res{'NAME'}->[0], file => $file, version => $res{'VERSION'}->[0], release => $res{'RELEASE'}->[0], arch => $arch};
+}
+
+my $prevbuild = shift @ARGV || die "USAGE: $0 <oldpkgdir> <directories...>";
+my @prevbuild = ($prevbuild);
+my $i = 1;
+while (-e $prevbuild.$i) {
+    push @prevbuild, $prevbuild.$i;
+    ++$i;
+}
+for my $dir (@prevbuild) {
+    for my $file (glob $dir.'/*.rpm') {
+	my $q = query($file);
+	next unless $q;
+	my $n = $q->{'name'}.'.'.$q->{'arch'};
+	push @{$oldpkgs{$n}}, $q;
+    }
+}
+
+my $sysret = 0;
+for my $dir (@ARGV) {
+    for my $file (glob $dir.'/*.rpm') {
+	my $q = query($file);
+	next unless $q;
+	my $n = $q->{'name'}.'.'.$q->{'arch'};
+	next unless exists $oldpkgs{$n};
+	for my $old (@{$oldpkgs{$n}}) {
+	    my $v = $old->{'version'};
+	    my $r = $old->{'release'};
+	    if ($v eq $q->{'version'} && $r eq $q->{'release'}) {
+		# skip if same version and release
+		next;
+	    }
+	    $v .= '_'.$q->{'version'} unless $v eq $q->{'version'};
+	    $r .= '_'.$q->{'release'} unless $r eq $q->{'release'};
+	    my $on = $old->{'file'};
+	    my $nn = $q->{'file'};
+	    my $dn = sprintf("%s-%s-%s.%s.delta.rpm", $q->{'name'}, $v, $r, $q->{'arch'});
+	    print "$dn ... ";
+	    $dn = $dir.'/'.$dn;
+	    my $ret = system('makedeltarpm', $on, $nn, $dn);
+	    if ($ret || ! -e $dn) {
+		print "FAILED\n";
+		$sysret = 1;
+	    } else {
+		my $ns = (stat($dn))[7] || 1;
+		my $os = (stat($file))[7] || 1;
+		my $saved = int($ns / $os * 100);
+		if ($ns >= $os) {
+		    print "too big ($saved%), removed\n";
+		    unlink $file;
+		} else {
+		    print "ok ($saved%)\n";
+		}
+	    }
+	}
+    }
+}
+
+exit $sysret;
--- spec_add_patch
+++ spec_add_patch
@@ -29,7 +29,7 @@
 }
 
 
-open(S, "<$specname") or die;
+open(S, '<', $specname) or die;
 
 my $ifdef_level = 0;
 my $in_prep = 0;
@@ -112,7 +112,7 @@
 
 # determine strip level
 my $striplevel = "";
-open(P, "<$diffname") or die;
+open(P, '<', $diffname) or die;
 while(<P>) {
     $striplevel = " -p1" if (m/^--- a/ or m/^--- [^\/]+-\d+\./);
     last if (/^--- /);
@@ -125,7 +125,7 @@
 splice @c, $last_patch_in_global_index+1, 0,
     (sprintf "Patch%s:%s%s\n", $patchnum, ' ' x (10-length($patchnum)), $diffname);
 
-open(O, ">$specname.new") or die;
+open(O, '>', "$specname.new") or die;
 print O @c;
 close(O);
 
--- substitutedeps
+++ substitutedeps
@@ -125,12 +125,18 @@
 	    $l =~ s/<B_CNT>/$b/;
 	  } elsif ($release =~ /(\d+)$/) {
 	    my $b = $1;
-	    $l =~ s/<B_CNT>/$b/ unless $l =~ s/<CI_CNT>/$b/;
+	    $b = '0' if $l =~ s/<CI_CNT>/$b/;
+	    $l =~ s/<B_CNT>/$b/;
 	  }
 	} else {
 	  $l =~ s/^(Release:\s*).*/$1$release/i;
 	}
       }
+    } else {
+      # remove macros, as rpm doesn't like them
+      $l =~ s/<RELEASE\d*>/0/;
+      $l =~ s/<CI_CNT>/0/;
+      $l =~ s/<B_CNT>/0/;
     }
     # this is to be compatible to legacy autobuild.
     # you can specify a releaseprg in the project configuration,
@@ -206,6 +212,11 @@
     print F "$l\n";
     next;
   }
+  if ($l =~ /%\(/) {
+    # too hard for us
+    print F "$l\n";
+    next;
+  }
 
   my $isbuildrequires = 0;
   $isbuildrequires = 1 if $l =~ /^BuildRequires:/i;
--- test/baselibs.conf
+++ test/baselibs.conf
+libdummy1
--- test/common
+++ test/common
@@ -93,8 +93,7 @@
 		/usr/bin/build \
 		--root "${build_root}" \
 		"${repos[@]}" \
-		"${build_args[@]}" \
-		"$@"
+		"${build_args[@]}"
 	echo "$@"
 	"$@" || fail
 	find $build_root/.build.packages/ -type f -name '*.rpm' -print0 | xargs --no-run-if-empty -0 rpm -K || fail
--- test/dummy.spec
+++ test/dummy.spec
-Name:		dummy
-Version:	0
-Release:	0
-Group:		None
-Summary:	Dummy
-License:	GPL
-BuildRoot:	%_tmppath/%name-%version-build
-
-%build
-gcc --version
-%install
-mkdir -p %buildroot/etc
-cp /etc/shells %buildroot/etc/foo
-
-%description
-%_target_cpu
-%_arch
-%_build_arch
-
-%files
-%defattr(-,root,root)
-/etc/foo
-
-%changelog
--- test/libdummy1.spec
+++ test/libdummy1.spec
+Name:		libdummy1
+Version:	0
+Release:	0
+Group:		None
+Summary:	Dummy
+License:	GPL
+BuildRoot:	%_tmppath/%name-%version-build
+
+%build
+gcc --version
+echo "int dummy(void) {}" | gcc -shared -Wl,-soname=libdummy.so.1 -o libdummy.so.1 -x c -
+%install
+mkdir -p %buildroot%_libdir
+install libdummy.so.1 %buildroot%_libdir
+
+%clean
+rm -rf %buildroot
+
+%description
+target_cpu %_target_cpu
+arch       %_arch
+build_arch %_build_arch
+
+%files
+%defattr(-,root,root)
+%_libdir/libdummy.so.1
+
+%changelog

++++++ debian.changelog
--- debian.changelog
+++ debian.changelog
@@ -1,3 +1,9 @@
+build (2010.08.04) unstable; urgency=low
+
+  * Update to 2010.08.04 git snapshot
+
+ -- Jian-feng Ding <jian-feng.ding at intel.com>  Tue, 10 Aug 2010 14:03:54 +0200
+
 build (2010.04.15) unstable; urgency=low
 
   * Update to current git trunk




More information about the MeeGo-commits mailing list