#!/bin/sh
# *NATIVE* build script for POSIX systems by Pierre-Marie Baty <pm@pmbaty.com>
THISDIR="$(pwd)"
cd ../qnx800
. ./qnxsdp-env.sh > /dev/null || exit 1
cd "${THISDIR}"
# figure out the target triple
if [ "$(uname)" = "QNX" ]; then
# host is native QNX8. Neutrino has its own ABI.
TRIPLE="$(uname -p)-$(test "$(uname -m)" = "x86pc" && echo "pc" || echo "unknown")-nto-qnx800"
SYSROOT="../qnx800/host/qnx8/$(uname -p)"
elif [ "$(uname)" = "FreeBSD" ] || [ "$(uname)" = "NetBSD" ] || [ "$(uname)" = "OpenBSD" ]; then
# host is a BSD. BSDs have their own ABI.
TRIPLE="$(uname -m)-unknown-$(uname|tr '[:upper:]' '[:lower:]')"
elif [ "$(uname)" = "Linux" ]; then
# host is Linux. Linux uses the GNU ABI (same as Hurd)
TRIPLE="$(uname -m)-unknown-linux-gnu"
SYSROOT="../qnx800/host/linux/$(uname -m)"
elif [ "$(uname)" = "Darwin" ]; then
# host is Apple. May be macOS or even a mobile platform (heh, why not?) - they use the Mach-O ABI
TRIPLE="$(uname -m)-apple-$(uname|tr '[:upper:]' '[:lower:]')"
else
# best guess... assume a GNU ABI
TRIPLE="$(uname -m)-unknown-$(uname|tr '[:upper:]' '[:lower:]')-gnu"
fi
CPPFLAGS="-D_QNX_SOURCE -Ilibucl/include -Ilibucl/src -Ilibucl -Iliblzo"
LDFLAGS=""
# for debug CPPFLAGS add: -fsanitize=address -g
# for debug LDFLAGS add: -static-libasan
rm -f ifstool.$(uname) > /dev/null 2>&1
rm -rf .build > /dev/null 2>&1
mkdir .build > /dev/null 2>&1
echo "Building ifstool for ${TRIPLE}..."
cc ${CPPFLAGS} $(grep 'ClCompile Include' ifstool.vcxproj|awk -F'"' '{print $2}'|tr '\\' '/') ${LDFLAGS} -o "${TRIPLE}-ifstool" || exit 1
if [ -d "${SYSROOT}/usr/bin" ]; then
echo Deploying ifstool to QNX8 $(uname) host toolchain...
cp "${TRIPLE}-ifstool" "${SYSROOT}/usr/bin/ifstool" || exit 1
fi
echo "Done"
exit 0