From: Frank Lichtenheld Date: Mon, 11 Feb 2008 22:30:29 +0000 (+0100) Subject: dpkg-buildpackage: Set a set of compiler flags for a build X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a143d3b44001f328453e0b71d272e06eb60903fa;p=dpkg 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 --- diff --git a/ChangeLog b/ChangeLog index ac1daa96..1e2c95e4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2008-02-17 Frank Lichtenheld + Matthias Klose + + * 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 * scripts/Dpkg/Version.pm: Import Dpkg::Gettext since we use _g(). diff --git a/debian/changelog b/debian/changelog index 5dca07a1..cc7e34cb 100644 --- a/debian/changelog +++ b/debian/changelog @@ -41,6 +41,10 @@ dpkg (1.14.17) UNRELEASED; urgency=low satisfied during -S. Closes: #445552 * Add a missing space in the German scripts translation. Closes: #463398 * 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 ] * Korean (Changwoo Ryu). diff --git a/man/ChangeLog b/man/ChangeLog index 3d76ebad..5e355c49 100644 --- a/man/ChangeLog +++ b/man/ChangeLog @@ -3,6 +3,12 @@ * po/dpkg-man.pot: Regenerated. * po/*.po: Merged with dpkg-man.pot. +2008-02-17 Frank Lichtenheld + Matthias Klose + + * man/dpkg-buildpackage.1: Document the new + behaviour for build related environment variables. + 2008-02-17 Zack Weinberg * deb-shlibs.5: Make this manual page a bit diff --git a/man/dpkg-buildpackage.1 b/man/dpkg-buildpackage.1 index f12cb07c..e220f87e 100644 --- a/man/dpkg-buildpackage.1 +++ b/man/dpkg-buildpackage.1 @@ -204,6 +204,77 @@ Show the usage message and exit. .BR \-\-version 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 It should be possible to specify spaces and shell metacharacters in and initial arguments for diff --git a/scripts/dpkg-buildpackage.pl b/scripts/dpkg-buildpackage.pl index 72854dda..6e1dc0e5 100755 --- a/scripts/dpkg-buildpackage.pl +++ b/scripts/dpkg-buildpackage.pl @@ -242,9 +242,8 @@ if ($signcommand) { } } +my $build_opts = Dpkg::BuildOptions::parse(); if ($parallel) { - my $build_opts = Dpkg::BuildOptions::parse(); - $parallel = $build_opts->{parallel} if (defined $build_opts->{parallel}); $ENV{MAKEFLAGS} ||= ''; if ($parallel eq '-1') { @@ -256,6 +255,28 @@ if ($parallel) { 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 $dir = basename($cwd);