Index: trunk/Ohana/configure.tcsh
===================================================================
--- trunk/Ohana/configure.tcsh	(revision 11753)
+++ trunk/Ohana/configure.tcsh	(revision 11888)
@@ -17,6 +17,9 @@
 # evaluate command-line options
 set vararch = 0
+set optimize = 0
+set pedantic = 0
+set memcheck = 0
+
 set prefix  = ""
-
 set bindir  = ""
 set libdir  = ""
@@ -25,24 +28,32 @@
 set datadir  = ""
 set sysconfdir  = ""
-set optflags = "-g -O0"
-set pedantic = ""
 
 set root    = ""
 set args    = ""
+
 while ("$1" != "") 
- switch ($1)
-  case --vararch
-   set vararch = 1
-   breaksw;
-  # options passed by jhbuild which we ignore
+ switch ("$1")
+  # options passed by jhbuild or others which we ignore
   case --enable-maintainer-mode
   case --no-create
   case --no-recursion
+  case --sbindir
+  case --libexecdir
+  case --sharedstatedir
+  case --localstatedir
+  case --oldincludedir
+  case --infodir
+   breaksw;
+  case --vararch
+   set vararch = 1
    breaksw;
   case --enable-optimize
-   set optflags = "-O2"
+   set optimize = 1
+   breaksw;
+  case --enable-memcheck
+   set memcheck = 1
    breaksw;
   case --pedantic
-   set pedantic = "-Wall -Werror"
+   set pedantic = 1
    breaksw;
   case --prefix*
@@ -116,4 +127,25 @@
 end
 if ($#args != 1) goto usage
+
+# set values for CC, CFLAGS, CPPFLAGS, LDFLAGS
+if (! $?CC) then
+  set CC = gcc
+endif  
+
+if (! $?CFLAGS) then
+  set CFLAGS = "-g -O0"
+endif  
+# optimize overrides user-supplied CFLAGS
+if ($optimize) set CFLAGS = "-O2"
+
+if (! $?CPPFLAGS) then
+  set CPPFLAGS = 
+endif  
+if ($pedantic) set CPPFLAGS = "$CPPFLAGS -Wall -Werror"
+if ($memcheck) set CPPFLAGS = "$CPPFLAGS -DOHANA_MEMORY"
+
+if (! $?LDFLAGS) then
+  set LDFLAGS = 
+endif  
 
 set syslibpath = "/lib /usr/lib /usr/X11R6/lib /usr/openwin/lib /usr/local/lib"
@@ -165,5 +197,5 @@
 set needincs = "$needincs zlib.h"
 
-# need to have options for non-ANSI includes? (ie, varargs.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
 # set needincs = "$needincs float.h" - is from missing_proto (CFHT)
@@ -174,4 +206,5 @@
 # check the hardware architecture:
 set sys=`uname -s` 
+set ranlib = "ranlib"
 switch ($sys)
  case IRIX64:
@@ -186,5 +219,6 @@
    endif
    # sun (at least) seems to need the socket library (linux does not)
-   # set needlibs = "$needlibs libsocket libnsl"
+   set needlibs = "$needlibs libsocket libnsl"
+   set ranlib = "touch"
    breaksw;
  case Linux:
@@ -208,5 +242,4 @@
 
 # set up the basic directory names:
-# XXX : this should be set based on the rules for libdir below
 set root = `pwd`
 if ($prefix == "") set prefix = $root
@@ -246,9 +279,9 @@
     echo "$libdirs" | grep -- "-L$g " > /dev/null
     if ($status) then
-      set libdirs  = "$libdirs -L$g "
+      set libdirs  = "$libdirs-L$g "
     endif
     echo "$libflags" | grep -- "-l$f " > /dev/null
     if ($status) then
-      set libflags = "$libflags -l$f "
+      set libflags = "$libflags-l$f "
     endif
 end
@@ -274,9 +307,9 @@
   echo "$libdirs" | grep -- "-L$g " > /dev/null
   if ($status) then
-    set libdirs  = "$libdirs -L$g "
+    set libdirs  = "$libdirs-L$g "
   endif
   echo "$libflags" | grep -- "-l$f " > /dev/null
   if ($status) then
-    set libflags = "$libflags -l$f "
+    set libflags = "$libflags-l$f"
   endif
 
@@ -305,5 +338,5 @@
   echo "$incdirs" | grep -- "-I$g " > /dev/null
   if ($status) then
-    set incdirs = "$incdirs -I$g "
+    set incdirs = "$incdirs-I$g "
   endif
 end
@@ -315,24 +348,26 @@
 endif    
 
-echo ""
-echo INCDIRS: $incdirs
-echo LIBDIRS: $libdirs
-echo LIBFLAGS: $libflags
-
-echo ARCH: $arch
-echo ROOT: $root
-echo PREFIX: $prefix
 echo 
-
-#echo BINDIR $bindir
-#echo LIBDIR $libdir
-#echo INCDIR $incdir
-#echo DATADIR $datadir
-#echo MANDIR $mandir
-
+echo "Compiler options:"
+echo "CC: $CC"
+echo "CFLAGS: $CFLAGS"
+echo "CPPFLAGS: $CPPFLAGS"
+echo "LDFLAGS: $LDFLAGS"
+
+echo
+echo "Additional compiler flags:"
+echo "INCDIRS: $incdirs"
+echo "LIBDIRS: $libdirs"
+echo "LIBFLAGS: $libflags"
+
+echo 
+echo "ARCH: $arch"
+echo "ROOT: $root"
+echo "PREFIX: $prefix"
+echo 
+
+# the config.tools fixconf operations below interpolate values in Configure
 if (-e Configure) mv Configure Configure.bak
-
-rm -f Configure.in.tmp Configure.tmp
-cp Configure.in Configure.in.tmp
+cp Configure.in Configure
 
 # we don't currently need to modify the Makefile but since configure
@@ -340,5 +375,10 @@
 cp -f Makefile.in Makefile
 
-# modify the BINDIR
+# the ROOTDIR defines the location of the source tree
+./config.tools fixconf @ROOTDIR@  "$root"
+
+# the following entries define the target installation locations 
+
+# BINDIR (DESTBIN) holds the output binary files
 if ("$bindir" == "") then
   set subdir = bin
@@ -351,10 +391,9 @@
   set binpath = $prefix/$subpath
 endif
-cat Configure.in.tmp | sed "s|@BINDIR@| $bindir|" > Configure.tmp
-rm -f Configure.in.tmp
-mv Configure.tmp Configure.in.tmp
-echo BINDIR $bindir
-
-# modify the INCDIR
+set bindir = `./config.tools fixpath $bindir`
+./config.tools fixconf @BINDIR@ $bindir
+echo DESTBIN $bindir
+
+# INCDIR (DESTINC) holds the output header files
 if ("$incdir" == "") then
   set subdir = include
@@ -362,10 +401,9 @@
   set incdir = $prefix/$subdir
 endif
-cat Configure.in.tmp | sed "s|@INCDIR@|$incdir|" > Configure.tmp
-rm -f Configure.in.tmp
-mv Configure.tmp Configure.in.tmp
-echo INCDIR $incdir
-
-# modify the LIBDIR
+set incdir = `./config.tools fixpath $incdir`
+./config.tools fixconf @INCDIR@ $incdir
+echo DESTINC $incdir
+
+# LIBDIR (DESTLIB) holds the output library files
 if ("$libdir" == "") then
   set subdir = lib
@@ -373,37 +411,46 @@
   set libdir = $prefix/$subdir
 endif
-cat Configure.in.tmp | sed "s|@LIBDIR@|$libdir|" > Configure.tmp
-rm -f Configure.in.tmp
-mv Configure.tmp Configure.in.tmp
-echo LIBDIR $libdir
-
-# modify the MANDIR
+set libdir = `./config.tools fixpath $libdir`
+./config.tools fixconf @LIBDIR@ $libdir
+echo DESTLIB $libdir
+
+# MANDIR (DESTMAN) holds the output man pages
 if ("$mandir" == "") then
   set mandir = $prefix/man
 endif
-cat Configure.in.tmp | sed "s|@MANDIR@|$mandir|" > Configure.tmp
-rm -f Configure.in.tmp
-mv Configure.tmp Configure.in.tmp
-echo MANDIR $mandir
-
-# modify the DATADIR
+set mandir = `./config.tools fixpath $mandir`
+./config.tools fixconf @MANDIR@ $mandir
+echo DESTMAN $mandir
+
+# DATADIR (DESTDATA) holds the general non-binary files
 if ("$datadir" == "") then
   set datadir = $prefix/share
 endif
-cat Configure.in.tmp | sed "s|@DATADIR@|$datadir|" > Configure.tmp
-rm -f Configure.in.tmp
-mv Configure.tmp Configure.in.tmp
-echo DATADIR $datadir
-
+set datadir = `./config.tools fixpath $datadir`
+./config.tools fixconf @DATADIR@ $datadir
+echo DESTDATA $datadir
+
+# the vararch option defines an automatic arch-dependent directory 
+# tree for DESTBIN, DESTLIB, DESTINC
 if ($vararch) then
-  cat Configure.in.tmp | sed "s|^\s*ARCH|# ARCH|" > Configure.tmp
+  ./config.tools fixconf "^\s*ARCH" "# ARCH"
 else 
-  cat Configure.in.tmp | sed "s|@ARCHVAL@|$arch|" > Configure.tmp
+  ./config.tools fixconf @ARCHVAL@ $arch
 endif 
-rm -f Configure.in.tmp
-mv Configure.tmp Configure.in.tmp
-
-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
+
+# INCDIRS, LIBDIRS, LIBFLAGS define include and library flags needed
+# by the externally-supplied libraries
+./config.tools fixconf @INCDIRS@  "$incdirs"
+./config.tools fixconf @LIBDIRS@  "$libdirs"
+./config.tools fixconf @LIBFLAGS@ "$libflags"
+
+# these are the compiler options
+./config.tools fixconf @CC@ "$CC"
+./config.tools fixconf @CFLAGS@ "$CFLAGS"
+./config.tools fixconf @CPPFLAGS@ "$CPPFLAGS"
+./config.tools fixconf @LDFLAGS@ "$LDFLAGS"
+
+# other architecture dependent options
+./config.tools fixconf @RANLIB@ "$ranlib"
 
 cat ohana-config.in | sed "s|@INCDIR@|$incdir|" | sed "s|@LIBDIR@|$libdir|" | sed "s|(ARCH)|ARCH|" > ohana-config
