-
-
Notifications
You must be signed in to change notification settings - Fork 83
/
Allwmake
executable file
·126 lines (112 loc) · 5.23 KB
/
Allwmake
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
#!/bin/sh
set -e -u
########## CONFIGURATION - You may want to change these ########################
# Optional: Preprocessor flags
# "-DADAPTER_DEBUG_MODE" enables debug messages
# "-DADAPTER_ENABLE_TIMINGS" enables time measurements
ADAPTER_PREP_FLAGS="${ADAPTER_PREP_FLAGS:-}"
# Build command and options
# In order to compile with multiple threads, set the environment variable WM_NCOMPPROCS,
# e.g., add "export WM_NCOMPPROCS=4" to your ~/.bashrc
# Make sure that these options are supported by your OpenFOAM version.
adapter_build_command(){
wmake libso
}
# Where should the adapter be built? Default: "${FOAM_USER_LIBBIN}"
ADAPTER_TARGET_DIR="${FOAM_USER_LIBBIN:-}"
# More information for compatibility with OpenFOAM
DOC_COMPATIBILITY="https://precice.org/adapter-openfoam-support.html"
################################################################################
# Function to print to screen and copy to a logfile
log() {
echo "$@" | tee -a "Allwmake.log"
}
# Function to print warnings
warning() {
log "WARNING: $*"
export ADAPTER_WARNINGS="true"
}
################################################################################
# Information header
log "Building the OpenFOAM-preCICE adapter..."
# Export the environment variables
export ADAPTER_PREP_FLAGS
export ADAPTER_TARGET_DIR
# Check if pkg-config is available and get the config for preCICE
ADAPTER_PKG_CONFIG_CFLAGS=""
ADAPTER_PKG_CONFIG_LIBS=""
if command -v pkg-config >/dev/null 2>&1; then
if pkg-config libprecice; then
ADAPTER_PKG_CONFIG_CFLAGS="$(pkg-config --silence-errors --cflags libprecice)"
ADAPTER_PKG_CONFIG_LIBS="$(pkg-config --silence-errors --libs libprecice)"
log ""
log "If not already known by the system, preCICE may be located using:"
log " pkg-config --cflags libprecice = ${ADAPTER_PKG_CONFIG_CFLAGS}"
log " pkg-config --libs libprecice = ${ADAPTER_PKG_CONFIG_LIBS}"
else
warning "pkg-config configuration file 'libprecice.pc' was not found in the PKG_CONFIG_PATH.
Check the preCICE documentation page 'Linking to preCICE' for more details, or proceed if you know what you are doing."
fi
else
warning "pkg-config is not installed and cannot be used to detect the preCICE installation. If building succeeds, ignore this warning."
fi
export ADAPTER_PKG_CONFIG_CFLAGS
export ADAPTER_PKG_CONFIG_LIBS
# Check if an OpenFOAM environment is available
log ""
log "Current OpenFOAM environment:"
log " WM_PROJECT = ${WM_PROJECT:-}"
log " WM_PROJECT_VERSION = ${WM_PROJECT_VERSION:-}"
log " WM_NCOMPPROCS = ${WM_NCOMPPROCS:=1} (number of threads for parallel builds)"
if [ -z "${WM_PROJECT:-}" ]; then
log ""
log "=== ERROR: It looks like no OpenFOAM environment is available. ==="
log "Possible reasons:"
log "- Have you loaded the OpenFOAM etc/bashrc file?"
log "- Are you using a compatible OpenFOAM version?"
log " See ${DOC_COMPATIBILITY}"
exit 1
fi
# Check if this is a compatible OpenFOAM environment
# For now, only check if it is not foam-extend, the main incompatible variant.
if [ "${WM_PROJECT:-}" = "foam" ]; then
log ""
log "=== ERROR: foam-extend is not compatible with the adapter."
log "Make sure you are using a compatible OpenFOAM version:"
log " ${DOC_COMPATIBILITY}"
exit 1
fi
log ""
log "The adapter will be built into ${ADAPTER_TARGET_DIR}"
log "Additional preprocessor/compiler options: ${ADAPTER_PREP_FLAGS}"
# Run wmake (build the adapter) and check the exit code
log ""
log "Building with WMake (see the wmake.log log file)...\n"
if ! adapter_build_command 2>&1 | tee wmake.log ||
[ "$(grep -c -E "error:" wmake.log)" -ne 0 ]; then
log "=== ERROR: Building failed. See wmake.log for more. ==="
log "Possible causes:"
log "- Make sure you are using a compatible version of the adapter for your OpenFOAM version:"
log " ${DOC_COMPATIBILITY}"
log "- Is preCICE discoverable at compile time? Check the content of ADAPTER_PKG_CONFIG_CFLAGS above."
log "Attach your Allwmake.log and wmake.log when asking for help."
exit 1
else
ADAPTER_WMAKE_UNDEFINED_SYMBOLS=$(grep -c -E "undefined|not defined" wmake.log) || echo "Everything looks fine in wmake.log."
ldd -r "${ADAPTER_TARGET_DIR}/libpreciceAdapterFunctionObject.so" >ldd.log 2>&1
ADAPTER_LD_UNDEFINED_SYMBOLS=$(grep -c -E "undefined|not defined" ldd.log) || echo "Everything looks fine in ldd.log."
if [ "${ADAPTER_WMAKE_UNDEFINED_SYMBOLS}" -gt 0 ] || [ "${ADAPTER_LD_UNDEFINED_SYMBOLS}" -gt 0 ]; then
log "=== ERROR: Building completed with linking problems: there were undefined symbols. ==="
log "Possible causes:"
log "- Is preCICE discoverable at runtime? Check the content of pkg-config output above."
log "- Did anything go wrong while installing preCICE? Can you run any other preCICE tutorials?"
log "- Did anything go wrong while installing OpenFOAM? Can you run any other OpenFOAM tutorials?"
log "See wmake.log and ldd.log for more details."
log "Attach your Allwmake.log, wmake.log, and ldd.log when asking for help."
else
log "=== OK: Building completed successfully! ==="
fi
fi
if [ "${ADAPTER_WARNINGS:-}" = "true" ]; then
echo "There have been warnings. Check the log above."
fi