Index: trunk/Ohana/configure.tcsh
===================================================================
--- trunk/Ohana/configure.tcsh	(revision 12875)
+++ trunk/Ohana/configure.tcsh	(revision 13615)
@@ -150,8 +150,8 @@
 
 if (! $?CPPFLAGS) then
-  set CPPFLAGS = 
+  set CPPFLAGS = ""
 endif  
-if ($pedantic) set CPPFLAGS = "$CPPFLAGS -Wall -Werror"
-if ($memcheck) set CPPFLAGS = "$CPPFLAGS -DOHANA_MEMORY"
+if ($pedantic) set CPPFLAGS = "$CPPFLAGS-Wall -Werror "
+if ($memcheck) set CPPFLAGS = "$CPPFLAGS-DOHANA_MEMORY "
 
 if (! $?LDFLAGS) then
@@ -169,5 +169,7 @@
 set needlibs   = "$needlibs m"
 
-# /usr/local/include/libpng is really pretty lame...
+set optlibs    = ""
+set optlibs    = "$optlibs mysqlclient"
+
 set sysincpath = "/usr/include /usr/local/include /usr/X11R6/include"
 
@@ -211,4 +213,7 @@
 set needincs = "$needincs zlib.h"
 
+set optincs  = ""
+set optincs = "$optincs mysql.h"
+
 # XXX need to have options for non-ANSI includes? (ie, varargs.h)
 # set needincs = "$needincs cfuncs.h" - from non-ANSI option in ohana.h
@@ -304,5 +309,5 @@
 # check for basic libraries
 echo ""
-echo "searching for needed external libraries..."
+echo "searching for required external libraries..."
 set faillibs = ""
 set libflags = ""
@@ -310,5 +315,5 @@
 set nonomatch
 foreach f ( $needlibs )
-  foreach g ( $syslibpath $libdir $libpath )
+  foreach g ( $libpath $libdir $syslibpath )
     set name = $g/lib$f.a
     if (-e $name[1]) goto got_lib;
@@ -335,5 +340,5 @@
 # check for termcap, curses, etc
 foreach f ( ncurses curses termcap )
-    foreach g ( $syslibpath $libdir $libpath )
+    foreach g ( $libpath $libdir $syslibpath )
         set name = $g/lib$f.a
         if (-e $name[1]) goto got_curses;
@@ -356,5 +361,5 @@
   echo "$libflags" | grep -- "-l$f " > /dev/null
   if ($status) then
-    set libflags = "$libflags-l$f"
+    set libflags = "$libflags-l$f "
   endif
 
@@ -366,4 +371,33 @@
 endif    
 
+# check for optional libraries
+echo ""
+echo "searching for optional external libraries..."
+foreach f ( $optlibs )
+  foreach g ( $libpath $libdir $syslibpath )
+    set name = $g/lib$f.a
+    if (-e $name[1]) goto got_optlib;
+    set name = $g/lib$f.$dlltype
+    if (-e $name[1]) goto got_optlib;
+    set name = $g/*/lib$f.a
+    if (-e $name[1]) goto got_optlib;
+    set name = $g/*/lib$f.$dlltype
+    if (-e $name[1]) goto got_optlib;
+  end
+  echo "missing lib$f; skipping"
+  continue
+got_optlib:
+  echo "found lib$f ($name[1])"
+  set gotlibdir = `dirname $name[1]`
+  echo "$libdirs" | grep -- "-L$gotlibdir " > /dev/null
+  if ($status) then
+    set libdirs  = "$libdirs-L$gotlibdir "
+  endif
+  echo "$libflags" | grep -- "-l$f " > /dev/null
+  if ($status) then
+    set libflags = "$libflags-l$f "
+  endif
+end
+
 # add the CPATH
 if ($?CPATH) then 
@@ -373,7 +407,7 @@
 endif
 
-# check for headers (including in subdirectories)
+# check for required headers (including in subdirectories)
 echo ""
-echo "searching for needed external header files..."
+echo "searching for required external header files..."
 set failincs = ""
 set incdirs = ""
@@ -382,4 +416,10 @@
     set name = "$g/$f"
     if (-e $name) goto got_inc;
+    set nonomatch
+    set name = $g/*/$f
+    echo "$name" | grep "*" > /dev/null
+    if (! $status) continue
+    unset nonomatch
+    if (-e $name[1]) goto got_inc;
   end
   echo "missing $f"
@@ -387,8 +427,13 @@
   continue
 got_inc:
-  echo "found $f ($name[1])"
-  echo "$incdirs" | grep -- "-I$g " > /dev/null
-  if ($status) then
-    set incdirs = "$incdirs-I$g "
+  set gotinc = $name[1]
+  echo "found $f ($gotinc)"
+  set gotincdir = `dirname $name[1]`
+  if (`dirname $f` != ".") then
+    set gotincdir = `dirname $gotincdir`
+  endif
+  echo "$incdirs" | grep -- "-I$gotincdir " > /dev/null
+  if ($status) then
+    set incdirs = "$incdirs-I$gotincdir "
   endif
 end
@@ -399,4 +444,35 @@
   exit 1
 endif    
+
+# check for optional headers (including in subdirectories)
+echo ""
+echo "searching for optional external header files..."
+foreach f ( $optincs )
+  foreach g ( $incdir $incpath $sysincpath )
+    set name = "$g/$f"
+    if (-e $name) goto got_optinc;
+    set nonomatch
+    set name = $g/*/$f
+    echo "$name" | grep "*" > /dev/null
+    if (! $status) continue
+    unset nonomatch
+    if (-e $name[1]) goto got_optinc;
+  end
+  echo "missing $f; skipping"
+  continue
+got_optinc:
+  set gotinc = $name[1]
+  echo "found $f ($gotinc)"
+  set gotincdir = `dirname $name[1]`
+  if (`dirname $f` != ".") then
+    set gotincdir = `dirname $gotincdir`
+  endif
+  echo "$incdirs" | grep -- "-I$gotincdir " > /dev/null
+  if ($status) then
+    set incdirs = "$incdirs-I$gotincdir "
+  endif
+  set haveflag = `echo $f | tr '[:lower:]' '[:upper:]' | tr '.' '_'`
+  set CPPFLAGS = "$CPPFLAGS-DHAVE_$haveflag "
+end
 
 echo 
