]> git.donarmstrong.com Git - debhelper.git/commitdiff
dpkg-buildflags support
authorJoey Hess <joey@kitenet.net>
Tue, 14 Jun 2011 21:22:34 +0000 (17:22 -0400)
committerJoey Hess <joey@kitenet.net>
Tue, 14 Jun 2011 21:24:27 +0000 (17:24 -0400)
* dh_auto_build, dh_auto_configure, dh: Set environment variables
  listed by dpkg-buildflags --export. Any environment variables that
  are already set to other values will not be changed.
Closes: #544844
* Also, support DEB_BUILD_OPTIONS=noopt, by changing -O2 to -O0.

Debian/Debhelper/Dh_Buildsystems.pm
Debian/Debhelper/Dh_Lib.pm
debhelper.pod
debian/changelog
dh

index 22f80f9ebdacb39435e8a952ccd9d753199a2c03..9c3fc0597c969b6639d8355c46a2ad21b266584d 100644 (file)
@@ -159,6 +159,7 @@ sub buildsystems_init {
        );
        $args{options}{$_} = $options{$_} foreach keys(%options);
        Debian::Debhelper::Dh_Lib::init(%args);
+       Debian::Debhelper::Dh_Lib::set_buildflags();
        set_parallel($max_parallel);
 }
 
index 51b53d3e600b158223f6b32ec68eab16abb4556e..51f16a6f8226fc29b9258d3ec3b084b85fd1be5e 100644 (file)
@@ -18,7 +18,7 @@ use vars qw(@ISA @EXPORT %dh);
            &inhibit_log &load_log &write_log &commit_override_log
            &dpkg_architecture_value &sourcepackage
            &is_make_jobserver_unavailable &clean_jobserver_makeflags
-           &cross_command);
+           &cross_command &set_buildflags);
 
 my $max_compat=9;
 
@@ -900,4 +900,35 @@ sub cross_command {
        }
 }
 
+# Sets environment variables from dpkg-buildflags. Avoids changing
+# any existing environment variables. Supports DEB_BUILD_OPTIONS=noopt.
+sub set_buildflags {
+       # optimisation
+       return if $ENV{DH_INTERNAL_BUILDFLAGS};
+       $ENV{DH_INTERNAL_BUILDFLAGS}=1;
+
+       my $noopt=$ENV{DEB_BUILD_OPTIONS}=~/noopt/;
+
+       my @shell=`dpkg-buildflags --export`;
+       foreach my $line (@shell) {
+               chomp $line;
+               if ($line=~/^export\s+([^=]+)=(["'])(.*)\2$/) {
+                       my $var=$1;
+                       my $val=$3;
+                       if ($noopt) {
+                               $val=$ENV{$var} if exists $ENV{$var};
+                               $val=~s/-O\d+/-O0/;
+                               $ENV{$var}=$val;
+                               next;
+                       }
+                       elsif (! exists $ENV{$var}) {
+                               $ENV{$var}=$val;
+                       }
+               }
+               else {
+                       warning "unparsable line from dpkg-buildflags: $line";
+               }
+       }
+}
+
 1
index d61cc84da057334d4982c9a40c4cfc5e1f762679..c076acf04f31d69e6e90f98520463a25270e9fd7 100644 (file)
@@ -191,6 +191,10 @@ in ALL packages acted on, not just the first.
 
 =head1 BUILD SYSTEM OPTIONS
 
+All of the B<dh_auto_>I<*> debhelper programs sets environment variables
+listed by B<dpkg-buildflags>, unless they are already set. They
+support DEB_BUILD_OPTIONS=noopt too.
+
 The following command line options are supported by all of the B<dh_auto_>I<*>
 debhelper programs. These programs support a variety of build systems,
 and normally heuristically determine which to use, and how to use them.
index 35692dadac02f86f0f71527b5b2fc3f8eebdc49d..fb01bc65d27762f53c75f54cfbbc3ccd0ddb9ab6 100644 (file)
@@ -5,6 +5,12 @@ debhelper (8.1.7) UNRELEASED; urgency=low
   * dh_movefiles: Optimise use of xargs. Closes: #627737
   * dh_auto_configure: In v9, does not include the source package name
     in --libexecdir when using autoconf. Closes: #541458
+  * dh_auto_build, dh_auto_configure, dh: Set environment variables
+    listed by dpkg-buildflags --export. Any environment variables that
+    are already set to other values will not be changed.
+    Closes: #544844
+  * Also, support DEB_BUILD_OPTIONS=noopt, by changing -O2 to -O0
+    in any variables listed by dpkg-buildflags.
 
  -- Joey Hess <joeyh@debian.org>  Sat, 21 May 2011 15:24:19 -0400
 
diff --git a/dh b/dh
index 50e0f14dbd90895295b82c98d08627da0aba349b..7c53611a60827ed1837a84a3aaf783d4be60a07b 100755 (executable)
--- a/dh
+++ b/dh
@@ -273,6 +273,9 @@ that is in the specified sequence. It then continues with the next command
 in the sequence. The B<--until>, B<--before>, B<--after>, and B<--remaining>
 options can override this behavior.
 
+B<dh> sets environment variables listed by B<dpkg-buildflags>, unless
+they are already set. It supports DEB_BUILD_OPTIONS=noopt too.
+
 B<dh> uses the B<DH_INTERNAL_OPTIONS> environment variable to pass information
 through to debhelper commands that are run inside override targets. The
 contents (and indeed, existence) of this environment variable, as the name
@@ -310,7 +313,7 @@ init(options => {
        bundling => 0,
 );
 inhibit_log();
-
+set_buildflags();
 
 # If make is using a jobserver, but it is not available
 # to this process, clean out MAKEFLAGS. This avoids