Automatic compiler flags for gcc 5 and clang

To make compilation easier on gcc5/clang hosts, this patch automatically selects the appropriate c89 option, when modperl is being built with either gcc 5 or clang.

Tested by the author on Ubuntu 15.10 (with gcc 5.2.1), Fedora 23 (with gcc 5.3.1) and FreeBSD 10.2 (with clang).

Thanks to Klaus S. Madsen <ksm@jobindex.dk> for the patch.

git-svn-id: https://svn.apache.org/repos/asf/perl/modperl/trunk@1733566 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/README b/README
index 7539400..8d7c79e 100644
--- a/README
+++ b/README
@@ -25,14 +25,6 @@
   configurations) are currently believed to work, but this is not
   guaranteed to be the case, either now or in the future.
 
-C compiler:
-  The mod_perl source currently uses GNU89 inline semantics on GCC, but
-  GCC 5 defaults to newer C99 semantics.  If you see MP_INLINE related
-  warnings during the build and missing symbols when starting the test
-  suite, adding "-fgnu89-inline" to MP_CCOPTS may help.
-  There are also some reports of this happening with the Clang compiler,
-  where the corresponding option to try is "-std=gnu89".
-
 *** Status ***
 
 mod_perl is currently considered stable.
diff --git a/lib/Apache2/Build.pm b/lib/Apache2/Build.pm
index bb635df..68ea07d 100644
--- a/lib/Apache2/Build.pm
+++ b/lib/Apache2/Build.pm
@@ -611,6 +611,14 @@
         $ccopts .= " -DMP_TRACE";
     }
 
+    if ($self->has_gcc_version('5.0.0') && $ccopts !~ /-fgnu89-inline/) {
+        $ccopts .= " -fgnu89-inline";
+    }
+
+    if ($self->has_clang && $ccopts !~ /-std=gnu89/) {
+        $ccopts .= " -std=gnu89";
+    }
+
     # make sure apr.h can be safely included
     # for example Perl's included -D_GNU_SOURCE implies
     # -D_LARGEFILE64_SOURCE on linux, but this won't happen on
@@ -641,6 +649,16 @@
     return cmp_tuples(\@tuples, \@r_tuples) == 1;
 }
 
+sub has_clang {
+    my $self = shift;
+
+    my $has_version = $self->perl_config('gccversion');
+
+    return 0 unless $has_version;
+
+    return $has_version =~ m/Clang/;
+}
+
 sub cmp_tuples {
     my ($num_a, $num_b) = @_;