getpkg/test/build.sh
2025-05-26 21:52:09 +12:00

71 lines
1.7 KiB
Bash
Executable File

#!/bin/bash
set -e
SCRIPT_DIR=$(dirname $(realpath $0))
PROJECT=ipdemo
function title() {
# print a title with a line of dashes
echo "--------------------------------"
echo "$1"
echo "--------------------------------"
}
function build() {
ARCH="$1"
title "Building $PROJECT.$ARCH"
if [ "$ARCH" != "arm64" ] && [ "$ARCH" != "x86_64" ]; then
echo "Unsupported architecture: $ARCH"
exit 1
fi
# Directory to copy the executable to
OUTDIR="$SCRIPT_DIR/output"
WORKDIR="$SCRIPT_DIR/build/${ARCH}"
mkdir -p "$OUTDIR"
mkdir -p "$WORKDIR"
echo "WORKDIR: $WORKDIR"
echo "OUTDIR: $OUTDIR"
echo "SCRIPT_DIR: $SCRIPT_DIR"
case $ARCH in
"arm64") export DOCKCROSS="dockcross-linux-arm64-full";;
"x86_64") export DOCKCROSS="dockcross-linux-x86_64-full";;
*) echo "Unsupported architecture $ARCH"; exit 1;;
esac
export CC="zig cc"
export CXX="zig c++"
export LD="mold"
cd $WORKDIR
cmake -B${WORKDIR} ${SCRIPT_DIR}
make -j$(nproc) -C${WORKDIR}
cp "${WORKDIR}/$PROJECT" "${OUTDIR}/$PROJECT.$ARCH"
# Run the executable if it exists
if [ ! -f $OUTDIR/$PROJECT.$ARCH ]; then
echo "Executable not found: $OUTDIR/$PROJECT.$ARCH"
exit 1
fi
# Check if the executable is dynamically linked using ldd
if ldd "$OUTDIR/$PROJECT.$ARCH"; then
echo "Error: Dynamic dependencies found for $OUTDIR/$PROJECT.$ARCH"
exit 1 # Exit the script with an error
else
echo "Successfully verified no dynamic dependencies for $OUTDIR/$PROJECT.$ARCH"
fi
file $OUTDIR/$PROJECT.$ARCH
}
build x86_64
build arm64