+
+ if ($option_buildd) {
+ $statistics{preprocess}++ if $preprocess;
+ $statistics{compile}++ if $compile;
+ $statistics{compile_cpp}++ if $compile_cpp;
+ $statistics{link}++ if $link;
+ }
+
+ # Check hardening flags.
+ my @missing;
+ if ($compile and not all_flags_used($line, \@missing, @cflags)
+ # Libraries linked with -fPIC don't have to (and can't) be
+ # linked with -fPIE as well. It's no error if only PIE flags
+ # are missing.
+ and not pic_pie_conflict($line, $harden_pie, \@missing, @def_cflags_pie)
+ # Assume dpkg-buildflags returns the correct flags.
+ and index($line, '`dpkg-buildflags --get CFLAGS`') == -1) {
+ if (not $option_buildd) {
+ error_flags('CFLAGS missing', \@missing, \%flag_renames, $input[$i]);
+ $exit |= $exit_code{flags_missing};
+ } else {
+ $statistics{compile_missing}++;
+ }
+ } elsif ($compile_cpp and not all_flags_used($line, \@missing, @cflags)
+ # Libraries linked with -fPIC don't have to (and can't) be
+ # linked with -fPIE as well. It's no error if only PIE flags
+ # are missing.
+ and not pic_pie_conflict($line, $harden_pie, \@missing, @def_cflags_pie)
+ # Assume dpkg-buildflags returns the correct flags.
+ and index($line, '`dpkg-buildflags --get CXXFLAGS`') == -1) {
+ if (not $option_buildd) {
+ error_flags('CXXFLAGS missing', \@missing, \%flag_renames, $input[$i]);
+ $exit |= $exit_code{flags_missing};
+ } else {
+ $statistics{compile_cpp_missing}++;
+ }
+ }
+ if ($preprocess
+ and (not all_flags_used($line, \@missing, @cppflags)
+ # The fortify flag might be overwritten, detect that.
+ or ($harden_fortify
+ and cppflags_fortify_broken($line, \@missing)))
+ # Assume dpkg-buildflags returns the correct flags.
+ and index($line, '`dpkg-buildflags --get CPPFLAGS`') == -1) {
+ if (not $option_buildd) {
+ error_flags('CPPFLAGS missing', \@missing, \%flag_renames, $input[$i]);
+ $exit |= $exit_code{flags_missing};
+ } else {
+ $statistics{preprocess_missing}++;
+ }
+ }
+ if ($link and not all_flags_used($line, \@missing, @ldflags)
+ # Same here, -fPIC conflicts with -fPIE.
+ and not pic_pie_conflict($line, $harden_pie, \@missing, @def_ldflags_pie)
+ # Assume dpkg-buildflags returns the correct flags.
+ and index($line, '`dpkg-buildflags --get LDFLAGS`') == -1) {
+ if (not $option_buildd) {
+ error_flags('LDFLAGS missing', \@missing, \%flag_renames, $input[$i]);
+ $exit |= $exit_code{flags_missing};
+ } else {
+ $statistics{link_missing}++;
+ }
+ }
+
+ # Restore normal CFLAGS.
+ if ($compile_ada) {
+ @cflags = @cflags_backup;
+ }
+ }
+}
+
+# Print statistics for buildd mode, only output in this mode.
+if ($option_buildd) {
+ my @warning;
+
+ if ($statistics{preprocess_missing}) {
+ push @warning, sprintf 'CPPFLAGS %d (of %d)',
+ $statistics{preprocess_missing},
+ $statistics{preprocess};
+ }
+ if ($statistics{compile_missing}) {
+ push @warning, sprintf 'CFLAGS %d (of %d)',
+ $statistics{compile_missing},
+ $statistics{compile};
+ }
+ if ($statistics{compile_cpp_missing}) {
+ push @warning, sprintf 'CXXFLAGS %d (of %d)',
+ $statistics{compile_cpp_missing},
+ $statistics{compile_cpp};
+ }
+ if ($statistics{link_missing}) {
+ push @warning, sprintf 'LDFLAGS %d (of %d)',
+ $statistics{link_missing},
+ $statistics{link};
+ }
+ if (scalar @warning) {
+ local $" = ', '; # array join string
+ print "$buildd_tag{flags_missing}|@warning missing|\n";