From 698e47136818bb4290d87e7f7d9b98ade7444cf7 Mon Sep 17 00:00:00 2001
From: Slaven Rezic <slaven@rezic.de>
Date: Wed, 9 Mar 2016 21:33:06 +0100
Subject: [PATCH] amend freebsd patch for 1.19_1

---
 F77.pm | 47 ++++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 44 insertions(+), 3 deletions(-)

diff --git a/F77.pm b/F77.pm
index 6ac28ab..04f046b 100644
--- a/F77.pm
+++ b/F77.pm
@@ -344,9 +344,49 @@ $F77config{Aix}{DEFAULT}     = 'F77';
 
 ### FreeBSD ###
 
-$F77config{Freebsd}{F77}{Trail_} = 1;
-$F77config{Freebsd}{F77}{Link}   = '-L/usr/lib -lf2c -lm';
-$F77config{Freebsd}{DEFAULT}     = 'F77';
+if($^O =~ /Freebsd/i) {
+  $gfortran = 'gfortran48'; # requires rewrite
+  $fallback_compiler = 'G77';
+}
+
+$F77config{Freebsd}{G77}{Link} = sub {
+    $dir = `g77-34 -print-file-name=libg2c.a`;
+    chomp $dir;
+    # Note that -print-file-name returns just the library name
+    # if it cant be found - make sure that we only accept the
+    # directory if it returns a proper path (or matches a /)
+
+    if( defined $dir ) {
+        $dir =~ s,/libg2c.a$,,;
+    } else {
+        $dir = "/usr/local/lib";
+    }    
+    return( "-L$dir -L/usr/lib -lg2c -lm" );
+};
+
+$F77config{Freebsd}{GFortran}{Link} = sub {
+    $dir = `$gfortran -print-file-name=libgfortran.a`;
+    chomp $dir;
+    # Note that -print-file-name returns just the library name
+    # if it cant be found - make sure that we only accept the
+    # directory if it returns a proper path (or matches a /)
+
+    if( defined $dir ) {
+        $dir =~ s,/libgfortran.a$,,;
+    } else {
+        $dir = "/usr/local/lib";
+    }    
+    return( "-L$dir -L/usr/lib -lgfortran -lm" );
+};
+
+$F77config{Freebsd}{G77}{Trail_} = 1;
+$F77config{Freebsd}{GFortran}{Trail_} = 1;
+$F77config{Freebsd}{G77}{Compiler} = 'g77-34';
+$F77config{Freebsd}{GFortran}{Compiler} = "$gfortran";
+$F77config{Freebsd}{G77}{Cflags} = '-O2';
+$F77config{Freebsd}{GFortran}{Cflags}   = '-O2';
+$F77config{Freebsd}{DEFAULT}     = 'GFortran';
+
 
 ### VMS ###
 
@@ -444,6 +484,7 @@ sub import {
 EOD
          $system   =
          $Config{cc} =~ /\bgcc/ && $^O =~ /MSWin32/i ? "MinGW"
+                                 : $^O =~ /Freebsd/i ? "Freebsd"
          :"Generic";
          $compiler = $fallback_compiler;
          my $flibs = get ($F77config{$system}{$compiler}{Link});
-- 
2.1.2