Explorar o código

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)
Raphaël Hertzog %!s(int64=16) %!d(string=hai) anos
pai
achega
408541a398
Modificáronse 3 ficheiros con 36 adicións e 6 borrados
  1. 1 0
      debian/changelog
  2. 8 0
      man/dpkg-buildflags.1
  3. 27 6
      scripts/dpkg-buildflags.pl

+ 1 - 0
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:

+ 8 - 0
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.

+ 27 - 6
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);