Kaynağa Gözat

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.
Raphaël Hertzog 16 yıl önce
ebeveyn
işleme
9dc0466a5e

+ 5 - 0
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).

+ 2 - 0
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

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

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

+ 5 - 0
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

+ 2 - 0
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 \

+ 105 - 0
scripts/dpkg-buildflags.pl

@@ -0,0 +1,105 @@
+#!/usr/bin/perl
+#
+# dpkg-vendor
+#
+# Copyright © 2010 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
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+use strict;
+use warnings;
+
+use Dpkg;
+use Dpkg::Gettext;
+use Dpkg::ErrorHandling;
+use Dpkg::BuildFlags;
+
+textdomain("dpkg-dev");
+
+sub version {
+    printf _g("Debian %s version %s.\n"), $progname, $version;
+
+    printf _g("
+Copyright (C) 2010 Raphael Hertzog <hertzog\@debian.org>.");
+
+    printf _g("
+This is free software; see the GNU General Public License version 2 or
+later for copying conditions. There is NO warranty.
+");
+}
+
+sub usage {
+    printf _g(
+"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.
+"), $progname;
+}
+
+my ($param, $action);
+
+while (@ARGV) {
+    $_ = shift(@ARGV);
+    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;
+    } elsif (m/^--version$/) {
+        version();
+        exit 0;
+    } else {
+	usageerr(_g("unknown option \`%s'"), $_);
+    }
+}
+
+usageerr(_g("need an action option")) unless defined($action);
+
+my $build_flags = Dpkg::BuildFlags->new();
+
+if ($action eq "list") {
+    foreach my $flag ($build_flags->list()) {
+	print "$flag\n";
+    }
+    exit(0);
+}
+
+$build_flags->load_config();
+
+if ($action eq "get") {
+    if ($build_flags->has($param)) {
+	print $build_flags->get($param) . "\n";
+	exit(0);
+    }
+} elsif ($action eq "origin") {
+    if ($build_flags->has($param)) {
+	print $build_flags->get_origin($param) . "\n";
+	exit(0);
+    }
+}
+
+exit(1);

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