#!/bin/sh
# Guess values for system-dependent variables and create Makefiles.
# Generated automatically using autoconf.
# Copyright (C) 1991, 1992, 1993 Free Software Foundation, Inc.

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

# Usage: configure [--srcdir=DIR] [--host=HOST] [--gas] [--nfp]
#        [--prefix=PREFIX] [--exec-prefix=PREFIX] [--with-PACKAGE[=VALUE]]
# Ignores all args except --srcdir, --prefix, --exec-prefix, and
# --with-PACKAGE[=VALUE] unless this script has special code to handle it.

for arg
do
  # Handle --exec-prefix with a space before the argument.
  if test x$next_exec_prefix = xyes; then exec_prefix=$arg; next_exec_prefix=
  # Handle --host with a space before the argument.
  elif test x$next_host = xyes; then next_host=
  # Handle --prefix with a space before the argument.
  elif test x$next_prefix = xyes; then prefix=$arg; next_prefix=
  # Handle --srcdir with a space before the argument.
  elif test x$next_srcdir = xyes; then srcdir=$arg; next_srcdir=
  else
    case $arg in
     # For backward compatibility, recognize -exec-prefix and --exec_prefix.
     -exec-prefix=* | --exec_prefix=* | --exec-prefix=* | --exec-prefi=* | --exec-pref=* | --exec-pre=* | --exec-pr=* | --exec-p=* | --exec-=* | --exec=* | --exe=* | --ex=* | --e=*)
	exec_prefix=`echo $arg | sed 's/[-a-z_]*=//'` ;;
     -exec-prefix | --exec_prefix | --exec-prefix | --exec-prefi | --exec-pref | --exec-pre | --exec-pr | --exec-p | --exec- | --exec | --exe | --ex | --e)
	next_exec_prefix=yes ;;

     -gas | --gas | --ga | --g) ;;

     -host=* | --host=* | --hos=* | --ho=* | --h=*) ;;
     -host | --host | --hos | --ho | --h)
	next_host=yes ;;

     -nfp | --nfp | --nf) ;;

     -prefix=* | --prefix=* | --prefi=* | --pref=* | --pre=* | --pr=* | --p=*)
	prefix=`echo $arg | sed 's/[-a-z_]*=//'` ;;
     -prefix | --prefix | --prefi | --pref | --pre | --pr | --p)
	next_prefix=yes ;;

     -srcdir=* | --srcdir=* | --srcdi=* | --srcd=* | --src=* | --sr=* | --s=*)
	srcdir=`echo $arg | sed 's/[-a-z_]*=//'` ;;
     -srcdir | --srcdir | --srcdi | --srcd | --src | --sr | --s)
	next_srcdir=yes ;;

     -with-* | --with-*)
       package=`echo $arg|sed -e 's/-*with-//' -e 's/=.*//'`
       # Reject names that aren't valid shell variable names.
       if test -n "`echo $package| sed 's/[-a-zA-Z0-9_]//g'`"; then
         echo "configure: $package: invalid package name" >&2; exit 1
       fi
       package=`echo $package| sed 's/-/_/g'`
       case "$arg" in
         *=*) val="`echo $arg|sed 's/[^=]*=//'`" ;;
         *) val=1 ;;
       esac
       eval "with_$package='$val'" ;;

     -v | -verbose | --verbose | --verbos | --verbo | --verb | --ver | --ve | --v)
       verbose=yes ;;

     *) ;;
    esac
  fi
done

trap 'rm -fr conftest* confdefs* core; exit 1' 1 3 15
trap 'rm -f confdefs*' 0

# NLS nuisances.
# These must not be set unconditionally because not all systems understand
# e.g. LANG=C (notably SCO).
if test "${LC_ALL+set}" = 'set' ; then LC_ALL=C; export LC_ALL; fi
if test "${LANG+set}"   = 'set' ; then LANG=C;   export LANG;   fi

rm -f conftest* confdefs.h
# AIX cpp loses on an empty file, so make sure it contains at least a newline.
echo > confdefs.h
compile='${CC-cc} $CFLAGS conftest.c -o conftest $LIBS >/dev/null 2>&1'

# A filename unique to this package, relative to the directory that
# configure is in, which we can look for to find out if srcdir is correct.
unique_file=source/pga.c

# Find the source files, if location was not specified.
if test -z "$srcdir"; then
  srcdirdefaulted=yes
  # Try the directory containing this script, then `..'.
  prog=$0
  confdir=`echo $prog|sed 's%/[^/][^/]*$%%'`
  test "X$confdir" = "X$prog" && confdir=.
  srcdir=$confdir
  if test ! -r $srcdir/$unique_file; then
    srcdir=..
  fi
fi
if test ! -r $srcdir/$unique_file; then
  if test x$srcdirdefaulted = xyes; then
    echo "configure: Can not find sources in \`${confdir}' or \`..'." 1>&2
  else
    echo "configure: Can not find sources in \`${srcdir}'." 1>&2
  fi
  exit 1
fi
# Preserve a srcdir of `.' to avoid automounter screwups with pwd.
# But we can't avoid them for `..', to make subdirectories work.
case $srcdir in
  .|/*|~*) ;;
  *) srcdir=`cd $srcdir; pwd` ;; # Make relative path absolute.
esac


# Save the original args to write them into config.status later.
configure_args="$*"


print_error() {
    echo "*# $*" 2>&1 ;
    }

print_usage() {
cat <<.
Usage: configure -arch ARCH_TYPE -f77 FC -cc CC -optimize -help 
                 -parallel -mpiincdir MPI_INC_DIR -mpilib MPI_LIB
where
   ARCH_TYPE    = the type of machine that PGAPack is to be configured for
   MPI_INC_DIR  = the MPI include directory
   MPI_LIB      = the name of the MPI library with full path
   FC           = the name of the FORTRAN 77 compiler
   CC           = the name of the ANSI C compiler

In the absence of the -f77 option, configure assumes the name of a FORTRAN 77
compiler based on the ARCH_TYPE.

In the absence of the -cc option, configures assumes the name of an ANSI C
compiler based on the ARCH_TYPE.

If the -optimize flag is set, then "make install" will send "-O" to the
compiler.  Also, this will disable the extensive memory debugging features
that PGAPack provides.

If the -parallel flag is set, "make install" will compile the code to allow
parallel processing.  If -parallel is set but one of -mpiincdir and -mpilib is
missing, configure assumes values based on the ARCH_TYPE and aborts if they are
invalid.

The -help flag causes this usage guide to be printed.

Sample Configure Usage:

To make for running in parallel on a sun4 with /usr/local/mpi/include as the
mpi include directory and /usr/local/mpi/lib/sun4/ch_p4/libmpi.a as the mpi
library, type the following:

  configure -mpilib /usr/local/mpi/lib/sun4/ch_p4/libmpi.a -arch sun4 -parallel
            -mpiincdir /usr/local/mpi/include
  make install

Known architectures include
        sun4
        NeXT
	AIX
	IRIX
	freebsd
	Linux
.
}

ARCH=""
PARALLEL=0
CPPFLAGS=""
PGA_DIR="`pwd`"
HEADERS="$PGA_DIR/include/pgapack.h"
PGA_LIB="$PGA_DIR/lib/libpga.a"
INCLUDES="-I$PGA_DIR/include"
LIBS="-lm"
SHELL="/usr/bin/sh"
RM="/bin/rm -f"

for arg
do
    if test x$next_arch = xyes
        then
            ARCH=$arg
            next_arch=
        elif test x$next_mpiincdir = xyes
            then
                USR_MPI_INC_DIR=$arg
                next_mpiincdir=
        elif test x$next_mpilib = xyes
            then
                USR_MPI_LIB=$arg
                next_mpilib=
        elif test x$next_f77 = xyes
            then
                USR_FC=$arg
                next_f77=
        elif test x$next_cc = xyes
            then
                USR_CC=$arg
                next_cc=
        else
            case $arg in
                -arch)
                    next_arch=yes
                    ;;
                -f77)
                    next_f77=yes
                    ;;
                -cc)
                    next_cc=yes
                    ;;
                -mpilib)
                    next_mpilib=yes
                    ;;
                -mpiincdir)
                    next_mpiincdir=yes
                    ;;
                -parallel)
                    print_error "Parallelism not yet implemented ... aborting."
                    exit 1
                    PARALLEL=1
                    CPPFLAGS="-DPARALLEL $CPPFLAGS"
                    ;;
                -optimize)
                    CPPFLAGS="-DOPTIMIZE $CPPFLAGS"
                    CFLAGS="-O"
                    ;;
                -help)
                    print_usage >& 2
                    exit 1
                    ;;
                *) 
                    ;;
            esac
    fi
done

if test -z "$ARCH"
    then
        print_error "You must specify the architecture with -arch <value>"
        print_error "Valid architectures are the following:"
	print_error "sun4"
	print_error "NeXT"
	print_error "AIX"
	print_error "freebsd"
	print_error "Linux"
	print_error "IRIX"
	print_error "For more information type configure -help."
        exit 1
fi

case $ARCH in
    sun4)
        CC=cc
        FC=f77
        MPI_INC_DIR=/usr/local/mpi/include
        MPI_LIB=/usr/local/mpi/lib/sun4/ch_p4/libmpi.a
        CPPFLAGS="-DFORTRANUNDERSCORE $CPPFLAGS"
        ;;
    NeXT)
        CC=cc
        FC=
        MPI_INC_DIR=
        MPI_LIB=
        CPPFLAGS="-DFORTRANUNDERSCORE $CPPFLAGS"
        ;;
    AIX)
        CC=cc
        FC=f77
        MPI_INC_DIR=
        MPI_LIB=
        ;;
    freebsd)
        CC=cc
        FC=f77
        MPI_INC_DIR=
        MPI_LIB=
        CPPFLAGS="-DFORTRANUNDERSCORE $CPPFLAGS"
	FFLAGS="-w"
        ;;
    Linux)
        SHELL="/bin/sh"
        CC=cc
        FC=f77
        MPI_INC_DIR=
        MPI_LIB=
        CPPFLAGS="-DFORTRANUNDERSCORE $CPPFLAGS"
        FFLAGS="-w"
        ;;
    IRIX)
        CC=cc
        FC=f77
        MPI_INC_DIR=
        MPI_LIB=
        CPPFLAGS="-DFORTRANUNDERSCORE $CPPFLAGS"
        ;;
    *)
        ;;
esac

CPPFLAGS="-D$ARCH $CPPFLAGS"

test -n "$USR_CC" && CC=$USR_CC

test -n "$USR_FC" &&  FC=$USR_FC

test -n "$USR_MPI_INC_DIR" && MPI_INC_DIR=$USR_MPI_INC_DIR

test -n "$USR_MPI_LIB" &&  MPI_LIB=$USR_MPI_LIB

if test -z "$RANLIB"; then
  # Extract the first word of `ranlib', so it can be a program name with args.
  set dummy ranlib; word=$2
  echo checking for $word
  IFS="${IFS= 	}"; saveifs="$IFS"; IFS="${IFS}:"
  for dir in $PATH; do
    test -z "$dir" && dir=.
    if test -f $dir/$word; then
      RANLIB="ranlib"
      break
    fi
  done
  IFS="$saveifs"
fi
test -z "$RANLIB" && RANLIB=":"
test -n "$RANLIB" && test -n "$verbose" && echo "	setting RANLIB to $RANLIB"

if test -z "$CC"; then
  # Extract the first word of `gcc', so it can be a program name with args.
  set dummy gcc; word=$2
  echo checking for $word
  IFS="${IFS= 	}"; saveifs="$IFS"; IFS="${IFS}:"
  for dir in $PATH; do
    test -z "$dir" && dir=.
    if test -f $dir/$word; then
      CC="gcc"
      break
    fi
  done
  IFS="$saveifs"
fi
test -z "$CC" && CC="cc"
test -n "$CC" && test -n "$verbose" && echo "	setting CC to $CC"

# Find out if we are using GNU C, under whatever name.
cat > conftest.c <<EOF
#ifdef __GNUC__
  yes
#endif
EOF
${CC-cc} -E conftest.c > conftest.out 2>&1
if egrep yes conftest.out >/dev/null 2>&1; then
  GCC=1 # For later tests.
fi
rm -f conftest*

for p in f77 fortran xlf gf77 mpxlf if77
do
if test -z "$FC"; then
  # Extract the first word of `$p', so it can be a program name with args.
  set dummy $p; word=$2
  echo checking for $word
  IFS="${IFS= 	}"; saveifs="$IFS"; IFS="${IFS}:"
  for dir in $PATH; do
    test -z "$dir" && dir=.
    if test -f $dir/$word; then
      FC="$p"
      break
    fi
  done
  IFS="$saveifs"
fi

test -n "$FC" && test -n "$verbose" && echo "	setting FC to $FC"

test -n "$FC" && break
done


test -z "$CFLAGS" && CFLAGS="-g"

OBJS='../lib/binary.o        \\\
              ../lib/crossover.o     \\\
              ../lib/debug.o         \\\
              ../lib/duplicate.o     \\\
              ../lib/fitness.o       \\\
              ../lib/get.o           \\\
              ../lib/hamming.o       \\\
              ../lib/heap.o          \\\
              ../lib/integer.o       \\\
              ../lib/mutation.o      \\\
              ../lib/pga.o           \\\
              ../lib/real.o          \\\
              ../lib/report.o        \\\
              ../lib/select.o        \\\
              ../lib/set.o           \\\
              ../lib/system.o '

if test $PARALLEL -eq 1
    then
        if test -z "$MPI_INC_DIR" -o -z "$MPI_LIB"
            then
                for dir in /bin /usr/bin /usr/local /usr/local/bin
                do
                    test -d $dir/mpi && (MPI_DIR=$dir/mpi ; break)
                    test -d $dir/mpich && (MPI_DIR=$dir/mpich ; break)
                done
                if test -n "$MPI_DIR"
                    then
                       test -d $MPI_DIR/include && MPI_INC_DIR=$MPI_DIR/include
                       test -f $MPI_DIR/lib/libmpi.a && MPI_LIB=$MPI_DIR/lib/libmpi.a
                fi
                if test -z "$MPI_INC_DIR" -o -z "$MPI_LIB"
                    then
                        print_error "You must set -mpiincdir and -mpidir."
                        exit 1
                fi
            elif test ! -d $MPI_INC_DIR -o ! -f $MPI_LIB
                then
                    print_error "You must set -mpiincdir and -mpidir."
                    exit 1
        fi

        INCLUDES="$INCLUDES -I$MPI_INC_DIR"
        LIBS="$MPI_LIB $LIBS"
        OBJS="$OBJS ../lib/parallel.o"
        PARACOMP='../lib/parallel.o: parallel.c $(HEADERS)\
	$(COMPILE2.c) -o ../lib/parallel.o parallel.c'
fi

if test -n "$FC"
    then
        OBJS="$OBJS ../lib/f2c_interface.o"
        FORTWRAP='../lib/f2c_interface.o: f2c_interface.c $(HEADERS)\
	$(COMPILE.c) -o ../lib/f2c_interface.o f2c_interface.c'
fi
FFLAGS="$CFLAGS $FFLAGS"















# Set default prefixes.
if test -n "$prefix"; then
  test -z "$exec_prefix" && exec_prefix='${prefix}'
  prsub="s%^prefix\\([ 	]*\\)=\\([ 	]*\\).*$%prefix\\1=\\2$prefix%"
fi
if test -n "$exec_prefix"; then
  prsub="$prsub
s%^exec_prefix\\([ 	]*\\)=\\([ 	]*\\).*$%exec_prefix\\1=\\2$exec_prefix%"
fi
# Quote sed substitution magic chars in DEFS.
cat >conftest.def <<EOF
$DEFS
EOF
escape_ampersand_and_backslash='s%[&\\]%\\&%g'
DEFS=`sed "$escape_ampersand_and_backslash" <conftest.def`
rm -f conftest.def
# Substitute for predefined variables.

trap 'rm -f config.status; exit 1' 1 3 15
echo creating config.status
rm -f config.status
cat > config.status <<EOF
#!/bin/sh
# Generated automatically by configure.
# Run this file to recreate the current configuration.
# This directory was configured as follows,
# on host `(hostname || uname -n) 2>/dev/null | sed 1q`:
#
# $0 $configure_args

for arg
do
  case "\$arg" in
    -recheck | --recheck | --rechec | --reche | --rech | --rec | --re | --r)
    echo running \${CONFIG_SHELL-/bin/sh} $0 $configure_args
    exec \${CONFIG_SHELL-/bin/sh} $0 $configure_args ;;
    *) echo "Usage: config.status --recheck" 2>&1; exit 1 ;;
  esac
done

trap 'rm -f Makefile source/Makefile examples/Makefile examples/c/Makefile\
	examples/fortran/Makefile examples/mgh/Makefile; exit 1' 1 3 15
RANLIB='$RANLIB'
CC='$CC'
FC='$FC'
CFLAGS='$CFLAGS'
FFLAGS='$FFLAGS'
CPPFLAGS='$CPPFLAGS'
FORTWRAP='$FORTWRAP'
HEADERS='$HEADERS'
INCLUDES='$INCLUDES'
LIBS='$LIBS'
OBJS='$OBJS'
PARACOMP='$PARACOMP'
PGA_LIB='$PGA_LIB'
SHELL='$SHELL'
RM='$RM'
srcdir='$srcdir'
DEFS='$DEFS'
prefix='$prefix'
exec_prefix='$exec_prefix'
prsub='$prsub'
extrasub='$extrasub'
EOF
cat >> config.status <<\EOF

top_srcdir=$srcdir

CONFIG_FILES=${CONFIG_FILES-"Makefile source/Makefile examples/Makefile examples/c/Makefile\
	examples/fortran/Makefile examples/mgh/Makefile"}
for file in .. ${CONFIG_FILES}; do if test "x$file" != x..; then
  srcdir=$top_srcdir
  # Remove last slash and all that follows it.  Not all systems have dirname.
  dir=`echo $file|sed 's%/[^/][^/]*$%%'`
  if test "$dir" != "$file"; then
    test "$top_srcdir" != . && srcdir=$top_srcdir/$dir
    test ! -d $dir && mkdir $dir
  fi
  echo creating $file
  rm -f $file
  echo "# Generated automatically from `echo $file|sed 's|.*/||'`.in by configure." > $file
  sed -e "
$prsub
$extrasub
s%@RANLIB@%$RANLIB%g
s%@CC@%$CC%g
s%@FC@%$FC%g
s%@CFLAGS@%$CFLAGS%g
s%@FFLAGS@%$FFLAGS%g
s%@CPPFLAGS@%$CPPFLAGS%g
s%@FORTWRAP@%$FORTWRAP%g
s%@HEADERS@%$HEADERS%g
s%@INCLUDES@%$INCLUDES%g
s%@LIBS@%$LIBS%g
s%@OBJS@%$OBJS%g
s%@PARACOMP@%$PARACOMP%g
s%@PGA_LIB@%$PGA_LIB%g
s%@SHELL@%$SHELL%g
s%@RM@%$RM%g
s%@srcdir@%$srcdir%g
s%@DEFS@%$DEFS%
" $top_srcdir/${file}.in >> $file
fi; done


exit 0
EOF
chmod +x config.status
${CONFIG_SHELL-/bin/sh} config.status

