Browse Source

dpkg-buildflags: implement support of DEB_<flag>_MAINT_<op> env variables

Those variables are meant to be used by the package maintainer within
debian/rules to alter the resulting build flags if needed.
Raphaël Hertzog 15 years ago
parent
commit
a174a9ed4b
3 changed files with 58 additions and 13 deletions
  1. 2 1
      debian/changelog
  2. 17 4
      man/dpkg-buildflags.1
  3. 39 8
      scripts/Dpkg/BuildFlags.pm

+ 2 - 1
debian/changelog

@@ -92,7 +92,8 @@ dpkg (1.16.1) UNRELEASED; urgency=low
     Closes: #615899
     Closes: #615899
   * dpkg-buildflags now supports "--export=configure" to output compilation
   * dpkg-buildflags now supports "--export=configure" to output compilation
     flags on a single line with double quotes as delimiter of the various
     flags on a single line with double quotes as delimiter of the various
-    values.
+    values. It also uses DEB_<flag>_MAINT_<op> to let the maintainer
+    extend the build flags to use.
 
 
   [ Guillem Jover ]
   [ Guillem Jover ]
   * Install deb-src-control(5) man pages in dpkg-dev. Closes: #620520
   * Install deb-src-control(5) man pages in dpkg-dev. Closes: #620520

+ 17 - 4
man/dpkg-buildflags.1

@@ -18,7 +18,11 @@ system-wide with \fB/etc/dpkg/buildflags.conf\fP;
 for the current user with \fB$XDG_CONFIG_HOME/dpkg/buildflags.conf\fP
 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;
 where \fB$XDG_CONFIG_HOME\fP defaults to \fB$HOME/.config\fP;
 .IP 3.
 .IP 3.
-temporarily by the user with environment variables (see section \fBENVIRONMENT\fP).
+temporarily by the user with environment variables (see section
+\fBENVIRONMENT\fP);
+.IP 4.
+dynamically by the package maintainer with environment variables set via
+\fBdebian/rules\fP (see section \fBENVIRONMENT\fP).
 .P
 .P
 The configuration files can contain two types of directives:
 The configuration files can contain two types of directives:
 .TP
 .TP
@@ -119,19 +123,28 @@ System wide configuration file.
 .BR $XDG_CONFIG_HOME/dpkg/buildflags.conf " or " $HOME/.config/dpkg/buildflags.conf
 .BR $XDG_CONFIG_HOME/dpkg/buildflags.conf " or " $HOME/.config/dpkg/buildflags.conf
 User configuration file.
 User configuration file.
 .SH ENVIRONMENT
 .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
-change the compilation flags.
+There are 2 sets of environment variables doing the same operations, the
+first one (DEB_\fIflag\fP_\fIop\fP) should never be used within
+\fBdebian/rules\fP. It's meant for any user that wants to rebuild the
+source package with different build flags. The second set
+(DEB_\fIflag\fP_MAINT_\fIop\fP) should only be used in \fBdebian/rules\fP
+by package maintainers to change the resulting build flags.
 .TP
 .TP
 .BI DEB_ flag _SET
 .BI DEB_ flag _SET
+.TQ
+.BI DEB_ flag _MAINT_SET
 This variable can be used to force the value returned for the given
 This variable can be used to force the value returned for the given
 \fIflag\fP.
 \fIflag\fP.
 .TP
 .TP
 .BI DEB_ flag _APPEND
 .BI DEB_ flag _APPEND
+.TQ
+.BI DEB_ flag _MAINT_APPEND
 This variable can be used to append supplementary options to the value
 This variable can be used to append supplementary options to the value
 returned for the given \fIflag\fP.
 returned for the given \fIflag\fP.
 .TP
 .TP
 .BI DEB_ flag _PREPEND
 .BI DEB_ flag _PREPEND
+.TQ
+.BI DEB_ flag _MAINT_PREPEND
 This variable can be used to prepend supplementary options to the value
 This variable can be used to prepend supplementary options to the value
 returned for the given \fIflag\fP.
 returned for the given \fIflag\fP.
 .
 .

+ 39 - 8
scripts/Dpkg/BuildFlags.pm

@@ -115,7 +115,7 @@ sub load_user_config {
 
 
 =item $bf->load_environment_config()
 =item $bf->load_environment_config()
 
 
-Update flags based on directives stored in the environment. See
+Update flags based on user directives stored in the environment. See
 dpkg-buildflags(1) for details.
 dpkg-buildflags(1) for details.
 
 
 =cut
 =cut
@@ -138,11 +138,37 @@ sub load_environment_config {
     }
     }
 }
 }
 
 
+=item $bf->load_maintainer_config()
+
+Update flags based on maintainer directives stored in the environment. See
+dpkg-buildflags(1) for details.
+
+=cut
+
+sub load_maintainer_config {
+    my ($self) = @_;
+    foreach my $flag (keys %{$self->{flags}}) {
+	my $envvar = "DEB_" . $flag . "_MAINT_SET";
+	if (exists $ENV{$envvar}) {
+	    $self->set($flag, $ENV{$envvar}, undef);
+	}
+	$envvar = "DEB_" . $flag . "_MAINT_APPEND";
+	if (exists $ENV{$envvar}) {
+	    $self->append($flag, $ENV{$envvar}, undef);
+	}
+	$envvar = "DEB_" . $flag . "_MAINT_PREPEND";
+	if (exists $ENV{$envvar}) {
+	    $self->prepend($flag, $ENV{$envvar}, undef);
+	}
+    }
+}
+
+
 =item $bf->load_config()
 =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_maintainer_config() to update the
+default build flags defined by the vendor.
 
 
 =cut
 =cut
 
 
@@ -151,24 +177,26 @@ sub load_config {
     $self->load_system_config();
     $self->load_system_config();
     $self->load_user_config();
     $self->load_user_config();
     $self->load_environment_config();
     $self->load_environment_config();
+    $self->load_maintainer_config();
 }
 }
 
 
 =item $bf->set($flag, $value, $source)
 =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
 =cut
 
 
 sub set {
 sub set {
     my ($self, $flag, $value, $src) = @_;
     my ($self, $flag, $value, $src) = @_;
     $self->{flags}->{$flag} = $value;
     $self->{flags}->{$flag} = $value;
-    $self->{origin}->{$flag} = $src;
+    $self->{origin}->{$flag} = $src if defined $src;
 }
 }
 
 
 =item $bf->append($flag, $value, $source)
 =item $bf->append($flag, $value, $source)
 
 
 Append the options listed in $value to the current value of the flag $flag.
 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
 =cut
 
 
@@ -179,7 +207,7 @@ sub append {
     } else {
     } else {
         $self->{flags}->{$flag} = $value;
         $self->{flags}->{$flag} = $value;
     }
     }
-    $self->{origin}->{$flag} = $src;
+    $self->{origin}->{$flag} = $src if defined $src;
 }
 }
 
 
 =item $bf->prepend($flag, $value, $source)
 =item $bf->prepend($flag, $value, $source)
@@ -292,6 +320,9 @@ sub list {
 New method: $bf->prepend() very similar to append(). Implement support of
 New method: $bf->prepend() very similar to append(). Implement support of
 the prepend operation everywhere.
 the prepend operation everywhere.
 
 
+New method: $bf->load_maintainer_config() that update the build flags
+based on the package maintainer directives.
+
 =head1 AUTHOR
 =head1 AUTHOR
 
 
 Raphaël Hertzog <hertzog@debian.org>
 Raphaël Hertzog <hertzog@debian.org>