32 lines
1.8 KiB
Bash
Executable File
32 lines
1.8 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; }
|
|
make all check native check-native check-supervisor
|
|
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'
|