configure 27.1 KB
Newer Older
ulrich_y's avatar
ulrich_y committed
1 2 3
#! /bin/bash
# configure script
# note: has nothing to do with GNU autoconf
ulrich_y's avatar
ulrich_y committed
4 5 6 7 8 9
if [[ -z $LOGFILE ]]; then
  exec 2> /dev/null 3>&1
else
  exec 3> >(while read TEXT ; do echo $TEXT ; echo $(date +"%d.%m.%Y %H:%M:%S") $TEXT >> $LOGFILE; done)
  exec 2>> $LOGFILE
fi
ulrich_y's avatar
ulrich_y committed
10 11 12 13 14


shopt -s nullglob
export LC_ALL=C

ulrich_y's avatar
ulrich_y committed
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
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
38 39 40
  --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
41 42 43 44 45 46

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
47
  --native                do optimize code for the host machine
ulrich_y's avatar
ulrich_y committed
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

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
77 78
CONF_DIR="${0%/*}"
CONF_OS="`uname -s`"
ulrich_y's avatar
ulrich_y committed
79 80 81
HAVE_GINAC=false
HAVE_MCC=false
CONF_BITS=
ulrich_y's avatar
ulrich_y committed
82

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


ulrich_y's avatar
ulrich_y committed
95
if [ "$CONF_OS" == "Darwin" ]; then
ulrich_y's avatar
ulrich_y committed
96 97 98 99 100
    CONF_PREFIX=/usr/local/
else
    CONF_PREFIX=/usr/
fi

ulrich_y's avatar
ulrich_y committed
101

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


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

ulrich_y's avatar
ulrich_y committed
153 154 155 156 157 158 159 160 161 162 163 164
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
ulrich_y's avatar
ulrich_y committed
165
    VERSION=`git describe --tag`
ulrich_y's avatar
ulrich_y committed
166 167 168 169 170 171 172 173 174 175 176 177 178
    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
179

ulrich_y's avatar
ulrich_y committed
180 181 182 183
if $COVERAGE ; then
  $DEBUG || echo "Warning: --coverage implies --debug!" 1>&3
  DEBUG=true
fi
ulrich_y's avatar
ulrich_y committed
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
ulrich_y's avatar
ulrich_y committed
191
        echo "Checking option $prog in path" 1>&2
ulrich_y's avatar
ulrich_y committed
192 193
        full="`type -P "$prog"`" && {
            echo "$full" 1>&3
ulrich_y's avatar
ulrich_y committed
194
            printf -v "CONF_$var" "%q" "$full"
ulrich_y's avatar
ulrich_y committed
195 196 197 198 199 200
            return 0
        }
    done
    echo "no $@ in your path" 1>&3
    return 1
}
ulrich_y's avatar
ulrich_y committed
201 202 203 204 205 206 207

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

gnuflags() {
    eval addflag FFLAGS -cpp                         # C pre-processor
ulrich_y's avatar
ulrich_y committed
235
    eval addflag FFLAGS -pedantic-errors -std=f2008  # folow f08 strictly
ulrich_y's avatar
ulrich_y committed
236 237
    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
238
    eval addflag FFLAGS -Wno-uninitialized
ulrich_y's avatar
ulrich_y committed
239
    eval addflag FFLAGS -ffree-line-length-0
ulrich_y's avatar
ulrich_y committed
240 241
}

ulrich_y's avatar
ulrich_y committed
242

ulrich_y's avatar
ulrich_y committed
243 244 245
if [ -z $FC ]; then
    findprog fortran FC  ifort gfortran  || exit 1
fi
ulrich_y's avatar
ulrich_y committed
246 247


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

ulrich_y's avatar
ulrich_y committed
323 324 325 326
echo -n "extracting the Fortran libraries... " 1>&3

rm -fr $test*

ulrich_y's avatar
ulrich_y committed
327
echo "Trying the following program as $test.f90" 1>&2
ulrich_y's avatar
ulrich_y committed
328 329 330 331
tee $test.f90 << _EOF_ 1>&2
    program test
    integer i
    common /uscore/ i
ulrich_y's avatar
ulrich_y committed
332
    call exit(i)
ulrich_y's avatar
ulrich_y committed
333 334 335
    end
_EOF_

ulrich_y's avatar
ulrich_y committed
336 337
echo "Executing $CONF_FC  -v -o $test $test.f90" 1>&2

ulrich_y's avatar
ulrich_y committed
338
while read line ; do
ulrich_y's avatar
ulrich_y committed
339
  echo "Parsing line $line" 1>&2
ulrich_y's avatar
ulrich_y committed
340 341 342 343 344 345 346
  set -- ${line//[:,()]/ }
  [[ "$1" =~ (/collect2|/ld|^ld)$ ]] && while test $# -gt 1 ; do
    shift
    case "$1" in
    *.o | -lc*)
      ;;
    -l* | -L* | *.a)
ulrich_y's avatar
ulrich_y committed
347
      echo "Found linker flag $1" 1>&2
ulrich_y's avatar
ulrich_y committed
348 349
      FLDFLAGS+=" $1" ;;
    -Bstatic | -Bdynamic | *.ld)
ulrich_y's avatar
ulrich_y committed
350
      echo "Found linker flag $1" 1>&2
ulrich_y's avatar
ulrich_y committed
351 352
      FLDFLAGS+=" -Wl,$1" ;;
    /*)
ulrich_y's avatar
ulrich_y committed
353
      echo "Found linker flag $1" 1>&2
ulrich_y's avatar
ulrich_y committed
354 355
      FLDFLAGS+=" -L$1" ;;
    -rpath*)
ulrich_y's avatar
ulrich_y committed
356
      echo "Found linker flag $1" 1>&2
ulrich_y's avatar
ulrich_y committed
357 358 359 360 361 362
      FLDFLAGS+=" -Wl,$1,$2"
      shift ;;
    -dynamic-linker)
      shift ;;
    esac
  done
ulrich_y's avatar
ulrich_y committed
363 364 365 366 367 368 369

  if [[ "$line" == *"-fintrinsic-modules-path"* ]]; then
    set -- ${line//[:,()]/ }
    while test $# -gt 1 ; do
      shift
      case "$1" in
        -fintrinsic-modules-path )
ulrich_y's avatar
ulrich_y committed
370
          echo "Found module path $1" 1>&2
ulrich_y's avatar
ulrich_y committed
371 372 373 374 375
          CONF_MODPATH=$2
          ;;
      esac
    done
  fi
ulrich_y's avatar
ulrich_y committed
376
done < <(eval $CONF_FC  -v -o $test $test.f90 2>&1)
ulrich_y's avatar
ulrich_y committed
377 378
echo "ok" 1>&3

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

ulrich_y's avatar
ulrich_y committed
381 382
if [[ -z "$CONF_MODDIR" ]]; then
  if [[ ! -z "$CONF_MODPATH" ]]; then
ulrich_y's avatar
ulrich_y committed
383 384 385
    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
386
        CONF_MODDIR=$CONF_MODPATH
ulrich_y's avatar
ulrich_y committed
387 388
    else
        echo " no" 1>&3
ulrich_y's avatar
ulrich_y committed
389
        CONF_MODDIR=
ulrich_y's avatar
ulrich_y committed
390
    fi
ulrich_y's avatar
ulrich_y committed
391
  fi
ulrich_y's avatar
ulrich_y committed
392 393
fi

ulrich_y's avatar
ulrich_y committed
394

395
findprog pkg-config PKGCONFIG pkg-config
ulrich_y's avatar
ulrich_y committed
396
if [[ -z "$CONF_MODDIR" ]]; then
ulrich_y's avatar
ulrich_y committed
397
  if [[ -z "$CONF_PKGCONFIG" ]]; then
398 399 400 401 402 403 404 405 406
    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
407
  fi
408
fi
ulrich_y's avatar
ulrich_y committed
409 410 411 412 413 414 415 416 417 418

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

ulrich_y's avatar
ulrich_y committed
419
    echo "Trying the following program as $test-c.c" 1>&2
ulrich_y's avatar
ulrich_y committed
420 421 422 423 424 425
    tee $test-c.c << _EOF_ 1>&2
int uscore_ = 95;
int uscore = 59;
_EOF_

    for CONF_BITS in ${CONF_BITS:--m64 -m32} ; do
ulrich_y's avatar
ulrich_y committed
426
      echo "Executing $CONF_CC $CONF_CFLAGS $CONF_BITS -c $test-c.c" 1>&2
ulrich_y's avatar
ulrich_y committed
427
      eval $CONF_CC $CONF_CFLAGS $CONF_BITS -c $test-c.c 1>&2 || continue
ulrich_y's avatar
ulrich_y committed
428
      echo "Executing $CONF_FC  -o $test $test.f90 $test-c.o" 1>&2
ulrich_y's avatar
ulrich_y committed
429
      eval $CONF_FC  -o $test $test.f90 $test-c.o 1>&2 && break
ulrich_y's avatar
ulrich_y committed
430 431
    done

ulrich_y's avatar
ulrich_y committed
432 433 434 435
    if [[ ! -x "$test" ]]; then
        echo "error: linking failed. Please check logfile $LOGFILE." 1>&3
    fi

ulrich_y's avatar
ulrich_y committed
436 437 438 439 440 441 442 443 444 445 446 447 448 449
    ./$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
ulrich_y's avatar
ulrich_y committed
450 451 452 453
    CONF_CC=
    CONF_CXX=
    CONF_CFLAGS=
    CONF_NOUNDERSCORE=
ulrich_y's avatar
ulrich_y committed
454 455
fi

ulrich_y's avatar
ulrich_y committed
456 457 458

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
459
    eval addflag FFLAGS -DHAVE_MM
ulrich_y's avatar
ulrich_y committed
460 461 462 463 464

    # Checking Mathematica system id

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

ulrich_y's avatar
ulrich_y committed
465
    echo "Trying the following program as $test.m" 1>&2
ulrich_y's avatar
ulrich_y committed
466 467 468
    tee $test.m << _EOF_ 1>&2
        Print["SYSID "<>ToString[\$SystemID]];
        Print["INSTDIR "<>ToString[\$InstallationDirectory]];
ulrich_y's avatar
ulrich_y committed
469
        Print["USERDIR "<>ToString[\$UserBaseDirectory]];
ulrich_y's avatar
ulrich_y committed
470 471
_EOF_
    $CONF_MATH < $test.m > $test.log
ulrich_y's avatar
ulrich_y committed
472 473
    echo "Mathematica returned" 1>&2
    cat $test.log 1>&2
ulrich_y's avatar
ulrich_y committed
474 475
    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
476
    CONF_MATH_USR=`cat $test.log | grep "USERDIR" | sed 's/.*USERDIR //'`
ulrich_y's avatar
ulrich_y committed
477 478
    [[ -z "$CONF_MMPREFIX" ]] && \
       CONF_MMPREFIX=${CONF_MMPREFIX:=$CONF_MATH_USR/Kernel}
ulrich_y's avatar
ulrich_y committed
479 480 481 482 483 484 485 486
    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
ulrich_y's avatar
ulrich_y committed
487
    echo "Running $CONF_MCC --internals" 1>&2
ulrich_y's avatar
ulrich_y committed
488
    $CONF_MCC --internals > $test.int
ulrich_y's avatar
ulrich_y committed
489
    cat $test.int 1>&2
ulrich_y's avatar
ulrich_y committed
490 491 492 493 494 495
    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
496
    CONF_MCC_LFLAGS="$CONF_LFLAGS $CONF_MCC_LFLAGS"
ulrich_y's avatar
ulrich_y committed
497 498 499 500 501 502 503
    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
504
    if [[ $CONF_MCC_LFLAGS == *"uuid"* ]]; then
ulrich_y's avatar
ulrich_y committed
505 506 507 508 509 510 511 512 513 514
        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
515 516 517 518 519 520 521 522
        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
ulrich_y's avatar
ulrich_y committed
523
    echo "Trying the following program as $test.tm" 1>&2
ulrich_y's avatar
ulrich_y committed
524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542
    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_
ulrich_y's avatar
ulrich_y committed
543
    echo "Executing $CONF_MPREP $test.tm" 1>&2
ulrich_y's avatar
ulrich_y committed
544
    $CONF_MPREP $test.tm > $test.tm.c
ulrich_y's avatar
ulrich_y committed
545
    echo "Executing $CONF_CC $CONF_MCC_CFLAGS $CONF_CFLAGS -c $test.tm.c" 1>&2
ulrich_y's avatar
ulrich_y committed
546
    $CONF_CC $CONF_MCC_CFLAGS $CONF_CFLAGS -c $test.tm.c
ulrich_y's avatar
ulrich_y committed
547
    echo "Executing $CONF_CC -o $test.math $test.tm.o $CONF_MCC_LFLAGS" 1>&2
ulrich_y's avatar
ulrich_y committed
548
    $CONF_CC -o $test.math $test.tm.o $CONF_MCC_LFLAGS
ulrich_y's avatar
ulrich_y committed
549
    if [[ -x "$test.math" ]] ; then
ulrich_y's avatar
ulrich_y committed
550 551
        echo "yes" 1>&3
        CONF_ML=1
ulrich_y's avatar
ulrich_y committed
552
    else
ulrich_y's avatar
ulrich_y committed
553 554
        echo "no" 1>&3
        CONF_ML=0
ulrich_y's avatar
ulrich_y committed
555
        exit 1;
ulrich_y's avatar
ulrich_y committed
556
    fi
ulrich_y's avatar
ulrich_y committed
557
fi
ulrich_y's avatar
ulrich_y committed
558 559


ulrich_y's avatar
ulrich_y committed
560
CONF_LD=${LD:-$CONF_FC}
ulrich_y's avatar
ulrich_y committed
561 562


ulrich_y's avatar
ulrich_y committed
563 564 565 566 567 568



if $CONF_QUAD ; then
  echo -n "does $CONF_FC support quad-precision... " 1>&3
  rm -fr $test*
ulrich_y's avatar
ulrich_y committed
569
  echo "Trying the following program as $test.f90" 1>&2
ulrich_y's avatar
ulrich_y committed
570 571 572 573 574 575 576 577
  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_
ulrich_y's avatar
ulrich_y committed
578
  echo "Running $CONF_FC $CONF_FFLAGS -o $test $test.f90" 1>&2
ulrich_y's avatar
ulrich_y committed
579
  $CONF_FC $CONF_FFLAGS -o $test $test.f90 1>&2
ulrich_y's avatar
ulrich_y committed
580 581 582
  if [[ ! -x "$test" ]]; then
    echo "no. Compilation failed."
  fi
ulrich_y's avatar
ulrich_y committed
583 584 585 586
  ./$test 1>&2 && {
    echo "yes" 1>&3
    eval addflag FFLAGS -DKINDREAL=16 -DKINDINT=8
  } || {
ulrich_y's avatar
ulrich_y committed
587
    echo "no. Running failed" 1>&3
ulrich_y's avatar
ulrich_y committed
588 589
    exit 1
  }
ulrich_y's avatar
ulrich_y committed
590
  $HAVE_MCC && eval addflag CFLAGS -DHAVE_QUAD
ulrich_y's avatar
ulrich_y committed
591 592 593 594 595 596 597
fi






ulrich_y's avatar
ulrich_y committed
598
if $HAVE_GINAC ; then
ulrich_y's avatar
ulrich_y committed
599
    eval addflag CXXFLAGS "-std=c++11"
ulrich_y's avatar
ulrich_y committed
600 601
    if [[ ! -z "$CONF_PKGCONFIG" ]]; then
        echo -n "Does pkg-config know about GiNaC... " 1>&3
ulrich_y's avatar
ulrich_y committed
602
        if $CONF_PKGCONFIG --atleast-version=1.7.4 ginac ; then
ulrich_y's avatar
ulrich_y committed
603
            echo "yes" 1>&3
ulrich_y's avatar
ulrich_y committed
604
            eval addflag CXXFLAGS `$CONF_PKGCONFIG --cflags ginac`
ulrich_y's avatar
ulrich_y committed
605 606
            eval addflag LFLAGS `$CONF_PKGCONFIG --libs ginac`
            FOUND_GINAC=true
ulrich_y's avatar
ulrich_y committed
607
            CONF_GINAC=`$CONF_PKGCONFIG --variable=libdir ginac`
ulrich_y's avatar
ulrich_y committed
608 609 610 611 612
        else
            echo "no" 1>&3
            FOUND_GINAC=false
        fi
    fi
ulrich_y's avatar
ulrich_y committed
613 614
    if ! $FOUND_GINAC ; then
        findlib ginac GINAC && findlib cln CLN && FOUND_GINAC=true
ulrich_y's avatar
ulrich_y committed
615 616 617 618
        eval addflag LFLAGS "-L`dirname $CONF_GINAC`"
        eval addflag LFLAGS "-L`dirname $CONF_CLN`"
        eval addflag LFLAGS "-lginac -lcln"
    fi
ulrich_y's avatar
ulrich_y committed
619
    if $FOUND_GINAC; then
ulrich_y's avatar
ulrich_y committed
620
        CONF_LD=${LD:-$CONF_CXX}
ulrich_y's avatar
ulrich_y committed
621
        echo -n "Checking if GiNaC works... " 1>&3
ulrich_y's avatar
ulrich_y committed
622
        echo "Trying the following program as $test.ginac.cpp" 1>&2
ulrich_y's avatar
ulrich_y committed
623 624 625
        tee $test.ginac.cpp << _EOF_ 1>&2
#include <ginac/ginac.h>
#include <iostream>
626 627 628
#include <cln/cln.h>


ulrich_y's avatar
ulrich_y committed
629

630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655
typedef struct {double r,i;} complex_t;
typedef struct {complex_t c; signed char i0;} inum_t;

complex_t geval_(inum_t * z, int* n) {
  cln::cl_inhibit_floating_point_underflow = true;
  GiNaC::lst w,s;
  for(long i=0;i<(*n)-1;i++)
  {
    GiNaC::ex zz;
    if (abs(z->c.i) < 1e-15)
      w.append((z->c.r));
    else
      w.append((z->c.r)+(z->c.i)*GiNaC::I);
    s.append(z->i0);
    z++;
  }
  GiNaC::ex ans = GiNaC::G(w,s,z->c.r).evalf();
  return {
    .r = GiNaC::ex_to<GiNaC::numeric>(GiNaC::evalf(GiNaC::real_part(ans))).to_double(),
    .i = GiNaC::ex_to<GiNaC::numeric>(GiNaC::evalf(GiNaC::imag_part(ans))).to_double()
  };

}

int main() {
    // Test 1
ulrich_y's avatar
ulrich_y committed
656 657 658
    GiNaC::ex ans = GiNaC::G(0.3,0.5,0.7);
    ans -= 0.2876820724517808812+3.1415926535897932385*GiNaC::I;
    ans = GiNaC::abs(ans);
659 660 661 662 663 664 665 666 667 668 669

    // Test 2
    inum_t x[] = {
      { .c = {.r = 0.73, .i=0}, .i0 = -1 },
      { .c = {.r = 0.00, .i=0}, .i0 = +1 },
      { .c = {.r = 1.00, .i=0}, .i0 = +1 }
    };
    int n=3;
    complex_t cans = geval_(&x[0],&n);
    float del = (2.2982889094420660-cans.r)*(2.2982889094420660-cans.r) + (0.98869296399417417-cans.i)*(0.98869296399417417-cans.i);

ulrich_y's avatar
ulrich_y committed
670 671 672
    if (ans>1e-15) return 1;
    if (del>1e-15) return 2;
    return 0;
ulrich_y's avatar
ulrich_y committed
673 674
}
_EOF_
ulrich_y's avatar
ulrich_y committed
675
        echo "Running $CONF_CXX $CONF_CXXFLAGS $CONF_BITS -c $test.ginac.cpp" 1>&2
ulrich_y's avatar
ulrich_y committed
676
        $CONF_CXX $CONF_CXXFLAGS $CONF_BITS -c $test.ginac.cpp
ulrich_y's avatar
ulrich_y committed
677
        echo "Running $CONF_LD -o $test.ginac $test.ginac.o $CONF_LFLAGS" 1>&2
ulrich_y's avatar
ulrich_y committed
678
        $CONF_LD -o $test.ginac $test.ginac.o $CONF_LFLAGS
679
        if [[ ! -x "$test.ginac" ]]; then
ulrich_y's avatar
ulrich_y committed
680 681 682
          echo "error compiling GiNaC" 1>&3
          exit 1
        fi
ulrich_y's avatar
ulrich_y committed
683 684 685 686 687 688 689 690
        ./$test.ginac
        case $? in
            0)
              echo "yes" 1>&3
              eval addflag FFLAGS "-DHAVE_GINAC" ;;
            1)
              echo "no" 1>&3
              exit 1 ;;
ulrich_y's avatar
ulrich_y committed
691 692 693
            2)
              echo "no. Try updating your GiNaC version" 1>&3
              exit 1 ;;
ulrich_y's avatar
ulrich_y committed
694 695 696 697 698 699 700 701 702 703 704
            *)
              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
705 706 707
if $HAVE_GINAC && $HAVE_MCC; then
  eval addflag LFLAGS -lrt
fi
ulrich_y's avatar
ulrich_y committed
708

709 710 711 712 713 714 715 716 717 718 719
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
720
Cflags: -I\${includedir}
721 722 723 724
EOF

fi

ulrich_y's avatar
ulrich_y committed
725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744
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
745 746
echo "creating makefile" 1>&3

ulrich_y's avatar
ulrich_y committed
747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789
cat 1>&2 <<EOF

The makefile was created through $0 $allargs on `date` by `whoami`

handyG version $VERSION

The following capabilities are supported:
EOF
$HAVE_MCC && echo " * mcc / MathLink interface" 1>&2
$HAVE_GINAC && echo " * GiNaC test interface" 1>&2
$COVERAGE && echo " * coverage reporting" 1>&2
$CONF_QUAD && echo " * quadrouple precision" 1>&2
$HAVE_LCOV && echo " * lcov coverage reporting" 1>&2
$DEBUG && echo " * debugging mode" 1>&2
$NATIVE && echo " * native compilation" 1>&2
cat 1>&2 <<EOF
The following compilers are used

> AR=ar rcs
> FC=$CONF_FC
> CC=$CONF_CC
> CXX=$CONF_CXX
> LD=$CONF_LD
> MPREP=$CONF_MPREP
> MATH=$CONF_MATH
> GCOV=$CONF_GCOV
> LCOV=$CONF_LCOV
> GENHTML=$CONF_GENHTML

with the following flags

> FFLAGS=$CONF_FFLAGS
> CFLAGS=$CONF_CFLAGS
> CXXFLAGS=$CONF_CXXFLAGS
> LFLAGS=$CONF_LFLAGS
> MCFLAGS=$CONF_MCC_CFLAGS
> MLFLAGS=$CONF_MCC_LFLAGS
> PREFIX=$CONF_PREFIX
> MMPREFIX=$CONF_MMPREFIX
> MODDIR=$CONF_MODDIR

EOF

ulrich_y's avatar
ulrich_y committed
790 791

cat  > makefile <<EOF
ulrich_y's avatar
ulrich_y committed
792
# Generated through $0 $allargs on `date` by `whoami`
ulrich_y's avatar
ulrich_y committed
793 794 795 796 797 798 799

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
800
MATH=$CONF_MATH
ulrich_y's avatar
ulrich_y committed
801 802 803
GCOV=$CONF_GCOV
LCOV=$CONF_LCOV
GENHTML=$CONF_GENHTML
ulrich_y's avatar
ulrich_y committed
804 805 806

FFLAGS=$CONF_FFLAGS
CFLAGS=$CONF_CFLAGS
ulrich_y's avatar
ulrich_y committed
807
CXXFLAGS=$CONF_CXXFLAGS
ulrich_y's avatar
ulrich_y committed
808 809 810 811
LFLAGS=$CONF_LFLAGS
MCFLAGS=$CONF_MCC_CFLAGS
MLFLAGS=$CONF_MCC_LFLAGS

ulrich_y's avatar
ulrich_y committed
812 813
PREFIX=$CONF_PREFIX
MMPREFIX=$CONF_MMPREFIX
ulrich_y's avatar
ulrich_y committed
814
MODDIR=$CONF_MODDIR
ulrich_y's avatar
ulrich_y committed
815

ulrich_y's avatar
ulrich_y committed
816

ulrich_y's avatar
ulrich_y committed
817
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
818 819 820
objects = \$(addprefix build/,\$(files))


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

ulrich_y's avatar
ulrich_y committed
823
libhandyg.a:\$(objects)
ulrich_y's avatar
ulrich_y committed
824
		@echo "AR \$@"
ulrich_y's avatar
ulrich_y committed
825 826 827 828 829
		@\$(AR) \$@ \$^

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

ulrich_y's avatar
ulrich_y committed
830 831 832 833

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

ulrich_y's avatar
ulrich_y committed
836 837
build/%.o: checks/%.f90
		@echo "F90 \$@"
ulrich_y's avatar
ulrich_y committed
838
		@\$(FC) \$(FFLAGS) -Wno-unused-function -c \$< -o \$@
ulrich_y's avatar
ulrich_y committed
839

ulrich_y's avatar
ulrich_y committed
840 841
build/%.o: src/%.cpp
		@echo "C++ \$@"
ulrich_y's avatar
ulrich_y committed
842
		@\$(CC) \$(CXXFLAGS) -c \$<  -o \$@
ulrich_y's avatar
ulrich_y committed
843

ulrich_y's avatar
ulrich_y committed
844
geval: libhandyg.a build/geval.o
ulrich_y's avatar
ulrich_y committed
845
		@echo "LD \$@"
ulrich_y's avatar
ulrich_y committed
846
		@\$(LD) -o \$@ build/geval.o -L. -lhandyg \$(LFLAGS)
ulrich_y's avatar
ulrich_y committed
847

ulrich_y's avatar
ulrich_y committed
848 849 850 851 852
EOF

$HAVE_MCC && cat >> makefile <<EOF
build/%.tm.c: src/%.tm
		@echo "MPREP \$@"
ulrich_y's avatar
ulrich_y committed
853 854
		@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
855

ulrich_y's avatar
ulrich_y committed
856
build/mathlink.o: build/mathlink.tm.c
ulrich_y's avatar
ulrich_y committed
857 858 859
		@echo "CC \$<"
		@\$(CC) \$(MCFLAGS) \$(CFLAGS) -o \$@ -c \$<

ulrich_y's avatar
ulrich_y committed
860
handyG: build/mathlink.o libhandyg.a
ulrich_y's avatar
ulrich_y committed
861
		@echo "LD \$@"
ulrich_y's avatar
ulrich_y committed
862
		@\$(LD)  \$< libhandyg.a -o \$@ \$(LFLAGS) \$(MLFLAGS)
ulrich_y's avatar
ulrich_y committed
863

ulrich_y's avatar
ulrich_y committed
864 865 866
checks/test-chen.f90: checks/generate.m
		@echo "MATH generate \$@"
		@\$(MATH) -script \$< \$@
ulrich_y's avatar
ulrich_y committed
867
checks/test-chenff.f90: checks/generate.m
ulrich_y's avatar
ulrich_y committed
868 869
		@echo "MATH generate \$@"
		@\$(MATH) -script \$< \$@
ulrich_y's avatar
ulrich_y committed
870 871 872 873 874 875
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
876 877


ulrich_y's avatar
ulrich_y committed
878 879 880
EOF
echo -n "test: \$(objects) " >> makefile

ulrich_y's avatar
ulrich_y committed
881
                            echo -n "build/tools.o " >> makefile
ulrich_y's avatar
ulrich_y committed
882 883 884
                            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
885
$HAVE_GINAC && $HAVE_MCC && echo -n "build/test-chenff.o " >> makefile
ulrich_y's avatar
ulrich_y committed
886 887
$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
888

ulrich_y's avatar
ulrich_y committed
889 890
echo "build/test.o" >> makefile
cat  >> makefile <<EOF
ulrich_y's avatar
ulrich_y committed
891
		@echo "LD \$@"
ulrich_y's avatar
ulrich_y committed
892
		@\$(LD) -o \$@ \$^ \$(LFLAGS)
ulrich_y's avatar
ulrich_y committed
893

ulrich_y's avatar
ulrich_y committed
894
install: libhandyg.a handyg.mod ${CONF_MPREP:+handyG} geval
ulrich_y's avatar
ulrich_y committed
895
		mkdir -p \$(PREFIX)
ulrich_y's avatar
ulrich_y committed
896
		mkdir -p \$(PREFIX)/bin
ulrich_y's avatar
ulrich_y committed
897
		cp geval \$(PREFIX)/bin/geval
ulrich_y's avatar
ulrich_y committed
898
		mkdir -p \$(PREFIX)/lib
ulrich_y's avatar
ulrich_y committed
899
		cp libhandyg.a \$(PREFIX)/lib/
ulrich_y's avatar
ulrich_y committed
900
		mkdir -p \$(PREFIX)/include
ulrich_y's avatar
ulrich_y committed
901
		cp handyg.mod \$(PREFIX)/include/
ulrich_y's avatar
ulrich_y committed
902 903 904
EOF
$HAVE_MCC && cat >> makefile <<EOF
		mkdir -p \$(MMPREFIX)
ulrich_y's avatar
ulrich_y committed
905
		cp handyg \$(MMPREFIX)
ulrich_y's avatar
ulrich_y committed
906
EOF
907 908 909 910 911 912
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
913
if [[ ! -z "$CONF_MODDIR" ]]; then
ulrich_y's avatar
ulrich_y committed
914
cat >> makefile <<EOF
ulrich_y's avatar
ulrich_y committed
915
		mkdir -p \$(MODDIR)
ulrich_y's avatar
ulrich_y committed
916
		cp handyg.mod \$(MODDIR)
ulrich_y's avatar
ulrich_y committed
917 918 919
EOF
fi

ulrich_y's avatar
ulrich_y committed
920 921 922

echo "uninstall:" >> makefile
echo -ne "\t\trm -i " >> makefile
ulrich_y's avatar
ulrich_y committed
923 924
echo -n "\$(PREFIX)/lib/libhandyg.a " >> makefile
echo -n "\$(PREFIX)/include/handyg.mod " >> makefile
ulrich_y's avatar
ulrich_y committed
925
echo -n "\$(PREFIX)/bin/geval " >> makefile
ulrich_y's avatar
ulrich_y committed
926
$HAVE_MCC && echo -n "\$(MMPREFIX)/handyg" >> makefile
927 928 929
if [[ ! -z "$CONF_PKGCONFIG" ]]; then
echo -n "\$(PREFIX)/lib/pkgconfig " >> makefile
fi
ulrich_y's avatar
ulrich_y committed
930 931
if [[ ! -z "$CONF_MODDIR" ]]; then
echo -n "\$(MODDIR)/handyg.mod " >> makefile
ulrich_y's avatar
ulrich_y committed
932
fi
ulrich_y's avatar
ulrich_y committed
933 934 935
cat  >> makefile <<EOF


936 937 938 939 940 941
check-mpl: test
		./$< -mpl-test
check-gpl: test
		./$< -gpl-test
check-chen: test
		./$< -chen-test
ulrich_y's avatar
ulrich_y committed
942 943
EOF

944 945 946 947 948 949 950 951 952 953 954 955 956 957 958
$HAVE_GINAC && $HAVE_MCC && cat >> makefile <<EOF
check-ginac: test
		./$< -ginac-tests
check-speed: test
		./$< -speed-tests 5
check-hw: test
		./$< -hw-tests
check-long: test
		./$< -long-test
EOF

($HAVE_GINAC && $HAVE_MCC) && echo "check: check-mpl check-gpl check-chen check-ginac" >> makefile \
                           || echo "check: check-mpl check-gpl check-chen"             >> makefile


ulrich_y's avatar
ulrich_y committed
959 960 961

if $COVERAGE ; then
  cat  >> makefile <<EOF
962 963


ulrich_y's avatar
ulrich_y committed
964 965
report/report.txt: test
		mkdir -p report
966
		./test -report > /dev/null
ulrich_y's avatar
ulrich_y committed
967 968 969 970 971 972 973 974 975 976
		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
977
report/coverage.full.info: report/report.txt
ulrich_y's avatar
ulrich_y committed
978
		\$(LCOV) --capture --directory build/ --output-file \$@
ulrich_y's avatar
ulrich_y committed
979 980
report/coverage.info: report/coverage.full.info
		\$(LCOV) --remove \$< "\$\$(pwd)/checks/test-chenff.f90" -o \$@
ulrich_y's avatar
ulrich_y committed
981 982 983 984 985 986 987 988 989 990 991
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
992

ulrich_y's avatar
ulrich_y committed
993 994 995 996

fi

cat  >> makefile <<EOF
ulrich_y's avatar
ulrich_y committed
997
clean:
ulrich_y's avatar
ulrich_y committed
998
		@rm -f build/*.gcda build/*.gcno build/*.gcov
ulrich_y's avatar
ulrich_y committed
999
		@rm -rf report/
ulrich_y's avatar
ulrich_y committed
1000
		@rm -f build/*.o build/*.mod build/*.c build/mcc.internals*
ulrich_y's avatar
ulrich_y committed
1001
		@rm -f test geval libhandyg.a handyG handyg.mod
ulrich_y's avatar
ulrich_y committed
1002
		@rm -f checks/test-chen.f90 checks/test-muone.f90 checks/test-muoneNP.f90
ulrich_y's avatar
ulrich_y committed
1003 1004

distclean:
ulrich_y's avatar
ulrich_y committed
1005
		@rm -f build/*.gcda build/*.gcno build/*.gcov
ulrich_y's avatar
ulrich_y committed
1006
		@rm -rf report/
ulrich_y's avatar
ulrich_y committed
1007
		@rm -f build/*.o build/*.mod build/*.c build/mcc.internals*
ulrich_y's avatar
ulrich_y committed
1008
		@rm -f test geval libhandyg.a handyG handyg.mod
ulrich_y's avatar
ulrich_y committed
1009
		@rm -f checks/test-chen.f90 checks/test-muone.f90 checks/test-muoneNP.f90
1010
		@rm -f makefile handyg.pc
ulrich_y's avatar
ulrich_y committed
1011
EOF
ulrich_y's avatar
ulrich_y committed
1012 1013


ulrich_y's avatar
ulrich_y committed
1014
echo "Configuration of handyG $VERSION done. Now type \"make\"." 1>&3