configure.sh 3.85 KB
Newer Older
1
#!/usr/bin/env bash
2
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
3 4 5

{
function clone_from_git(){
6 7 8 9
     rm -rf $DIR/configure.sh
    cd $DIR
    git init .	
    git remote add -f origin  https://iffgit.fz-juelich.de/fleur/fleur.git 
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
    git checkout release
    echo "Current FLEUR source code obtained from iffgit.fz-juelich.de"
    echo "Restart the configure.sh script"
    exit
    }
    
function check_git(){
    git_found=`which git`
    ping -q -c1 -W1 iffgit.fz-juelich.de
    iffgit_reachable=$?
    if [ $git_found ] && [ $iffgit_reachable == 0 ] ; then
       return 0;
    fi
    return 1;
}

function update_git(){
    if [ -r $DIR/.git ]
    then
	cd $DIR ; git pull ; cd -
    else
	echo "WARNING........."
	echo "You asked to pull the current version from IFFGIT"
	echo "So far your version is not controlled by git."
	echo "If you modified any source code in your directory it will be deleted"
	echo "Interrupt the script now to abort or press ENTER to continue"
	echo ""
	read y
	clone_from_git
    fi
    }

if [ ! -r $DIR/cmake ]
then
    if check_git
    then
	clone_from_git
    else
	echo "ERROR: No source present"
	echo "You have no 'git' executable and/or the iffgit server is not reachable"
	echo "Please download the complete source manually to your machine"
	exit
    fi
fi

55 56
#These contain functions to be used later on...
. $DIR/cmake/machines.sh
Daniel Wortmann's avatar
Daniel Wortmann committed
57
. $DIR/external/install_external.sh
58 59

#variables to store arguments
Daniel Wortmann's avatar
Daniel Wortmann committed
60 61 62 63 64 65 66 67

all_tests=0
machine=""
label=""
backup=0
gitupdate=0
debug=0
error=""
68
external_lib=""
Daniel Wortmann's avatar
Daniel Wortmann committed
69 70


71
echo "------------ Welcome to the FLEUR configuration script -------------"
Daniel Wortmann's avatar
Daniel Wortmann committed
72

73
. $DIR/cmake/process_arguments.sh
Daniel Wortmann's avatar
Daniel Wortmann committed
74 75


76 77 78 79 80
if [ $gitupdate -gt 0 ] 
then
    update_git
fi

Daniel Wortmann's avatar
Daniel Wortmann committed
81

82
#Check if we are using the git version and update if pull was used as an argument
Daniel Wortmann's avatar
Daniel Wortmann committed
83 84
if test -d $DIR/.git
then
85 86 87 88 89
    #Check if hook is installed and install it if needed
    if test -h $DIR/.git/hooks/pre-commit
    then
        echo "Git version found"
    else
90
        mkdir -p $DIR/.git/hooks
91 92 93
        ln -s $DIR/tests/git-hooks/pre-commit $DIR/.git/hooks
        echo "Git version found, hook installed"
    fi
94 95 96
fi


97 98 99 100 101 102 103 104
#Name of the build directory
if [ -n "$label" ]
then
    buildname="build.$label"
else
    buildname="build"
fi

Daniel Wortmann's avatar
Daniel Wortmann committed
105 106 107 108 109 110 111 112 113
if [ $debug -gt 0 ]
then
   echo "Debug version will be build"
   BUILD=Debug
   buildname="$buildname.debug"
else
   BUILD=Release
fi

114
#check if there is a build directory
115
if test -d $buildname
116
then
Daniel Wortmann's avatar
Daniel Wortmann committed
117 118 119 120
    if [ $backup -gt 0 ]
    then
	echo "OLD build directory found, saved in build.$$"
	mv $buildname $buildname.$$
121
        mkdir $buildname
Daniel Wortmann's avatar
Daniel Wortmann committed
122 123
    else
	echo "Overwriting old build"
124 125 126
        cd $buildname
        for file in *
        do
127
          if [[ "$file" == "external" ]] || [[ "$file" == "Testing" ]] 
128
          then
129
            echo "Keeping $file directory"
130 131 132 133
          else
            rm -r $file
          fi
        done
Andreas Beckmann's avatar
Andreas Beckmann committed
134
        cd -
Daniel Wortmann's avatar
Daniel Wortmann committed
135
    fi  
136 137
else
   mkdir $buildname
138
fi
139
cd $buildname
Daniel Wortmann's avatar
Daniel Wortmann committed
140 141

#Now check the machine and set some defaults 
Daniel Wortmann's avatar
Daniel Wortmann committed
142
if [[ $machine =~ FLEUR_CONFIG_MACHINE ]]
143
then
Daniel Wortmann's avatar
Daniel Wortmann committed
144
    machine=$FLEUR_CONFIG_MACHINE
145
fi
Daniel Wortmann's avatar
Daniel Wortmann committed
146 147 148 149
if [ "$machine" = "" ]
then
    machine=AUTO
fi
150
echo "Machine config:$machine"
Daniel Wortmann's avatar
Daniel Wortmann committed
151 152
configure_machine

153
#run cmake
154 155 156 157 158 159
if [ "$cmake" ]
then
    echo "Using provided cmake:$cmake"
else
    cmake="cmake"
fi
Daniel Wortmann's avatar
Daniel Wortmann committed
160

161 162 163 164 165 166 167 168 169 170
# 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
171

Andreas Beckmann's avatar
Andreas Beckmann committed
172 173 174
cd -

if [ ! -r $buildname/Makefile ]
175
then
Daniel Wortmann's avatar
Daniel Wortmann committed
176 177 178
    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"
179
else
Daniel Wortmann's avatar
Daniel Wortmann committed
180
    echo "Configuration finished"
181 182 183 184 185 186 187 188
    if [ "$make_directly" ]
    then
	cd $buildname
	make -j
    else
	echo "You should change into directory $buildname "
	echo "run 'make' or 'make -j'"
    fi
189
fi
190 191
}
exit