add support for --define, --with and --without
authorLudwig Nussel <ludwig.nussel@suse.de>
Fri, 15 Feb 2008 15:11:00 +0000 (15:11 +0000)
committerLudwig Nussel <ludwig.nussel@suse.de>
Fri, 15 Feb 2008 15:11:00 +0000 (15:11 +0000)
Build.pm
build
expanddeps
init_buildsystem

index 0bf4633..f1f23b9 100644 (file)
--- a/Build.pm
+++ b/Build.pm
@@ -29,12 +29,19 @@ my $std_macros = q{
 %define arml armv4l armv5l armv5tel
 %define armb armv4b armv5b armv5teb
 };
+my $extra_macros = '';
 
 sub unify {
   my %h = map {$_ => 1} @_;
   return grep(delete($h{$_}), @_);
 }
 
+sub define($)
+{
+       my $def = shift;
+       $extra_macros .= '%define '.$def."\n";
+}
+
 sub init_helper_hashes {
   my ($config) = @_;
 
@@ -88,7 +95,7 @@ sub read_config_dist {
 
 sub read_config {
   my ($arch, $cfile) = @_;
-  my @macros = split("\n", $std_macros);
+  my @macros = split("\n", $std_macros.$extra_macros);
   push @macros, "%define _target_cpu $arch";
   push @macros, "%define _target_os linux";
   my $config = {'macros' => \@macros};
diff --git a/build b/build
index b7eac02..d47057a 100755 (executable)
--- a/build
+++ b/build
@@ -16,6 +16,8 @@ test -z "$BUILD_ARCH" && {
 }
 export BUILD_ARCH BUILD_ROOT BUILD_RPMS BUILD_DIR
 
+definesnstuff=()
+
 export PATH=$BUILD_DIR:$PATH
 
 # This is for insserv
@@ -129,6 +131,27 @@ cleanup_and_exit () {
     exit $1
 }
 
+shellquote()
+{
+    for arg; do
+       arg=${arg/\$/\\\$}
+       arg=${arg/\"/\\\"}
+       arg=${arg/\`/\\\`}
+       arg=${arg/\\/\\\\}
+       echo -n " \"$arg\""
+    done
+}
+
+# create a shell script from command line. Used for preserving arguments
+# through /bin/su -c
+toshellscript()
+{
+       echo "#!/bin/sh -x"
+       echo -n exec
+       shellquote "$@"
+       echo
+}
+
 function create_baselibs {
     echo "... creating baselibs"
     BRPMS=
@@ -322,6 +345,11 @@ while test -n "$1"; do
       *-list*state)
        LIST_STATE=true
       ;;
+      --define|--with|--without)
+        definesnstuff[${#definesnstuff[@]}]="$PARAM";
+        definesnstuff[${#definesnstuff[@]}]="$ARG";
+        shift
+      ;;
       ----noarg)
         echo "$ARG does not take an argument"
         cleanup_and_exit
@@ -423,7 +451,7 @@ if test -n "$LIST_STATE" ; then
        }
        for SPECFILE in $BUILD_ROOT/usr/src/packages/SPECS/*.spec ; do : ; done
     fi
-    init_buildsystem --list-state $USEUSEDFORBUILD $SPECFILE $BUILD_EXTRA_PACKS
+    init_buildsystem --list-state "${definesnstuff[@]}" $USEUSEDFORBUILD $SPECFILE $BUILD_EXTRA_PACKS
     ERR=$?
     rm -rf $BUILD_ROOT
     cleanup_and_exit $ERR
@@ -550,7 +578,7 @@ for SPECFILE in $SPECFILES ; do
     if test -n "$XENIMAGE" ; then
        # do fist stage of init_buildsystem
         echo init_buildsystem $USEUSEDFORBUILD $RPMLIST $SPECFILE $ADDITIONAL_PACKS ...
-        init_buildsystem --prepare $USEUSEDFORBUILD $RPMLIST "$MYSRCDIR/$SPECFILE" $ADDITIONAL_PACKS || cleanup_and_exit 1
+        init_buildsystem --prepare "${definesnstuff[@]}" $USEUSEDFORBUILD $RPMLIST "$MYSRCDIR/$SPECFILE" $ADDITIONAL_PACKS || cleanup_and_exit 1
        # start up xen, rerun ourself
        mkdir -p $BUILD_ROOT/.build
        cp -a $BUILD_DIR/. $BUILD_ROOT/.build
@@ -586,6 +614,9 @@ for SPECFILE in $SPECFILES ; do
        test -n "$PERSONALITY_SYSCALL" && PERSONALITY=`perl -e 'print syscall('$PERSONALITY_SYSCALL', 0)."\n"'`
        echo "PERSONALITY='$PERSONALITY'" >> $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
+       echo ")" >> $BUILD_ROOT/.build/build.data
        umount $BUILD_ROOT
        XMROOT=file:$XENIMAGE
        XMROOT=${XMROOT/#file:\/dev/phy:}
@@ -618,7 +649,7 @@ for SPECFILE in $SPECFILES ; do
     fi
 
     if test "$DO_INIT" = true ; then
-        echo init_buildsystem $USEUSEDFORBUILD $RPMLIST $SPECFILE $ADDITIONAL_PACKS ...
+        echo init_buildsystem "${definesnstuff[@]}" $USEUSEDFORBUILD $RPMLIST $SPECFILE $ADDITIONAL_PACKS ...
         $BUILD_INIT_BUILDSYSTEM $USEUSEDFORBUILD $RPMLIST "$MYSRCDIR/$SPECFILE" $ADDITIONAL_PACKS || cleanup_and_exit 1
     fi
 
@@ -757,13 +788,27 @@ for SPECFILE in $SPECFILES ; do
     if test "$SPECFILE" = "${SPECFILE%.dsc}" ; then
        test -z "$BUILD_RPM_BUILD_STAGE" && BUILD_RPM_BUILD_STAGE=-ba
 
-       BUILD_PARAMETERS="$BUILD_RPM_BUILD_STAGE"
-       test -n "$ABUILD_TARGET_ARCH" && BUILD_PARAMETERS="$BUILD_PARAMETERS --target=\"$ABUILD_TARGET_ARCH\""
-       test -n "$BUILD_JOBS" && BUILD_PARAMETERS="$BUILD_PARAMETERS --eval \"%define jobs \\\"$BUILD_JOBS\\\"\""
-       test root != "$BUILD_USER" && BUILD_PARAMETERS="$BUILD_PARAMETERS --eval \"%define _srcdefattr (-,root,root)\""
-       RPMBUILD=rpmbuild
-       test -x $BUILD_ROOT/usr/lib/rpm/rpmi || RPMBUILD=rpm
-       chroot $BUILD_ROOT su -c "$RPMBUILD $BUILD_PARAMETERS $TOPDIR/SOURCES/$SPECFILE" - $BUILD_USER < /dev/null && BUILD_SUCCEDED=true
+       # XXX: move _srcdefattr to macro file?
+       rpmbopts=("$BUILD_RPM_BUILD_STAGE" "--eval" "%define _srcdefattr (-,root,root)")
+       if [ -n "$ABUILD_TARGET_ARCH" ]; then
+               rpmbopts[${#rpmbopts[@]}]="--target=$ABUILD_TARGET_ARCH"
+       fi
+       if [ -n "$BUILD_JOBS" ]; then
+               rpmbopts[${#rpmbopts[@]}]='--eval'
+               rpmbopts[${#rpmbopts[@]}]="%define jobs $BUILD_JOBS"
+       fi
+       rpmbuild=rpmbuild
+
+       test -x $BUILD_ROOT/usr/lib/rpm/rpmi || rpmbuild=rpm
+       # su involves a shell which would require even more
+       # complicated quoting to bypass than this
+       toshellscript $rpmbuild \
+               "${definesnstuff[@]}" \
+               "${rpmbopts[@]}" \
+               "$TOPDIR/SOURCES/$SPECFILE" \
+               > $BUILD_ROOT/.build.command
+       chmod 755 $BUILD_ROOT/.build.command
+       chroot $BUILD_ROOT su -c /.build.command - $BUILD_USER < /dev/null && BUILD_SUCCEDED=true
     else
        chroot $BUILD_ROOT su -c "cd $TOPDIR/BUILD && dpkg-buildpackage -us -uc -rfakeroot" - $BUILD_USER < /dev/null && BUILD_SUCCEDED=true
        mkdir -p $BUILD_ROOT/$TOPDIR/DEBS
index e44aae0..ef7f29e 100755 (executable)
@@ -36,6 +36,24 @@ while (@ARGV)  {
     $useusedforbuild = 1;
     next;
   }
+  if ($ARGV[0] eq '--define') {
+    shift @ARGV;
+    my $def = shift @ARGV;
+    Build::define($def);
+    next;
+  }
+  if ($ARGV[0] eq '--with') {
+    shift @ARGV;
+    my $def = shift @ARGV;
+    Build::define("_with_$def --with-$def");
+    next;
+  }
+  if ($ARGV[0] eq '--without') {
+    shift @ARGV;
+    my $def = shift @ARGV;
+    Build::define("_without_$def --without-$def");
+    next;
+  }
   last;
 }
 $configdir = '.' unless defined $configdir;
index ce2f383..9ac4722 100755 (executable)
@@ -18,6 +18,7 @@ export DEBIAN_FRONTEND=noninteractive
 export DEBIAN_PRIORITY=critical
 export BUILD_DIR=${BUILD_DIR:-/usr/lib/build}
 PROC_IS_MOUNTED=
+definesnstuff=()
 
 # should RPMs be installed with --force ?
 USE_FORCE=false
@@ -52,6 +53,11 @@ while test -n "$1" ; do
            RPMLIST=$1
            shift
            ;;
+       --define|--with|--without)
+           definesnstuff[${#definesnstuff[@]}]="$1";
+           definesnstuff[${#definesnstuff[@]}]="$2";
+           shift 2
+       ;;
        *)
            break
            ;;
@@ -261,7 +267,7 @@ else
        #
        RPMLIST=$BUILD_ROOT/.init_b_cache/rpmlist
        test -z "$LIST_STATE" && echo "expanding package dependencies..."
-       if ! expanddeps $USEUSEDFORBUILD --dist "$BUILD_DIST" --depfile "$CACHE_FILE" --archpath "$BUILD_ARCH" --configdir $BUILD_DIR/configs $PKGS > $RPMLIST ; then
+       if ! $BUILD_DIR/expanddeps $USEUSEDFORBUILD "${definesnstuff[@]}" --dist "$BUILD_DIST" --depfile "$CACHE_FILE" --archpath "$BUILD_ARCH" --configdir $BUILD_DIR/configs $PKGS > $RPMLIST ; then
            rm -f $BUILD_IS_RUNNING
            cleanup_and_exit 1
        fi