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


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

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

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

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

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

109 110 111 112 113 114 115 116 117 118
# 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
119 120

if [ -r $buildname/Makefile ]
121
then
Daniel Wortmann's avatar
Daniel Wortmann committed
122 123 124
    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"
125
else
Daniel Wortmann's avatar
Daniel Wortmann committed
126
    echo "Configuration finished"
127 128 129 130 131 132 133 134
    if [ "$make_directly" ]
    then
	cd $buildname
	make -j
    else
	echo "You should change into directory $buildname "
	echo "run 'make' or 'make -j'"
    fi
135
fi