Index: trunk/Ohana/configure
===================================================================
--- trunk/Ohana/configure	(revision 7080)
+++ trunk/Ohana/configure	(revision 10298)
@@ -76,7 +76,9 @@
 if ($#args != 1) goto usage
 
-# sun (at least) seems to need the socket library 
-# linux does not
-set archlib = ""
+set needlibs = "png z jpeg readline X11 pthread m"
+set syslibpath = "/usr/lib /usr/X11R6/lib /usr/openwin/lib"
+
+set needincs = "math.h fcntl.h malloc.h errno.h time.h memory.h stdlib.h string.h X11/X.h"
+set sysincpath = "/usr/include /usr/X11R6/include /usr/openwin/include"
 
 # check the hardware architecture:
@@ -93,6 +95,6 @@
      set arch="sun4";
    endif
-   # XXX old solaris needed termcap for readline
-   set archlib = "libsocket libnsl"
+   # sun (at least) seems to need the socket library (linux does not)
+   set needlibs = "$needlibs libsocket libnsl"
    breaksw;
  case Linux:
@@ -118,6 +120,11 @@
 set root = `pwd`
 if ($prefix == "") set prefix = $root
-set inc = $prefix/include/$arch
-set lib = $prefix/lib/$arch
+if ($vararch) then
+  set inc = $prefix/include/$arch
+  set lib = $prefix/lib/$arch
+else
+  set inc = $prefix/include
+  set lib = $prefix/lib
+endif
 if ($?LD_LIBRARY_PATH) then 
   set libpath = `echo $LD_LIBRARY_PATH | tr ':' ' '`
@@ -127,103 +134,91 @@
 
 # check for basic libraries
-set fail = 0
-foreach f ( libpng libz libjpeg libreadline $archlib )
-    foreach g ( /usr/lib $lib $libpath )
-	set name = "$g/$f.a"
-	if (-e $name) then
-	    echo "found $name"
-	    goto next_lib;
-	endif
-	set name = "$g/$f.so"
-	if (-e $name) then
-	    echo "found $name"
-	    goto next_lib;
-	endif
+set faillibs = ""
+set libflags = ""
+set libdirs  = ""
+foreach f ( $needlibs )
+    foreach g ( $syslibpath $lib $libpath )
+	set name = "$g/lib$f.a"
+	if (-e $name) goto got_lib;
+	set name = "$g/lib$f.so"
+	if (-e $name) goto got_lib;
     end
-    echo "missing $f"
-    set fail = 1
-next_lib:
+    echo "missing lib$f"
+    set faillibs = "$faillibs lib$f"
     continue
+got_lib:
+    echo "found lib$f ($name)"
+    echo "$libdirs" | grep -- "-L$g " > /dev/null
+    if ($status) then
+      set libdirs  = "$libdirs -L$g "
+    endif
+    echo "$libflags" | grep -- "-l$f " > /dev/null
+    if ($status) then
+      set libflags = "$libflags -l$f "
+    endif
 end
 
+# we need a curses library; can choose one of the following:
 # check for termcap, curses, etc
-set tlibflag = ""
 foreach f ( ncurses curses termcap )
-      foreach g ( /usr/lib $lib $libpath )
+    foreach g ( $syslibpath $lib $libpath )
 	set name = "$g/lib$f.a"
-	if (-e $name) then
-	    echo "found $name"
-	    set tlibflag = "-l$f"
-	    goto got_curses;
-	endif
+	if (-e $name) goto got_curses;
 	set name = "$g/lib$f.so"
-	if (-e $name) then
-	    echo "found $name"
-	    set tlibflag = "-l$f"
-	    goto got_curses;
-	endif
+	if (-e $name) goto got_curses;
     end
 end
-if ("$tlibflag" == "") then
-  echo "missing a valid curses library"
-  set fail = 1
-endif
+set faillibs = "$faillibs (ncurses | curses | termcap)"
+echo "missing a valid curses library"
+echo "missing: $faillibs"
+echo "please find them and install them in $lib"
+exit 1
 
 got_curses:
-
-if ($fail) then
+  echo "found $f ($name)"
+  echo "$libdirs" | grep -- "-L$g " > /dev/null
+  if ($status) then
+    set libdirs  = "$libdirs -L$g "
+  endif
+  echo "$libflags" | grep -- "-l$f " > /dev/null
+  if ($status) then
+    set libflags = "$libflags -l$f "
+  endif
+
+if ("$faillibs" != "") then
   echo "your installation is missing some important libraries"
+  echo "missing: $faillibs"
   echo "please find them and install them in $lib"
   exit 1
 endif    
 
-# check for basic libraries
-set fail = 0
-foreach f ( libX11.a )
-    foreach g ( /usr/lib $lib $libpath /usr/X11R6/lib /usr/openwin/lib )
-	set name = "$g/$f"
-	if (-e $name) then 
-	    echo "found $g/$f"
-	    set xlib = $g
-	    goto next_xlib;
-	endif
-    end
-    echo "missing $f"
-    set fail = 1
-next_xlib:
-    continue
+# check for headers
+set failincs = ""
+set incdirs = ""
+foreach f ( $needincs )
+  foreach g ( $sysincpath $inc )
+    set name = "$g/$f"
+    if (-e $name) goto got_inc;
+  end
+  echo "missing $f"
+  set failincs = "$failincs $f"
+  continue
+got_inc:
+  echo "found $f ($name)"
+  echo "$incdirs" | grep -- "-I$g " > /dev/null
+  if ($status) then
+    set incdirs = "$incdirs -I$g "
+  endif
 end
 
-if ($fail) then
-  echo "your installation is missing some important libraries"
-  echo "please find them and install them in $lib"
+if ("$failincs" != "") then
+  echo "your installation is missing some important library headers"
+  echo "please find them and install them in $inc"
   exit 1
 endif    
 
-# check for X11 headers
-set fail = 0
-foreach f ( X11/X.h )
-    foreach g ( /usr/include $inc /usr/X11R6/include /usr/openwin/include )
-	set name = "$g/$f"
-	if (-e $name) then 
-	    echo "found $g/$f"
-	    set xinc = $g
-	    goto next_xinc;
-	endif
-    end
-    echo "missing $f"
-    set fail = 1
-next_xinc:
-    continue
-end
-
-if ($fail) then
-  echo "your installation is missing some important libraries"
-  echo "please find them and install them in $lib"
-  exit 1
-endif    
-
-echo XINC: $xinc
-echo XLIB: $xlib
+echo INCDIRS: $incdirs
+echo LIBDIRS: $libdirs
+echo LIBFLAGS: $libflags
 
 echo ARCH: $arch
@@ -245,9 +240,9 @@
 # modify the BINDIR
 if ("$bindir" == "") then
-  set subdir = bin/$arch
+  set subdir = bin
   if ($vararch) set subdir = 'bin/$(ARCH)'
   set bindir = $prefix/$subdir
 endif
-cat Configure.in.tmp | sed "s| BINDIR| $bindir|" > Configure.tmp
+cat Configure.in.tmp | sed "s|@BINDIR@| $bindir|" > Configure.tmp
 rm -f Configure.in.tmp
 mv Configure.tmp Configure.in.tmp
@@ -256,9 +251,9 @@
 # modify the INCDIR
 if ("$incdir" == "") then
-  set subdir = include/$arch
+  set subdir = include
   if ($vararch) set subdir = 'include/$(ARCH)'
   set incdir = $prefix/$subdir
 endif
-cat Configure.in.tmp | sed "s| INCDIR| $incdir|" > Configure.tmp
+cat Configure.in.tmp | sed "s|@INCDIR@|$incdir|" > Configure.tmp
 rm -f Configure.in.tmp
 mv Configure.tmp Configure.in.tmp
@@ -267,9 +262,9 @@
 # modify the LIBDIR
 if ("$libdir" == "") then
-  set subdir = lib/$arch
+  set subdir = lib
   if ($vararch) set subdir = 'lib/$(ARCH)'
   set libdir = $prefix/$subdir
 endif
-cat Configure.in.tmp | sed "s| LIBDIR| $libdir|" > Configure.tmp
+cat Configure.in.tmp | sed "s|@LIBDIR@|$libdir|" > Configure.tmp
 rm -f Configure.in.tmp
 mv Configure.tmp Configure.in.tmp
@@ -280,5 +275,5 @@
   set mandir = $prefix/man
 endif
-cat Configure.in.tmp | sed "s| MANDIR| $mandir|" > Configure.tmp
+cat Configure.in.tmp | sed "s|@MANDIR@|$mandir|" > Configure.tmp
 rm -f Configure.in.tmp
 mv Configure.tmp Configure.in.tmp
@@ -290,5 +285,5 @@
 endif
 set helpdir = $datadir/help
-cat Configure.in.tmp | sed "s| HELPDIR| $helpdir|" > Configure.tmp
+cat Configure.in.tmp | sed "s|@HELPDIR@|$helpdir|" > Configure.tmp
 rm -f Configure.in.tmp
 mv Configure.tmp Configure.in.tmp
@@ -298,10 +293,10 @@
   cat Configure.in.tmp | sed "s|^\s*ARCH|# ARCH|" > Configure.tmp
 else 
-  cat Configure.in.tmp | sed "s|ARCHVAL|$arch|" > Configure.tmp
+  cat Configure.in.tmp | sed "s|@ARCHVAL@|$arch|" > Configure.tmp
 endif 
 rm -f Configure.in.tmp
 mv Configure.tmp Configure.in.tmp
 
-cat Configure.in.tmp | sed "s|ROOTDIR|$root|" | sed "s|XINCDIR|$xinc|" | sed "s|XLIBDIR|$xlib|" | sed "s|TLIBFLAG|$tlibflag|" | sed "s|OPTFLAGS|$optflags $pedantic|" > Configure
+cat Configure.in.tmp | sed "s|@ROOTDIR@|$root|" | sed "s|@INCDIRS@|$incdirs|" | sed "s|@LIBDIRS@|$libdirs|" | sed "s|@LIBFLAGS@|$libflags|" | sed "s|@OPTFLAGS@|$optflags $pedantic|" > Configure
 rm -f Configure.in.tmp Configure.tmp
 
