瀏覽代碼

dpkg-buildflags: new --dump action, make it the default

The --export command is useful to retrieve the compilation flags
in a shell script or in a makefile, and to export them in the environment,
but it's not well suited for parsing by another script (or even by a
human).

The new --dump option becomes the default action and prints
the flags and their values following a documented template: "flag=value".
Raphaël Hertzog 15 年之前
父節點
當前提交
d415c388d3
共有 3 個文件被更改,包括 21 次插入4 次删除
  1. 2 0
      debian/changelog
  2. 6 1
      man/dpkg-buildflags.1
  3. 13 3
      scripts/dpkg-buildflags.pl

+ 2 - 0
debian/changelog

@@ -69,6 +69,8 @@ dpkg (1.16.1) UNRELEASED; urgency=low
     flags. Particularly useful for package maintainers who don't want
     their supplementary flags to take precedence over user submitted
     flags.
+  * Add new --dump action to dpkg-buildflags and make it the default action.
+    Closes: #603435
 
   [ Guillem Jover ]
   * Install deb-src-control(5) man pages in dpkg-dev. Closes: #620520

+ 6 - 1
man/dpkg-buildflags.1

@@ -4,7 +4,7 @@ dpkg\-buildflags \- returns build flags to use during package build
 .
 .SH SYNOPSIS
 .B dpkg\-buildflags
-.RI [ option "...] " command
+.RI [ option "...] [" command ]
 .
 .SH DESCRIPTION
 \fBdpkg\-buildflags\fP is a tool to retrieve compilation flags to use during
@@ -43,6 +43,11 @@ The configuration files can contain comments on lines starting with a hash
 (#). Empty lines are also ignored.
 .SH COMMANDS
 .TP
+.BI \-\-dump
+Print to standard output all compilation flags and their values. It prints
+one flag per line separated from its value by an equal sign
+("\fIflag\fP=\fIvalue\fP"). This is the default action.
+.TP
 .BI \-\-list
 Print the list of flags supported by the current vendor
 (one per line). See the \fBSUPPORTED FLAGS\fP section for more

+ 13 - 3
scripts/dpkg-buildflags.pl

@@ -2,7 +2,7 @@
 #
 # dpkg-buildflags
 #
-# Copyright © 2010 Raphaël Hertzog <hertzog@debian.org>
+# Copyright © 2010-2011 Raphaël Hertzog <hertzog@debian.org>
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -31,7 +31,7 @@ sub version {
     printf _g("Debian %s version %s.\n"), $progname, $version;
 
     printf _g("
-Copyright (C) 2010 Raphael Hertzog <hertzog\@debian.org>.");
+Copyright (C) 2010-2011 Raphael Hertzog <hertzog\@debian.org>.");
 
     printf _g("
 This is free software; see the GNU General Public License version 2 or
@@ -50,6 +50,7 @@ Actions:
   --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.
+  --dump             output all compilation flags with their values
   --help             show this help message.
   --version          show the version.
 "), $progname;
@@ -70,6 +71,10 @@ while (@ARGV) {
             if defined($action);
         my $type = $1 || "sh";
         $action = "export-$type";
+    } elsif (m/^--dump$/) {
+        usageerr(_g("two commands specified: --%s and --%s"), "dump", $action)
+            if defined($action);
+        $action = "dump";
     } elsif (m/^--list$/) {
         usageerr(_g("two commands specified: --%s and --%s"), "list", $action)
             if defined($action);
@@ -85,7 +90,7 @@ while (@ARGV) {
     }
 }
 
-usageerr(_g("need an action option")) unless defined($action);
+$action = "dump" unless defined($action);
 
 my $build_flags = Dpkg::BuildFlags->new();
 
@@ -122,6 +127,11 @@ if ($action eq "get") {
 	}
     }
     exit(0);
+} elsif ($action eq "dump") {
+    foreach my $flag ($build_flags->list()) {
+	my $value = $build_flags->get($flag);
+	print "$flag=$value\n";
+    }
 }
 
 exit(1);