-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakems.sh
More file actions
executable file
·100 lines (88 loc) · 3.46 KB
/
Copy pathmakems.sh
File metadata and controls
executable file
·100 lines (88 loc) · 3.46 KB
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
#!/usr/bin/env bash
# makems.sh — CMake build for macos + smacos (no smacos_dvr, no GMI)
#
# Usage:
# source ./makems.sh [debug|release] [gfortran] [npsol]
#
# Options (order-independent, defaults: release, ifx, no-npsol):
# debug — -O0 -check all
# release — -O2 (default)
# gfortran — use gfortran instead of ifx
# npsol — build with -DUSE_NPSOL=ON (constrained-optim path);
# requires macos_f90/npsol/ tree (only on opt-dev branch).
# Build dir gets _npsol suffix.
#
# Output locations (default build):
# macos executable : ./build_release/bin/macos
# smacos library : ./build_release/lib/libsmacos.a
#
# Note: PGPLOT support was removed on release-candidate. Giza is the
# only PGPLOT-API provider; the [giza|pgplot] arg is gone.
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# --- Parse arguments ---
BUILD_TYPE="Release"
FC="ifx"
USE_NPSOL="OFF"
for arg in "$@"; do
case "$arg" in
debug) BUILD_TYPE="Debug" ;;
release) BUILD_TYPE="Release" ;;
ifx) FC="ifx" ;;
gfortran) FC="gfortran" ;;
npsol) USE_NPSOL="ON" ;;
*)
echo "makems.sh: unknown option '$arg'"
echo "Usage: source ./makems.sh [debug|release] [gfortran] [npsol]"
return 1 2>/dev/null || exit 1
;;
esac
done
BUILD_TAG="$(echo "${BUILD_TYPE}" | tr '[:upper:]' '[:lower:]')"
[ "${FC}" = "gfortran" ] && BUILD_TAG="${BUILD_TAG}_gfortran"
[ "${USE_NPSOL}" = "ON" ] && BUILD_TAG="${BUILD_TAG}_npsol"
BUILD_DIR="${SCRIPT_DIR}/build_${BUILD_TAG}"
echo "makems: FC=${FC} BUILD_TYPE=${BUILD_TYPE} USE_NPSOL=${USE_NPSOL}"
echo "makems: BUILD_DIR=${BUILD_DIR}"
# --- Intel oneAPI environment (ifx builds) ---
ONEAPI_SETVARS="/opt/intel/oneapi/setvars.sh"
if [ "${FC}" = "ifx" ] && [ -f "${ONEAPI_SETVARS}" ]; then
source "${ONEAPI_SETVARS}" --force > /dev/null 2>&1
fi
# --- Readline bootstrap (one-time, on first clone) ---
READLINE_DIR="${SCRIPT_DIR}/macos_f90/readline-8.2"
if [ ! -f "${READLINE_DIR}/libreadline.a" ]; then
echo "makems: bootstrapping bundled readline (one-time setup) ..."
( cd "${READLINE_DIR}" && ./configure -q && make -j"$(nproc)" ) \
> /tmp/makems_readline_bootstrap.log 2>&1 \
|| { echo "makems: readline bootstrap FAILED — see /tmp/makems_readline_bootstrap.log"
return 1 2>/dev/null || exit 1; }
fi
# --- LD_LIBRARY_PATH ---
READLINE_LIB="${READLINE_DIR}/shlib"
INTEL_LIB="/opt/intel/oneapi/compiler/latest/lib"
export LD_LIBRARY_PATH="${READLINE_LIB}:${INTEL_LIB}:${LD_LIBRARY_PATH}"
# --- Generator: prefer Ninja if installed, else Unix Makefiles. On a
# --- re-configure, reuse the existing cache's generator (avoids a mismatch). ---
if [ -f "${BUILD_DIR}/CMakeCache.txt" ]; then
GEN_ARG=()
elif command -v ninja >/dev/null 2>&1 || command -v ninja-build >/dev/null 2>&1; then
GEN_ARG=(-G Ninja)
else
GEN_ARG=(-G "Unix Makefiles")
fi
# --- Configure ---
cmake -S "${SCRIPT_DIR}" -B "${BUILD_DIR}" "${GEN_ARG[@]}" \
-DCMAKE_Fortran_COMPILER="${FC}" \
-DCMAKE_C_COMPILER=gcc \
-DCMAKE_BUILD_TYPE="${BUILD_TYPE}" \
-DBUILD_MACOS=ON \
-DBUILD_SMACOS=ON \
-DUSE_NPSOL="${USE_NPSOL}" \
|| { echo "makems: cmake configure FAILED"; return 1 2>/dev/null || exit 1; }
# --- Build ---
cmake --build "${BUILD_DIR}" -j"$(nproc)" \
|| { echo "makems: cmake build FAILED"; return 1 2>/dev/null || exit 1; }
echo ""
echo "makems: BUILD SUCCEEDED"
echo " macos : ${BUILD_DIR}/bin/macos"
echo " smacos : ${BUILD_DIR}/lib/libsmacos.a"