configure.sh 4.53 KB
Newer Older
1
#!/usr/bin/env bash
2
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
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

#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) label=$1;shift;;
	-m) machine=$1;shift;;
	-*) 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
    else
	error="You specified the -l switch and gave an additional LABEL argument"
    fi
fi
if [ $# -gt 0 ]
then
    error="Extra unkown arguments"
fi


55
echo "------------ Welcome to the FLEUR configuration script -------------"
56 57 58 59 60 61 62

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

63
. $DIR/cmake/machines.sh
64 65 66

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

  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'"
98
echo "
99 100 101
   By specifying a label which contains 'debug' in addition to your 
   machine configuration you will build a debugging version. Otherwise
   the label will be added to the build directory name."
102
  exit 1
103
fi
Daniel Wortmann's avatar
Daniel Wortmann committed
104

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


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

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

139 140 141 142 143 144 145 146 147
if [ $debug -gt 0 ]
then
   echo "Debug version will be build"
   BUILD=Debug
   $buildname="$buildname.debug"
else
   BUILD=Release
fi

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

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

175
#run cmake
176 177 178 179

cmake -Dall_tests=$all_tests -DCMAKE_BUILD_TYPE=$BUILD $DIR

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