configure 3.9 KB
Newer Older
ulrich_y's avatar
ulrich_y committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
#! /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`"
CONF_GINAC=false
CONF_MCC=false

DEBUG=false
for arg in "$@" ; do
    case "$arg" in
        --debug)
            DEBUG=true ;;
        --prefix=*)
            CONF_PREFIX="${arg#--prefix=}" ;;
        --host=*)
            CONF_TARGET="${arg#--host=}" ;;
        --with-ginac)
            CONF_GINAC=true ;;
        --with-mcc)
            CONF_MCC=true ;;
        -*)
            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}"
    test -n "$CONF_TARGET" && for prog in "$@" ; do
        full="`type -P "$CONF_TARGET-$prog"`" && {
            echo "$full" 1>&3
            printf -v "CONF_$var" "%q" "$CONF_TARGET-$prog"
            return 0
        }
    done
    for prog in "$@" ; do
        full="`type -P "$prog"`" && {
            echo "$full" 1>&3
            printf -v "CONF_$var" "%q" "$prog"
            return 0
        }
    done
    echo "no $@ in your path" 1>&3
    return 1
}
addflag() {
    eval "CONF_$1=\"\${CONF_$1} $@\""
}

gnuflags() {
    eval addflag FFLAGS -fdefault-real-8             # default double is 8 byte
    eval addflag FFLAGS -cpp                         # C pre-processor
    eval addflag FFLAGS -pedantic-errors -std=2008   # folow f08 strictly
    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



set -- `eval $CONF_FC --version -c | sed '/^$/d;s/(.*)//;q' 2>&1`
case "$1,$2,$3" in
    GNU,Fortran,[123].*)
        echo "Only version >= 4 are supported"
        exit
    ;;
    GNU,Fortran,4)
    echo "Code optimisation is *not* suported on gfortran 4"
        gnuflags
        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
        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
        if $DEBUG ; then
            eval addflag FFLAGS -g -O0
            eval addflag FFLAGS -DDEBUG
        else
            eval addflag FFLAGS -DRELEASE -O3
            eval addflag FFLAGS -xHost -fast
        fi
        if CONF_GINAC ; then
            echo "Option --with-ginac is incompatible with ifort, disabling"
            CONF_GINAC=false
        fi
        if CONF_MCC ; then
            echo "Option --with-mcc is incompatible with ifort, disabling"
            CONF_MCC=false
        fi
    ;;
    *)
        echo "Unknown compiler"
        exit
    ;;
esac

if $CONF_MCC ; then
    findprog 
fi

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