From e8c799129672d5b7dbac58a06fadd175cffaa7ed Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Tue, 14 Jun 2011 17:22:34 -0400 Subject: dpkg-buildflags support * 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 | 1 + Debian/Debhelper/Dh_Lib.pm | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) (limited to 'Debian') diff --git a/Debian/Debhelper/Dh_Buildsystems.pm b/Debian/Debhelper/Dh_Buildsystems.pm index 22f80f9e..9c3fc059 100644 --- a/Debian/Debhelper/Dh_Buildsystems.pm +++ b/Debian/Debhelper/Dh_Buildsystems.pm @@ -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); } diff --git a/Debian/Debhelper/Dh_Lib.pm b/Debian/Debhelper/Dh_Lib.pm index 51b53d3e..51f16a6f 100644 --- a/Debian/Debhelper/Dh_Lib.pm +++ b/Debian/Debhelper/Dh_Lib.pm @@ -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 -- cgit v1.2.3