From ee383ed962cf5ecc205e47de65a1eb8608f69607 Mon Sep 17 00:00:00 2001
From: Robert Izzard <r.izzard@surrey.ac.uk>
Date: Sat, 7 Sep 2019 14:30:10 +0100
Subject: [PATCH] add checks to prevent undef var messages in configure on RPi2

---
 configure | 38 ++++++++++++++++++++++++++++----------
 1 file changed, 28 insertions(+), 10 deletions(-)

diff --git a/configure b/configure
index 1ea388d13..608b283ea 100755
--- a/configure
+++ b/configure
@@ -1,21 +1,36 @@
 #!/usr/bin/env perl
 #
-# configuration script for the binary_c/nucsyn code
+# The binary_c stellar population nucleosynthesis framework.
+#
+# Contact: r.izzard@surrey.ac.uk or rob.izzard@gmail.com
+#
+# http://personal.ph.surrey.ac.uk/~ri0005/binary_c.html
+# https://gitlab.eps.surrey.ac.uk/ri0005/binary_c
+# https://groups.google.com/forum/#!forum/binary_c-nucsyn-announce
+# https://groups.google.com/forum/#!forum/binary_c-nucsyn-devel
+# https://twitter.com/binary_c_code
+# https://www.facebook.com/groups/149489915089142/
+#
+# Please see the files README, LICENCE and CHANGES,
+# and the doc/ directory for documentation.
+#
+# This file is the configuration script for binary_c.
+#
 # This is version 2, a more modular, flexible script (I hope)
 # without all the dirty hacks, just some of them! :)
 #
-# usage:
+# Usage:
 # 
-# Normal use, auto-detected CPU optimization:
+# Normal use:
 # ./configure
 #
-# Debugging (-g):
+# Debugging (-g -Og):
 # ./confgure debug
 #
 # Debugging with -O3:
 # ./configure optdebug
 #
-# Accurate (try to prevent floating point issues)
+# Accurate (try to prevent floating point issues, slower):
 # ./configure accurate
 #
 # For DUMA (http://en.wikipedia.org/wiki/Duma_%28software%29)
@@ -363,7 +378,8 @@ sub secondary_variables
 		    my $orig=$regexp;
 		    $regexp=~s/^\d+ //;
 		    #print "Check regexp\n";
-		    if($cpuinfo{'flags'}=~/$regexp/)
+		    if(defined $cpuinfo{'flags'} &&
+                       $cpuinfo{'flags'}=~/$regexp/)
 		    {
 			$coptflags.=$sse_hash{$orig}.' ';
 			last;
@@ -413,8 +429,8 @@ sub secondary_variables
     {
 	$coptflags.=' -ffunction-sections ';
 	$lib.=' -L/usr/lib ';
-
-	print 'CPU Flags ',$cpuinfo{'flags'},"\n";
+        
+	print 'CPU Flags ',$cpuinfo{'flags'}//'',"\n";
 		
 	if($cpu=~/pentium/)
 	{
@@ -726,7 +742,8 @@ sub get_cpu
              $cpuinfo{'model name'}=~/atom/i ? 'atom' :
              $cpuinfo{'model name'}=~/Core/ ? 
              ($cpuinfo{'model name'}=~/i7/ ?
-              ($cpuinfo{flags}=~/\bavx\b/ ? 'corei7-avx' : 'i7') :
+              (defined $cpuinfo{flags} &&
+               ($cpuinfo{flags}=~/\bavx\b/ ? 'corei7-avx' : 'i7')) :
               'core2')  : 'i686' ) : 'i686';
     }
     elsif($cpuinfo{'model name'}=~/amd/i)
@@ -1753,7 +1770,8 @@ sub features
         # CPU has AVX or not?
         have_avx =>
         {
-            check =>(!$generic && 
+            check =>(!$generic &&
+                     defined $cpuinfp{flags} &&
                      $cpuinfo{flags}=~/\bavx\b/) ? 1 : 0,
             cflags => ' -mavx ',
         },
-- 
GitLab