Files
mars_nwe_pcab/build.sh

37 lines
2.2 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
cd "$(dirname "${BASH_SOURCE[0]}")"
base=$PWD
source_dir=${MARS_SOURCE_DIR:-}
prefix=${PREFIX:-/usr/local}
[[ $prefix = /usr/local ]] || { echo 'PREFIX must be /usr/local for native service' >&2; exit 2; }
for tool in cc make cmake git pkg-config; do
command -v "$tool" >/dev/null || { echo "Missing build tool: $tool. See GUIDE.md." >&2; exit 1; }
done
pkg-config --exists json-c openssl || { echo 'Install libjson-c-dev and libssl-dev.' >&2; exit 1; }
printf '#include <civetweb.h>\n' | cc -E -x c - >/dev/null || { echo 'Install libcivetweb-dev.' >&2; exit 1; }
make all check native check-native check-supervisor check-gateway check-gateway-auto check-winclient
mkdir -p upstream
if [[ ! -d upstream/original ]]; then
if [[ -n $source_dir ]]; then
cp -a -- "$source_dir" upstream/original
else
git clone --depth 1 --branch main https://github.com/davidrg/mars_nwe.git upstream/original
fi
fi
if [[ -d upstream/original/.git ]]; then git -C upstream/original rev-parse HEAD > upstream/source-revision.txt; else echo 'Locally supplied source tree' > upstream/source-revision.txt; fi
[[ ! -e upstream/patched ]] || { echo 'Remove upstream/patched and upstream/build to rebuild from original (or run ./rebuild.sh).' >&2; exit 2; }
cp -a upstream/original upstream/patched
./patch-upstream.sh upstream/patched
cmake_args=()
if cmake --version | head -1 | grep -q 'version 4\.'; then cmake_args+=(-DCMAKE_POLICY_VERSION_MINIMUM=3.5); fi
# Old C code needs legacy inline semantics, tentative definitions and GCC compatibility.
cmake -S upstream/patched -B upstream/build "${cmake_args[@]}" \
-DCMAKE_INSTALL_PREFIX="$prefix" -DCMAKE_INSTALL_SBINDIR=sbin \
-DCMAKE_INSTALL_LOCALSTATEDIR=/var -DENABLE_INTERNAL_RIP_SAP=ON \
-DCMAKE_C_FLAGS="-std=gnu99 -fcommon -fgnu89-inline -Wno-error=incompatible-pointer-types -Wno-error=int-conversion -Wno-error=implicit-function-declaration" \
-DMARS_PCAP_LIBRARY="$base/build/libmarspcap.a"
cmake --build upstream/build --parallel "${JOBS:-$(getconf _NPROCESSORS_ONLN)}"
printf '%s\n' "$prefix" > upstream/install-prefix.txt
printf '\nBuild finished. Run sudo ./install.sh (review configuration before starting).\n'