configure.sh 4.64 KB
Newer Older
1
#!/usr/bin/env bash
2
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
Daniel Wortmann's avatar
Daniel Wortmann committed
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25

#process arguments
help=0
all_tests=0
machine=""
label=""
backup=0
gitupdate=0
debug=0
error=""
while [ $# -gt 0 ]
do
    case "$1" in
        -h) help=1;;
	-help) help=1;;
        -b) backup=1;;
        -backup) backup=1;;
        -g) gitupdate=1;;
	-gitupdate) gitupdate=1;;
	-t) all_tests=1;;
	-all_tests) all_tests=1;;
	-l) shift;label=$1;;
	-m) shift;machine=$1;;
26
	-cmake) shift;cmake=$1;;
Daniel Wortmann's avatar
Daniel Wortmann committed
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 55 56
        -d) debug=1;;
	-*) error="Unkown argument";;
	*)  break;;	# terminate while loop
    esac
    shift
done
if [ $# -gt 0 ]
then
    if [ "$machine" = "" ]
    then
	machine=$1;shift
    else
	error="You specified the -m switch and gave an additional MACHINE argument" 
    fi
fi
if [ $# -gt 0 ]
then
    if [ "$label" = "" ]
    then
	label=$1;shift
    else
	error="You specified the -l switch and gave an additional LABEL argument"
    fi
fi
if [ $# -gt 0 ]
then
    error="Extra unkown arguments"
fi


57
echo "------------ Welcome to the FLEUR configuration script -------------"
Daniel Wortmann's avatar
Daniel Wortmann committed
58 59 60 61 62 63 64 65

if [ "$error" != "" ]
then
    echo $error
    echo "ERROR in calling configure. Please use -h for help on usage"
    exit 1
fi

66
. $DIR/cmake/machines.sh
Daniel Wortmann's avatar
Daniel Wortmann committed
67 68 69

#check if -h or  -help was given as argument
if [ $help -gt 0 ] 
70
then
Daniel Wortmann's avatar
Daniel Wortmann committed
71
   echo "USAGE: configure.sh [options] [MACHINE] [label]"
72
   echo "
Daniel Wortmann's avatar
Daniel Wortmann committed
73 74 75 76 77 78 79 80 81 82 83
  The following command line options are supported:
  -h   : print this help-page
  -m # : specify the machine to build on (see below for possible options)
         This can also be specified without -m as a first argument
  -l # : label for the build. It will be attached to the name of the build directory.
         This option can also be specified as second argument without -l
  -d   : build a debugging version of FLEUR (adds .debug to label)
  -g   : do a git pull first if this is a git version
  -t   : generate all tests including those that run longer
  -b   : backup an old build directory if present
  
84 85 86 87 88 89
  To help the script finding a proper configuration you should
  provide the name of a specific machine to compile on.
  Currently known machine configurations are:
  " 
   echo "   $known_machines"
   echo " 
Daniel Wortmann's avatar
Daniel Wortmann committed
90 91
  If you do not specify the machine the AUTO option will be used in which some
  defaults are tested. It might work if your machine is not one of those known.
92 93 94 95 96 97 98 99 100

  You might also want to add your configuration to the file 
  cmake/machines.sh in this case :-)
  
  In addition you can modify some environment variables:
        FC                  -- name of Fortran compiler
        CC                  -- name of C compiler
        FLEUR_LIBRARIES     -- list of linker arguments i.e. '-L/lib;-lbla'
        CMAKE_Fortran_FLAGS -- list of compiler options i.e. '-r8'"
101
echo "
Daniel Wortmann's avatar
Daniel Wortmann committed
102 103 104
   By specifying a label you can have different build directories.
   The label will be added to the 'build' directory name."
  exit 1
105
fi
Daniel Wortmann's avatar
Daniel Wortmann committed
106

107 108
#Check if we are using the git version and update if pull was used as an argument
if test -d $DIR/.git 
109 110 111 112 113 114 115 116
    #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
117
then
Daniel Wortmann's avatar
Daniel Wortmann committed
118
   if [ $gitupdate -gt 0 ] 
119 120
   then
       cd $DIR 
121
       git pull
122
       cd -
123 124 125 126 127 128 129 130 131 132
   fi
fi


#include a configfile if present
if test -r config.sh
then
 . config.sh
fi

133 134 135 136 137 138 139 140
#Name of the build directory
if [ -n "$label" ]
then
    buildname="build.$label"
else
    buildname="build"
fi

Daniel Wortmann's avatar
Daniel Wortmann committed
141 142 143 144 145 146 147 148 149
if [ $debug -gt 0 ]
then
   echo "Debug version will be build"
   BUILD=Debug
   buildname="$buildname.debug"
else
   BUILD=Release
fi

150
#check if there is a build directory
151
if test -d $buildname
152
then
Daniel Wortmann's avatar
Daniel Wortmann committed
153 154 155 156 157 158 159 160
    if [ $backup -gt 0 ]
    then
	echo "OLD build directory found, saved in build.$$"
	mv $buildname $buildname.$$
    else
	echo "Overwriting old build"
	rm -r $buildname
    fi  
161
fi
162 163
mkdir $buildname
cd $buildname
Daniel Wortmann's avatar
Daniel Wortmann committed
164 165

#Now check the machine and set some defaults 
Daniel Wortmann's avatar
Daniel Wortmann committed
166
if [[ $machine =~ FLEUR_CONFIG_MACHINE ]]
167
then
Daniel Wortmann's avatar
Daniel Wortmann committed
168
    machine=$FLEUR_CONFIG_MACHINE
169
fi
Daniel Wortmann's avatar
Daniel Wortmann committed
170 171 172 173
if [ "$machine" = "" ]
then
    machine=AUTO
fi
174
echo "Machine config:$machine"
Daniel Wortmann's avatar
Daniel Wortmann committed
175 176
configure_machine

177
#run cmake
178 179 180 181 182 183
if [ "$cmake" ]
then
    echo "Using provided cmake:$cmake"
else
    cmake="cmake"
fi
Daniel Wortmann's avatar
Daniel Wortmann committed
184

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

if [ -r $buildname/Makefile ]
188
then
Daniel Wortmann's avatar
Daniel Wortmann committed
189 190 191
    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"
192
else
Daniel Wortmann's avatar
Daniel Wortmann committed
193 194 195
    echo "Configuration finished"
    echo "You should change into directory $buildname "
    echo "run 'make' or 'make -j'"
196
fi