#!/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" mkdir -p "$WORKDIR/.ccache" 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="ccache gcc" export CXX="ccache g++" export LD="mold" export CCACHE_DIR=${WORKDIR}/.ccache cd $SCRIPT_DIR $DOCKCROSS bash -c "cmake -B./build/${ARCH} . -GNinja" $DOCKCROSS bash -c "ninja -j$(nproc) -C./build/${ARCH}" 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