The following commit has been merged in the master branch:
commit 408541a3980ee505e2064bb5c8ee844b4baf3a2b
Author: Raphaël Hertzog <[email protected]>
Date:   Sun Jul 25 16:19:40 2010 +0200

    dpkg-buildflags: new --export command
    
    This action outputs shell code (or a makefile snippet) that exports all
    the compilations flags in the environment.
    
    For instance, the following command can be used a shell script:
     eval $(dpkg-buildflags --export=sh)

diff --git a/debian/changelog b/debian/changelog
index c6a4c59..3ebe406 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -43,6 +43,7 @@ dpkg (1.15.8) UNRELEASED; urgency=low
     that the user can better diagnose what went wrong. Closes: #575304
   * Fix Dpkg::Changelog to cope properly with an entry of version "0".
     Add non-regression test for this. Closes: #587382
+  * Add --export command to dpkg-buildflags to be used in shell with eval.
 
   [ Guillem Jover ]
   * Require gettext 0.18:
diff --git a/man/dpkg-buildflags.1 b/man/dpkg-buildflags.1
index d71aff5..d151262 100644
--- a/man/dpkg-buildflags.1
+++ b/man/dpkg-buildflags.1
@@ -38,6 +38,14 @@ Print the list of flags supported by the current vendor
 (one per line). See the \fBSUPPORTED FLAGS\fP section for more
 information about them.
 .TP
+.BI \-\-export= format
+Print to standard output shell (if \fIformat\fP is \fBsh\fP) or make
+(if \fIformat\fP is \fBmake\fP) commands that can be used to export
+all the compilation flags in the environment. If the \fIformat\fP value is not
+given, \fBsh\fP is assumed. Only compilations flags starting with an
+upper case character are included, others are assumed to not be suitable
+for the environment.
+.TP
 .BI \-\-get " flag"
 Print the value of the flag on standard output. Exits with 0
 if the flag is known otherwise exits with 1.
diff --git a/scripts/dpkg-buildflags.pl b/scripts/dpkg-buildflags.pl
index 6e1508a..3c66cb8 100755
--- a/scripts/dpkg-buildflags.pl
+++ b/scripts/dpkg-buildflags.pl
@@ -44,12 +44,14 @@ sub usage {
 "Usage: %s [<action>]
 
 Actions:
-  --get <flag>     output the requested flag to stdout.
-  --origin <flag>  output the origin of the flag to stdout:
-                   value is one of vendor, system, user, env.
-  --list           output a list of the flags supported by the current vendor.
-  --help           show this help message.
-  --version        show the version.
+  --get <flag>       output the requested flag to stdout.
+  --origin <flag>    output the origin of the flag to stdout:
+                     value is one of vendor, system, user, env.
+  --list             output a list of the flags supported by the current 
vendor.
+  --export=(sh|make) output commands to be executed in shell or make that 
export
+                     all the compilation flags as environment variables.
+  --help             show this help message.
+  --version          show the version.
 "), $progname;
 }
 
@@ -63,6 +65,11 @@ while (@ARGV) {
         $action = $1;
         $param = shift(@ARGV);
        usageerr(_g("%s needs a parameter"), $_) unless defined $param;
+    } elsif (m/^--export(?:=(sh|make))?$/) {
+        usageerr(_g("two commands specified: --%s and --%s"), "export", 
$action)
+            if defined($action);
+        my $type = $1 || "sh";
+        $action = "export-$type";
     } elsif (m/^--list$/) {
         usageerr(_g("two commands specified: --%s and --%s"), "list", $action)
             if defined($action);
@@ -101,6 +108,20 @@ if ($action eq "get") {
        print $build_flags->get_origin($param) . "\n";
        exit(0);
     }
+} elsif ($action =~ m/^export-(.*)$/) {
+    my $export_type = $1;
+    foreach my $flag ($build_flags->list()) {
+       next unless $flag =~ /^[A-Z]/; # Skip flags starting with lowercase
+       my $value = $build_flags->get($flag);
+       if ($export_type eq "sh") {
+           $value =~ s/"/\"/g;
+           print "export $flag=\"$value\"\n";
+       } elsif ($export_type eq "make") {
+           $value =~ s/\$/\$\$/g;
+           print "export $flag := $value\n";
+       }
+    }
+    exit(0);
 }
 
 exit(1);

-- 
dpkg's main repository


-- 
To UNSUBSCRIBE, email to [email protected]
with a subject of "unsubscribe". Trouble? Contact [email protected]

Reply via email to