-
Notifications
You must be signed in to change notification settings - Fork 5
/
autogen.sh
executable file
·390 lines (310 loc) · 13.6 KB
/
autogen.sh
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
#! /bin/bash
# TODO: automatic hypre/trilinos pull source + install?
set -o errexit
set -o nounset
# Get the directory that autogen.sh is in (stolen frome stackoverflow:
# http://stackoverflow.com/questions/59895/can-a-bash-script-tell-what-directory-its-stored-in
# ), this is the oomph-lib root directory. Doesn't follow symlinks to the
# script itself, should be robust for anything else. If you move autogen.sh
# this will need to change a little.
oomph_root="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# Load helper functions
source "${oomph_root}/bin/autogen_helpers.sh"
# Handle command line input
# ============================================================
# Default values for arguments
build_dir=""
make_options=""
extra_configure_options=""
generate_config_files="false"
only_generate_config_files="false"
configure_options_file="config/configure_options/current"
# If "current" configure options does not exist then use "default".
if [[ ! -f "${oomph_root}/config/configure_options/current" ]]; then
echo "No current configure options found, copying over the default options"
cp "${oomph_root}/config/configure_options/default" "${oomph_root}/config/configure_options/current"
fi
# Parse command line arguments
while getopts ":hrd:c:b:j:sko" opt; do
case $opt in
h)
echo "Options for autogen.sh:"
echo
EchoUsage
exit 0
;;
r)
generate_config_files="true"
echo "Doing a complete rebuild from scratch."
;;
c)
configure_options_file="$OPTARG"
;;
b)
build_dir="$OPTARG"
;;
o)
only_generate_config_files="true"
generate_config_files="true"
echo "Regenerating the config files only"
;;
# flags for make
j)
job_option="--jobs $OPTARG"
make_options="$make_options $job_option"
echo "Added make option $job_option"
;;
k)
k_option="--keep-going"
make_options="$make_options $k_option"
echo "Added make option $k_option"
;;
s)
silent_option="--silent LIBTOOLFLAGS=--silent"
make_options="$make_options $silent_option"
extra_configure_options="$extra_configure_options -q"
echo "Added make option $silent_option, configure option -q"
;;
\?)
echo "Invalid option: -$OPTARG" >&2
echo "Valid options are:"
echo
EchoUsage
exit 3
;;
esac
done
# and for build dir
if [[ $build_dir == "" ]]; then
build_dir=${oomph_root}/build
fi
# Convert some things to absolute paths
build_dir="$(AbsPath $build_dir)"
configure_options_file="$(AbsPath $configure_options_file)"
# Now switch to the oomph lib directory
cd "$oomph_root"
# Force generate config files if we are missing important files
if [ ! -e configure ]; then
echo "No ./configure found, assuming this is a new build and regenerating everything."
generate_config_files="true"
elif [ ! -e Makefile ]; then
echo "No Makefile found in root, I assume you did a distclean so I'll regenerate everything."
generate_config_files="true"
elif [ ! -e Makefile.in ]; then
echo "No Makefile.in found in root, no idea how you managed that but I'll regenerate everything anyway"
generate_config_files="true"
fi
if [ ! -e $configure_options_file ]; then
echo "Configure options file $configure_options_file does not exist"
exit 8
fi
# Print information about command line options selected
echo
echo "Building using the oomph-lib source in \"$PWD\""
echo "Using configure options file \"$configure_options_file\""
echo "Placing built files in \"$build_dir\""
if [[ $make_options != "" ]]; then
echo "Using make options: \"$make_options\""
fi
if [[ $extra_configure_options != "" ]]; then
echo "Using extra configure options \"$extra_configure_options\""
fi
# If this is a new build or a forced rebuild then we need to do some extra
# stuff.
if [[ $generate_config_files == "true" ]]; then
# David Shepherd's automake compatability fix
#=========================================================================
# This is an awful hack but I can't find any other way to handle it :(
# If we have automake version more recent than 1.13 then the default is to
# use the new parallel self test harness which doesn't work with
# parallel_self_tests.py (and doesn't actually run tests in parallel
# without a major rewrite of all Makefile.am s). So we need to disable it.
# However the command to disable the new test harness was only introduced
# in version 1.12 which is still very new! So it looks like the only way
# around this for now is to modify configure.ac here if the automake
# version is greater than 1.12.
# Update 03/11/15 (by david)
# -------------------------------------------------------------------------
# There might be a way to do this "properly" within autoconfigure.
# Details are here:
# http://stackoverflow.com/questions/15820844/how-to-define-automake-options-conditionally
# However I'm not going to change it because 1) what we have at the
# moment works, 2) debugging sh script is a nightmare (even more so for
# shell script within autoconfigure) and 3) I'm leaving soon so I don't
# want to potentially break things and vanish. Also the sample code
# looks dodgy: what happens if we have version 1.10? Version 1.1.11?
# In case the website moves/vanishes the relevant code is something like:
# AM_INIT_AUTOMAKE([m4_esyscmd([case `automake --version | head -n 1` in
# *1.11*);;
# *) echo serial-tests;;
# esac])], [foreign])
# Which goes in configure.ac instead of the file include.
# -------------------------------------------------------------------------
# Version comparison function from
# http://stackoverflow.com/questions/3511006/how-to-compare-versions-of-some-products-in-unix-shell
# We can't use the much simpler sort -V, or bash code because might not
# have them on some systems...
version_greater_equal_1_12_0()
{
# Put each value into a variable
v1=$(echo $1 | cut -d "." --output-delimiter=" " -f 1)
v2=$(echo $1 | cut -d "." --output-delimiter=" " -f 2)
v3=$(echo $1 | cut -d "." --output-delimiter=" " -f 3)
# The values to compare against
c1=1
c2=12
c3=0
# Test each value and echo the result
if test $v1 -gt $c1; then
echo "1"
elif test $v1 -eq $c1; then
if test $v2 -gt $c2; then
echo "1"
elif test $v2 -eq $c2; then
if test $v3 -ge $c3; then
echo "1"
else
echo "0"
fi
else
echo "0"
fi
else
echo "0"
fi
}
# Now we need to get the automake version (hopefully they don't change the
# formatting of the --version output! Don't think there's any other way to
# get the version).
automake_version=$(automake --version | head -1 | tr ' ' '\n' | tail -1)
# Create the file to contain the automake init command
automake_init_command_file="config/configure.ac_scripts/automake_init_command_file"
echo '# File generated by autogen.sh, DO NOT MODIFY' > $automake_init_command_file
# Check automake version and pick the command to use
echo "Detected automake version $automake_version"
if test $(version_greater_equal_1_12_0 $automake_version) -gt 0; then
echo "I'm modifying configure.ac to use serial self tests in automake because you have a recent enough version of automake."
# Enforce serial tests and require automake version 1.12 or above (just
# in case someone does something really weird..)
echo 'AM_INIT_AUTOMAKE([1.12 serial-tests foreign])' >> $automake_init_command_file
else
echo "Not setting serial tests option in configure.ac because your version"
echo "of automake is old enough to use it by default (older than 1.12.0)."
echo 'AM_INIT_AUTOMAKE([foreign])' >> $automake_init_command_file
fi
# ??ds not really sure why this is here or what it does
echo
echo "Building Auxillary Files in /src/meshes"
./bin/build_mesh_makefile.sh .
fi
# Autodetection of Makefiles to generate
#============================================================================
confdir="config/configure.ac_scripts"
# Generate a sorted list of all the makefiles in the project, wrap it into
# an autoconfigure command and put it into a file.
makefile_list="$(find -path './external_distributions' -prune \
-o -type f -name 'Makefile.am' -print \
| sed -e 's:Makefile\.am:Makefile:' -e 's:^./::' \
| sort)"
# A bit more explanation of the above command:
# First we find all Makefile.ams in the project except those in
# ./external_distributions (because that is where hypre/trilinos/etc live
# and we don't want to build those directly).
# Then we remove the .am using sed to get a list of Makefiles to create. We
# also remove the "./" here because the autotools don't like it.
# Finally we sort the output so that the order of the resulting list is
# deterministic.
# Create the file containing the list of Makefiles
cat > "$confdir/new_makefile_list" <<EOF
# GENERATED FILE, DO NOT MODIFY.
AC_CONFIG_FILES([
$makefile_list
external_distributions/Makefile
external_distributions/hypre/Makefile
external_distributions/trilinos/Makefile
external_distributions/mumps_and_scalapack/Makefile
])
EOF
# In case you haven't seen it before: this writes the lines between <<EOF
# and EOF into the file $confdir/new_makefile_list. Variables are
# substituted as normal.
# If we found some new dirs then write it into the list file that is
# included in configure.ac and tell the user. The fact that we have
# modified a file included in configure.ac will cause make to rerun
# autoconf and configure.
touch "$confdir/makefile_list"
if ! diff -q "$confdir/new_makefile_list" "$confdir/makefile_list" > /dev/null 2>&1;
then
echo "New/removed directories detected and $confdir/makefile_list updated,"
echo "./configure will be rerun automatically by make."
mv "$confdir/new_makefile_list" "$confdir/makefile_list"
fi
# If this is a new build or a forced rebuild then we need to explicitly run
# all the autotools magic now.
if $generate_config_files == "true"; then
# Run all the autotools and just do the right things to generate
# configure, Makefile.in and all the dependency relationships.
autoreconf --install --force
fi
if [[ $only_generate_config_files == "true" ]]; then
# Done, exit with success code
exit 0
fi
# Set up configure options
#============================================================================
# Read the options from the files and convert them into a single one-line string
new_configure_options=$(ProcessOptionsFile < "$configure_options_file")
old_configure_options=$(ProcessOptionsFile < config/configure_options/current)
# If configure options have changed then we need to reconfigure
if [[ "$new_configure_options" != "$old_configure_options" || "$generate_config_files" == "true" ]]; then
# Slight problem here: if we change the options and add a new
# driver at the same time then configure will end up being rerun twice.
# Don't think there's anything we can do about it
echo "Using configure options:"
cat "$configure_options_file" | ProcessOptionsFile
echo
# Check that the options are in the correct order
configure_options_are_ok="$(CheckOptions $configure_options_file)"
if test "$configure_options_are_ok" != ""; then
echo 1>&2
echo "===============================================================" 1>&2
echo "Error message from autogen.sh:" 1>&2
echo 1>&2
echo $configure_options_are_ok 1>&2
echo 1>&2
echo "===============================================================" 1>&2
# Failed
exit 4
fi
# Update current options, unless the files are the same
if [[ "$(AbsPath $configure_options_file)" != "$(AbsPath config/configure_options/current)" ]]; then
cp "$configure_options_file" "config/configure_options/current"
fi
# Finally run configure itself to convert "Makefile.in"s into "Makefile"s
echo
echo "Running ./configure --prefix $build_dir $new_configure_options $extra_configure_options"
echo
/bin/sh -c "./configure --prefix $build_dir $new_configure_options $extra_configure_options"
# Test that the mpi commands work with these configure options
# (automatically passes if no variable MPI_RUN_COMMAND in makefile).
# This needs to go after configure so that we can use the generated
# Makefile to (robustly) get the run and compile commands.
set +e
./bin/check_mpi_command.sh Makefile
set -e
fi
# make is smart enough to automatically rerun automake, configure etc. if
# they are needed for other reasons (e.g if we have added new dirs to one
# of the dir lists or modified a Makefile.am).
# Build!
# ============================================================
# Make all libraries
echo
echo "Running `make $make_options` in $PWD"
make $make_options
echo "done"
# Install the libraries (in build directory specified above)
# echo
# echo "running `make $make_options install` in $PWD"
make $make_options install
echo "done"