-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfigure
executable file
·198 lines (173 loc) · 5.63 KB
/
configure
1
2
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#!/bin/bash
############################## variables ##############################
description="Description: This script auto-generates a make.inc file for make compilation\n"
usage="Usage: ./configure [-h, --help] || [options]\n"
options="Options: \n\
[-h, --help] print help menu\n\
[-m, --mpidir] mpidir path to mpi (e.g. '~/.openmpi' or '/usr')\n\
[-f, --fftdir] fftdir path to fft (e.g. '/usr/local' or '~/.fftw-3.3.8')\n\
[-c, --mpicom] mpicom mpi executable used to compile code (e.g. 'mpifort')\n\
[-e, --empty] create empty 'make.inc' file for manual editing (overrides other options)\n"
mpicommands="mpifort mpiifort mpif90 mpif77"
lfftdir=false
indent=" "
fftwfile="fftw3.f03"
scriptdir=$(dirname $0)
############################## funcitons ##############################
function checkArguments(){
# handles command line arguments
lempty=false
while [ ! -z "$1" ]; do
if [ "$1" == "-h" ] || [ "$1" == "--help" ]; then
printf "$description\n$usage\n$options"
exit 0
elif [ "$1" == "-e" ] || [ "$1" == "--empty" ]; then
lempty=true
break
elif [ "$1" == "-m" ] || [ "$1" == "--mpidir" ]; then
if [ -d "$2" ]; then
mpidir=$(realpath $2)
shift ; shift
else
echo "Error: Directory '$2' does not exist"
exit 1
fi
elif [ "$1" == "-f" ] || [ "$1" == "--fftdir" ]; then
if [ -d "$2" ]; then
fftdir=$(realpath $2)
shift ; shift
else
echo "Error: Directory '$2' does not exist"
exit 1
fi
elif [ "$1" == "-c" ] || [ "$1" == "--mpicom" ]; then
mpicom=$2
shift ; shift
else
echo "Error: Command line option '$1' is not recognized"
exit 1
fi
done
}
function findMPI_command(){
# find mpi command
if [ -z "$mpicom" ]; then
lmpicom=false
echo "${indent}Mpi compiler executable specified ... no"
for mpicom in $mpicommands; do
if type ${1}$mpicom > /dev/null 2>&1 ; then
echo "${indent}Found mpi compiler ... $mpicom"
lmpicom=true
break
fi
done
if ! $lmpicom ; then
printf "Error: No fortran mpi compiler found. \n\
Please use option [-c] to specify compiler name.\n"
exit 1
fi
else
lmpicom=true
echo "${indent}Mpi compiler executable specified ... $mpicom"
fi
}
function findMPI(){
# find mpi directory and make call to findMPI_command
if [ -z "$mpidir" ]; then
echo "${indent}Mpi compiler path specified ... no"
findMPI_command
mpidir=$(dirname $(which $mpicom))
fixMPIdir
if [ ! -d "$mpidir" ]; then
printf "Error: Could not resolve location of mpi compiler '$mpicom'. \n\
Please use option [-m] to specify path to mpi compiler.\n"
exit 1
fi
echo "${indent}Found mpi compiler path ... $mpidir"
else
echo "${indent}Mpi compiler path specified ... $mpidir"
findMPI_command "$mpidir/bin/"
fi
if type $mpidir/bin/$mpicom > /dev/null 2>&1 ; then
echo "${indent}Confirmed mpi command '$mpidir/bin/$mpicom' exists ... yes"
else
echo "Error: Command '$mpidir/bin/$mpicom' does not exist or is not executable."
exit 1
fi
}
function checkUserFFTW(){
# check user provided fftw
echo "${indent}Checking user pvodided FFTW ... $fftdir"
if [ -d "$fftdir/include" ] && [ -f "$fftdir/include/$fftwfile" ] && [ -d "$fftdir/lib" ]; then
lfftdir=true
fi
if $lfftdir; then
echo "${indent}FFTW provided is valid ... yes"
else
echo "${indent}FFTW provided is valid ... no"
echo "Error: Invalid fftw directory provided."
exit 1
fi
}
function fixMPIdir(){
# remove '/bin' from path name
if [ $(echo $mpidir | rev | cut -d '/' -f1 | rev) == "bin" ]; then
mpidir=$(echo $mpidir | rev | cut -d '/' -f2- | rev)
fi
}
function locateFFTW(){
# check user provided fftw
for fftdir in $(for d in $(locate fftw | grep include | grep "$fftwfile"); do dirname $d; done); do
fftdir=$(realpath $fftdir | rev | sed -e 's/edulcni\///' | rev)
if [ -d "$fftdir/lib" ]; then
lfftdir=true
break
fi
done
if $lfftdir; then
echo "${indent}FFTW found ... $fftdir"
else
echo "${indent}FFTW not found or version is not supported."
fi
}
function createMakeInc(){
# create make.inc
make_inc="make.inc"
cat > $make_inc << EOF
# Auto-generated make.inc file from configure
FC = ${mpidir}/bin/${mpicom}
flags = \\
-ffree-line-length-none \\
-pthread \\
-fopenmp \\
-lfftw3 \\
-I${mpidir}/include \\
-L${mpidir}/lib \\
EOF
if [ "$fftdir" != "$mpidir" ]; then
echo "${indent}-I${fftdir}/include \\" >> $make_inc
echo "${indent}-L${fftdir}/lib \\" >> $make_inc
fi
echo >> $make_inc
}
############################### program ###############################
if [ "$PWD" != "$scriptdir" ]; then
cd $scriptdir
fi
checkArguments $@
echo "Configuration to be written in 'make.inc'"
if $lempty ; then
echo "${indent}Creating 'empty' make.inc for manual creation"
mpidir=""
mpicom=""
else
echo "${indent}Collecting variables for creating make.inc"
findMPI
if [ ! -z $fftdir ]; then
checkUserFFTW
else
locateFFTW
fi
fi
createMakeInc
echo "Done! :)"