]> ruderich.org/simon Gitweb - blhc/blhc.git/blobdiff - bin/blhc
Improve Fortran support, also for Open MPI (mpifort)
[blhc/blhc.git] / bin / blhc
index 4a16a36ee3edeeda74fab554625a86598ae176da..6afff57ff521485c9c6a4db9437bc826ea26b18d 100755 (executable)
--- a/bin/blhc
+++ b/bin/blhc
@@ -33,7 +33,7 @@ our $VERSION = '0.07';
 my $cc_regex = qr/
     (?<!\s-)               # ignore options, e.g. "-c++" [sic!] (used by swig)
     (?<!\.)                # ignore file names, e.g. "test.gcc"
-    (?:cc|gcc|g\+\+|c\+\+|mpicc|mpicxx)
+    (?:cc|gcc|g\+\+|c\+\+|gfortran|mpicc|mpicxx|mpifort)
     (?:-[\d.]+)?           # version suffix, e.g. "gcc-4.6"
     /x;
 # Full regex which matches the complete compiler name. Used in a few places to
@@ -63,6 +63,10 @@ my @source_preprocess_compile_cpp = (
     # Objective-C++
     qw( mm M ),
 );
+my @source_preprocess_compile_fortran = (
+    # Fortran
+    qw( F FOR fpp FPP FTN F90 F95 F03 F08 ),
+);
 my @source_preprocess_compile = (
     # C
     qw( c ),
@@ -71,7 +75,7 @@ my @source_preprocess_compile = (
     # (Objective-)C++
     @source_preprocess_compile_cpp,
     # Fortran
-    qw( F FOR fpp FPP FTN F90 F95 F03 F08 ),
+    @source_preprocess_compile_fortran,
 );
 my @source_preprocess_no_compile = (
     # Assembly
@@ -94,6 +98,10 @@ my @source_no_preprocess_compile_ada = (
     # Ada body
     qw( adb ),
 );
+my @source_no_preprocess_compile_fortran = (
+    # Fortran
+    qw( f for ftn f90 f95 f03 f08 ),
+);
 my @source_no_preprocess_compile = (
     # C
     qw( i ),
@@ -102,7 +110,7 @@ my @source_no_preprocess_compile = (
     # Objective-C
     qw( mi ),
     # Fortran
-    qw( f for ftn f90 f95 f03 f08 ),
+    @source_no_preprocess_compile_fortran,
     # Ada
     @source_no_preprocess_compile_ada,
 );
@@ -169,6 +177,10 @@ my %extensions_ada = map { $_ => 1 } (
     @source_no_preprocess_compile_ada,
     @source_no_preprocess_no_compile_ada,
 );
+my %extensions_fortran = map { $_ => 1 } (
+    @source_no_preprocess_compile_fortran,
+    @source_preprocess_compile_fortran,
+);
 my %extensions_object = map { $_ => 1 } (
     @object,
 );
@@ -730,6 +742,8 @@ foreach my $file (@ARGV) {
     # different CFLAGS. But only perform ada checks if an ada compiler is used
     # for performance reasons.
     my $ada = 0;
+    # Fortran also requires different CFLAGS.
+    my $fortran = 0;
 
     # Number of parallel jobs to prevent false positives when detecting
     # non-verbose builds. As not all jobs declare the number of parallel jobs
@@ -827,6 +841,10 @@ foreach my $file (@ARGV) {
             if ($line =~ /\bgnat\b/) {
                 $ada = 1;
             }
+            # Fortran compiler.
+            if ($line =~ /\bgfortran\b/) {
+                $fortran = 1;
+            }
         }
 
         # This flags is not always available, but if it is use it.
@@ -1088,10 +1106,11 @@ foreach my $file (@ARGV) {
     }
 
     # Ada doesn't support format hardening flags, see #680117 for more
-    # information. Filter them out if ada is used.
+    # information. Same for fortran. Filter them out if either language is
+    # used.
     my @cflags_backup;
     my @cflags_noformat;
-    if ($ada and $harden_format) {
+    if (($ada or $fortran) and $harden_format) {
         @cflags_noformat = grep {
             my $ok = 1;
             foreach my $flag (@def_cflags_format) {
@@ -1248,6 +1267,12 @@ LINE:
             $preprocess = 0; # Ada uses no CPPFLAGS
             @cflags_backup = @cflags;
             @cflags        = @cflags_noformat;
+        # Same for fortran.
+        } elsif ($fortran
+                and extension_found(\%extensions_fortran, @extensions)) {
+            $restore_cflags = 1;
+            @cflags_backup = @cflags;
+            @cflags        = @cflags_noformat;
         }
 
         if ($option_buildd) {