changetarget - allow change of rpmbuilds --target through a macro in prjconf.
authorJan-Simon Möller <jansimon.moeller@opensuse.org>
Wed, 3 Jun 2009 10:25:20 +0000 (10:25 +0000)
committerJan-Simon Möller <jansimon.moeller@opensuse.org>
Wed, 3 Jun 2009 10:25:20 +0000 (10:25 +0000)
For building ARM packages, we need to be able to set the target of the build because in the qemu-usermode environment
this is not what rpmbuild autodetects. With this patch we can use this in the prjconf:
%ifarch armv5el
Changetarget: armv5tel-suse-linux
%endif
'osc build' needs this change, too. Otherwise we'd end up with a wrong autodetection when doing a osc build on real hardware > armv5.

Build.pm
Makefile
build
getchangetarget [new file with mode: 0644]

index fa0e543..659bfbd 100644 (file)
--- a/Build.pm
+++ b/Build.pm
@@ -216,6 +216,8 @@ sub read_config {
       $config->{'patterntype'} = [ @l ];
     } elsif ($l0 eq 'release:') {
       $config->{'release'} = $l[0];
+    } elsif ($l0 eq 'changetarget:') {
+      $config->{'changetarget'} = join(' ', @l);
     } elsif ($l0 !~ /^[#%]/) {
       warn("unknown keyword in config: $l0\n");
     }
index 307f4a0..5299679 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -37,6 +37,7 @@ install:
            xen.conf \
            getmacros \
            getoptflags \
+           getchangetarget \
            common_functions \
            init_buildsystem \
            initscript_qemu_vm \
diff --git a/build b/build
index 3d95eac..d2bd995 100755 (executable)
--- a/build
+++ b/build
@@ -62,6 +62,7 @@ BUILD_DEBUG=
 PERSONALITY_SYSCALL=
 INCARNATION=
 DISTURL=
+CHANGETARGET=
 
 export PATH=$BUILD_DIR:/sbin:/usr/sbin:$PATH
 
@@ -1261,6 +1262,14 @@ for SPECFILE in "${SPECFILES[@]}" ; do
        # 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
+       buildarchtest=$( echo $BUILD_ARCH | grep -i arm )
+       if [ x"$buildarchtest" != x"" ]; then
+           echo "changing targetarch" 
+           CHANGETARGET=$(getchangetarget --dist "$BUILD_DIST" --configdir "$BUILD_DIR/configs" --archpath "$BUILD_ARCH" )
+           echo "NEW TARGET: $CHANGETARGET"
+       fi
     fi
     if test -f $BUILD_ROOT/.spec.new ; then
        if ! cmp -s $BUILD_ROOT$TOPDIR/SOURCES/$SPECFILE $BUILD_ROOT/.spec.new ; then
@@ -1343,6 +1352,10 @@ for SPECFILE in "${SPECFILES[@]}" ; do
                rpmbopts[${#rpmbopts[@]}]='--eval'
                rpmbopts[${#rpmbopts[@]}]="%suse_insert_debug_package"
        fi
+       if [ -n "$CHANGETARGET" ]; then
+               rpmbopts[${#rpmbopts[@]}]='--target'
+               rpmbopts[${#rpmbopts[@]}]="$CHANGETARGET"
+       fi
        rpmbuild=rpmbuild
 
        test -x $BUILD_ROOT/usr/bin/rpmbuild || rpmbuild=rpm
diff --git a/getchangetarget b/getchangetarget
new file mode 100644 (file)
index 0000000..8ef2794
--- /dev/null
@@ -0,0 +1,43 @@
+#!/usr/bin/perl -w
+
+BEGIN {
+  unshift @INC, ($::ENV{'BUILD_DIR'} || '/usr/lib/build');
+}
+
+use strict;
+
+use Build;
+
+my ($dist, $archs, $configdir, $debug);
+
+while (@ARGV)  {
+  if ($ARGV[0] eq '--dist') {
+    shift @ARGV;
+    $dist = shift @ARGV;
+    next;
+  }
+  if ($ARGV[0] eq '--archpath') {
+    shift @ARGV;
+    $archs = shift @ARGV;
+    next;
+  }
+  if ($ARGV[0] eq '--configdir') {
+    shift @ARGV;
+    $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;
+
+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 "$arch";