From d15590796d1389db43f6aabb3f7039198d42b6c4 Mon Sep 17 00:00:00 2001
From: Robert Izzard <r.izzard@surrey.ac.uk>
Date: Sat, 9 Dec 2017 13:23:02 +0000
Subject: [PATCH] update configure and clean scripts

---
 clean_release.sh |  4 ++++
 configure        | 35 ++++++++++++++++++++++++++++++-----
 2 files changed, 34 insertions(+), 5 deletions(-)

diff --git a/clean_release.sh b/clean_release.sh
index acc65d0e6..f860a6550 100644
--- a/clean_release.sh
+++ b/clean_release.sh
@@ -20,3 +20,7 @@ rm amanda_sn_plot.pl binary_c-antiTZ  binary_c-Ba binary_c.orig binary_c-sn2014
 rm -rf faillist fails imfticks fionread
 rm *~ src/*~ src/*/*~
 clean-svn.pl
+
+svn rm novae*pdf
+svn rm novae*plt
+svn rm cemps
diff --git a/configure b/configure
index ca1c1ba15..bd469ebba 100755
--- a/configure
+++ b/configure
@@ -462,9 +462,9 @@ sub secondary_variables
     if($cc =~ /^(?:gcc|clang)/)
     {
         # libraries we should include if we can
-	if((checklib('libbfd')=~/libbfd-(\d+\.\d+)/)[0] &&
+	if(checklib('libbfd') &&
 	   test_for_header_file('bfd.h'))
-	{
+           {
             $cflags .= ' -D__HAVE_LIBBFD__ ';
 	    $extralibs.= ' -lbfd ';
         }
@@ -1215,12 +1215,37 @@ sub stripversion
 
 sub checklib
 {
-    # simple library checker : beware unescaped grep
+    # simple library checking function :
+    # on error return '' (empty string)
+
+    # get the library name
     my $lib = shift;
-    my $r = `ldconfig -p |grep $lib`;
+    my $striplib = ($lib=~/lib(.*)/)[0];
+    my $r;
+    
+    # first try with ld because this is supposed to work on the mac
+    $r = `ld -l$striplib 2>\&1`; 
+    
+    # check for error string : if the library isn't found
+    # then return an empty
+    if($r=~/cannot find -l$striplib/ || 
+       $r=~/not found for -l$striplib/)
+    {
+        # library not found : return empty string
+        return '';
+    }
+
+    # find location using ld, return if found
+    $r = `ld --verbose -l$striplib 2>\&1`;
+    if($r=~/attempt to open (\S+lib$striplib.so) succeeded/)
+    {
+        return $1;
+    }
+    
+    # ld failed, try ldconfig
+    $r = `ldconfig -p |grep $lib`;
     $r=~s/^\s+//;
     $r=~s/\s+$//;
-
     return $r if($r ne '');
 
     # check in LIBRARY_PATH and LD_LIBRARY_PATH
-- 
GitLab