#!/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}" ################################################################################ # yaml stuff YAML_INCLUDE="${HOME}/CalculiX/yaml-cpp-yaml-cpp-0.6.2/include/" YAML_LIBS="${HOME}/CalculiX/yaml-cpp-yaml-cpp-0.6.2/build/" # Information header echo "Building the OpenFOAM adapter for preCICE..." echo "Make sure that all the required dependencies (mainly yaml-cpp and preCICE) are installed." # 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`" export YAML_INCLUDE export YAML_LIBS # Inform the user about the environment echo "Using the following environment variables:" echo " ADAPTER_PRECICE_ROOT = ${ADAPTER_PRECICE_ROOT}" if [ "${ADAPTER_PRECICE_DEP}" ]; then echo " preCICE dependencies:" echo " ADAPTER_PRECICE_DEP = ${ADAPTER_PRECICE_DEP}" else echo " preCICE dependencies: not specified (ok if preCICE is built as a shared library)" fi echo " ADAPTER_PREP_FLAGS = ${ADAPTER_PREP_FLAGS}" echo " ADAPTER_TARGET_DIR = ${ADAPTER_TARGET_DIR}" echo " ADAPTER_WMAKE_OPTIONS = ${ADAPTER_WMAKE_OPTIONS}" echo " ADAPTER_PKG_CONFIG_CFLAGS = ${ADAPTER_PKG_CONFIG_CFLAGS}" echo " ADAPTER_GLOBAL_CPLUS_INC_PATHS = ${ADAPTER_GLOBAL_CPLUS_INC_PATHS}" echo " ADAPTER_GLOBAL_LD_LIBRARY_PATHS = ${ADAPTER_GLOBAL_LD_LIBRARY_PATHS}" echo " ADAPTER_GLOBAL_LIBRARY_PATHS = ${ADAPTER_GLOBAL_LIBRARY_PATHS}" echo " YAML_INCLUDE = ${YAML_INCLUDE}" echo " YAML_LIBS = ${YAML_LIBS}" # Check if an OpenFOAM environment is available echo " WM_PROJECT = ${WM_PROJECT}" echo " WM_PROJECT_VERSION = ${WM_PROJECT_VERSION}" if [ -z "${WM_PROJECT}" ]; then echo " It looks like no OpenFOAM environment is available. Have you loaded the OpenFOAM etc/bashrc file?" echo "Building failed." 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 echo " foam-extend is not compatible with the adapter. Please refer to the adapter's wiki for notes on compatibility." echo "Building failed." exit 1 fi echo "" # Run wmake (build the adapter) and check the exit code echo "Building with WMake (see the wmake.log log file)..." wmake ${ADAPTER_WMAKE_OPTIONS} libso > wmake.log 2>&1 echo "" if [ $? -ne 0 ] || [ "$(grep -c -E "error:" wmake.log)" -ne 0 ]; then echo "Building failed. See wmake.log for more." 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 echo "Building completed with linking problems: there were undefined symbols. See wmake.log and ldd.log for more." echo "If preCICE is only build as a static library, please set the ADAPTER_PRECICE_DEP in this script appropriately (see comments)." else echo "Building completed successfully!" echo "Next step: Run an example from the tutorials/ directory." fi fi