--- configure.orig	Thu Jan 31 07:23:55 2002
+++ configure	Thu Feb 28 04:05:01 2002
@@ -1435,7 +1435,9 @@
 
 # Defaults
 
-M4=m4
+if test -z "$M4"; then
+    M4=m4
+fi
 
 # Double precision
 # Note that because there is no standard way to invoke double
@@ -1667,9 +1669,9 @@
 # Optimization
 
 if test "$with_opt" = "yes"; then
-    OPT_FLAG_C=-O
-    OPT_FLAG_CXX=-O
-    OPT_FLAG_F=-O
+    OPT_FLAG_C="$CFLAGS"
+    OPT_FLAG_CXX="$CXXFLAGS"
+    OPT_FLAG_F="$FFLAGS"
 fi
 
 # ----------------------------------------------------------------------------
@@ -2143,16 +2145,36 @@
 # Default linker library commands.  These may need version numbers
 # appended to them though.
 
-ITKLIBSTR=-litk
-TKLIBSTR=-ltk
-ITCLLIBSTR=-litcl
-TCLLIBSTR=-ltcl
-XLIBSTR=-lX11
-GDLIBSTR=-lgd
-CDLIBSTR=-lcd
-PNGLIBSTR=-lpng
-JPEGLIBSTR=-ljpeg
-ZLIBLIBSTR=-lz
+if test -z "$ITKLIBSTR"; then
+    ITKLIBSTR=-litk
+fi
+if test -z "$TKLIBSTR"; then
+    TKLIBSTR=-ltk
+fi
+if test -z "$ITCLLIBSTR"; then
+    ITCLLIBSTR=-litcl
+fi
+if test -z "$TCLLIBSTR"; then
+    TCLLIBSTR=-ltcl
+fi
+if test -z "$XLIBSTR"; then
+    XLIBSTR=-lX11
+fi
+if test -z "$GDLIBSTR"; then
+    GDLIBSTR=-lgd
+fi
+if test -z "$CDLIBSTR"; then
+    CDLIBSTR=-lcd
+fi
+if test -z "$PNGLIBSTR"; then
+    PNGLIBSTR=-lpng
+fi
+if test -z "$JPEGLIBSTR"; then
+    JPEGLIBSTR=-ljpeg
+fi
+if test -z "$ZLIBSTR"; then
+    ZLIBLIBSTR=-lz
+fi
 
 # Add the current directory to the include path.  This must occur
 # first in the list, before we add the directories for any auxilliary
@@ -2646,8 +2668,7 @@
   rm -rf conftest*
   
 	incdirs="\
-	/usr/include \
-	/usr/local/include"
+	/usr/include"
 
         for dir in $incdirs; do
 	    if test -r "$dir/gd.h"; then
@@ -2705,8 +2726,7 @@
   echo "$ac_t""no" 1>&6
 
 	libdirs="\
-	/usr/lib \
-	/usr/local/lib"
+	/usr/lib"
 
         for dir in $libdirs; do
 	    if test -r "$dir/libgd.so" -o -r "$dir/libgd.a"; then
@@ -2767,8 +2787,7 @@
   echo "$ac_t""no" 1>&6
 
 	libdirs="\
-	/usr/lib \
-	/usr/local/lib"
+	/usr/lib"
 
         for dir in $libdirs; do
 	    if test -r "$dir/libpng.so" -o -r "$dir/libpng.a"; then
@@ -2829,8 +2848,7 @@
   echo "$ac_t""no" 1>&6
 
 	libdirs="\
-	/usr/lib \
-	/usr/local/lib"
+	/usr/lib"
 
         for dir in $libdirs; do
 	    if test -r "$dir/libjpeg.so" -o -r "$dir/libjpeg.a"; then
@@ -2891,8 +2909,7 @@
   echo "$ac_t""no" 1>&6
 
 	libdirs="\
-	/usr/lib \
-	/usr/local/lib"
+	/usr/lib"
 
         for dir in $libdirs; do
 	    if test -r "$dir/libz.so" -o -r "$dir/libz.a"; then
@@ -2915,6 +2932,7 @@
     fi
 fi
 
+if /usr/bin/false ; then
 GDLIBS=""
 GDINCS=""
 if test "$enable_png" = "yes" -o "$enable_jpeg" = "yes"; then
@@ -3037,6 +3055,7 @@
 
     fi
 fi
+fi
 
 #next test requires C language
 
@@ -3161,8 +3180,7 @@
   rm -rf conftest*
   
 	incdirs="\
-	/usr/include \
-	/usr/local/include"
+	/usr/include"
 
         for dir in $incdirs; do
 	    if test -r "$dir/cd.h"; then
@@ -3219,8 +3237,7 @@
   echo "$ac_t""no" 1>&6
 
 	libdirs="\
-	/usr/lib \
-	/usr/local/lib"
+	/usr/lib"
 
         for dir in $libdirs; do
 	    if test -r "$dir/libcd.so" -o -r "$dir/libcd.a"; then
@@ -3322,7 +3339,6 @@
 $prefix/include \
 $HOME/local/include \
 $HOME/include \
-/usr/local/include \
 /usr/include/tcl \
 /usr/include"
 
@@ -3333,7 +3349,6 @@
 $prefix/lib \
 $HOME/local/lib \
 $HOME/lib \
-/usr/local/lib \
 /usr/lib"
 
 incdirs=$incdirs_default
@@ -5072,7 +5087,6 @@
 	$HOME/local/lib \
 	$HOME/dbmalloc/lib \
 	$HOME/lib \
-	/usr/local/lib \
 	/usr/local/dbmalloc/lib \
 	/usr/lib"
 
@@ -5512,6 +5526,13 @@
 		EXTRA_LIBS="-ldl -lm"
 	    fi
 	;;
+	FreeBSD* )
+	    if test "$enable_f77" = "yes"; then
+		EXTRA_LIBS="$EXTRA_LIBS -lm -lg2c"
+	    else
+		EXTRA_LIBS="$EXTRA_LIBS -lm"
+	    fi
+	;;
 	* ) 	
 	    echo $ac_n "checking for main in -lXbsd""... $ac_c" 1>&6
 echo "configure:5518: checking for main in -lXbsd" >&5
@@ -5793,6 +5814,20 @@
             # for Linux.)
 	    SHLIB_F77FLAGS=-fPIC
 	;;
+	FreeBSD* )
+	    SHLIB_CCFLAGS="-fpic -DPIC"
+	    SHLIB_CXXFLAGS="-fpic -DPIC"
+	    echo "$ac_t""okay" 1>&6
+	    if [ "${PORTOBJFORMAT}" = "elf" ]; then
+		SO='.so.$(MAJOR_VERSION)'
+		SHLIB_BUILD="$CC -shared -Wl,-soname -Wl,\$@ -o"
+		SOVERSION='$(MAJOR_VERSION)'
+	    else
+		SO='.so.$(MAJOR_VERSION).$(MINOR_VERSION)'
+		SHLIB_BUILD="ld -Bshareable -o"
+		SOVERSION='$(MAJOR_VERSION).$(MINOR_VERSION)'
+	    fi
+	;;
 	HP-UX-* )
 	    SO=".sl"
 	    SHLIB_F77FLAGS="+z"
@@ -9672,6 +9707,7 @@
 s%@LDCXX_FLAGS@%$LDCXX_FLAGS%g
 s%@F77_FLAGS@%$F77_FLAGS%g
 s%@LDF_FLAGS@%$LDF_FLAGS%g
+s%@M4@%$M4%g
 s%@M4_FLAGS@%$M4_FLAGS%g
 s%@CPP@%$CPP%g
 s%@GTK_CONFIG@%$GTK_CONFIG%g