-
Notifications
You must be signed in to change notification settings - Fork 38
/
opm-build.sh
executable file
·237 lines (186 loc) · 6.11 KB
/
opm-build.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
#! /bin/bash
usage() {
echo "Manages the build, update and install process of OPM modules"
echo ""
echo "Usage: $0 COMMAND SOURCE_DIR BUILD_DIR"
echo ""
echo "COMMAND is one of"
echo " update Fetch the latest version of the module from the"
echo " git repository"
echo " cmake run cmake on all modules"
echo " build Build all binaries of the modules"
echo " install Run 'make install' on all modules"
echo ""
echo "Additional parameters for cmake can be specified via the "
echo "'CMAKE_FLAGS' environment variable, additional parameters "
echo "for the 'make' command can be set via the 'MAKE_FLAGS' variable."
}
OPM_INSTALLED_MODULES=""
declare -A OPM_MODULE_SOURCE_DIR
declare -A PROCESSED_MODULES
declare -A OPM_MODULE_DEPENDS
OPM_MODULE_DEPENDS[opm-common]=""
OPM_MODULE_DEPENDS[opm-parser]="opm-common"
OPM_MODULE_DEPENDS[opm-material]="opm-common opm-parser"
OPM_MODULE_DEPENDS[opm-models]="opm-common opm-material opm-parser"
OPM_MODULE_DEPENDS[opm-core]="opm-common opm-parser opm-material"
OPM_MODULE_DEPENDS[dune-cornerpoint]="opm-common opm-parser opm-core"
OPM_MODULE_DEPENDS[opm-autodiff]="opm-common opm-parser opm-core dune-cornerpoint"
OPM_MODULE_DEPENDS[opm-porsol]="opm-common opm-core dune-cornerpoint"
OPM_MODULE_DEPENDS[opm-upscaling]="opm-porsol"
OPM_MODULE_DEPENDS[opm-benchmarks]="opm-upscaling"
OPM_MODULE_DEPENDS[opm-polymer]="opm-autodiff"
OPM_MODULE_DEPENDS[opm-verteq]="opm-core"
OPM_ORDERED_MODULES=""
find_all_modules() {
OPM_INSTALLED_MODULES=""
for TMP in "$SRC_ROOT_DIR"/*; do
if ! test -d "$TMP"; then
# skip non-directories
continue
fi
# transform the directory name to the module name
case "$TMP" in
*opm-*)
TMP2="$(echo "$TMP" | sed "s/.*\(opm-[a-z]*\).*/\1/")"
;;
*dune-cornerpoint*)
TMP2="dune-cornerpoint"
;;
*opm-models*)
TMP2="opm-models"
;;
*)
# the directory contains stuff which we're not sure about
continue
;;
esac
if ! test "${OPM_MODULE_DEPENDS[$TMP2]+foo}"; then
echo "unknown module $TMP2. skipping."
continue
fi
OPM_INSTALLED_MODULES="$OPM_INSTALLED_MODULES $TMP2"
OPM_MODULE_SOURCE_DIR["$TMP2"]="$TMP"
done
echo "Found the following modules: $OPM_INSTALLED_MODULES"
}
# order a list of modules according to their dependency graph. (the
# graph is assumed to be acylic and directed.)
order_module_list() {
local ALL_MODS="$@"
local CUR_MODULE
for CUR_MODULE in $ALL_MODS; do
order_module_list ${OPM_MODULE_DEPENDS[$CUR_MODULE]}
MODULE_SOURCE_DIR=${OPM_MODULE_SOURCE_DIR[$CUR_MODULE]}
if ! test -d "$MODULE_SOURCE_DIR"; then
echo "required module '$CUR_MODULE' seems to be missing abort."
exit 1
fi
if test "${PROCESSED_MODULES["$CUR_MODULE"]}" != "1"; then
PROCESSED_MODULES["$CUR_MODULE"]="1"
OPM_ORDERED_MODULES="$OPM_ORDERED_MODULES $CUR_MODULE"
fi
done
}
do_update() {
echo "do update"
for CUR_MODULE in $@; do
SOURCE_DIR="${OPM_MODULE_SOURCE_DIR[$CUR_MODULE]}"
echo "$CUR_MODULE: $CUR_MODULE; SOURCE_DIR: $SOURCE_DIR"
if ! test -d "$SOURCE_DIR/.git"; then
echo "$SOURCE_DIR seems to be not managed by git. skipping."
continue
fi
GIT_BRANCH=$(GIT_DIR="$SOURCE_DIR/.git" git branch | grep "^\*" | sed -e "s/^\*[ ]*//")
if test "$GIT_BRANCH" != "master"; then
echo "$SOURCE_DIR is not on the 'master' branch. skipping."
continue
fi
echo "Updating working copy of module $CUR_MODULE"
(cd $SOURCE_DIR; git pull --rebase)
done
}
do_cmake() {
echo "do cmake"
local MODS="$@"
local CUR_MODULE
ROOT_DIRS=""
for CUR_MODULE in $MODS; do
MODULE_SOURCE_DIR="${OPM_MODULE_SOURCE_DIR[$CUR_MODULE]}"
MODULE_BUILD_DIR="$BUILD_ROOT_DIR/$CUR_MODULE"
MODULE_ROOT_DIRS="$ROOT_DIRS -D${CUR_MODULE}_ROOT=${MODULE_SOURCE_DIR}"
done
for CUR_MODULE in $MODS; do
MODULE_SOURCE_DIR="${OPM_MODULE_SOURCE_DIR[$CUR_MODULE]}"
MODULE_BUILD_DIR="$BUILD_ROOT_DIR/$CUR_MODULE"
mkdir -p $MODULE_BUILD_DIR
echo "running: cmake ${CMAKE_FLAGS} ${MODULE_ROOT_DIRS}"
(cd $MODULE_BUILD_DIR; cmake ${CMAKE_FLAGS} ${MODULE_ROOT_DIRS}) || exit 1
done
}
do_build() {
echo "do build"
local MODS="$@"
local CUR_MODULE
for CUR_MODULE in $MODS; do
MODULE_SOURCE_DIR="${OPM_MODULE_SOURCE_DIR[$CUR_MODULE]}"
MODULE_BUILD_DIR="$BUILD_ROOT_DIR/$CUR_MODULE"
(cd $MODULE_BUILD_DIR; make ${MAKE_FLAGS}) || exit 1
done
}
do_all() {
echo "do all"
local MODS="$@"
local CUR_MODULE
do_update $MODS
for CUR_MODULE in $MODS; do
MODULE_SOURCE_DIR="${OPM_MODULE_SOURCE_DIR[$CUR_MODULE]}"
MODULE_BUILD_DIR="$BUILD_ROOT_DIR/$CUR_MODULE"
do_cmake $CUR_MODULE
do_build $CUR_MODULE
done
}
do_install() {
echo "do install"
local MODS="$@"
local CUR_MODULE
for CUR_MODULE in $MODS; do
MODULE_SOURCE_DIR="${OPM_MODULE_SOURCE_DIR[$CUR_MODULE]}"
MODULE_BUILD_DIR="$BUILD_ROOT_DIR/$CUR_MODULE"
(cd $MODULE_BUILD_DIR; make install) || exit 1
done
}
if test "$#" -lt 3; then
usage
exit 0
fi
COMMAND="$1"
SRC_ROOT_DIR="$2"
BUILD_ROOT_DIR="$3"
find_all_modules
order_module_list $OPM_INSTALLED_MODULES
echo "running '$COMMAND' on the following modules:$ORDERED_MODULES"
case "$COMMAND" in
update)
do_update $OPM_ORDERED_MODULES
;;
cmake)
do_cmake $OPM_ORDERED_MODULES
;;
build)
do_build $OPM_ORDERED_MODULES
;;
install)
do_install $OPM_ORDERED_MODULES
;;
all)
do_all $OPM_ORDERED_MODULES
;;
*)
echo "Unknown command '$COMMAND'"
echo ""
usage
exit 1
;;
esac
echo "$COMMAND $SRC_ROOT_DIR $BUILD_ROOT_DIR"