-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild_crossbasic.sh
More file actions
94 lines (81 loc) · 2.77 KB
/
Copy pathbuild_crossbasic.sh
File metadata and controls
94 lines (81 loc) · 2.77 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
#!/usr/bin/env bash
set -euo pipefail
# --- Config ---
SRC="./CrossBasic-SRC/crossbasic.cpp"
BIN_NAME="crossbasic"
RELEASE_DIR="release-64"
ERROR_LOG="error.log"
ERROR_LIB_LOG="errorlib.log"
SCRIPTS_SRC="Scripts"
RUNALL_SCRIPT="runallscripts.sh"
# --- Helper ---
fail() {
echo "❌ ERROR: $*" >&2
exit 1
}
echo "🔧 Building CrossBasic..."
# Sanity checks
if [[ ! -f "${SRC}" ]]; then
fail "Source file '${SRC}' not found."
fi
if ! command -v g++ &>/dev/null; then
fail "g++ compiler not found in PATH."
fi
# Ensure release directory
mkdir -p "${RELEASE_DIR}"
# --- 1. Build executable ---
echo "↪ Compiling executable ${BIN_NAME}..."
# Prevent collisions if directory with same name exists
if [[ -d "${BIN_NAME}" ]]; then
fail "'${BIN_NAME}' exists and is a directory; cannot emit binary with that name."
fi
g++ -O3 -march=native -mtune=native -flto -m64 "${SRC}" -o "${BIN_NAME}" -lffi 2> "${ERROR_LOG}" || {
echo "❌ Compilation of executable failed. See ${ERROR_LOG}:"
sed -n '1,200p' "${ERROR_LOG}" || true
fail "Executable build failed."
}
# Move executable
mv -f "${BIN_NAME}" "${RELEASE_DIR}/"
# --- 2. Build embeddable/shared library variant ---
if [[ "$(uname)" == "Darwin" ]]; then
LIB_OUT="crossbasic.dylib"
echo "↪ Building macOS dynamic library ${LIB_OUT}..."
# Position-independent code and dynamic lib
g++ -dynamiclib -O3 -march=native -mtune=native -flto -m64 "${SRC}" -o "${LIB_OUT}" -lffi 2> "${ERROR_LIB_LOG}" || {
echo "❌ Dynamic library build failed. See ${ERROR_LIB_LOG}:"
sed -n '1,200p' "${ERROR_LIB_LOG}" || true
fail "dylib build failed."
}
mv -f "${LIB_OUT}" "${RELEASE_DIR}/"
echo "Dylib dependencies:"
otool -L "${RELEASE_DIR}/${LIB_OUT}"
elif [[ "$(uname)" == "Linux" ]]; then
LIB_OUT="crossbasic.so"
echo "↪ Building Linux shared object ${LIB_OUT}..."
g++ -shared -fPIC -O3 -march=native -mtune=native -flto -m64 "${SRC}" -o "${LIB_OUT}" -lffi 2> "${ERROR_LIB_LOG}" || {
echo "❌ Shared object build failed. See ${ERROR_LIB_LOG}:"
sed -n '1,200p' "${ERROR_LIB_LOG}" || true
fail "so build failed."
}
mv -f "${LIB_OUT}" "${RELEASE_DIR}/"
echo "Shared library dependencies of executable:"
ldd "${RELEASE_DIR}/${BIN_NAME}"
else
echo "⚠️ Unsupported OS: $(uname); skipping shared library build."
fi
# --- 3. Copy auxiliary resources ---
if [[ -d "${SCRIPTS_SRC}" ]]; then
rm -rf "${RELEASE_DIR}/${SCRIPTS_SRC}"
cp -r "${SCRIPTS_SRC}" "${RELEASE_DIR}/"
else
echo "[WARN] Scripts directory '${SCRIPTS_SRC}' not found; skipping."
fi
if [[ -f "${RUNALL_SCRIPT}" ]]; then
cp -f "${RUNALL_SCRIPT}" "${RELEASE_DIR}/"
else
echo "[WARN] Run-all script '${RUNALL_SCRIPT}' not found; skipping."
fi
echo
echo "✅ CrossBasic Built Successfully. Contents of ${RELEASE_DIR}/:"
ls -lah "${RELEASE_DIR}/"
exit 0