Browse Source

dpkg-buildflags: support debian/buildflags

This file is for use by package maintainers. Since the call to
dpkg-buildflags might be hidden by packaging helpers, it's a good
idea to offer a simple way for package maintainers to extend
the set of flags returned. Otherwise each package helper must provide
its own way to extend the compilation flags.
Raphaël Hertzog 15 years ago
parent
commit
316df0a76f
3 changed files with 49 additions and 12 deletions
  1. 3 0
      debian/changelog
  2. 11 2
      man/dpkg-buildflags.1
  3. 35 10
      scripts/Dpkg/BuildFlags.pm

+ 3 - 0
debian/changelog

@@ -62,6 +62,9 @@ dpkg (1.16.1) UNRELEASED; urgency=low
     to be clearer. Closes: #608260
   * dpkg-buildpackage no longer exports the compiler flags. Closes: #560070
     Packages must directly call dpkg-buildflags to retrieve them.
+  * dpkg-buildflags parses a supplementary configuration file under the
+    control of the package maintainer: debian/buildflags (or the corresponding
+    architecture/os specific variants).
 
   [ Guillem Jover ]
   * Install deb-src-control(5) man pages in dpkg-dev. Closes: #620520

+ 11 - 2
man/dpkg-buildflags.1

@@ -1,4 +1,4 @@
-.TH dpkg\-buildflags 1 "2010-07-29" "Debian Project" "dpkg suite"
+.TH dpkg\-buildflags 1 "2011-07-07" "Debian Project" "dpkg suite"
 .SH NAME
 dpkg\-buildflags \- returns build flags to use during package build
 .
@@ -19,6 +19,12 @@ for the current user with \fB$XDG_CONFIG_HOME/dpkg/buildflags.conf\fP
 where \fB$XDG_CONFIG_HOME\fP defaults to \fB$HOME/.config\fP;
 .IP 3.
 temporarily by the user with environment variables (see section \fBENVIRONMENT\fP).
+.IP 4.
+by the package maintainer with one of the following files (the first found
+is used): \fBdebian/buildflags.\fP\fIarch\fP, \fBdebian/buildflags.\fP\fIos\fP,
+\fBdebian/buildflags\fP. The \fIarch\fP substitution corresponds to the
+DEB_HOST_ARCH variable returned by \fBdpkg\-architecture\fP while \fIos\fP
+corresponds to DEB_HOST_ARCH_OS.
 .P
 The configuration files can contain two types of directives:
 .TP
@@ -107,6 +113,9 @@ System wide configuration file.
 .TP
 .BR $XDG_CONFIG_HOME/dpkg/buildflags.conf " or " $HOME/.config/dpkg/buildflags.conf
 User configuration file.
+.TP
+\fBdebian/buildflags.\fIarch\fP, \fBdebian/buildflags.\fIos\fP, \fBdebian/buildflags\fP
+Package maintainer configuration file.
 .SH ENVIRONMENT
 Those environment variables should not be set by official packages, they
 are meant for users who are recompiling a Debian package and would like to
@@ -121,7 +130,7 @@ 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
+Copyright \(co 2010-2011 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.

+ 35 - 10
scripts/Dpkg/BuildFlags.pm

@@ -1,4 +1,4 @@
-# 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
@@ -18,11 +18,12 @@ package Dpkg::BuildFlags;
 use strict;
 use warnings;
 
-our $VERSION = "1.00";
+our $VERSION = "1.01";
 
 use Dpkg::Gettext;
 use Dpkg::BuildOptions;
 use Dpkg::ErrorHandling;
+use Dpkg::Path qw(find_build_file);
 use Dpkg::Vendor qw(run_vendor_hook);
 
 =encoding utf8
@@ -134,11 +135,26 @@ sub load_environment_config {
     }
 }
 
+=item $bf->load_package_config()
+
+Update flags based on directives stored in debian/buildflags
+and associated arch-specific variants.
+
+=cut
+
+sub load_package_config {
+    my ($self) = @_;
+    my $config = find_build_file("debian/buildflags");
+    if (defined $config) {
+        $self->update_from_conffile($config, undef);
+    }
+}
+
 =item $bf->load_config()
 
-Call successively load_system_config(), load_user_config() and
-load_environment_config() to update the default build flags
-defined by the vendor.
+Call successively load_system_config(), load_user_config(),
+load_environment_config() and load_package_config() to update the default
+build flags defined by the vendor.
 
 =cut
 
@@ -147,24 +163,26 @@ sub load_config {
     $self->load_system_config();
     $self->load_user_config();
     $self->load_environment_config();
+    $self->load_package_config();
 }
 
 =item $bf->set($flag, $value, $source)
 
-Update the build flag $flag with value $value and record its origin as $source.
+Update the build flag $flag with value $value and record its origin as
+$source (if defined).
 
 =cut
 
 sub set {
     my ($self, $flag, $value, $src) = @_;
     $self->{flags}->{$flag} = $value;
-    $self->{origin}->{$flag} = $src;
+    $self->{origin}->{$flag} = $src if defined $src;
 }
 
 =item $bf->append($flag, $value, $source)
 
 Append the options listed in $value to the current value of the flag $flag.
-Record its origin as $source.
+Record its origin as $source (if defined).
 
 =cut
 
@@ -175,7 +193,7 @@ sub append {
     } else {
         $self->{flags}->{$flag} = $value;
     }
-    $self->{origin}->{$flag} = $src;
+    $self->{origin}->{$flag} = $src if defined $src;
 }
 
 =item $bf->update_from_conffile($file, $source)
@@ -183,7 +201,7 @@ sub append {
 Update the current build flags based on the configuration directives
 contained in $file. See dpkg-buildflags(1) for the format of the directives.
 
-$source is the origin recorded for any build flag set or modified.
+If defined, $source is the origin recorded for any build flag set or modified.
 
 =cut
 
@@ -261,6 +279,13 @@ sub list {
 
 =back
 
+=head1 CHANGES
+
+=head2 Version 1.01
+
+New method: $bf->load_package_config(). This method is called last as part
+of load_config().
+
 =head1 AUTHOR
 
 Raphaël Hertzog <hertzog@debian.org>