configure 15.6 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

ulrich_y's avatar
ulrich_y committed
19 20 21 22 23 24 25 26 27 28
CONF_FFLAGS=$FFLAGS
CONF_CFLAGS=$CFLAGS
CONF_CPPFLAGS=$CPPFLAGS
CONF_LFLAGS=$LDFLAGS
CONF_FC=$FC
CONF_CC=$CC
CONF_CXX=$CXX
CONF_LD=$LD


ulrich_y's avatar
ulrich_y committed
29 30 31 32 33 34
if [ "$CONF_OS" -eq "Darwin" ]; then
    CONF_PREFIX=/usr/local/
else
    CONF_PREFIX=/usr/
fi

ulrich_y's avatar
ulrich_y committed
35
NATIVE=true
ulrich_y's avatar
ulrich_y committed
36 37 38 39 40 41 42 43 44 45
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
46
            HAVE_GINAC=true ;;
ulrich_y's avatar
ulrich_y committed
47
        --with-mcc)
ulrich_y's avatar
ulrich_y committed
48
            HAVE_MCC=true ;;
ulrich_y's avatar
ulrich_y committed
49 50
        --mmprefix=*)
            CONF_MMPREFIX="${arg#--mmprefix=}" ;;
ulrich_y's avatar
ulrich_y committed
51 52
        --generic)
            NATIVE=false ;;
ulrich_y's avatar
ulrich_y committed
53 54 55 56
        --32)
            CONF_BITS="-m32" ;;
        --64)
            CONF_BITS="-m64" ;;
ulrich_y's avatar
ulrich_y committed
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
        -*)
            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
80
            printf -v "CONF_$var" "%q" "$full"
ulrich_y's avatar
ulrich_y committed
81 82 83 84 85 86
            return 0
        }
    done
    echo "no $@ in your path" 1>&3
    return 1
}
ulrich_y's avatar
ulrich_y committed
87 88 89 90 91 92 93 94

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
95
                    path=`readlink -f -- "$libfolder/lib$1.so"`
ulrich_y's avatar
ulrich_y committed
96
                    echo $path 1>&3
ulrich_y's avatar
ulrich_y committed
97
                    printf -v "CONF_$2" "%q" "$path"
ulrich_y's avatar
ulrich_y committed
98 99 100
                    return 0
                fi
                if [ -f "$libfolder/lib$1.a" ] ; then
ulrich_y's avatar
ulrich_y committed
101
                    path=`readlinf -f -- "$libfolder/lib$1.a"`
ulrich_y's avatar
ulrich_y committed
102
                    echo $path 1>&3
ulrich_y's avatar
ulrich_y committed
103
                    printf -v "CONF_$2" "%q" "$path"
ulrich_y's avatar
ulrich_y committed
104 105 106 107 108 109 110 111
                    return 0
                fi
            ;;
        esac
    done
    echo "not found" 1>&3
    return 1
}
ulrich_y's avatar
ulrich_y committed
112
addflag() {
ulrich_y's avatar
ulrich_y committed
113
    eval "CONF_$1=\"\${CONF_$1} ${@:2}\""
ulrich_y's avatar
ulrich_y committed
114 115 116 117 118
}

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
119
    eval addflag FFLAGS -pedantic-errors -std=f2008  # folow f08 strictly
ulrich_y's avatar
ulrich_y committed
120 121
    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
122
    eval addflag FFLAGS -Wno-uninitialized
ulrich_y's avatar
ulrich_y committed
123
    eval addflag FFLAGS -ffree-line-length-0
ulrich_y's avatar
ulrich_y committed
124 125
}

ulrich_y's avatar
ulrich_y committed
126

ulrich_y's avatar
ulrich_y committed
127 128 129
if [ -z $FC ]; then
    findprog fortran FC  ifort gfortran  || exit 1
fi
ulrich_y's avatar
ulrich_y committed
130 131


ulrich_y's avatar
ulrich_y committed
132
set -- `eval $CONF_FC --version -c | sed '/^$/d;s/([^)]*)//;q' 2>&1`
ulrich_y's avatar
ulrich_y committed
133 134
case "$1,$2,$3" in
    GNU,Fortran,[123].*)
135
        echo "Only version >= 4 are supported" 1>&3
ulrich_y's avatar
ulrich_y committed
136 137
        exit
    ;;
ulrich_y's avatar
ulrich_y committed
138
    GNU,Fortran,4.*)
139
    echo "Code optimisation is *not* suported on gfortran 4" 1>&3
ulrich_y's avatar
ulrich_y committed
140
        gnuflags
ulrich_y's avatar
ulrich_y committed
141
        eval addflag $CONF_BITS
ulrich_y's avatar
ulrich_y committed
142 143
        if $DEBUG ; then
            eval addflag FFLAGS -g -O0
ulrich_y's avatar
ulrich_y committed
144
            eval addflag FFLAGS -ffpe-trap=invalid,overflow
ulrich_y's avatar
ulrich_y committed
145 146 147 148 149
            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
150
            $NATIVE && eval addflag FFLAGS -march=native -mtune=native
ulrich_y's avatar
ulrich_y committed
151 152 153 154 155
        fi
    ;;
    GNU,Fortran,*)
        gnuflags
        eval addflag FFLAGS -Wno-maybe-uninitialized
ulrich_y's avatar
ulrich_y committed
156
        eval addflag $CONF_BITS
ulrich_y's avatar
ulrich_y committed
157 158
        if $DEBUG ; then
            eval addflag FFLAGS -g -O0
ulrich_y's avatar
ulrich_y committed
159
            eval addflag FFLAGS -ffpe-trap=invalid,overflow
ulrich_y's avatar
ulrich_y committed
160 161 162 163 164
            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
165
            $NATIVE && eval addflag FFLAGS -march=native -mtune=native
ulrich_y's avatar
ulrich_y committed
166 167 168 169 170 171 172
        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
173
        eval addflag $CONF_BITS
ulrich_y's avatar
ulrich_y committed
174 175 176 177
        if $DEBUG ; then
            eval addflag FFLAGS -g -O0
            eval addflag FFLAGS -DDEBUG
        else
ulrich_y's avatar
ulrich_y committed
178 179
            eval addflag FFLAGS -DRELEASE -O3 -fast
            $NATIVE && eval addflag FFLAGS -xHost
ulrich_y's avatar
ulrich_y committed
180
        fi
ulrich_y's avatar
ulrich_y committed
181
        if HAVE_GINAC ; then
182
            echo "Option --with-ginac is incompatible with ifort, disabling" 1>&3
ulrich_y's avatar
ulrich_y committed
183
            HAVE_GINAC=false
ulrich_y's avatar
ulrich_y committed
184
        fi
ulrich_y's avatar
ulrich_y committed
185
        if HAVE_MCC ; then
186
            echo "Option --with-mcc is incompatible with ifort, disabling" 1>&3
ulrich_y's avatar
ulrich_y committed
187
            HAVE_MCC=false
ulrich_y's avatar
ulrich_y committed
188 189 190
        fi
    ;;
    *)
191
        echo "Unknown compiler" 1>&3
ulrich_y's avatar
ulrich_y committed
192 193 194 195
        exit
    ;;
esac

ulrich_y's avatar
ulrich_y committed
196 197 198 199 200 201 202 203
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
204
    call exit(i)
ulrich_y's avatar
ulrich_y committed
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227
    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
228
done < <(eval $CONF_FC  -v -o $test $test.f90 2>&1)
ulrich_y's avatar
ulrich_y committed
229 230
echo "ok" 1>&3

ulrich_y's avatar
ulrich_y committed
231
eval addflag LFLAGS "$LDFLAGS $CONF_LDFLAGS $FLDFLAGS -L$CONF_PREFIX/lib"
ulrich_y's avatar
ulrich_y committed
232 233


234 235 236 237 238 239 240 241 242 243 244 245
findprog pkg-config PKGCONFIG pkg-config
if [[ -z "$CONF_PKGCONFIG" ]]; then
    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
fi
ulrich_y's avatar
ulrich_y committed
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262

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
263
      eval $CONF_FC  -o $test $test.f90 $test-c.o 1>&2 && break
ulrich_y's avatar
ulrich_y committed
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283
    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
284 285
fi

ulrich_y's avatar
ulrich_y committed
286 287 288

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
289
    eval addflag FFLAGS -DHAVE_MM
ulrich_y's avatar
ulrich_y committed
290 291 292 293 294 295 296 297

    # 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
298
        Print["USERDIR "<>ToString[\$UserBaseDirectory]];
ulrich_y's avatar
ulrich_y committed
299 300 301 302
_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
303 304
    CONF_MATH_USR=`cat $test.log | grep "USERDIR" | sed 's/.*USERDIR //'`
    CONF_MMPREFIX=${CONF_MMPREFIX:=$CONF_MATH_USR/Kernel}
ulrich_y's avatar
ulrich_y committed
305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327
    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":"`
    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
328
    if [[ $CONF_MCC_LFLAGS == *"uuid"* ]]; then
ulrich_y's avatar
ulrich_y committed
329 330 331 332 333 334 335 336 337 338
        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
339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374
        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
375
        exit 1;
ulrich_y's avatar
ulrich_y committed
376 377
    }
fi
ulrich_y's avatar
ulrich_y committed
378 379


ulrich_y's avatar
ulrich_y committed
380
CONF_LD=${LD:-$CONF_FC}
ulrich_y's avatar
ulrich_y committed
381 382 383


if $HAVE_GINAC ; then
ulrich_y's avatar
ulrich_y committed
384
    eval addflag CPPFLAGS "-std=c++11"
ulrich_y's avatar
ulrich_y committed
385 386 387 388 389 390 391
    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
            eval addflag CPPFLAGS `$CONF_PKGCONFIG --cflags ginac`
            eval addflag LFLAGS `$CONF_PKGCONFIG --libs ginac`
            FOUND_GINAC=true
ulrich_y's avatar
ulrich_y committed
392
            CONF_GINAC=`$CONF_PKGCONFIG --variable=libdir ginac`
ulrich_y's avatar
ulrich_y committed
393 394 395 396 397 398 399 400 401 402 403 404
        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
405
        CONF_LD=${LD:-$CONF_CXX}
ulrich_y's avatar
ulrich_y committed
406 407 408 409 410 411 412 413 414 415 416 417 418 419 420
        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
421
        $CONF_CXX $CONF_CPPFLAGS $CONF_BITS -c $test.ginac.cpp
ulrich_y's avatar
ulrich_y committed
422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441
        $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
442 443 444
if $HAVE_GINAC && $HAVE_MCC; then
  eval addflag LFLAGS -lrt
fi
ulrich_y's avatar
ulrich_y committed
445

446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461
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
Cflags: -I\${includedir}
EOF

fi

ulrich_y's avatar
ulrich_y committed
462 463 464 465 466 467 468 469 470 471 472 473
echo "creating makefile" 1>&3


cat  > makefile <<EOF
# Generated through $0 $@ on `date` by `whoami`

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
474
MATH=$CONF_MATH
ulrich_y's avatar
ulrich_y committed
475 476 477

FFLAGS=$CONF_FFLAGS
CFLAGS=$CONF_CFLAGS
ulrich_y's avatar
ulrich_y committed
478
CPPFLAGS=$CONF_CPPFLAGS
ulrich_y's avatar
ulrich_y committed
479 480 481 482
LFLAGS=$CONF_LFLAGS
MCFLAGS=$CONF_MCC_CFLAGS
MLFLAGS=$CONF_MCC_LFLAGS

ulrich_y's avatar
ulrich_y committed
483 484 485
PREFIX=$CONF_PREFIX
MMPREFIX=$CONF_MMPREFIX

ulrich_y's avatar
ulrich_y committed
486

ulrich_y's avatar
ulrich_y committed
487
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
488 489 490
objects = \$(addprefix build/,\$(files))


ulrich_y's avatar
ulrich_y committed
491
all: libhandyg.a ${CONF_MPREP:+handyg} geval test
ulrich_y's avatar
ulrich_y committed
492

ulrich_y's avatar
ulrich_y committed
493
libhandyg.a:\$(objects)
ulrich_y's avatar
ulrich_y committed
494 495 496 497 498 499 500 501
		@echo "AR \$@"
		@\$(AR) \$@ $^

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

ulrich_y's avatar
ulrich_y committed
502 503 504 505
build/%.o: checks/%.f90
		@echo "F90 \$@"
		@\$(FC) \$(FFLAGS) -c $< -o \$@

ulrich_y's avatar
ulrich_y committed
506 507
build/%.o: src/%.cpp
		@echo "C++ \$@"
ulrich_y's avatar
ulrich_y committed
508
		@\$(CC) \$(CPPFLAGS) -c $<  -o \$@
ulrich_y's avatar
ulrich_y committed
509

ulrich_y's avatar
ulrich_y committed
510
geval: libhandyg.a build/geval.o
ulrich_y's avatar
ulrich_y committed
511
		@echo "LD \$@"
ulrich_y's avatar
ulrich_y committed
512
		@\$(LD) -o \$@ build/geval.o -L. -lhandyg \$(LFLAGS)
ulrich_y's avatar
ulrich_y committed
513

ulrich_y's avatar
ulrich_y committed
514 515 516 517 518 519 520
EOF

$HAVE_MCC && cat >> makefile <<EOF
build/%.tm.c: src/%.tm
		@echo "MPREP \$@"
		@\$(MPREP) \$< -o \$@

ulrich_y's avatar
ulrich_y committed
521
build/mathlink.o: build/mathlink.tm.c
ulrich_y's avatar
ulrich_y committed
522 523 524
		@echo "CC \$<"
		@\$(CC) \$(MCFLAGS) \$(CFLAGS) -o \$@ -c \$<

ulrich_y's avatar
ulrich_y committed
525
handyg: build/mathlink.o libhandyg.a
ulrich_y's avatar
ulrich_y committed
526
		@echo "LD \$@"
ulrich_y's avatar
ulrich_y committed
527
		@\$(LD)  \$< libhandyg.a -o \$@ \$(LFLAGS) \$(MLFLAGS)
ulrich_y's avatar
ulrich_y committed
528

ulrich_y's avatar
ulrich_y committed
529 530 531
checks/test-chen.f90: checks/generate.m
		@echo "MATH generate \$@"
		@\$(MATH) -script \$< \$@
ulrich_y's avatar
ulrich_y committed
532
checks/test-chenff.f90: checks/generate.m
ulrich_y's avatar
ulrich_y committed
533 534
		@echo "MATH generate \$@"
		@\$(MATH) -script \$< \$@
ulrich_y's avatar
ulrich_y committed
535 536 537 538 539 540
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
541 542


ulrich_y's avatar
ulrich_y committed
543 544 545 546 547 548
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
549
$HAVE_GINAC && $HAVE_MCC && echo -n "build/test-chenff.o " >> makefile
ulrich_y's avatar
ulrich_y committed
550 551
$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
552

ulrich_y's avatar
ulrich_y committed
553 554
echo "build/test.o" >> makefile
cat  >> makefile <<EOF
ulrich_y's avatar
ulrich_y committed
555 556 557
		@echo "LD \$@"
		@\$(LD) -o \$@ $^ \$(LFLAGS)

ulrich_y's avatar
ulrich_y committed
558
install: libhandyg.a build/handyg.mod ${CONF_MPREP:+handyg} geval
ulrich_y's avatar
ulrich_y committed
559
		mkdir -p \$(PREFIX)
ulrich_y's avatar
ulrich_y committed
560
		mkdir -p \$(PREFIX)/bin
ulrich_y's avatar
ulrich_y committed
561
		cp geval \$(PREFIX)/bin/geval
ulrich_y's avatar
ulrich_y committed
562
		mkdir -p \$(PREFIX)/lib
ulrich_y's avatar
ulrich_y committed
563
		cp libhandyg.a \$(PREFIX)/lib/
ulrich_y's avatar
ulrich_y committed
564
		mkdir -p \$(PREFIX)/include
ulrich_y's avatar
ulrich_y committed
565
		cp build/handyg.mod \$(PREFIX)/include/
ulrich_y's avatar
ulrich_y committed
566 567 568
EOF
$HAVE_MCC && cat >> makefile <<EOF
		mkdir -p \$(MMPREFIX)
ulrich_y's avatar
ulrich_y committed
569
		cp handyg \$(MMPREFIX)
ulrich_y's avatar
ulrich_y committed
570
EOF
571 572 573 574 575 576
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
577 578 579

echo "uninstall:" >> makefile
echo -ne "\t\trm -i " >> makefile
ulrich_y's avatar
ulrich_y committed
580 581
echo -n "\$(PREFIX)/lib/libhandyg.a " >> makefile
echo -n "\$(PREFIX)/include/handyg.mod " >> makefile
ulrich_y's avatar
ulrich_y committed
582
echo -n "\$(PREFIX)/bin/geval " >> makefile
ulrich_y's avatar
ulrich_y committed
583
$HAVE_MCC && echo -n "\$(MMPREFIX)/handyg" >> makefile
584 585 586
if [[ ! -z "$CONF_PKGCONFIG" ]]; then
echo -n "\$(PREFIX)/lib/pkgconfig " >> makefile
fi
ulrich_y's avatar
ulrich_y committed
587 588 589
cat  >> makefile <<EOF


ulrich_y's avatar
ulrich_y committed
590 591 592 593 594
check: test
		./$<

clean:
		@rm -f build/*.o build/*.mod build/*.c build/mcc.internals*
ulrich_y's avatar
ulrich_y committed
595
		@rm -f test geval libhandyg.a handyg
ulrich_y's avatar
ulrich_y committed
596
		@rm -f checks/test-chen.f90 checks/test-muone.f90 checks/test-muoneNP.f90
ulrich_y's avatar
ulrich_y committed
597 598 599

distclean:
		@rm -f build/*.o build/*.mod build/*.c build/mcc.internals*
ulrich_y's avatar
ulrich_y committed
600
		@rm -f test geval libhandyg.a handyg
ulrich_y's avatar
ulrich_y committed
601
		@rm -f checks/test-chen.f90 checks/test-muone.f90 checks/test-muoneNP.f90
602
		@rm -f makefile handyg.pc
ulrich_y's avatar
ulrich_y committed
603
EOF