--- configure.in.orig	2006-03-22 19:04:54.000000000 +0100
+++ configure.in	2010-10-28 00:09:59.000000000 +0200
@@ -349,6 +349,31 @@
 
 ac_default_prefix="/usr/local/mpqc/$SC_VERSION"
 
+AC_ARG_WITH(blas,
+[  --with-blas             Gives BLAS name you use(e.g., -lblas).],
+BLASNAME=$withval
+)
+
+AC_ARG_WITH(lapack,
+[  --with-lapack           Gives LAPACK name you use(e.g., -llapack).],
+LAPACKNAME=$withval
+)
+
+AC_ARG_WITH(cxxoptflags,
+[  --with-cxxoptflags      Gives the C++ compiler optimization flags to use.],
+CXXOPTFLAGS=$withval
+)
+
+AC_ARG_WITH(ccoptflags,
+[  --with-ccoptflags       Gives the C compiler optimization flags to use.],
+CCOPTFLAGS=$withval
+)
+
+AC_ARG_WITH(f77optflags,
+[  --with-f77optflags      Gives the FORTRAN 77 optimization compiler flags to use.],
+F77OPTFLAGS=$withval
+)
+
 AC_ARG_WITH(cc,
 [  --with-cc               Gives the name of the C compiler to use.],
 CC=$withval
@@ -488,7 +513,7 @@
   CCA_CHEM_CONFIG=$withval
   echo Using cca-chem-config: $withval
 ],[
-  if test "$components" == "yes"; then
+  if test "$components" = "yes"; then
     AC_PATH_PROG(CCA_CHEM_CONFIG,cca-chem-config,"not-found")
   fi
 ]
@@ -736,6 +761,23 @@
   ;;
 esac
 
+if test "$CCOPTFLAGS" = NONE; then
+else
+   echo "overrides the cc optimization flag with $CCOPTFLAGS"
+   COPTIONS_OPT="$CCOPTFLAGS"
+fi
+if test "$CXXOPTFLAGS" = NONE; then
+else
+   echo "overrides the c++ optimization flag with $CXXOPTFLAGS"
+   CXXOPTIONS_OPT="$CXXOPTFLAGS"
+fi
+
+if test "$F77OPTFLAGS" = NONE; then
+else
+   echo "overrides the Fortran 77 optimization flag with $F77OPTFLAGS"
+   F77OPTIONS_OPT="$F77OPTFLAGS"
+fi
+
 dnl -- special architecture options --
 
 case $target_cpu in
@@ -747,7 +789,7 @@
      ;;
 esac
 
-if test X$GXX == Xyes; then
+if test X$GXX = Xyes; then
   AC_MSG_CHECKING([for C++ cpu tuning flag])
   AC_LANG_SAVE
   AC_LANG_CPLUSPLUS
@@ -759,7 +801,7 @@
   AC_MSG_RESULT($cxx_tuneflag)
 fi
 
-if test X$GCC == Xyes; then
+if test X$GCC = Xyes; then
   AC_MSG_CHECKING([for C cpu tuning flag])
   CFLAGS_SAV=$CFLAGS
   CFLAGS="-mtune=$opt_target_cpu $CFLAGS_SAV"
@@ -969,6 +1011,7 @@
 elif test $DEBUG = opt; then
   CFLAGS="$COPTIONS_DBG $COPTIONS_OPT $COPTIONS_MISC"
   CXXFLAGS="$CXXOPTIONS_DBG $CXXOPTIONS_OPT $CXXOPTIONS_MISC"
+  FFLAGS="$F77OPTIONS_OPT"
   LDFLAGS="$LDFLAGS -g"
 else
   CFLAGS="$COPTIONS_OPT $COPTIONS_MISC"
@@ -1055,7 +1098,7 @@
     char c[sizeof (long)];
   } u;
   u.l = 1;
-  exit (u.c[sizeof (long) - 1] == 1);
+  exit (u.c[sizeof (long) - 1] = 1);
 }], sc_cv_c_bigendian=no, sc_cv_c_bigendian=yes,
 AC_MSG_ERROR([Could not determine endianness and cross compiling])
 )
@@ -1073,47 +1116,28 @@
 dnl -- seems to be in libc on IRIX and we must generate a -lpthread in LIBS.
 if test "(" X$PARALLEL = Xyes -a X$THREADS != Xno ")" -o X$THREADS = Xyes; then
 
-AC_MSG_CHECKING([pthreads])
-dnl see if posix threads are automatically linked ...
-AC_LANG_SAVE
-AC_LANG_CPLUSPLUS
-LIBSSAV="$LIBS"
-AC_TRY_LINK([#include <pthread.h>],[pthread_join(0,0);],[
-HAVE_PTHREAD=yes],[
-HAVE_PTHREAD=no])
-AC_LANG_RESTORE
-
-dnl see if posix threads are in -lpthread
-if test $HAVE_PTHREAD = no; then
-AC_LANG_SAVE
-AC_LANG_CPLUSPLUS
-LIBSSAV="$LIBS"
-LIBS="$LIBS -lpthread"
-AC_TRY_LINK([#include <pthread.h>],[pthread_join(0,0);],[
-HAVE_PTHREAD=yes],[
-HAVE_PTHREAD=no
-LIBS="$LIBSSAV"])
-AC_LANG_RESTORE
-fi
-
-dnl see if posix threads are in -lpthreads
-if test $HAVE_PTHREAD = no; then
-AC_LANG_SAVE
-AC_LANG_CPLUSPLUS
-LIBSSAV="$LIBS"
-LIBS="$LIBS -lpthreads"
-AC_TRY_LINK([#include <pthread.h>],[pthread_join(0,0);],[
-HAVE_PTHREAD=yes],[
-HAVE_PTHREAD=no
-LIBS="$LIBSSAV"])
-AC_LANG_RESTORE
-fi
-
+for flag in -pthread -lpthreads -lpthread; do
+AC_MSG_CHECKING([for pthread_create using $flag])
+  SAVELIBS="$LIBS"
+  LIBS="$flag $LIBS"
+  AC_TRY_LINK([#include <pthread.h>],[pthread_join(0,0);],[
+  HAVE_PTHREAD=yes],[
+  HAVE_PTHREAD=no])
+  AC_MSG_RESULT([$have_pthread])
+      if test X$HAVE_PTHREAD = Xyes; then
+      break
+      fi
+done
+  
 AC_MSG_RESULT($HAVE_PTHREAD)
 fi
 if test X$HAVE_PTHREAD = Xyes; then
   AC_DEFINE(HAVE_PTHREAD)
   EXTRADEFINES="-D_REENTRANT $EXTRADEFINES"
+  # Solaris requires -D_POSIX_PTHREAD_SEMANTICS
+  if test x$uname = xSunOS; then
+    PTHREAD_FLAGS="$PTHREAD_FLAGS -D_POSIX_PTHREAD_SEMANTICS"
+  fi
   AC_CHECK_FUNC(pthread_attr_getstacksize)
   AC_CHECK_FUNC(pthread_attr_setstacksize)
   AC_CHECK_FUNC(pthread_attr_setscope)
@@ -1165,7 +1189,8 @@
       AC_CHECK_LIB(mpi,MPI_Init,[HAVE_MPI=yes;LIBS="-lmpi $LIBS"])
     fi
     if test "$HAVE_MPI" = no; then
-      AC_CHECK_LIB(mpich,MPI_Init,[HAVE_MPI=yes;LIBS="-lmpich $LIBS"])
+      LIBS="-lmpl $PTHREAD_LIBS $LIBS"
+      AC_CHECK_LIB(mpich,MPI_Init,[HAVE_MPI=yes;LIBS="-lmpich -lmpl $PTHREAD_LIBS $LIBS"])
     fi
   fi
   if test X$HAVE_MPI = Xyes; then
@@ -1769,10 +1794,10 @@
 
 dnl --------- CCA component configuration ---------
 
-if test $components == "yes"; then
+if test $components = "yes"; then
 
-  if test $HAVE_MPI == "yes" &&
-     test $HAVE_MPIPP == "no"; then
+  if test $HAVE_MPI = "yes" &&
+     test $HAVE_MPIPP = "no"; then
     AC_MSG_ERROR([libmpi++ needed for mpi cca components])
   fi