X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=Debian%2FDebhelper%2FDh_Lib.pm;h=51f16a6f8226fc29b9258d3ec3b084b85fd1be5e;hb=e8c799129672d5b7dbac58a06fadd175cffaa7ed;hp=dcba4d246cb9adf641333010f2a456ffa7a75d2d;hpb=859b245e93028ff72ae9f19dc5f49af7406e7ac8;p=debhelper.git diff --git a/Debian/Debhelper/Dh_Lib.pm b/Debian/Debhelper/Dh_Lib.pm index dcba4d2..51f16a6 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; @@ -609,7 +609,7 @@ sub filedoublearray { my $globdir=shift; my @ret; - open (DH_FARRAY_IN, $file) || error("cannot read $file: $1"); + open (DH_FARRAY_IN, $file) || error("cannot read $file: $!"); while () { chomp; # Only ignore comments and empty lines in v5 mode. @@ -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