configure.sh 2.67 KB
Newer Older
1
#!/usr/bin/env bash
2
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
3 4
#These contain functions to be used later on...
. $DIR/cmake/machines.sh
5
. $DIR/external/install_external.sh
6 7

#variables to store arguments
Daniel Wortmann's avatar
Daniel Wortmann committed
8 9 10 11 12 13 14 15

all_tests=0
machine=""
label=""
backup=0
gitupdate=0
debug=0
error=""
16
external_lib=""
Daniel Wortmann's avatar
Daniel Wortmann committed
17 18


19
echo "------------ Welcome to the FLEUR configuration script -------------"
Daniel Wortmann's avatar
Daniel Wortmann committed
20

21
. $DIR/cmake/process_arguments.sh
Daniel Wortmann's avatar
Daniel Wortmann committed
22 23


24

25
#Check if we are using the git version and update if pull was used as an argument
Daniel Wortmann's avatar
Daniel Wortmann committed
26 27
if test -d $DIR/.git
then
28 29 30 31 32
    #Check if hook is installed and install it if needed
    if test -h $DIR/.git/hooks/pre-commit
    then
        echo "Git version found"
    else
33
        mkdir -p $DIR/.git/hooks
34 35 36
        ln -s $DIR/tests/git-hooks/pre-commit $DIR/.git/hooks
        echo "Git version found, hook installed"
    fi
Daniel Wortmann's avatar
Daniel Wortmann committed
37 38
    if [ $gitupdate -gt 0 ] 
    then
39
       cd $DIR 
40
       git pull
41
       cd -
Daniel Wortmann's avatar
Daniel Wortmann committed
42
    fi
43 44 45
fi


46 47 48 49 50 51 52 53
#Name of the build directory
if [ -n "$label" ]
then
    buildname="build.$label"
else
    buildname="build"
fi

Daniel Wortmann's avatar
Daniel Wortmann committed
54 55 56 57 58 59 60 61 62
if [ $debug -gt 0 ]
then
   echo "Debug version will be build"
   BUILD=Debug
   buildname="$buildname.debug"
else
   BUILD=Release
fi

63
#check if there is a build directory
64
if test -d $buildname
65
then
Daniel Wortmann's avatar
Daniel Wortmann committed
66 67 68 69
    if [ $backup -gt 0 ]
    then
	echo "OLD build directory found, saved in build.$$"
	mv $buildname $buildname.$$
70
        mkdir $buildname
Daniel Wortmann's avatar
Daniel Wortmann committed
71 72
    else
	echo "Overwriting old build"
73 74 75
        cd $buildname
        for file in *
        do
76
          if [[ "$file" == "external" ]] || [[ "$file" == "Testing" ]] 
77
          then
78
            echo "Keeping $file directory"
79 80 81 82 83
          else
            rm -r $file
          fi
        done
        cd ..
Daniel Wortmann's avatar
Daniel Wortmann committed
84
    fi  
85 86
else
   mkdir $buildname
87
fi
88
cd $buildname
89 90

#Now check the machine and set some defaults 
Daniel Wortmann's avatar
Daniel Wortmann committed
91
if [[ $machine =~ FLEUR_CONFIG_MACHINE ]]
92
then
Daniel Wortmann's avatar
Daniel Wortmann committed
93
    machine=$FLEUR_CONFIG_MACHINE
94
fi
Daniel Wortmann's avatar
Daniel Wortmann committed
95 96 97 98
if [ "$machine" = "" ]
then
    machine=AUTO
fi
99
echo "Machine config:$machine"
100 101
configure_machine

102
#run cmake
103 104 105 106 107 108
if [ "$cmake" ]
then
    echo "Using provided cmake:$cmake"
else
    cmake="cmake"
fi
Daniel Wortmann's avatar
Daniel Wortmann committed
109

110 111 112 113 114 115 116 117 118 119
# compile external libraries if needed
for library in ${external_lib}
do
    compile_external
done

. $DIR/cmake/store_environment.sh


${cmake} $CMAKE_OPTIONS -Dall_tests=$all_tests -DCMAKE_BUILD_TYPE=$BUILD $DIR 2>&1 |tee configure.out
Daniel Wortmann's avatar
Daniel Wortmann committed
120 121

if [ -r $buildname/Makefile ]
122
then
Daniel Wortmann's avatar
Daniel Wortmann committed
123 124 125
    echo "Your configuration failed"
    echo "Perhaps you have to specify compiler options or give a machine dependent configuration."
    echo "You might want to call the configure.sh script with -h"
126
else
Daniel Wortmann's avatar
Daniel Wortmann committed
127
    echo "Configuration finished"
128 129 130 131 132 133 134 135
    if [ "$make_directly" ]
    then
	cd $buildname
	make -j
    else
	echo "You should change into directory $buildname "
	echo "run 'make' or 'make -j'"
    fi
136
fi