
  * dpkg-buildpackage: 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 the details.

--- ./man/dpkg-buildpackage.1~	2008-01-26 19:15:39.000000000 +0100
+++ ./man/dpkg-buildpackage.1	2008-02-11 15:03:01.000000000 +0100
@@ -196,6 +196,74 @@
 .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. See
+https://wiki.ubuntu.com/DistCompilerFlags for the details.
+.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). 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: 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
--- ./scripts/dpkg-buildpackage.pl~	2008-01-26 19:15:39.000000000 +0100
+++ ./scripts/dpkg-buildpackage.pl	2008-02-11 15:04:52.000000000 +0100
@@ -232,9 +232,8 @@
     warning(_g("unknown sign command, assuming pgp style interface"));
 }
 
+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') {
@@ -246,6 +245,57 @@
     Dpkg::BuildOptions::set($build_opts);
 }
 
+if ($ENV{CPPFLAGS}) {
+  print "$progname: use CPPFLAGS from environment: $ENV{CPPFLAGS}\n";
+} else {
+  $ENV{CPPFLAGS} = "";
+  print "$progname: set CPPFLAGS to default value: $ENV{CPPFLAGS}\n";
+}
+if ($ENV{CPPFLAGS_APPEND}) {
+  $ENV{CPPFLAGS} .= " $ENV{CPPFLAGS_APPEND}";
+}
+
+if ($ENV{CFLAGS}) {
+  print "$progname: use CFLAGS from environment: $ENV{CFLAGS}\n";
+} else {
+  $ENV{CFLAGS} = defined $build_opts->{debug} ? "-g -O0" : "-g -O2";
+  print "$progname: set CFLAGS to default value: $ENV{CFLAGS}\n";
+}
+if ($ENV{CFLAGS_APPEND}) {
+  $ENV{CFLAGS} .= " $ENV{CFLAGS_APPEND}";
+}
+
+if ($ENV{CXXFLAGS}) {
+  print "$progname: use CXXFLAGS from environment: $ENV{CXXFLAGS}\n";
+} else {
+  $ENV{CXXFLAGS} = defined $build_opts->{debug} ? "-g -O0" : "-g -O2";
+  print "$progname: set CXXFLAGS to default value: $ENV{CXXFLAGS}\n";
+}
+if ($ENV{CXXFLAGS_APPEND}) {
+  $ENV{CXXFLAGS} .= " $ENV{CXXFLAGS_APPEND}";
+}
+
+
+if ($ENV{FFLAGS}) {
+  print "$progname: use FFLAGS from environment: $ENV{FFLAGS}\n";
+} else {
+  $ENV{FFLAGS} = defined $build_opts->{debug} ? "-g -O0" : "-g -O2";
+  print "$progname: set FFLAGS to default value: $ENV{FFLAGS}\n";
+}
+if ($ENV{FFLAGS_APPEND}) {
+  $ENV{FFLAGS} .= " $ENV{FFLAGS_APPEND}";
+}
+
+if ($ENV{LDFLAGS}) {
+  print "$progname: use LDFLAGS from environment: $ENV{LDFLAGS}\n";
+} else {
+  $ENV{LDFLAGS} = "-Wl,-Bsymbolic-functions";
+  print "$progname: set LDFLAGS to default value: $ENV{LDFLAGS}\n";
+}
+if ($ENV{LDFLAGS_APPEND}) {
+  $ENV{LDFLAGS} .= " $ENV{LDFLAGS_APPEND}";
+}
+
 my $cwd = cwd();
 my $dir = basename($cwd);
 
