configure 3.88 KB
Newer Older
ulrich_y's avatar
ulrich_y committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#! /bin/bash
# configure script
# note: has nothing to do with GNU autoconf

exec 2> ${LOGFILE:-/dev/null} 3>&1
eval ${LOGFILE:+set -x}


shopt -s nullglob
export LC_ALL=C

CONF_DIR="${0%/*}"
CONF_OS="`uname -s`"
CONF_MACH="`uname -m`"
ulrich_y's avatar
ulrich_y committed
15 16 17
HAVE_GINAC=false
HAVE_MCC=false
CONF_BITS=
ulrich_y's avatar
ulrich_y committed
18 19 20 21 22 23 24 25 26 27 28

DEBUG=false
for arg in "$@" ; do
    case "$arg" in
        --debug)
            DEBUG=true ;;
        --prefix=*)
            CONF_PREFIX="${arg#--prefix=}" ;;
        --host=*)
            CONF_TARGET="${arg#--host=}" ;;
        --with-ginac)
ulrich_y's avatar
ulrich_y committed
29
            HAVE_GINAC=true ;;
ulrich_y's avatar
ulrich_y committed
30
        --with-mcc)
ulrich_y's avatar
ulrich_y committed
31 32 33 34 35
            HAVE_MCC=true ;;
        --32)
            CONF_BITS="-m32" ;;
        --64)
            CONF_BITS="-m64" ;;
ulrich_y's avatar
ulrich_y committed
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
        -*)
            echo "Warning: $arg is not a valid option." 1>&3 ;;
        *=*)
            eval "$arg" ;;
        *)
            echo "Warning: $arg is not a valid argument." 1>&3 ;;
    esac
done


test=test$$
trap "rm -fr $test* =." 0 1 2 3 15


## look for some programs

findprog() {
    echo -n "looking for $1... " 1>&3
    var="$2"
    set -- ${!var:+"${!var}"} "${@:3}"
    for prog in "$@" ; do
        full="`type -P "$prog"`" && {
            echo "$full" 1>&3
ulrich_y's avatar
ulrich_y committed
59
            printf -v "CONF_$var" "%q" "$full"
ulrich_y's avatar
ulrich_y committed
60 61 62 63 64 65 66
            return 0
        }
    done
    echo "no $@ in your path" 1>&3
    return 1
}
addflag() {
ulrich_y's avatar
ulrich_y committed
67
    eval "CONF_$1=\"\${CONF_$1} ${@:2}\""
ulrich_y's avatar
ulrich_y committed
68 69 70 71 72
}

gnuflags() {
    eval addflag FFLAGS -fdefault-real-8             # default double is 8 byte
    eval addflag FFLAGS -cpp                         # C pre-processor
ulrich_y's avatar
ulrich_y committed
73
    eval addflag FFLAGS -pedantic-errors -std=f2008  # folow f08 strictly
ulrich_y's avatar
ulrich_y committed
74 75 76 77 78 79 80 81 82
    eval addflag FFLAGS -J build                     # where to put mods
    eval addflag FFLAGS -Werror -Wall                # make every warning an error
    eval addflag FFLAGS -Wno-uninitialized 
}

findprog fortran FC  ifort gfortran  || exit 1



ulrich_y's avatar
ulrich_y committed
83
set -- `eval $CONF_FC --version -c | sed '/^$/d;s/([^)]*)//;q' 2>&1`
ulrich_y's avatar
ulrich_y committed
84 85 86 87 88
case "$1,$2,$3" in
    GNU,Fortran,[123].*)
        echo "Only version >= 4 are supported"
        exit
    ;;
ulrich_y's avatar
ulrich_y committed
89
    GNU,Fortran,4.*)
ulrich_y's avatar
ulrich_y committed
90 91
    echo "Code optimisation is *not* suported on gfortran 4"
        gnuflags
ulrich_y's avatar
ulrich_y committed
92
        eval addflag $CONF_BITS
ulrich_y's avatar
ulrich_y committed
93 94 95 96 97 98 99 100 101 102 103 104 105 106
        if $DEBUG ; then
            eval addflag FFLAGS -g -O0
            eval addflag FFLAGS -ffpe-trap=invalid,overflow 
            eval addflag FFLAGS -fdump-core -fbacktrace
            eval addflag FFLAGS -frange-check
            eval addflag FFLAGS -DDEBUG
        else
            eval addflag FFLAGS -DRELEASE
            eval addflag FFLAGS -march=native -mtune=native
        fi
    ;;
    GNU,Fortran,*)
        gnuflags
        eval addflag FFLAGS -Wno-maybe-uninitialized
ulrich_y's avatar
ulrich_y committed
107
        eval addflag $CONF_BITS
ulrich_y's avatar
ulrich_y committed
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
        if $DEBUG ; then
            eval addflag FFLAGS -g -O0
            eval addflag FFLAGS -ffpe-trap=invalid,overflow 
            eval addflag FFLAGS -fdump-core -fbacktrace
            eval addflag FFLAGS -fcheck=all -frange-check
            eval addflag FFLAGS -DDEBUG
        else
            eval addflag FFLAGS -DRELEASE -O3
            eval addflag FFLAGS -march=native -mtune=native
        fi
    ;;
    ifort*)
        eval addflag FFLAGS -autodouble
        eval addflag FFLAGS -module build
        eval addflag FFLAGS -fpp
        eval addflag FFLAGS -stand f03
ulrich_y's avatar
ulrich_y committed
124
        eval addflag $CONF_BITS
ulrich_y's avatar
ulrich_y committed
125 126 127 128 129 130 131
        if $DEBUG ; then
            eval addflag FFLAGS -g -O0
            eval addflag FFLAGS -DDEBUG
        else
            eval addflag FFLAGS -DRELEASE -O3
            eval addflag FFLAGS -xHost -fast
        fi
ulrich_y's avatar
ulrich_y committed
132
        if HAVE_GINAC ; then
ulrich_y's avatar
ulrich_y committed
133
            echo "Option --with-ginac is incompatible with ifort, disabling"
ulrich_y's avatar
ulrich_y committed
134
            HAVE_GINAC=false
ulrich_y's avatar
ulrich_y committed
135
        fi
ulrich_y's avatar
ulrich_y committed
136
        if HAVE_MCC ; then
ulrich_y's avatar
ulrich_y committed
137
            echo "Option --with-mcc is incompatible with ifort, disabling"
ulrich_y's avatar
ulrich_y committed
138
            HAVE_MCC=false
ulrich_y's avatar
ulrich_y committed
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
        fi
    ;;
    *)
        echo "Unknown compiler"
        exit
    ;;
esac

if $CONF_MCC ; then
    findprog 
fi

#if ( $CONF_GINA || $CONF_MCC ); then
#
#fi