configure.sh 4.53 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 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 55

#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;;
        -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


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

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

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

#check if -h or  -help was given as argument
if [ $help -gt 0 ] 
69
then
Daniel Wortmann's avatar
Daniel Wortmann committed
70
   echo "USAGE: configure.sh [options] [MACHINE] [label]"
71
   echo "
Daniel Wortmann's avatar
Daniel Wortmann committed
72 73 74 75 76 77 78 79 80 81 82
  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
  
83 84 85 86 87 88
  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
89 90
  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.
91 92 93 94 95 96 97 98 99

  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'"
100
echo "
Daniel Wortmann's avatar
Daniel Wortmann committed
101 102 103
   By specifying a label you can have different build directories.
   The label will be added to the 'build' directory name."
  exit 1
104
fi
105

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


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

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

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

149
#check if there is a build directory
150
if test -d $buildname
151
then
Daniel Wortmann's avatar
Daniel Wortmann committed
152 153 154 155 156 157 158 159
    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  
160
fi
161 162
mkdir $buildname
cd $buildname
163 164

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

176
#run cmake
Daniel Wortmann's avatar
Daniel Wortmann committed
177 178 179 180

cmake -Dall_tests=$all_tests -DCMAKE_BUILD_TYPE=$BUILD $DIR 2>&1 |tee configure.out

if [ -r $buildname/Makefile ]
181
then
Daniel Wortmann's avatar
Daniel Wortmann committed
182 183 184
    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"
185
else
Daniel Wortmann's avatar
Daniel Wortmann committed
186 187 188
    echo "Configuration finished"
    echo "You should change into directory $buildname "
    echo "run 'make' or 'make -j'"
189
fi