#!/usr/bin/env bash usage() { echo "Usage: $0 [managed] [native] [BuildArch] [BuildType] [clean] [cross] [verbose] [objwriter] [clangx.y]" echo "managed - optional argument to build the managed code" echo "native - optional argument to build the native code" echo "The following arguments affect native builds only:" echo "BuildArch can be: x64, x86, arm, arm64, armel, wasm" echo "BuildType can be: Debug, Release" echo "clean - optional argument to force a clean build." echo "verbose - optional argument to enable verbose build output." echo "objwriter - optional argument to enable build ObjWriter library" echo "clangx.y - optional argument to build using clang version x.y." echo "cross - optional argument to signify cross compilation," echo " - will use ROOTFS_DIR environment variable if set." echo "skiptests - optional argument to skip running tests after building." exit 1 } setup_dirs() { echo Setting up directories for build mkdir -p "$__ProductBinDir" mkdir -p "$__IntermediatesDir" if [ $__CrossBuild = 1 ]; then mkdir -p "$__ProductHostBinDir" mkdir -p "$__IntermediatesHostDir" fi } # Performs "clean build" type actions (deleting and remaking directories) clean() { echo "Cleaning previous output for the selected configuration" rm -rf "$__ProductBinDir" rm -rf "$__IntermediatesDir" if [ $__CrossBuild = 1 ]; then rm -rf "$__ProductHostBinDir" rm -rf "$__IntermediatesHostDir" fi } # Check the system to ensure the right pre-reqs are in place check_native_prereqs() { echo "Checking pre-requisites..." # Check presence of CMake on the path hash cmake 2>/dev/null || { echo >&2 "Please install cmake before running this script"; exit 1; } # Check for clang hash clang-$__ClangMajorVersion.$__ClangMinorVersion 2>/dev/null || hash clang$__ClangMajorVersion$__ClangMinorVersion 2>/dev/null || hash clang 2>/dev/null || { echo >&2 "Please install clang before running this script"; exit 1; } } get_current_linux_rid() { # Construct RID for current distro rid=linux if [ -e /etc/os-release ]; then source /etc/os-release if [[ $ID == "alpine" ]]; then # remove the last version digit VERSION_ID=${VERSION_ID%.*} rid=alpine.$VERSION_ID elif [[ $ID == "ubuntu" ]]; then rid=$ID.$VERSION_ID fi elif [ -e /etc/redhat-release ]; then redhatRelease=$(