#!/bin/sh
# build_sp_lib.sh – builds luaglue.so and libsplib.so for FreeBSD
# Adjust the variables below to match your project layout.
# Exit on error, treat unset variables as an error, and propagate failures in pipelines.
set -eu
# The `pipefail` option is not available in /bin/sh on FreeBSD, but the
# combination of `set -e` and careful command usage gives similar safety.
# ----------------------------------------------------------------------
# Configuration – change these paths as needed
# ----------------------------------------------------------------------
SRCDIR="/home/sp/publisher-5.3.16/src" # root of the repository
BUILDDIR="/home/sp/publisher-5.3.16/lib" # where the shared objects will be placed
BUILD_PRO="${BUILD_PRO:-false}" # set to "true" to build the pro version
# ----------------------------------------------------------------------
# Prepare build directory
# ----------------------------------------------------------------------
DYLIB_BUILD="${BUILDDIR}/dylib"
mkdir -p "${DYLIB_BUILD}"
# ----------------------------------------------------------------------
# 1️⃣ Build the C glue library (luaglue.so)
# ----------------------------------------------------------------------
echo "=== Building luaglue.so (FreeBSD) ==="
cd "${SRCDIR}/c"
cc -shared -fPIC \
-o "${DYLIB_BUILD}/luaglue.so" \
luaglue.c \
-I /usr/local/include/lua53/
# ----------------------------------------------------------------------
# 2️⃣ Build the Go SPLib library (libsplib.so)
# ----------------------------------------------------------------------
echo "=== Building libsplib.so (FreeBSD) ==="
cd "${SRCDIR}/go/splib"
export CGO_ENABLED=1
export CGO_CFLAGS="-I /usr/local/include/lua53"
# FreeBSD does not need special LDFLAGS for this build
export CGO_LDFLAGS=""
LIB_EXT=".so" # FreeBSD shared‑object extension
OUTPUT="${DYLIB_BUILD}/libsplib${LIB_EXT}"
# POSIX‑compatible test – use single brackets instead of Bash’s [[ ]]
if [ "${BUILD_PRO}" = "true" ]; then
go build -tags pro -buildmode=c-shared -o "${OUTPUT}" speedatapublisher/splib
else
go build -buildmode=c-shared -o "${OUTPUT}" speedatapublisher/splib
fi
echo "=== Build complete ==="
echo "luaglue.so → ${DYLIB_BUILD}/luaglue.so"
echo "libsplib.so → ${OUTPUT}"