This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Remove -std=c89/-ansi if freebsd has "inline static" in <fenv.h>
authorJarkko Hietaniemi <jhi@iki.fi>
Tue, 25 Nov 2014 01:39:18 +0000 (20:39 -0500)
committerJarkko Hietaniemi <jhi@iki.fi>
Tue, 25 Nov 2014 02:18:00 +0000 (21:18 -0500)
Since -std=c89 (eq -ansi) simply isn't compatible with "inline static".

Based on a fix by TonyC.

ext/POSIX/Makefile.PL

index 5a24a34..fe93efc 100644 (file)
@@ -144,3 +144,35 @@ WriteConstants(
     NAME => 'POSIX',
     NAMES => \@names,
 );
+
+package MY;
+
+use strict;
+use Config;
+
+sub cflags {
+    my $self = shift;
+
+    my $cflags = $self->SUPER::cflags(@_);
+
+    if ($^O eq 'freebsd') {
+        my $issue = "use <fenv.h> with -std=c89/-ansi";
+        print "$^O: checking if you can $issue\n";
+        # For example FreeBSD 10.0 uses "...static inline int" in <fenv.h>,
+        # which is incompatible with -std=c89 aka -ansi.
+        if (open(my $fh, ">fenv$$.c")) {
+            print { $fh } "#include <fenv.h>\nint main() { return 0; }\n";
+            close $fh;
+            system("$Config{cc} -std=c89 -o fenv$$ fenv$$.c 2>/dev/null");
+            if (-x "fenv$$") {
+                print "$^O: you can $issue\n";
+            } else {
+                print "$^O: you cannot $issue, removing those from flags\n";
+                $cflags =~ s/(?<=[ =])(?:-ansi|-std=c89)\b//g;
+            }
+            unlink("fenv$$.c", "fenv$$");
+        }
+   }
+
+   $cflags;
+}