The following commit has been merged in the master branch:
commit 9dc0466a5e300dde0cf23a77aaa609b05b628242
Author: Raphaël Hertzog <[email protected]>
Date:   Fri Apr 9 17:46:15 2010 +0200

    dpkg-buildflags: new script to retrieve compilation flags during package 
build
    
    Forcing the value of compilation flags through environment variables set
    by dpkg-buildpackages has not been very successful up to now and suffered
    from the fact that calling debian/rules directly could lead to a different
    build than what dpkg-buildpackage would have done.
    
    This commit is the start of a new solution: dpkg-buildflags is a tool that
    package maintainers are supposed to use in order to retrieve compilation
    flags. It offers a way to control their default values at the distribution
    level while still allowing customizations by users who recompile the
    source packages.

diff --git a/debian/changelog b/debian/changelog
index 43a1451..0e0d0e9 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -20,6 +20,11 @@ dpkg (1.15.6.2) UNRELEASED; urgency=low
   * Tigthen the regex used by dpkg-source to match the component name of
     supplementary tarballs so that undercore (_) are not allowed as it was
     supposed to be.
+  * Introduce a new script called dpkg-buildflags: its purpose is to retrieve
+    compilation flags and it should be used within debian/rules to pass
+    the right compilation flags to the build process. dpkg-builpackage still
+    exports them to not break packages currently relying on them but packages
+    should now start using dpkg-buildflags instead. Closes: #560070
 
   [ Updated dpkg translations ]
   * German (Sven Joachim).
diff --git a/debian/dpkg-dev.install b/debian/dpkg-dev.install
index 9d911db..80ec5bd 100644
--- a/debian/dpkg-dev.install
+++ b/debian/dpkg-dev.install
@@ -2,6 +2,7 @@
 ../shlibs.override etc/dpkg
 
 usr/bin/dpkg-architecture
+usr/bin/dpkg-buildflags
 usr/bin/dpkg-buildpackage
 usr/bin/dpkg-checkbuilddeps
 usr/bin/dpkg-distaddfile
@@ -27,6 +28,7 @@ usr/share/man/{*/*,*}/deb-triggers.5
 usr/share/man/{*/*,*}/deb-old.5
 usr/share/man/{*/*,*}/deb.5
 usr/share/man/{*/*,*}/dpkg-architecture.1
+usr/share/man/{*/*,*}/dpkg-buildflags.1
 usr/share/man/{*/*,*}/dpkg-buildpackage.1
 usr/share/man/{*/*,*}/dpkg-checkbuilddeps.1
 usr/share/man/{*/*,*}/dpkg-distaddfile.1
diff --git a/man/Makefile.am b/man/Makefile.am
index b6e1287..8348832 100644
--- a/man/Makefile.am
+++ b/man/Makefile.am
@@ -97,6 +97,7 @@ dist_man_MANS = \
        deb-extra-override.5 \
        deb.5 \
        dpkg-architecture.1 \
+       dpkg-buildflags.1 \
        dpkg-buildpackage.1 \
        dpkg-checkbuilddeps.1 \
        dpkg-deb.1 \
diff --git a/man/dpkg-buildflags.1 b/man/dpkg-buildflags.1
new file mode 100644
index 0000000..1b462c2
--- /dev/null
+++ b/man/dpkg-buildflags.1
@@ -0,0 +1,116 @@
+.TH dpkg\-buildflags 1 "2010-04-11" "Debian Project" "dpkg suite"
+.SH NAME
+dpkg\-buildflags \- returns build flags to use during package build
+.
+.SH SYNOPSIS
+.B dpkg\-buildflags
+.RI [ option "...] " command
+.
+.SH DESCRIPTION
+\fBdpkg\-buildflags\fP is a tool to retrieve compilation flags to use during
+build of Debian packages.
+.
+The default flags are defined by the vendor but they can be
+extended/overriden in several ways:
+.IP 1.
+system-wide with \fB/etc/dpkg/buildflags.conf\fP;
+.IP 2.
+for the current user with \fB~/.config/dpkg-buildflags.conf\fP;
+.IP 3.
+temporarily with environment variables (see section \fBENVIRONMENT\fP).
+.P
+The configuration files can contain two types of directives:
+.TP
+.BI SET " flag value"
+Override the flag named \fIflag\fP to have the value \fIvalue\fP.
+.TP
+.BI APPEND " flag value"
+Extend the flag named \fIflag\fP with the options given in \fIvalue\fP.
+A space is prepended to the appended value if the flag's current value is 
non-empty.
+.P
+The configuration files can contain comments on lines starting with a hash
+(#). Empty lines are also ignored.
+.SH COMMANDS
+.TP
+.BI \-\-list
+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 \-\-get " flag"
+Print the value of the flag on standard output. Exits with 0
+if the flag is known otherwise exits with 1.
+.TP
+.BI \-\-origin " flag"
+Print the origin of the value that is returned by \fB\-\-get\fP. Exits
+with 0 if the flag is known otherwise exits with 1. The origin can be one
+of the following values:
+.RS
+.TP
+.B vendor
+the original flag set by the vendor is returned;
+.TP
+.B system
+the flag is set/modified by a system-wide configuration;
+.TP
+.B user
+the flag is set/modified by a user-specific configuration;
+.TP
+.B env
+the flag is set/modified by an environment-specific configuration.
+.RE
+.TP
+.B \-\-help
+Show the usage message and exit.
+.TP
+.B \-\-version
+Show the version and exit.
+.
+.SH SUPPORTED FLAGS
+.TP
+.B CFLAGS
+Options for the C compiler. The default value set by the vendor
+includes \fI-g\fP and the default optimization level (\fI-O2\fP usually,
+or \fI-O0\fP if the \fBDEB_BUILD_OPTIONS\fP environment variable defines
+\fInoopt\fP).
+.TP
+.B CPPFLAGS
+Options for the C preprocessor. Default value: empty.
+.TP
+.B CXXFLAGS
+Options for the C++ compiler. Same as \fBCFLAGS\fP.
+.TP
+.B FFLAGS
+Options for the Fortran compiler. Same as \fBCFLAGS\fP.
+.TP
+.B LDFLAGS
+Options passed to the compiler when linking executables or shared
+objects (if the linker is called directly, then
+.B -Wl
+and
+.B ,
+have to be stripped from these options). Default value: empty.
+.
+.SH FILES
+.TP
+.B /etc/dpkg/buildflags.conf
+System wide configuration file.
+.TP
+.B ~/.config/dpkg-buildflags.conf
+User configuration file.
+.SH ENVIRONMENT
+.TP
+.BI DEB_ flag _SET
+This variable can be used to force the value returned for the given
+\fIflag\fP.
+.TP
+.BI DEB_ flag _APPEND
+This variable can be used to append supplementary options to the value
+returned for the given \fIflag\fP.
+.
+.SH AUTHOR
+Copyright \(co 2010 Rapha\[:e]l Hertzog
+.sp
+This is free software; see the GNU General Public Licence version 2 or
+later for copying conditions. There is NO WARRANTY.
+
diff --git a/man/po/po4a.cfg b/man/po/po4a.cfg
index 1a3ed79..80089ae 100644
--- a/man/po/po4a.cfg
+++ b/man/po/po4a.cfg
@@ -83,6 +83,11 @@
            add_$lang:po/$lang.add
 
 
+[type:man] dpkg-buildflags.1          \
+           $lang:$(builddir)/$lang/dpkg-buildflags.1        \
+           add_$lang:po/$lang.add
+
+
 [type:man] dpkg-buildpackage.1        \
            $lang:$(builddir)/$lang/dpkg-buildpackage.1      \
            add_$lang:po/$lang.add
diff --git a/scripts/Makefile.am b/scripts/Makefile.am
index d70af7e..07c108d 100644
--- a/scripts/Makefile.am
+++ b/scripts/Makefile.am
@@ -4,6 +4,7 @@ SUBDIRS = po
 
 bin_SCRIPTS = \
        dpkg-architecture \
+       dpkg-buildflags \
        dpkg-buildpackage \
        dpkg-checkbuilddeps \
        dpkg-distaddfile \
@@ -30,6 +31,7 @@ changelog_SCRIPTS = \
 EXTRA_DIST = \
        README.alternatives \
        dpkg-architecture.pl \
+       dpkg-buildflags.pl \
        dpkg-buildpackage.pl \
        dpkg-checkbuilddeps.pl \
        dpkg-distaddfile.pl \
diff --git a/scripts/dpkg-vendor.pl b/scripts/dpkg-buildflags.pl
similarity index 50%
copy from scripts/dpkg-vendor.pl
copy to scripts/dpkg-buildflags.pl
index f59f4c6..bce8c31 100755
--- a/scripts/dpkg-vendor.pl
+++ b/scripts/dpkg-buildflags.pl
@@ -2,7 +2,7 @@
 #
 # dpkg-vendor
 #
-# Copyright © 2009 Raphaël Hertzog <[email protected]>
+# Copyright © 2010 Raphaël Hertzog <[email protected]>
 #
 # 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
@@ -23,7 +23,7 @@ use warnings;
 use Dpkg;
 use Dpkg::Gettext;
 use Dpkg::ErrorHandling;
-use Dpkg::Vendor qw(get_vendor_info get_current_vendor);
+use Dpkg::BuildFlags;
 
 textdomain("dpkg-dev");
 
@@ -31,7 +31,7 @@ sub version {
     printf _g("Debian %s version %s.\n"), $progname, $version;
 
     printf _g("
-Copyright (C) 2009 Raphael Hertzog <[email protected]>.");
+Copyright (C) 2010 Raphael Hertzog <[email protected]>.");
 
     printf _g("
 This is free software; see the GNU General Public License version 2 or
@@ -41,31 +41,31 @@ later for copying conditions. There is NO warranty.
 
 sub usage {
     printf _g(
-"Usage: %s [<option> ...] [<action>]
-
-Options:
-  --vendor <vendor>       assume <vendor> is the current vendor
+"Usage: %s [<action>]
 
 Actions:
-  --is <vendor>           returns true if current vendor is <vendor>.
-  --derives-from <vendor> returns true if current vendor derives from <vendor>.
-  --query <field>         print the content of the vendor-specific field.
-  --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.
+  --help           show this help message.
+  --version        show the version.
 "), $progname;
 }
 
-my ($vendor, $param, $action);
+my ($param, $action);
 
 while (@ARGV) {
     $_ = shift(@ARGV);
-    if (m/^--vendor$/) {
-        $vendor = shift(@ARGV);
-    } elsif (m/^--(is|derives-from|query)$/) {
+    if (m/^--(get|origin)$/) {
         usageerr(_g("two commands specified: --%s and --%s"), $1, $action)
             if defined($action);
         $action = $1;
         $param = shift(@ARGV);
+    } elsif (m/^--list$/) {
+        usageerr(_g("two commands specified: --%s and --%s"), "list", $action)
+            if defined($action);
+        $action = "list";
     } elsif (m/^-(h|-help)$/) {
         usage();
         exit 0;
@@ -79,36 +79,27 @@ while (@ARGV) {
 
 usageerr(_g("need an action option")) unless defined($action);
 
-# Uses $ENV{DEB_VENDOR} if set
-$vendor = get_current_vendor() unless defined($vendor);
+my $build_flags = Dpkg::BuildFlags->new();
 
-my $info = get_vendor_info($vendor);
-unless (defined($info)) {
-    error(_g("vendor %s doesn't exist in /etc/dpkg/origins/"),
-          $vendor || "default");
+if ($action eq "list") {
+    foreach my $flag ($build_flags->list()) {
+       print "$flag\n";
+    }
+    exit(0);
 }
 
-if ($action eq 'is') {
-
-    exit(0) if lc($param) eq lc($info->{'Vendor'});
-    exit(1);
-
-} elsif ($action eq 'derives-from') {
+$build_flags->load_config();
 
-    exit(0) if lc($param) eq lc($info->{'Vendor'});
-    while (defined($info) && exists $info->{'Parent'}) {
-        $info = get_vendor_info($info->{'Parent'});
-        exit(0) if lc($param) eq lc($info->{'Vendor'});
+if ($action eq "get") {
+    if ($build_flags->has($param)) {
+       print $build_flags->get($param) . "\n";
+       exit(0);
     }
-    exit(1);
-
-} elsif ($action eq 'query') {
-
-    if (exists $info->{$param}) {
-        print $info->{$param} . "\n";
-        exit(0);
-    } else {
-        exit(1);
+} elsif ($action eq "origin") {
+    if ($build_flags->has($param)) {
+       print $build_flags->get_origin($param) . "\n";
+       exit(0);
     }
-
 }
+
+exit(1);
diff --git a/scripts/po/POTFILES.in b/scripts/po/POTFILES.in
index 9b7483c..1bcd2d5 100644
--- a/scripts/po/POTFILES.in
+++ b/scripts/po/POTFILES.in
@@ -1,6 +1,7 @@
 # This is the list of all source files with translatable strings.
 
 scripts/dpkg-architecture.pl
+scripts/dpkg-buildflags.pl
 scripts/dpkg-buildpackage.pl
 scripts/dpkg-checkbuilddeps.pl
 scripts/dpkg-distaddfile.pl

-- 
dpkg's main repository


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

Reply via email to