configure 22.7 KB
Newer Older
ulrich_y's avatar
ulrich_y committed
1 2 3 4 5 6 7 8 9 10 11
#! /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

ulrich_y's avatar
ulrich_y committed
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
printhelp() {
cat << EOF
\`configure' configures handyG to adapt to many kinds of systems.

Usage: ./configure [OPTION]... [VAR=VALUE]...

To assign environment variables (e.g., CC, CFLAGS...), specify them as
VAR=VALUE.  See below for descriptions of some of the useful variables.

Defaults for the options are specified in brackets.

Installation directories:
  --prefix=PREFIX         install files in PREFIX [/usr/]
  --mmprefix=PREFIX       install files in for Mathematica
                          [\$UserBaseDirectory/Kernel/]

By default, \`make install' will install all the files in
\`/usr/local/bin', \`/usr/local/lib' etc.  You can specify
an installation prefix other than \`/usr/local' using \`--prefix',
for instance \`--prefix=\$HOME'.

For better control, use the options below.
  --moduledir=DIR         Fortran module files (compiler specific)
ulrich_y's avatar
ulrich_y committed
35 36 37
  --quad                  uses quadruple precision (128 bit) as the
                          working precision. This is not compatible with
                          the GiNaC interface.
ulrich_y's avatar
ulrich_y committed
38 39 40 41 42 43

Fine tuning of the installation directories:

System types:
  --32                    forces 32-bit compilation
  --64                    forces 64-bit compilation
ulrich_y's avatar
ulrich_y committed
44
  --native                do optimize code for the host machine
ulrich_y's avatar
ulrich_y committed
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

Optional Packages:
  --with-mcc              activates Mathematica interface
  --with-ginac            activates GiNaC interface for testing
  --debug                 compile with debug flags and without optimization

Some influential environment variables:
  FC          Fortran compiler command
  FFLAGS      Fortran compiler flags
  LD          linker command
  LDFLAGS     linker flags, e.g. -L<lib dir> if you have libraries in a
              nonstandard directory <lib dir>
  CC          C compiler command
  CFLAGS      C compiler flags
  CXX         C++ compiler command
  CXXFLAGS    C++ compiler flags
  FPATH       Path to put Fortran modules
  PKG_CONFIG_PATH
              directories to add to pkg-config's search path

Use these variables to override the choices made by \`configure' or to help
it to find libraries and programs with nonstandard names/locations.

Report bugs to <yannick.ulrich@psi.ch>.

EOF
exit
}

ulrich_y's avatar
ulrich_y committed
74 75
CONF_DIR="${0%/*}"
CONF_OS="`uname -s`"
ulrich_y's avatar
ulrich_y committed
76 77 78
HAVE_GINAC=false
HAVE_MCC=false
CONF_BITS=
ulrich_y's avatar
ulrich_y committed
79

ulrich_y's avatar
ulrich_y committed
80
CONF_QUAD=false
ulrich_y's avatar
ulrich_y committed
81 82
CONF_FFLAGS=$FFLAGS
CONF_CFLAGS=$CFLAGS
ulrich_y's avatar
ulrich_y committed
83
CONF_CXXFLAGS=$CXXFLAGS
ulrich_y's avatar
ulrich_y committed
84 85 86 87 88
CONF_LFLAGS=$LDFLAGS
CONF_FC=$FC
CONF_CC=$CC
CONF_CXX=$CXX
CONF_LD=$LD
ulrich_y's avatar
ulrich_y committed
89
CONF_MODDIR=$FPATH
ulrich_y's avatar
ulrich_y committed
90 91


ulrich_y's avatar
ulrich_y committed
92 93 94 95 96 97
if [ "$CONF_OS" -eq "Darwin" ]; then
    CONF_PREFIX=/usr/local/
else
    CONF_PREFIX=/usr/
fi

ulrich_y's avatar
ulrich_y committed
98

ulrich_y's avatar
ulrich_y committed
99
allargs="$@"
ulrich_y's avatar
ulrich_y committed
100
NATIVE=false
ulrich_y's avatar
ulrich_y committed
101
DEBUG=false
ulrich_y's avatar
ulrich_y committed
102
COVERAGE=false
ulrich_y's avatar
ulrich_y committed
103 104 105 106 107 108
for arg in "$@" ; do
    case "$arg" in
        --debug)
            DEBUG=true ;;
        --prefix=*)
            CONF_PREFIX="${arg#--prefix=}" ;;
ulrich_y's avatar
ulrich_y committed
109 110
        --moduledir=*)
            CONF_MODDIR="${arg#--moduledir=}" ;;
ulrich_y's avatar
ulrich_y committed
111
        --with-ginac)
ulrich_y's avatar
ulrich_y committed
112
            HAVE_GINAC=true ;;
ulrich_y's avatar
ulrich_y committed
113
        --with-mcc)
ulrich_y's avatar
ulrich_y committed
114
            HAVE_MCC=true ;;
ulrich_y's avatar
ulrich_y committed
115 116
        --mmprefix=*)
            CONF_MMPREFIX="${arg#--mmprefix=}" ;;
ulrich_y's avatar
ulrich_y committed
117 118
        --native)
            NATIVE=true ;;
ulrich_y's avatar
ulrich_y committed
119 120 121 122
        --32)
            CONF_BITS="-m32" ;;
        --64)
            CONF_BITS="-m64" ;;
ulrich_y's avatar
ulrich_y committed
123 124
        --quad)
            CONF_QUAD=true ;;
ulrich_y's avatar
ulrich_y committed
125 126
        --coverage)
            COVERAGE=true ;;
ulrich_y's avatar
ulrich_y committed
127 128 129 130 131 132 133
        --ci)
            echo "Running in CI configuration. Will not perform speed tests!"
            CONF_FFLAGS="$CONF_FLAGS -DNOSPEED"
            HAVE_MCC=true
            HAVE_GINAC=true
            DEBUG=true
            COVERAGE=true ;;
ulrich_y's avatar
ulrich_y committed
134 135
        --help )
            printhelp ;;
ulrich_y's avatar
ulrich_y committed
136
        -*)
ulrich_y's avatar
ulrich_y committed
137 138
            echo "Warning: $arg is not a valid option." 1>&3
            printhelp ;;
ulrich_y's avatar
ulrich_y committed
139 140 141
        *=*)
            eval "$arg" ;;
        *)
ulrich_y's avatar
ulrich_y committed
142 143
            echo "Warning: $arg is not a valid argument." 1>&3
            printhelp ;;
ulrich_y's avatar
ulrich_y committed
144 145 146 147 148 149 150
    esac
done


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

ulrich_y's avatar
ulrich_y committed
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
HAVE_GIT=false
if type -P git &>/dev/null ; then
    if [ -d .git ]; then
        HAVE_GIT=true
    fi
fi

# This will be set by git-archive
VTAG="$Format: %D, %h$"


if $HAVE_GIT ; then
    VERSION=`git describe`
    COMMIT=`git log -1 --pretty=format:"%h"`
elif [[ "$VTAG" == *"HEAD"* ]]; then
    VERSION=`echo $VTAG | perl -lpe 's/.*?(, tag: ([^,]*))?,.*? ([a-f\d]+)$/\2/g'`
    COMMIT=` echo $VTAG | perl -lpe 's/.*?(, tag: ([^,]*))?,.*? ([a-f\d]+)$/\3/g'`
    if [ -z "$VERSION" ]; then
        VERSION="untagged-$COMMIT"
    fi
else
    VERSION="v?.?.?"
    COMMIT="unknown"
fi


ulrich_y's avatar
ulrich_y committed
177

ulrich_y's avatar
ulrich_y committed
178 179 180 181
if $COVERAGE ; then
  $DEBUG || echo "Warning: --coverage implies --debug!" 1>&3
  DEBUG=true
fi
ulrich_y's avatar
ulrich_y committed
182 183 184 185 186 187 188 189 190
## 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
191
            printf -v "CONF_$var" "%q" "$full"
ulrich_y's avatar
ulrich_y committed
192 193 194 195 196 197
            return 0
        }
    done
    echo "no $@ in your path" 1>&3
    return 1
}
ulrich_y's avatar
ulrich_y committed
198 199 200 201 202 203 204 205

findlib() {
    echo -n "looking for lib$1... " 1>&3
    for flag in $CONF_LFLAGS ; do
        case "$flag" in
            -L* )
                libfolder=${flag/-L/}
                if [ -f "$libfolder/lib$1.so" ] ; then
ulrich_y's avatar
ulrich_y committed
206
                    path=`readlink -f -- "$libfolder/lib$1.so"`
ulrich_y's avatar
ulrich_y committed
207
                    echo $path 1>&3
ulrich_y's avatar
ulrich_y committed
208
                    printf -v "CONF_$2" "%q" "$path"
ulrich_y's avatar
ulrich_y committed
209 210 211
                    return 0
                fi
                if [ -f "$libfolder/lib$1.a" ] ; then
ulrich_y's avatar
ulrich_y committed
212
                    path=`readlinf -f -- "$libfolder/lib$1.a"`
ulrich_y's avatar
ulrich_y committed
213
                    echo $path 1>&3
ulrich_y's avatar
ulrich_y committed
214
                    printf -v "CONF_$2" "%q" "$path"
ulrich_y's avatar
ulrich_y committed
215 216 217 218 219 220 221 222
                    return 0
                fi
            ;;
        esac
    done
    echo "not found" 1>&3
    return 1
}
ulrich_y's avatar
ulrich_y committed
223
addflag() {
ulrich_y's avatar
ulrich_y committed
224
    eval "CONF_$1=\"\${CONF_$1} ${@:2}\""
ulrich_y's avatar
ulrich_y committed
225 226 227 228
}

gnuflags() {
    eval addflag FFLAGS -cpp                         # C pre-processor
ulrich_y's avatar
ulrich_y committed
229
    eval addflag FFLAGS -pedantic-errors -std=f2008  # folow f08 strictly
ulrich_y's avatar
ulrich_y committed
230 231
    eval addflag FFLAGS -J build                     # where to put mods
    eval addflag FFLAGS -Werror -Wall                # make every warning an error
ulrich_y's avatar
ulrich_y committed
232
    eval addflag FFLAGS -Wno-uninitialized
ulrich_y's avatar
ulrich_y committed
233
    eval addflag FFLAGS -ffree-line-length-0
ulrich_y's avatar
ulrich_y committed
234 235
}

ulrich_y's avatar
ulrich_y committed
236

ulrich_y's avatar
ulrich_y committed
237 238 239
if [ -z $FC ]; then
    findprog fortran FC  ifort gfortran  || exit 1
fi
ulrich_y's avatar
ulrich_y committed
240 241


ulrich_y's avatar
ulrich_y committed
242
set -- `eval $CONF_FC --version -c | sed '/^$/d;s/([^)]*)//;q' 2>&1`
ulrich_y's avatar
ulrich_y committed
243 244
case "$1,$2,$3" in
    GNU,Fortran,[123].*)
245
        echo "Only version >= 4 are supported" 1>&3
ulrich_y's avatar
ulrich_y committed
246 247
        exit
    ;;
ulrich_y's avatar
ulrich_y committed
248
    GNU,Fortran,4.*)
249
    echo "Code optimisation is *not* suported on gfortran 4" 1>&3
ulrich_y's avatar
ulrich_y committed
250
        gnuflags
ulrich_y's avatar
ulrich_y committed
251
        eval addflag $CONF_BITS
ulrich_y's avatar
ulrich_y committed
252 253
        if $DEBUG ; then
            eval addflag FFLAGS -g -O0
ulrich_y's avatar
ulrich_y committed
254
            eval addflag FFLAGS -ffpe-trap=invalid,overflow
ulrich_y's avatar
ulrich_y committed
255 256 257 258 259
            eval addflag FFLAGS -fdump-core -fbacktrace
            eval addflag FFLAGS -frange-check
            eval addflag FFLAGS -DDEBUG
        else
            eval addflag FFLAGS -DRELEASE
ulrich_y's avatar
ulrich_y committed
260
            $NATIVE && eval addflag FFLAGS -march=native -mtune=native
ulrich_y's avatar
ulrich_y committed
261
        fi
ulrich_y's avatar
ulrich_y committed
262 263 264 265
        if $COVERAGE ; then
            echo "Coverage analytics is currently only supported for gcc"
            exit 1
        fi
ulrich_y's avatar
ulrich_y committed
266 267 268 269
    ;;
    GNU,Fortran,*)
        gnuflags
        eval addflag FFLAGS -Wno-maybe-uninitialized
ulrich_y's avatar
ulrich_y committed
270
        eval addflag $CONF_BITS
ulrich_y's avatar
ulrich_y committed
271 272
        if $DEBUG ; then
            eval addflag FFLAGS -g -O0
ulrich_y's avatar
ulrich_y committed
273
            eval addflag FFLAGS -ffpe-trap=invalid,overflow
ulrich_y's avatar
ulrich_y committed
274 275 276 277 278
            eval addflag FFLAGS -fdump-core -fbacktrace
            eval addflag FFLAGS -fcheck=all -frange-check
            eval addflag FFLAGS -DDEBUG
        else
            eval addflag FFLAGS -DRELEASE -O3
ulrich_y's avatar
ulrich_y committed
279
            $NATIVE && eval addflag FFLAGS -march=native -mtune=native
ulrich_y's avatar
ulrich_y committed
280
        fi
ulrich_y's avatar
ulrich_y committed
281 282 283 284
        if $COVERAGE ; then
            eval addflag FFLAGS --coverage
            eval addflag LFLAGS -lgcov
        fi
ulrich_y's avatar
ulrich_y committed
285 286 287 288 289
    ;;
    ifort*)
        eval addflag FFLAGS -module build
        eval addflag FFLAGS -fpp
        eval addflag FFLAGS -stand f03
ulrich_y's avatar
ulrich_y committed
290
        eval addflag $CONF_BITS
ulrich_y's avatar
ulrich_y committed
291 292 293 294
        if $DEBUG ; then
            eval addflag FFLAGS -g -O0
            eval addflag FFLAGS -DDEBUG
        else
ulrich_y's avatar
ulrich_y committed
295 296
            eval addflag FFLAGS -DRELEASE -O3 -fast
            $NATIVE && eval addflag FFLAGS -xHost
ulrich_y's avatar
ulrich_y committed
297
        fi
ulrich_y's avatar
ulrich_y committed
298
        if $HAVE_GINAC ; then
299
            echo "Option --with-ginac is incompatible with ifort, disabling" 1>&3
ulrich_y's avatar
ulrich_y committed
300
            HAVE_GINAC=false
ulrich_y's avatar
ulrich_y committed
301
        fi
ulrich_y's avatar
ulrich_y committed
302
        if $HAVE_MCC ; then
303
            echo "Option --with-mcc is incompatible with ifort, disabling" 1>&3
ulrich_y's avatar
ulrich_y committed
304
            HAVE_MCC=false
ulrich_y's avatar
ulrich_y committed
305
        fi
ulrich_y's avatar
ulrich_y committed
306 307 308 309
        if $COVERAGE ; then
            echo "Coverage analytics is currently only supported for gcc"
            exit 1
        fi
ulrich_y's avatar
ulrich_y committed
310 311
    ;;
    *)
312
        echo "Unknown compiler" 1>&3
ulrich_y's avatar
ulrich_y committed
313 314 315 316
        exit
    ;;
esac

ulrich_y's avatar
ulrich_y committed
317 318 319 320 321 322 323 324
echo -n "extracting the Fortran libraries... " 1>&3

rm -fr $test*

tee $test.f90 << _EOF_ 1>&2
    program test
    integer i
    common /uscore/ i
ulrich_y's avatar
ulrich_y committed
325
    call exit(i)
ulrich_y's avatar
ulrich_y committed
326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348
    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
ulrich_y's avatar
ulrich_y committed
349 350 351 352 353 354 355 356 357 358 359 360

  if [[ "$line" == *"-fintrinsic-modules-path"* ]]; then
    set -- ${line//[:,()]/ }
    while test $# -gt 1 ; do
      shift
      case "$1" in
        -fintrinsic-modules-path )
          CONF_MODPATH=$2
          ;;
      esac
    done
  fi
ulrich_y's avatar
ulrich_y committed
361
done < <(eval $CONF_FC  -v -o $test $test.f90 2>&1)
ulrich_y's avatar
ulrich_y committed
362 363
echo "ok" 1>&3

ulrich_y's avatar
ulrich_y committed
364
eval addflag LFLAGS "$LDFLAGS $CONF_LDFLAGS $FLDFLAGS -L$CONF_PREFIX/lib"
ulrich_y's avatar
ulrich_y committed
365

ulrich_y's avatar
ulrich_y committed
366 367
if [[ -z "$CONF_MODDIR" ]]; then
  if [[ ! -z "$CONF_MODPATH" ]]; then
ulrich_y's avatar
ulrich_y committed
368 369 370
    echo -n "checking whether module path is in prefix... " 1>&3
    if [[ "${CONF_MODPATH##$CONF_PREFIX}" != "${CONF_MODPATH}" ]]; then
        echo " yes" 1>&3
ulrich_y's avatar
ulrich_y committed
371
        CONF_MODDIR=$CONF_MODPATH
ulrich_y's avatar
ulrich_y committed
372 373
    else
        echo " no" 1>&3
ulrich_y's avatar
ulrich_y committed
374
        CONF_MODDIR=
ulrich_y's avatar
ulrich_y committed
375
    fi
ulrich_y's avatar
ulrich_y committed
376
  fi
ulrich_y's avatar
ulrich_y committed
377 378
fi

ulrich_y's avatar
ulrich_y committed
379

380
findprog pkg-config PKGCONFIG pkg-config
ulrich_y's avatar
ulrich_y committed
381
if [[ -z "$CONF_MODDIR" ]]; then
ulrich_y's avatar
ulrich_y committed
382
  if [[ -z "$CONF_PKGCONFIG" ]]; then
383 384 385 386 387 388 389 390 391
    echo "*************************************************" 1>&3
    echo "Warning! pkg-config not found! This may lead to  " 1>&3
    echo "difficulties when you try to compile your own    " 1>&3
    echo "code. You will need to run                       " 1>&3
    echo "                                                 " 1>&3
    echo "  $CONF_FC -I$CONF_PREFIX/include                " 1>&3
    echo "                                                 " 1>&3
    echo "every time.                                      " 1>&3
    echo "*************************************************" 1>&3
ulrich_y's avatar
ulrich_y committed
392
  fi
393
fi
ulrich_y's avatar
ulrich_y committed
394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410

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
ulrich_y's avatar
ulrich_y committed
411
      eval $CONF_FC  -o $test $test.f90 $test-c.o 1>&2 && break
ulrich_y's avatar
ulrich_y committed
412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431
    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
432 433
fi

ulrich_y's avatar
ulrich_y committed
434 435 436

if $HAVE_MCC ; then
    PATH=$PATH:/Applications/Mathematica.app/Contents/MacOS/ findprog mathematica MATH math MathKernel math10 math11
ulrich_y's avatar
ulrich_y committed
437
    eval addflag FFLAGS -DHAVE_MM
ulrich_y's avatar
ulrich_y committed
438 439 440 441 442 443 444 445

    # Checking Mathematica system id

    echo -n "what is $CONF_MATH SystemID... " 1>&3

    tee $test.m << _EOF_ 1>&2
        Print["SYSID "<>ToString[\$SystemID]];
        Print["INSTDIR "<>ToString[\$InstallationDirectory]];
ulrich_y's avatar
ulrich_y committed
446
        Print["USERDIR "<>ToString[\$UserBaseDirectory]];
ulrich_y's avatar
ulrich_y committed
447 448 449 450
_EOF_
    $CONF_MATH < $test.m > $test.log
    CONF_MATH_SYS=`cat $test.log | grep "SYSID"   | sed 's/.*SYSID //'`
    CONF_MATH_DIR=`cat $test.log | grep "INSTDIR" | sed 's/.*INSTDIR //'`
ulrich_y's avatar
ulrich_y committed
451
    CONF_MATH_USR=`cat $test.log | grep "USERDIR" | sed 's/.*USERDIR //'`
ulrich_y's avatar
ulrich_y committed
452 453
    [[ -z "$CONF_MMPREFIX" ]] && \
       CONF_MMPREFIX=${CONF_MMPREFIX:=$CONF_MATH_USR/Kernel}
ulrich_y's avatar
ulrich_y committed
454 455 456 457 458 459 460 461 462 463 464 465 466 467 468
    echo  $CONF_MATH_SYS 1>&3


    # Finding mcc
    CONF_COMPAD=$CONF_MATH_DIR/SystemFiles/Links/MathLink/DeveloperKit/$CONF_MATH_SYS/CompilerAdditions/
    PATH=$CONF_COMPAD:$PATH findprog mcc MCC mcc

    echo -n "looking for MLDK directory... " 1>&3
    $CONF_MCC --internals > $test.int
    CONF_MLDK=`cat $test.int | grep "MLDK Directory" | cut -f2 -d":"`
    echo $CONF_MLDK 1>&3

    arch=`cat $test.int | grep "Library Bit Type:" | cut -f2 -d":"` ; \
    CONF_MCC_CFLAGS=`cat $test.int | grep "Compile Flags$arch:" | cut -f2 -d":"`
    CONF_MCC_LFLAGS=`cat $test.int | grep "Linker Libraries" | cut -f2 -d":"`
ulrich_y's avatar
ulrich_y committed
469
    CONF_MCC_LFLAGS="$CONF_LFLAGS $CONF_MCC_LFLAGS"
ulrich_y's avatar
ulrich_y committed
470 471 472 473 474 475 476 477
    cat $test.int | grep "Linker Libraries" | cut -f2 -d":"
    if [ ! -z $CONF_BITS ]; then
        if [ "$CONF_BITS" -ne "$MCC_BITS" ]; then
            echo "mcc wants $MCC_BITS ($arch), $CONF_BITS selected." 1>&3
            exit 1
        fi
    fi

ulrich_y's avatar
ulrich_y committed
478
    if [[ $CONF_MCC_LFLAGS == *"uuid"* ]]; then
ulrich_y's avatar
ulrich_y committed
479 480 481 482 483 484 485 486 487 488
        if ! findlib uuid UUID ; then
            echo -n "improvising uuid... " 1>&3
            CONF_MLIBDIR=$CONF_MATH_DIR/SystemFiles/Libraries/$CONF_MATH_SYS/
            if [ -f $CONF_MLIBDIR/libuuid.a ]; then
                CONF_MCC_LFLAGS="-L$CONF_MLIBDIR $CONF_MCC_LFLAGS"
                echo "okay" 1>&3
            else
                echo "failed" 1>&3
                exit 1
            fi
ulrich_y's avatar
ulrich_y committed
489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524
        fi
    fi

    # Finding MPREP
    PATH=$CONF_COMPAD:$PATH findprog mprep MPREP mprep

    ## can we do MathLink compilations
    echo -n "do we have working MathLink... " 1>&3
    tee $test.tm << _EOF_ 1>&2
:Begin:
:Function: test
:Pattern: Test[i_Integer]
:Arguments: {i}
:ArgumentTypes: {Integer}
:ReturnType: Integer
:End:

#include "mathlink.h"

static int test(const int i) {
  return i + 1;
}

int main(int argc, char **argv) {
  return MLMain(argc, argv);
}
_EOF_
    $CONF_MPREP $test.tm > $test.tm.c
    $CONF_CC $CONF_MCC_CFLAGS $CONF_CFLAGS -c $test.tm.c
    $CONF_CC -o $test.math $test.tm.o $CONF_MCC_LFLAGS
    test -x $test.math && {
        echo "yes" 1>&3
        CONF_ML=1
    } || {
        echo "no" 1>&3
        CONF_ML=0
ulrich_y's avatar
ulrich_y committed
525
        exit 1;
ulrich_y's avatar
ulrich_y committed
526 527
    }
fi
ulrich_y's avatar
ulrich_y committed
528 529


ulrich_y's avatar
ulrich_y committed
530
CONF_LD=${LD:-$CONF_FC}
ulrich_y's avatar
ulrich_y committed
531 532


ulrich_y's avatar
ulrich_y committed
533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558



if $CONF_QUAD ; then
  if $HAVE_GINAC ; then
    echo "GiNaC testing is not supported for quad-precision!" 1>&3
    exit 1
  fi
  echo -n "does $CONF_FC support quad-precision... " 1>&3
  rm -fr $test*
  tee $test.f90 << _EOF_ 1>&2
        program test
        real(selected_real_kind(30,32)) a, b
        a = 2D0**(52/2+2)
        b = a + 1/a
        if( a .eq. b ) stop 1
        end
_EOF_
  $CONF_FC $CONF_FFLAGS -o $test $test.f90 1>&2
  ./$test 1>&2 && {
    echo "yes" 1>&3
    eval addflag FFLAGS -DKINDREAL=16 -DKINDINT=8
  } || {
    echo "no" 1>&3
    exit 1
  }
ulrich_y's avatar
ulrich_y committed
559
  $HAVE_MCC && eval addflag CFLAGS -DHAVE_QUAD
ulrich_y's avatar
ulrich_y committed
560 561 562 563 564 565 566
fi






ulrich_y's avatar
ulrich_y committed
567
if $HAVE_GINAC ; then
ulrich_y's avatar
ulrich_y committed
568
    eval addflag CXXFLAGS "-std=c++11"
ulrich_y's avatar
ulrich_y committed
569 570 571 572
    if [[ ! -z "$CONF_PKGCONFIG" ]]; then
        echo -n "Does pkg-config know about GiNaC... " 1>&3
        if $CONF_PKGCONFIG --exists ginac ; then
            echo "yes" 1>&3
ulrich_y's avatar
ulrich_y committed
573
            eval addflag CXXFLAGS `$CONF_PKGCONFIG --cflags ginac`
ulrich_y's avatar
ulrich_y committed
574 575
            eval addflag LFLAGS `$CONF_PKGCONFIG --libs ginac`
            FOUND_GINAC=true
ulrich_y's avatar
ulrich_y committed
576
            CONF_GINAC=`$CONF_PKGCONFIG --variable=libdir ginac`
ulrich_y's avatar
ulrich_y committed
577 578 579 580 581 582 583 584 585 586 587 588
        else
            echo "no" 1>&3
            FOUND_GINAC=false
        fi
    fi
    if ! $FOUNDGINAC ; then
        FOUNDGINAC=`findlib ginac GINAC && findlib cln CLN`
        eval addflag LFLAGS "-L`dirname $CONF_GINAC`"
        eval addflag LFLAGS "-L`dirname $CONF_CLN`"
        eval addflag LFLAGS "-lginac -lcln"
    fi
    if $FOUNDGINAC; then
ulrich_y's avatar
ulrich_y committed
589
        CONF_LD=${LD:-$CONF_CXX}
ulrich_y's avatar
ulrich_y committed
590 591 592 593 594 595 596 597 598 599 600 601 602 603 604
        echo -n "Checking if GiNaC works... " 1>&3
        tee $test.ginac.cpp << _EOF_ 1>&2
#include <ginac/ginac.h>
#include <iostream>
int main() {

    GiNaC::ex ans = GiNaC::G(0.3,0.5,0.7);
    ans -= 0.2876820724517808812+3.1415926535897932385*GiNaC::I;
    ans = GiNaC::abs(ans);
    if (ans<1e-15)
        return 0;
    else
        return 1;
}
_EOF_
ulrich_y's avatar
ulrich_y committed
605
        $CONF_CXX $CONF_CXXFLAGS $CONF_BITS -c $test.ginac.cpp
ulrich_y's avatar
ulrich_y committed
606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625
        $CONF_LD -o $test.ginac $test.ginac.o $CONF_LFLAGS
        ./$test.ginac
        case $? in
            0)
              echo "yes" 1>&3
              eval addflag FFLAGS "-DHAVE_GINAC" ;;
            1)
              echo "no" 1>&3
              exit 1 ;;
            *)
              echo "error running GiNaC" 1>&3
              exit 1 ;;
        esac
    else
        echo "GiNaC could not be found" 1>&3
        exit 1
    fi
fi


ulrich_y's avatar
ulrich_y committed
626 627 628
if $HAVE_GINAC && $HAVE_MCC; then
  eval addflag LFLAGS -lrt
fi
ulrich_y's avatar
ulrich_y committed
629

630 631 632 633 634 635 636 637 638 639 640
if [[ ! -z "$CONF_PKGCONFIG" ]]; then
cat > handyg.pc <<EOF
prefix=$CONF_PREFIX
exec_prefix=\${prefix}
libdir=\${exec_prefix}/lib
includedir=\${prefix}/include

Name: handyG
Description: Numerical evaluation of GPL
Version: 0.1.0
Libs: -L\${libdir} -lhandyg
ulrich_y's avatar
ulrich_y committed
641
Cflags: -I\${includedir}
642 643 644 645
EOF

fi

ulrich_y's avatar
ulrich_y committed
646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665
if $COVERAGE ; then
    findprog gcov GCOV gcov gcov-7 gcov-6 gcov-5 gcov-34 || exit 1
    if ! findlib gcov LGCOV ; then
      echo "can't perform coverage tests without libgcov. Please specify using \$LFLAGS" 1>&3
      exit 1
    fi

    if ! findprog lcov LCOV lcov ; then
      echo "graphical coverage report won't be supported" 1>&3
      HAVE_LCOV=false
    else
      if ! findprog genhtml GENHTML genhtml ; then
        echo "graphical coverage report won't be supported" 1>&3
        HAVE_LCOV=false
      else
        HAVE_LCOV=true
      fi
    fi
fi

ulrich_y's avatar
ulrich_y committed
666 667 668 669
echo "creating makefile" 1>&3


cat  > makefile <<EOF
ulrich_y's avatar
ulrich_y committed
670
# Generated through $0 $allargs on `date` by `whoami`
ulrich_y's avatar
ulrich_y committed
671 672 673 674 675 676 677

AR=ar rcs
FC=$CONF_FC
CC=$CONF_CC
CXX=$CONF_CXX
LD=$CONF_LD
MPREP=$CONF_MPREP
ulrich_y's avatar
ulrich_y committed
678
MATH=$CONF_MATH
ulrich_y's avatar
ulrich_y committed
679 680 681
GCOV=$CONF_GCOV
LCOV=$CONF_LCOV
GENHTML=$CONF_GENHTML
ulrich_y's avatar
ulrich_y committed
682 683 684

FFLAGS=$CONF_FFLAGS
CFLAGS=$CONF_CFLAGS
ulrich_y's avatar
ulrich_y committed
685
CXXFLAGS=$CONF_CXXFLAGS
ulrich_y's avatar
ulrich_y committed
686 687 688 689
LFLAGS=$CONF_LFLAGS
MCFLAGS=$CONF_MCC_CFLAGS
MLFLAGS=$CONF_MCC_LFLAGS

ulrich_y's avatar
ulrich_y committed
690 691
PREFIX=$CONF_PREFIX
MMPREFIX=$CONF_MMPREFIX
ulrich_y's avatar
ulrich_y committed
692
MODDIR=$CONF_MODDIR
ulrich_y's avatar
ulrich_y committed
693

ulrich_y's avatar
ulrich_y committed
694

ulrich_y's avatar
ulrich_y committed
695
files=globals.o ieps.o utils.o shuffle.o maths_functions.o mpl_module.o gpl_module.o handyG.o
ulrich_y's avatar
ulrich_y committed
696 697 698
objects = \$(addprefix build/,\$(files))


ulrich_y's avatar
ulrich_y committed
699
all: libhandyg.a handyg.mod ${CONF_MPREP:+handyG} geval test
ulrich_y's avatar
ulrich_y committed
700

ulrich_y's avatar
ulrich_y committed
701
libhandyg.a:\$(objects)
ulrich_y's avatar
ulrich_y committed
702
		@echo "AR \$@"
ulrich_y's avatar
ulrich_y committed
703 704 705 706 707
		@\$(AR) \$@ \$^

handyg.mod: build/handyg.mod
		cp \$< \$@

ulrich_y's avatar
ulrich_y committed
708 709 710 711

# rules to make object files into /build
build/%.o: src/%.f90
		@echo "F90 \$@"
ulrich_y's avatar
ulrich_y committed
712
		@\$(FC) \$(FFLAGS) -c \$< -o \$@
ulrich_y's avatar
ulrich_y committed
713

ulrich_y's avatar
ulrich_y committed
714 715
build/%.o: checks/%.f90
		@echo "F90 \$@"
ulrich_y's avatar
ulrich_y committed
716
		@\$(FC) \$(FFLAGS) -c \$< -o \$@
ulrich_y's avatar
ulrich_y committed
717

ulrich_y's avatar
ulrich_y committed
718 719
build/%.o: src/%.cpp
		@echo "C++ \$@"
ulrich_y's avatar
ulrich_y committed
720
		@\$(CC) \$(CXXFLAGS) -c \$<  -o \$@
ulrich_y's avatar
ulrich_y committed
721

ulrich_y's avatar
ulrich_y committed
722
geval: libhandyg.a build/geval.o
ulrich_y's avatar
ulrich_y committed
723
		@echo "LD \$@"
ulrich_y's avatar
ulrich_y committed
724
		@\$(LD) -o \$@ build/geval.o -L. -lhandyg \$(LFLAGS)
ulrich_y's avatar
ulrich_y committed
725

ulrich_y's avatar
ulrich_y committed
726 727 728 729 730
EOF

$HAVE_MCC && cat >> makefile <<EOF
build/%.tm.c: src/%.tm
		@echo "MPREP \$@"
ulrich_y's avatar
ulrich_y committed
731 732
		@cat \$< | sed '/:Begin:/,/:End:/ s/Real/Real$($CONF_QUAD && echo 128)/g' \\
                 | sed 's/__VERSION__/$VERSION/g' | \$(MPREP) > \$@
ulrich_y's avatar
ulrich_y committed
733

ulrich_y's avatar
ulrich_y committed
734
build/mathlink.o: build/mathlink.tm.c
ulrich_y's avatar
ulrich_y committed
735 736 737
		@echo "CC \$<"
		@\$(CC) \$(MCFLAGS) \$(CFLAGS) -o \$@ -c \$<

ulrich_y's avatar
ulrich_y committed
738
handyG: build/mathlink.o libhandyg.a
ulrich_y's avatar
ulrich_y committed
739
		@echo "LD \$@"
ulrich_y's avatar
ulrich_y committed
740
		@\$(LD)  \$< libhandyg.a -o \$@ \$(LFLAGS) \$(MLFLAGS)
ulrich_y's avatar
ulrich_y committed
741

ulrich_y's avatar
ulrich_y committed
742 743 744
checks/test-chen.f90: checks/generate.m
		@echo "MATH generate \$@"
		@\$(MATH) -script \$< \$@
ulrich_y's avatar
ulrich_y committed
745
checks/test-chenff.f90: checks/generate.m
ulrich_y's avatar
ulrich_y committed
746 747
		@echo "MATH generate \$@"
		@\$(MATH) -script \$< \$@
ulrich_y's avatar
ulrich_y committed
748 749 750 751 752 753
checks/test-muone.f90: checks/generate.m
		@echo "MATH generate \$@"
		@\$(MATH) -script \$< \$@
checks/test-muoneNP.f90: checks/generate.m
		@echo "MATH generate \$@"
		@\$(MATH) -script \$< \$@
ulrich_y's avatar
ulrich_y committed
754 755


ulrich_y's avatar
ulrich_y committed
756 757 758 759 760 761
EOF
echo -n "test: \$(objects) " >> makefile

                            echo -n "build/test-chenref.o " >> makefile
$HAVE_GINAC              && echo -n "build/ginac.o " >> makefile
$HAVE_GINAC && $HAVE_MCC && echo -n "build/test-chen.o " >> makefile
ulrich_y's avatar
ulrich_y committed
762
$HAVE_GINAC && $HAVE_MCC && echo -n "build/test-chenff.o " >> makefile
ulrich_y's avatar
ulrich_y committed
763 764
$HAVE_GINAC && $HAVE_MCC && echo -n "build/test-muone.o " >> makefile
$HAVE_GINAC && $HAVE_MCC && echo -n "build/test-muoneNP.o " >> makefile
ulrich_y's avatar
ulrich_y committed
765

ulrich_y's avatar
ulrich_y committed
766 767
echo "build/test.o" >> makefile
cat  >> makefile <<EOF
ulrich_y's avatar
ulrich_y committed
768
		@echo "LD \$@"
ulrich_y's avatar
ulrich_y committed
769
		@\$(LD) -o \$@ \$^ \$(LFLAGS)
ulrich_y's avatar
ulrich_y committed
770

ulrich_y's avatar
ulrich_y committed
771
install: libhandyg.a handyg.mod ${CONF_MPREP:+handyg} geval
ulrich_y's avatar
ulrich_y committed
772
		mkdir -p \$(PREFIX)
ulrich_y's avatar
ulrich_y committed
773
		mkdir -p \$(PREFIX)/bin
ulrich_y's avatar
ulrich_y committed
774
		cp geval \$(PREFIX)/bin/geval
ulrich_y's avatar
ulrich_y committed
775
		mkdir -p \$(PREFIX)/lib
ulrich_y's avatar
ulrich_y committed
776
		cp libhandyg.a \$(PREFIX)/lib/
ulrich_y's avatar
ulrich_y committed
777
		mkdir -p \$(PREFIX)/include
ulrich_y's avatar
ulrich_y committed
778
		cp handyg.mod \$(PREFIX)/include/
ulrich_y's avatar
ulrich_y committed
779 780 781
EOF
$HAVE_MCC && cat >> makefile <<EOF
		mkdir -p \$(MMPREFIX)
ulrich_y's avatar
ulrich_y committed
782
		cp handyg \$(MMPREFIX)
ulrich_y's avatar
ulrich_y committed
783
EOF
784 785 786 787 788 789
if [[ ! -z "$CONF_PKGCONFIG" ]]; then
cat >> makefile <<EOF
		mkdir -p \$(PREFIX)/lib/pkgconfig
		cp handyg.pc \$(PREFIX)/lib/pkgconfig
EOF
fi
ulrich_y's avatar
ulrich_y committed
790
if [[ ! -z "$CONF_MODDIR" ]]; then
ulrich_y's avatar
ulrich_y committed
791
cat >> makefile <<EOF
ulrich_y's avatar
ulrich_y committed
792
		mkdir -p \$(MODDIR)
ulrich_y's avatar
ulrich_y committed
793
		cp handyg.mod \$(MODDIR)
ulrich_y's avatar
ulrich_y committed
794 795 796
EOF
fi

ulrich_y's avatar
ulrich_y committed
797 798 799

echo "uninstall:" >> makefile
echo -ne "\t\trm -i " >> makefile
ulrich_y's avatar
ulrich_y committed
800 801
echo -n "\$(PREFIX)/lib/libhandyg.a " >> makefile
echo -n "\$(PREFIX)/include/handyg.mod " >> makefile
ulrich_y's avatar
ulrich_y committed
802
echo -n "\$(PREFIX)/bin/geval " >> makefile
ulrich_y's avatar
ulrich_y committed
803
$HAVE_MCC && echo -n "\$(MMPREFIX)/handyg" >> makefile
804 805 806
if [[ ! -z "$CONF_PKGCONFIG" ]]; then
echo -n "\$(PREFIX)/lib/pkgconfig " >> makefile
fi
ulrich_y's avatar
ulrich_y committed
807 808
if [[ ! -z "$CONF_MODDIR" ]]; then
echo -n "\$(MODDIR)/handyg.mod " >> makefile
ulrich_y's avatar
ulrich_y committed
809
fi
ulrich_y's avatar
ulrich_y committed
810 811 812
cat  >> makefile <<EOF


ulrich_y's avatar
ulrich_y committed
813 814
check: test
		./$<
ulrich_y's avatar
ulrich_y committed
815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832
EOF


if $COVERAGE ; then
  cat  >> makefile <<EOF
report/report.txt: test
		mkdir -p report
		./test -verb 1000 > /dev/null
		echo "Report generated on \`date\` by `whoami`." > \$@
EOF

  for i in gpl_module ieps maths_functions mpl_module shuffle utils test
  do
    echo -e "\t\t\$(GCOV) build/$i.gcno >> \$@" >> makefile
    echo -e "\t\tmv $i.f90.gcov report/" >> makefile
  done

  $HAVE_LCOV && cat >> makefile <<EOF
ulrich_y's avatar
ulrich_y committed
833
report/coverage.full.info: report/report.txt
ulrich_y's avatar
ulrich_y committed
834
		\$(LCOV) --capture --directory build/ --output-file \$@
ulrich_y's avatar
ulrich_y committed
835 836
report/coverage.info: report/coverage.full.info
		\$(LCOV) --remove \$< "\$\$(pwd)/checks/test-chenff.f90" -o \$@
ulrich_y's avatar
ulrich_y committed
837 838 839 840 841 842 843 844 845 846 847
report/lcov.report: report/coverage.info
		\$(LCOV) --list \$< > \$@
		cat \$@
report/index.html: report/coverage.info
		\$(GENHTML) \$< --output-directory report
EOF
#cat \$@ | perl -nle "print \\\$\$1 if /Total:\\|(\\d+\\.?\\d+\\%)/"
  echo -n "coverage: report/report.txt" >> makefile
  $HAVE_LCOV && echo -n " report/coverage.info report/lcov.report report/index.html" >> makefile
  echo >> makefile

ulrich_y's avatar
ulrich_y committed
848

ulrich_y's avatar
ulrich_y committed
849 850 851 852

fi

cat  >> makefile <<EOF
ulrich_y's avatar
ulrich_y committed
853
clean:
ulrich_y's avatar
ulrich_y committed
854
		@rm -f build/*.gcda build/*.gcno build/*.gcov
ulrich_y's avatar
ulrich_y committed
855
		@rm -rf report/
ulrich_y's avatar
ulrich_y committed
856
		@rm -f build/*.o build/*.mod build/*.c build/mcc.internals*
ulrich_y's avatar
ulrich_y committed
857
		@rm -f test geval libhandyg.a handyG handyg.mod
ulrich_y's avatar
ulrich_y committed
858
		@rm -f checks/test-chen.f90 checks/test-muone.f90 checks/test-muoneNP.f90
ulrich_y's avatar
ulrich_y committed
859 860

distclean:
ulrich_y's avatar
ulrich_y committed
861
		@rm -f build/*.gcda build/*.gcno build/*.gcov
ulrich_y's avatar
ulrich_y committed
862
		@rm -rf report/
ulrich_y's avatar
ulrich_y committed
863
		@rm -f build/*.o build/*.mod build/*.c build/mcc.internals*
ulrich_y's avatar
ulrich_y committed
864
		@rm -f test geval libhandyg.a handyg
ulrich_y's avatar
ulrich_y committed
865
		@rm -f checks/test-chen.f90 checks/test-muone.f90 checks/test-muoneNP.f90
866
		@rm -f makefile handyg.pc
ulrich_y's avatar
ulrich_y committed
867
EOF
ulrich_y's avatar
ulrich_y committed
868 869 870


echo "Configuration of handyG $VERSION done. Now type \"make\"."