-
Notifications
You must be signed in to change notification settings - Fork 0
/
Allwmake
executable file
·150 lines (132 loc) · 6.67 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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/bin/sh
cd ${0%/*} || exit 1 # Run from this directory
########## CONFIGURATION - You may want to change these ########################
# preCICE root path (should be already globally set)
ADAPTER_PRECICE_ROOT="${PRECICE_ROOT}"
## preCICE as a static library?
# If you use preCICE as a static library, then you also need to
# specify its dependncies.
# For an up-to-date list of dependencies,
# look at https://github.com/precice/precice/wiki/Building
# Uncomment to use preCICE as a static library: preCICE dependencies
# ADAPTER_PRECICE_DEP="-lboost_system -lboost_filesystem -lboost_log -lboost_log_setup -lboost_thread -lboost_program_options -lpthread -lxml2"
# ADAPTER_PRECICE_DEP="${ADAPTER_PRECICE_DEP} -lmpi_cxx"
# ADAPTER_PRECICE_DEP="${ADAPTER_PRECICE_DEP} -lpetsc"
# ADAPTER_PRECICE_DEP="${ADAPTER_PRECICE_DEP} -lpython2.7"
# Optional: Preprocessor flags ("-DADAPTER_DEBUG_MODE" enables debug messages)
ADAPTER_PREP_FLAGS="-DADAPTER_DEBUG_MODE"
# Optional: Flags used by wmake.
# In order to compile with multiple threads, add e.g. "-j 4".
# Make sure that these options are supported by your OpenFOAM version.
ADAPTER_WMAKE_OPTIONS=""
# 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://github.com/precice/openfoam-adapter/wiki/Notes-on-OpenFOAM"
################################################################################
# Funtion to print to screen and copy to a logfile
log () {
echo "$@" | tee -a "Allwmake.log"
}
################################################################################
# Information header
log "Building the OpenFOAM adapter for preCICE..."
# What is going on here:
# 1. get the colon-separated paths (e.g. the CPLUS_INCLUDE_PATH),
# 2. translate all the colons to new line characters, i.e. move each entry to a new line,
# 3. remove the empty lines. These would result from ":path" or "path:" or "path::path".
# 4. add the respective "-I" or "-L" in the beginning of the line,
# 5. translate the new line characters to "\", i.e. make everything again one line.
# Extract the paths from the CPLUS_INCLUDE_PATH list and convert them to a sequence of "-I/path/ \"
if [ "${CPLUS_INCLUDE_PATH}" ]; then
ADAPTER_GLOBAL_CPLUS_INC_PATHS=$(echo $CPLUS_INCLUDE_PATH | tr ':' '\n' | sed '/^$/d' | sed 's/^/-I/' | tr '\n' ' \\')
fi
# Extract the paths from the LD_LIBRARY_PATH list and convert them to a sequence of "-L/path/ \"
if [ "${LD_LIBRARY_PATH}" ]; then
ADAPTER_GLOBAL_LD_LIBRARY_PATHS=$(echo $LD_LIBRARY_PATH | tr ':' '\n' | sed '/^$/d' | sed 's/^/-L/' | tr '\n' ' \\')
fi
# Extract the paths from the LIBRARY_PATH list and convert them to a sequence of "-L/path/ \"
if [ "${LIBRARY_PATH}" ]; then
ADAPTER_GLOBAL_LIBRARY_PATHS=$(echo $LIBRARY_PATH | tr ':' '\n' | sed '/^$/d' | sed 's/^/-L/' | tr '\n' ' \\')
fi
# Export the environment variables
export ADAPTER_PRECICE_ROOT
export ADAPTER_PRECICE_DEP
export ADAPTER_PREP_FLAGS
export ADAPTER_TARGET_DIR
export ADAPTER_GLOBAL_CPLUS_INC_PATHS
export ADAPTER_GLOBAL_LD_LIBRARY_PATHS
export ADAPTER_GLOBAL_LIBRARY_PATHS
export ADAPTER_PKG_CONFIG_CFLAGS="`pkg-config --silence-errors --cflags libprecice`"
export ADAPTER_PKG_CONFIG_LIBS="`pkg-config --silence-errors --libs libprecice`"
# Check if an OpenFOAM environment is available
log ""
log "Current OpenFOAM environment:"
log " WM_PROJECT = ${WM_PROJECT}"
log " WM_PROJECT_VERSION = ${WM_PROJECT_VERSION}"
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:"
log " ADAPTER_TARGET_DIR = ${ADAPTER_TARGET_DIR}"
log ""
log "The following building options will be used:"
log " ADAPTER_PREP_FLAGS = ${ADAPTER_PREP_FLAGS}"
log " ADAPTER_WMAKE_OPTIONS = ${ADAPTER_WMAKE_OPTIONS}"
log ""
log "Dependencies (preCICE) will be located using the following environment variables:"
log " ADAPTER_PRECICE_ROOT = ${ADAPTER_PRECICE_ROOT}"
if [ "${ADAPTER_PRECICE_DEP}" ]; then
log " preCICE dependencies:"
log " ADAPTER_PRECICE_DEP = ${ADAPTER_PRECICE_DEP}"
else
log " preCICE dependencies: not specified (ok if preCICE is built as a shared library)"
fi
log " ADAPTER_PKG_CONFIG_CFLAGS = ${ADAPTER_PKG_CONFIG_CFLAGS}"
log " ADAPTER_PKG_CONFIG_LIBS = ${ADAPTER_PKG_CONFIG_LIBS}"
log " ADAPTER_GLOBAL_CPLUS_INC_PATHS = ${ADAPTER_GLOBAL_CPLUS_INC_PATHS}"
log " ADAPTER_GLOBAL_LD_LIBRARY_PATHS = ${ADAPTER_GLOBAL_LD_LIBRARY_PATHS}"
log " ADAPTER_GLOBAL_LIBRARY_PATHS = ${ADAPTER_GLOBAL_LIBRARY_PATHS}"
# Run wmake (build the adapter) and check the exit code
log ""
log "Building with WMake (see the wmake.log log file)..."
wmake ${ADAPTER_WMAKE_OPTIONS} libso > wmake.log 2>&1
log ""
if [ $? -ne 0 ] || [ "$(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."
exit 1
else
ADAPTER_WMAKE_UNDEFINED_SYMBOLS=$(grep -c -E "undefined|not defined" 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)
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 ADAPTER_PKG_CONFIG_LIBS and ADAPTER_GLOBAL_LD_LIBRARY_PATHS above."
log "- If preCICE is (in purpose) only build as a static library, please set the ADAPTER_PRECICE_DEP in this script appropriately (see comments)."
log "See wmake.log and ldd.log for more details."
else
log "=== OK: Building completed successfully! ==="
log "Next step: Run an example from the tutorials/ directory."
fi
fi