Explorar el Código

dpkg-buildpackage: Set a set of compiler flags for a build

* scripts/dpkg-buildpackage.pl: Set a set of environment variables
for setting compiler and linker options, unless already set in the
environment. See https://wiki.ubuntu.com/DistCompilerFlags for
background information.
* man/dpkg-buildpackage.pl: Document the new behaviour.

Based on a patch by Matthias Klose <doko@cs.tu-berlin.de>
Frank Lichtenheld hace 18 años
padre
commit
a143d3b440
Se han modificado 5 ficheros con 112 adiciones y 2 borrados
  1. 8 0
      ChangeLog
  2. 4 0
      debian/changelog
  3. 6 0
      man/ChangeLog
  4. 71 0
      man/dpkg-buildpackage.1
  5. 23 2
      scripts/dpkg-buildpackage.pl

+ 8 - 0
ChangeLog

@@ -1,3 +1,11 @@
+2008-02-17  Frank Lichtenheld  <djpig@debian.org>
+	    Matthias Klose  <doko@cs.tu-berlin.de>
+
+	* scripts/dpkg-buildpackage.pl: Set a set of environment variables
+	for setting compiler and linker options, unless already set in the
+	environment. See https://wiki.ubuntu.com/DistCompilerFlags for
+	background information.
+
 2008-02-13  Raphael Hertzog  <hertzog@debian.org>
 2008-02-13  Raphael Hertzog  <hertzog@debian.org>
 
 
 	* scripts/Dpkg/Version.pm: Import Dpkg::Gettext since we use _g().
 	* scripts/Dpkg/Version.pm: Import Dpkg::Gettext since we use _g().

+ 4 - 0
debian/changelog

@@ -41,6 +41,10 @@ dpkg (1.14.17) UNRELEASED; urgency=low
     satisfied during -S. Closes: #445552
     satisfied during -S. Closes: #445552
   * Add a missing space in the German scripts translation. Closes: #463398
   * Add a missing space in the German scripts translation. Closes: #463398
   * Add improved deb-shlibs.5 manual page by Zack Weinberg. Closes: #466135
   * Add improved deb-shlibs.5 manual page by Zack Weinberg. Closes: #466135
+  * dpkg-buildpackage exports some build related environment variables
+    now. Based on a patch by Matthias Klose. Closes: #465282
+    (See dpkg-buildpackage(1) and https://wiki.ubuntu.com/DistCompilerFlags
+     for details)
 
 
   [ Updated dpkg translations ]
   [ Updated dpkg translations ]
   * Korean (Changwoo Ryu).
   * Korean (Changwoo Ryu).

+ 6 - 0
man/ChangeLog

@@ -3,6 +3,12 @@
 	* po/dpkg-man.pot: Regenerated.
 	* po/dpkg-man.pot: Regenerated.
 	* po/*.po: Merged with dpkg-man.pot.
 	* po/*.po: Merged with dpkg-man.pot.
 
 
+2008-02-17  Frank Lichtenheld  <djpig@debian.org>
+	    Matthias Klose  <doko@cs.tu-berlin.de>
+
+	* man/dpkg-buildpackage.1: Document the new
+	behaviour for build related environment variables.
+
 2008-02-17  Zack Weinberg  <zackw@panix.com>
 2008-02-17  Zack Weinberg  <zackw@panix.com>
 
 
 	* deb-shlibs.5: Make this manual page a bit
 	* deb-shlibs.5: Make this manual page a bit

+ 71 - 0
man/dpkg-buildpackage.1

@@ -204,6 +204,77 @@ Show the usage message and exit.
 .BR \-\-version
 .BR \-\-version
 Show the version and exit.
 Show the version and exit.
 .
 .
+.SH ENVIRONMENT
+A set of environment variables for setting compiler and linker options are
+set to default values unless already set in the environment. Note that
+this mechanism was only introduced in dpkg-dev, version 1.14.17 and
+not all \fIrules\fP files and build tools will honour these variables,
+yet.
+.TP
+.B CFLAGS
+Optimization options which are passed to the debian build system and
+can/should be overriden by the package build if needed (default value:
+.BR \-g\ \-O2
+, or
+.BR \-g\ \-O0
+if
+.BR noopt
+is specified in DEB_BUILD_OPTIONS). Overriding options can be
+used to explicitely set a
+higher optimization level, or work around compiler bugs, which only
+can be seen with some optimization levels (the last opt level "wins").
+.TP
+.B CFLAGS_APPEND
+Optimization options appended to the compiler flags, which must not be
+overwritten by the package (mostly used to for test builds). Default
+value: empty.
+.TP
+.B CXXFLAGS
+Same as
+.B CFLAGS
+for C++ sources.
+.TP
+.B CXXFLAGS_APPEND
+Same as
+.B CFLAGS_APPEND
+for C++ sources.
+.TP
+.B FFLAGS
+Same as
+.B FFLAGS
+for Fortran sources.
+.TP
+.B FFLAGS_APPEND
+Same as
+.B CFLAGS_APPEND
+for Fortran sources.
+.TP
+.B CPPFLAGS
+Preprocessor flags which are passed to the debian build system and
+can/should be overriden by the package build if needed (default:
+empty). This macro is seldom used (most build systems just use
+.B CFLAGS
+instead of
+.B CPPFLAGS).
+.TP
+.B CPPFLAGS_APPEND
+Preprocessor flags appended to the preprocessor flags, which must not
+be overwritten by the package (mostly used to for test
+builds). Default value: empty.
+.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.
+.TP
+.B LDFLAGS_APPEND
+Optimization options appended to the compiler flags when linking code,
+which must not be overwritten by the package (mostly used to for test
+builds). Default value: empty.
+.
 .SH BUGS
 .SH BUGS
 It should be possible to specify spaces and shell metacharacters in
 It should be possible to specify spaces and shell metacharacters in
 and initial arguments for
 and initial arguments for

+ 23 - 2
scripts/dpkg-buildpackage.pl

@@ -242,9 +242,8 @@ if ($signcommand) {
     }
     }
 }
 }
 
 
+my $build_opts = Dpkg::BuildOptions::parse();
 if ($parallel) {
 if ($parallel) {
-    my $build_opts = Dpkg::BuildOptions::parse();
-
     $parallel = $build_opts->{parallel} if (defined $build_opts->{parallel});
     $parallel = $build_opts->{parallel} if (defined $build_opts->{parallel});
     $ENV{MAKEFLAGS} ||= '';
     $ENV{MAKEFLAGS} ||= '';
     if ($parallel eq '-1') {
     if ($parallel eq '-1') {
@@ -256,6 +255,28 @@ if ($parallel) {
     Dpkg::BuildOptions::set($build_opts);
     Dpkg::BuildOptions::set($build_opts);
 }
 }
 
 
+my $default_flags = defined $build_opts->{noopt} ? "-g -O0" : "-g -O2";
+my %flags = ( CPPFLAGS => '',
+	      CFLAGS   => $default_flags,
+	      CXXFLAGS => $default_flags,
+	      FFLAGS   => $default_flags,
+	      LDFLAGS  => "-Wl,-Bsymbolic-functions",
+    );
+
+foreach my $flag (keys %flags) {
+    if ($ENV{$flag}) {
+	printf(_g("%s: use %s from environment: %s\n"), $progname,
+		  $flag, $ENV{$flag});
+    } else {
+	$ENV{$flag} = $flags{$flag};
+	printf(_g("%s: set %s to default value: %s\n"), $progname,
+		  $flag, $ENV{$flag});
+    }
+    if ($ENV{"${flag}_APPEND"}) {
+	$ENV{$flag} .= " ".$ENV{"${flag}_APPEND"};
+    }
+}
+
 my $cwd = cwd();
 my $cwd = cwd();
 my $dir = basename($cwd);
 my $dir = basename($cwd);