configure 5.38 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
        fi
    ;;
    *)
        echo "Unknown compiler"
        exit
    ;;
esac

ulrich_y's avatar
ulrich_y committed
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
echo -n "extracting the Fortran libraries... " 1>&3

rm -fr $test*

tee $test.f90 << _EOF_ 1>&2
    program test
    integer i
    common /uscore/ i
    stop i
    end
_EOF_

while read line ; do
  set -- ${line//[:,()]/ }
  [[ "$1" =~ (/collect2|/ld|^ld)$ ]] && while test $# -gt 1 ; do
    shift
    case "$1" in
    *.o | -lc*)
      ;;
    -l* | -L* | *.a)
      FLDFLAGS+=" $1" ;;
    -Bstatic | -Bdynamic | *.ld)
      FLDFLAGS+=" -Wl,$1" ;;
    /*)
      FLDFLAGS+=" -L$1" ;;
    -rpath*)
      FLDFLAGS+=" -Wl,$1,$2"
      shift ;;
    -dynamic-linker)
      shift ;;
    esac
  done
done < <(eval $CONF_FC $CONF_FFLAGS -v -o $test $test.f90 2>&1)
echo "ok" 1>&3

eval addflag LFLAGS "$LDFLAGS $CONF_LDFLAGS $FLDFLAGS"



if ( $HAVE_GINAC || $HAVE_MCC ); then
    findprog gcc CC clang gcc || exit 1
    findprog g++ CXX clang++ g++ || exit 1
    eval addflag CFLAGS "-std=c99"

    ## does Fortran append underscores to symbols?

    echo -n "does $CONF_FC append underscores... " 1>&3

    tee $test-c.c << _EOF_ 1>&2
int uscore_ = 95;
int uscore = 59;
_EOF_

    for CONF_BITS in ${CONF_BITS:--m64 -m32} ; do
      eval $CONF_CC $CONF_CFLAGS $CONF_BITS -c $test-c.c 1>&2 || continue
      eval $CONF_FC $CONF_FFLAGS -o $test $test.f90 $test-c.o 1>&2 && break
    done

    ./$test
    case $? in
    95)
      echo "yes" 1>&3
      CONF_NOUNDERSCORE=0 ;;
    59)
      echo "no" 1>&3
      CONF_NOUNDERSCORE=1 ;;
    *)
      echo "error linking Fortran and C" 1>&3
      exit 1 ;;
    esac

else
    $CONF_CC=
    $CONF_CXX=
    $CONF_CFLAGS=
    $CONF_NOUNDERSCORE=
ulrich_y's avatar
ulrich_y committed
223 224 225 226 227
fi

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