+# CONSTANTS/VARIABLES
+
+# Regex to catch compiler commands.
+my $cc_regex = qr/(?:[a-z0-9_]+-(?:linux-|kfreebsd-)?gnu(?:eabi|eabihf)?-)?
+ (?<!\.)(?:cc|gcc|g\+\+|c\+\+)
+ (?:-[\d.]+)?/x;
+# Regex to catch (GCC) compiler warnings.
+my $warning_regex = qr/^(.+?):([0-9]+):[0-9]+: warning: (.+?) \[(.+?)\]$/;
+
+# Regex for source files which require preprocessing.
+my $source_preprocess_compile_regex = qr/
+ # C
+ c
+ # Objective-C
+ | m
+ # C++
+ | cc | cp | cxx | cpp | CPP | c\+\+ | C
+ # Objective-C++
+ | mm | M
+ # Fortran
+ | F | FOR | fpp | FPP | FTN | F90 | F95 | F03 | F08
+ /x;
+my $source_preprocess_no_compile_regex = qr/
+ # Assembly
+ s
+ /x;
+my $source_preprocess_regex = qr/
+ $source_preprocess_compile_regex
+ | $source_preprocess_no_compile_regex
+ /x;
+# Regex for source files which don't require preprocessing.
+my $source_no_preprocess_compile_regex = qr/
+ # C
+ i
+ # C++
+ | ii
+ # Objective-C
+ | mi
+ # Objective-C++
+ | mii
+ # Fortran
+ | f | for | ftn | f90 | f95 | f03 | f08
+ /x;
+my $source_no_preprocess_no_compile_regex = qr/
+ # Assembly
+ S | sx
+ /x;
+my $source_no_preprocess_regex = qr/
+ $source_no_preprocess_compile_regex
+ | $source_no_preprocess_no_compile_regex
+ /x;
+# Regex for header files which require preprocessing.
+my $header_preprocess_regex = qr/
+ # C, C++, Objective-C, Objective-C++
+ h
+ # C++
+ | hh | H | hp | hxx | hpp | HPP | h\+\+ | tcc
+ /x;
+# Regexps to match files with the given characteristics.
+my $file_no_preprocess_regex = qr/
+ $cc_regex.+?
+ \.(?: $source_no_preprocess_regex)\b
+ /x;
+my $file_preprocess_regex = qr/
+ $cc_regex.+?
+ \.(?: $header_preprocess_regex
+ | $source_preprocess_regex)\b
+ /x;
+my $file_compile_link_regex = qr/
+ $cc_regex.+?
+ \.(?: $source_preprocess_regex
+ | $source_no_preprocess_regex)\b
+ /x;
+my $file_compile_regex = qr/
+ $cc_regex.+?
+ \.(?: $source_preprocess_compile_regex
+ | $source_no_preprocess_compile_regex)\b
+ /x;
+my $file_no_compile_regex = qr/
+ $cc_regex.+
+ \.(?: $source_preprocess_no_compile_regex
+ | $source_no_preprocess_no_compile_regex)\b
+ /x;
+
+# Expected (hardening) flags. All flags are used as regexps.
+my @cflags = (
+ '-g',
+ '-O(?:2|3)',
+);
+my @cflags_format = (
+ '-Wformat',
+ '-Wformat-security',
+ '-Werror=format-security',
+);
+my @cflags_fortify = (
+ # fortify needs at least -O1, but -O2 is recommended anyway
+);
+my @cflags_stack = (
+ '-fstack-protector',
+ '--param=ssp-buffer-size=4',
+);
+my @cflags_pie = (
+ '-fPIE',
+);
+my @cppflags = ();
+my @cppflags_fortify = (
+ '-D_FORTIFY_SOURCE=2',
+);
+my @ldflags = ();
+my @ldflags_relro = (
+ '-Wl,(-z,)?relro',
+);
+my @ldflags_bindnow = (
+ '-Wl,(-z,)?now',
+);
+my @ldflags_pie = (
+ '-fPIE',
+ '-pie',
+);
+# Renaming rules for the output so the regex parts are not visible.
+my %flag_renames = (
+ '-O(?:2|3)' => '-O2',
+ '-Wl,(-z,)?relro' => '-Wl,-z,relro',
+ '-Wl,(-z,)?now' => '-Wl,-z,now',
+);
+
+# Use colored (ANSI) output?
+my $option_color;
+
+