Index: /trunk/Ohana/Configure.in
===================================================================
--- /trunk/Ohana/Configure.in	(revision 11887)
+++ /trunk/Ohana/Configure.in	(revision 11888)
@@ -1,15 +1,10 @@
 # Configure file for Ohana Package
-#
-# this is the location of the package
-# change this to match your location of the source
+# the values of the form @WORD@ are filled in by configure
+
+# location of the package and architecture
 ROOT    = @ROOTDIR@
 ARCH    = @ARCHVAL@
 
 # destination directories:
-# these are the installation directories.
-# if you use a different toplevel directory than $(ROOT), you might 
-# need to copy the include files in $(ROOT)/include by hand to the destination
-# LBIN	= PREFIX/bin/$(ARCH)
-
 DESTBIN	 = @BINDIR@
 DESTINC	 = @INCDIR@
@@ -18,16 +13,15 @@
 DESTDATA = @DATADIR@
 
-# prefered C compiler
-# CC = gcc -g -DOHANA_MEMORY -Wall -Werror
-CC = gcc @OPTFLAGS@
-INCDIRS = @INCDIRS@
-LIBDIRS = @LIBDIRS@
+# C compiler options
+CC       = @CC@
+CFLAGS   = @CFLAGS@
+CPPFLAGS = @CPPFLAGS@
+LDFLAGS  = @LDFLAGS@
+
+# flags for external dependencies
+INCDIRS  = @INCDIRS@
+LIBDIRS  = @LIBDIRS@
 LIBFLAGS = @LIBFLAGS@
 
 # select the appropriate version of ranlib
-RANLIB-sid = ranlib
-RANLIB-sol = touch
-RANLIB-linux = ranlib
-RANLIB-lin64 = ranlib
-RANLIB-linrh = ranlib
-RANLIB = $(RANLIB-$(ARCH))
+RANLIB = @RANLIB@
Index: /trunk/Ohana/Makefile.Common
===================================================================
--- /trunk/Ohana/Makefile.Common	(revision 11887)
+++ /trunk/Ohana/Makefile.Common	(revision 11888)
@@ -1,8 +1,12 @@
 # this file must be added to the makefile *after* LIB,BIN, etc are defined
 
-# XXX replace BINDIR, etc with DESTBIN in Configure.in
+# (INC)     & (LIB)     are the program's local include & lib directories
+# (DESTINC) & (DESTLIB) are the target installation include & lib directories
+# (INCDIRS) & (LIBDIRS) are all of the probed include & lib directories
+# (LIBFLAGS) is the list of -lXXX directives from configure for external libs
 
-CFLAGS	=	-I$(INC) -I$(DESTINC) $(INCDIRS) -D$(ARCH)
-LDFLAGS = 	-L$(LIB) -L$(DESTLIB) $(LIBDIRS) $(LIBFLAGS)
+BASE_CFLAGS   =	$(CFLAGS)
+BASE_CPPFLAGS =	$(CPPFLAGS) -I$(INC) -I$(DESTINC) $(INCDIRS) -D$(ARCH)
+BASE_LDFLAGS  = $(LDFLAGS) -L$(LIB) -L$(DESTLIB) $(LIBDIRS) $(LIBFLAGS)
 
 .PRECIOUS: %.$(ARCH).o
@@ -18,10 +22,9 @@
 
 %.$(ARCH).o : %.c
-	$(CC) $(CFLAGS) -c $< -o $@
+	$(CC) $(FULL_CFLAGS) $(FULL_CPPFLAGS) -c $< -o $@
 
 $(BIN)/%.$(ARCH):
-	@echo "trying $*"
 	@if [ ! -d $(BIN) ]; then mkdir -p $(BIN); fi
-	$(CC) -o $@ $^ $(LDFLAGS)
+	$(CC) $(FULL_CFLAGS) -o $@ $^ $(FULL_LDFLAGS)
 	@echo "compiled $*"
 	@echo ""
Index: /trunk/Ohana/config.tools
===================================================================
--- /trunk/Ohana/config.tools	(revision 11888)
+++ /trunk/Ohana/config.tools	(revision 11888)
@@ -0,0 +1,47 @@
+#!/bin/csh -f
+
+if ($#argv == 0) then
+  echo "USAGE: config.tools [fixpath | fixconf]"
+  exit 2
+endif
+
+if ("$argv[1]" == "fixpath") goto fixpath
+if ("$argv[1]" == "fixconf") goto fixconf
+
+echo "unknown option $argv[1]"
+exit 1
+
+#######
+fixpath:
+
+if ($#argv != 2) then
+  echo "USAGE: config.tools fixpath (path)"
+  exit 2
+endif
+
+set indir = $argv[2]
+
+# convert // to / in pathnames
+echo $indir | grep "\/\/" > /dev/null
+set success = $status
+while ($success == 0) 
+  set indir = `echo $indir | sed 's|\/\/|\/|g'`
+  echo $indir | grep "\/\/" > /dev/null
+  set success = $status
+end
+
+set indir = `echo $indir | sed 's|\/$||'`
+echo $indir
+exit 0
+
+#######
+fixconf:
+
+if ($#argv != 3) then
+  echo "USAGE: config.tools fixconf (NAME) (value)"
+  exit 2
+endif
+
+cat Configure | sed "s|$argv[2]|$argv[3]|" > Configure.tmp
+mv -f Configure.tmp Configure
+exit 0;
Index: /trunk/Ohana/configure
===================================================================
--- /trunk/Ohana/configure	(revision 11887)
+++ /trunk/Ohana/configure	(revision 11888)
@@ -1,3 +1,41 @@
 #!/bin/sh
 
-./configure.tcsh $*
+# strip out CC, CFLAGS, CPPFLAGS, LDFLAGS and set env vars
+while (( $# > 0 )); do
+  skip=0
+
+  # strip out CC, set as env variable
+  echo $1 | grep "^CC=" > /dev/null
+  if (( $? == 0 )) ; then
+    val=`echo $1 | sed "s|^CC=||"`
+    export CC=$val
+    skip=1
+  fi
+  # strip out CFLAGS, set as env variable
+  echo $1 | grep "^CFLAGS=" > /dev/null
+  if (( $? == 0 )) ; then
+    val=`echo $1 | sed "s|^CFLAGS=||"`
+    export CFLAGS=$val
+    skip=1
+  fi
+  # strip out CPPFLAGS, set as env variable
+  echo $1 | grep "^CPPFLAGS=" > /dev/null
+  if (( $? == 0 )) ; then
+    val=`echo $1 | sed "s|^CPPFLAGS=||"`
+    export CPPFLAGS=$val
+    skip=1
+  fi
+  # strip out LDFLAGS, set as env variable
+  echo $1 | grep "^LDFLAGS=" > /dev/null
+  if (( $? == 0 )) ; then
+    val=`echo $1 | sed "s|^LDFLAGS=||"`
+    export LDFLAGS=$val
+    skip=1
+  fi
+  if (( $skip == 0 )) ; then
+    args+=" $1"
+  fi
+  shift
+done
+
+./configure.tcsh $args
Index: /trunk/Ohana/configure.tcsh
===================================================================
--- /trunk/Ohana/configure.tcsh	(revision 11887)
+++ /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
