new build system
This commit is contained in:
parent
8397e7c5e4
commit
0a834b2418
|
@ -16,3 +16,4 @@ run_tree/win32/*
|
||||||
run_tree/wasm/*
|
run_tree/wasm/*
|
||||||
run_tree/webgl/*
|
run_tree/webgl/*
|
||||||
run_tree/raspi/*
|
run_tree/raspi/*
|
||||||
|
build_local.sh
|
648
build/build.sh
648
build/build.sh
|
@ -1,56 +1,56 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# Ensure an error makes the script bail
|
|
||||||
set -e
|
|
||||||
|
|
||||||
# --------------------------------------------
|
# --------------------------------------------
|
||||||
# Usage
|
# Usage
|
||||||
|
|
||||||
print_usage () {
|
VALID_VALUES_COMPILER=("clang" "clang++" "msvc")
|
||||||
echo
|
VALID_VALUES_MODE=("debug" "release")
|
||||||
echo Build Command Syntax:
|
VALID_VALUES_PLATFORM=("win32" "osx" "linux" "raspi" "wasm")
|
||||||
echo " $0 [mode] [platform] [arch]"
|
VALID_VALUES_ARCH=("x64" "arm64")
|
||||||
echo
|
VALID_VALUES_PACKAGE=("true" "false")
|
||||||
echo "Release Mode Options:"
|
|
||||||
echo " debug"
|
printf_r () {
|
||||||
echo " prod"
|
printf "\e[31m$@\e[0m\n"
|
||||||
echo
|
|
||||||
echo "Platform Options:"
|
|
||||||
echo " win32"
|
|
||||||
echo " osx"
|
|
||||||
echo " wasm"
|
|
||||||
echo " raspi"
|
|
||||||
echo
|
|
||||||
echo "Arch Options: (architecture)"
|
|
||||||
echo " intel (valid with Platform Win32 and OSX) (default)"
|
|
||||||
echo " arm64 (only valid for Platform OSX)"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# --------------------------------------------
|
printf_g () {
|
||||||
# Arguments
|
printf "\e[32m%s\e[0m\n" "$@"
|
||||||
MODE=$1
|
}
|
||||||
PLATFORM=$2
|
|
||||||
ARCH=$3
|
|
||||||
PACKAGE=$4
|
|
||||||
|
|
||||||
if [ "${MODE}" == "" ] | [ "${PLATFORM}" == "" ]
|
print_usage () {
|
||||||
|
printf "\n"
|
||||||
|
printf "Build Command Syntax:\n"
|
||||||
|
printf_g " $0 [compiler] [mode] [platform] [arch] [package]"
|
||||||
|
printf "\n"
|
||||||
|
printf "Compiler Options:\n"
|
||||||
|
printf " \e[32m%s\e[m\n" "${VALID_VALUES_COMPILER[@]}"
|
||||||
|
printf "\n"
|
||||||
|
printf "Release Mode Options:\n"
|
||||||
|
printf " \e[32m%s\e[m\n" "${VALID_VALUES_MODE[@]}"
|
||||||
|
printf "\n"
|
||||||
|
printf "Platform Options:\n"
|
||||||
|
printf " \e[32m%s\e[m\n" "${VALID_VALUES_PLATFORM[@]}"
|
||||||
|
printf "\n"
|
||||||
|
printf "Arch Options: \n"
|
||||||
|
printf " \e[32m%s\e[m\n" "${VALID_VALUES_ARCH[@]}"
|
||||||
|
printf "\n"
|
||||||
|
printf "Package Options:\n"
|
||||||
|
printf_g " 'package' or no flag to omit packaging\n"
|
||||||
|
printf "\n"
|
||||||
|
printf "Examples:\n"
|
||||||
|
printf " $0 clang debug osx arm64\n"
|
||||||
|
printf " $0 msvc release win32 x64 package\n"
|
||||||
|
}
|
||||||
|
|
||||||
|
OPTS=()
|
||||||
|
for ((i=1; i<=$#; i+=1)); do
|
||||||
|
OPTS+=(${!i})
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ "${OPTS[0]}" == "-h" ] || [ "${OPTS[0]}" == "--help" ]
|
||||||
then
|
then
|
||||||
print_usage
|
print_usage
|
||||||
exit 0
|
exit 1
|
||||||
fi
|
|
||||||
|
|
||||||
# Default to Intel architecture if none provided
|
|
||||||
if [ "${ARCH}" == "" ]
|
|
||||||
then
|
|
||||||
ARCH="intel"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "${ARCH}" != "intel" ] && [ "${ARCH}" != "arm64" ]
|
|
||||||
then
|
|
||||||
echo "Uknown target architecture: ${ARCH}"
|
|
||||||
print_usage
|
|
||||||
exit 0
|
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# --------------------------------------------
|
# --------------------------------------------
|
||||||
|
@ -64,303 +64,345 @@ popdir () {
|
||||||
command popd "$@" > /dev/null
|
command popd "$@" > /dev/null
|
||||||
}
|
}
|
||||||
|
|
||||||
add_flag () {
|
|
||||||
local -n ref=$1
|
|
||||||
ref="$ref $2"
|
|
||||||
}
|
|
||||||
|
|
||||||
# --------------------------------------------
|
# --------------------------------------------
|
||||||
# Getting Project Path
|
# Project Directory Identification
|
||||||
#
|
|
||||||
# Project is stored in PROJECT_PATH
|
|
||||||
|
|
||||||
SCRIPT_REL_DIR=$(dirname "${BASH_SOURCE[0]}")
|
BUILD_SCRIPT_DIR=$(dirname "${BASH_SOURCE[0]}")
|
||||||
pushdir $SCRIPT_REL_DIR
|
pushdir $BUILD_SCRIPT_DIR
|
||||||
pushdir ..
|
pushdir ..
|
||||||
PROJECT_PATH=$(pwd)
|
PROJECT_PATH=$(pwd)
|
||||||
popdir
|
popdir
|
||||||
popdir
|
popdir
|
||||||
|
|
||||||
# --------------------------------------------
|
BLD_DIR="${PROJECT_PATH}/build"
|
||||||
# Platform/Mode Specific Variables
|
SRC_DIR="${PROJECT_PATH}/src"
|
||||||
|
OUT_DIR="${PROJECT_PATH}/run_tree"
|
||||||
# Compiler Selection
|
|
||||||
|
|
||||||
Compiler_win32="cl"
|
|
||||||
Compiler_osx="clang"
|
|
||||||
Compiler_raspi="clang"
|
|
||||||
WasiSdk="/c/drive/apps/wasi-sdk"
|
|
||||||
Compiler_wasm="$WasiSdk/bin/clang++"
|
|
||||||
Compiler_linux="clang++"
|
|
||||||
|
|
||||||
# Platform Entry Points
|
|
||||||
|
|
||||||
PlatformEntry_win32="src/platform/win32/lumenarium_first_win32.cpp"
|
|
||||||
PlatformEntry_osx="src/platform/osx/lumenarium_first_osx.c"
|
|
||||||
PlatformEntry_wasm="src/platform/wasm/lumenarium_first_wasm.cpp"
|
|
||||||
PlatformEntry_linux="src/platform/linux/lumenarium_first_linux.cpp"
|
|
||||||
PlatformEntry_raspi="src/platform/raspi/lumenarium_first_raspi.c"
|
|
||||||
|
|
||||||
# Intermediate Outputs
|
|
||||||
|
|
||||||
CompilerOutput_win32="lumenarium.o"
|
|
||||||
CompilerOutput_osx="lumenarium"
|
|
||||||
CompilerOutput_wasm="lumenarium.wasm"
|
|
||||||
CompilerOutput_linux=""
|
|
||||||
CompilerOutput_raspi="lumenarium"
|
|
||||||
|
|
||||||
# Executables
|
|
||||||
|
|
||||||
LinkerOutput_win32="lumenarium.exe"
|
|
||||||
LinkerOutput_osx="lumenarium"
|
|
||||||
LinkerOutput_wasm="lumenarium.wasm"
|
|
||||||
LinkerOutput_linux=""
|
|
||||||
LinkerOutput_raspi="lumenarium"
|
|
||||||
|
|
||||||
# Wasm Sys Root
|
|
||||||
WasmSysRoot="${PROJECT_PATH}/src/platform/wasm/sysroot/"
|
|
||||||
|
|
||||||
# Compiler Flags
|
|
||||||
|
|
||||||
CompilerFlags_win32="-nologo"
|
|
||||||
CompilerFlags_win32+=" -FC" # display errors with full path
|
|
||||||
CompilerFlags_win32+=" -WX" # treat warnings as errors
|
|
||||||
CompilerFlags_win32+=" -W4" # output warning level
|
|
||||||
CompilerFlags_win32+=" -Z7" # generate C compatible debug info
|
|
||||||
# CompilerFlags_win32+="-Oi" # generate intrinsic functions
|
|
||||||
# CompilerFlags_win32+="-MTd" # create a debug multithreaded exe w/ Libcmtd.lib
|
|
||||||
# CompilerFlags_win32+="-fp:fast" # fast floating point model
|
|
||||||
CompilerFlags_win32+=" -wd4505" #
|
|
||||||
CompilerFlags_win32+=" -wd4100" #
|
|
||||||
CompilerFlags_win32+=" -wd4189" #
|
|
||||||
CompilerFlags_win32+=" -wd4702" #
|
|
||||||
CompilerFlags_win32+=" -wd4996" # _CRT_SECURE_NO_WARNINGS
|
|
||||||
|
|
||||||
CompilerFlags_osx=""
|
|
||||||
|
|
||||||
CompilerFlags_wasm=""
|
|
||||||
CompilerFlags_wasm+=" -Wno-writable-strings" #
|
|
||||||
CompilerFlags_wasm+=" --target=wasm32" #
|
|
||||||
CompilerFlags_wasm+=" -nostdlib" #
|
|
||||||
CompilerFlags_wasm+=" -Wl,--no-entry" #
|
|
||||||
CompilerFlags_wasm+=" -Wl,--allow-undefined" #
|
|
||||||
CompilerFlags_wasm+=" -Wl,--export-all" #
|
|
||||||
|
|
||||||
CompilerFlags_linux=" -pthread"
|
|
||||||
|
|
||||||
CompilerFlags_raspi=" -pthread" # "--target=arm-rpi-linux-gnueabihf" # "--target=arm-linux-gnueabihf" #target
|
|
||||||
CompilerFlags_raspi+=" -lm" # link with local system math libraries
|
|
||||||
|
|
||||||
CompilerFlags_DEBUG_win32=""
|
|
||||||
CompilerFlags_DEBUG_win32+=" -Od" #
|
|
||||||
CompilerFlags_DEBUG_win32+=" -Zi" #
|
|
||||||
CompilerFlags_DEBUG_win32+=" -DDEBUG" #
|
|
||||||
# add_flag CompilerFlags_DEBUG_win32 "-DPRINT_ASSERTS"
|
|
||||||
|
|
||||||
CompilerFlags_DEBUG="-O0"
|
|
||||||
CompilerFlags_DEBUG+=" -g" #
|
|
||||||
CompilerFlags_DEBUG+=" -DDEBUG" #
|
|
||||||
if [ "${PLATFORM}" != "raspi" ]
|
|
||||||
then
|
|
||||||
CompilerFlags_DEBUG+=" -fsanitize=address" #address sanitizer
|
|
||||||
fi
|
|
||||||
|
|
||||||
CompilerFlags_PROD=" -O3"
|
|
||||||
|
|
||||||
# Compiler flags that no matter what, we want to define
|
|
||||||
# for the most part these pass the build parameters into the executable
|
|
||||||
CompilerFlags_common=" -DPLATFORM_${PLATFORM}=1 -DMODE_${MODE}=1 -DARCH_${ARCH}=1"
|
|
||||||
|
|
||||||
# Linker Flags
|
|
||||||
|
|
||||||
LinkerFlags_win32=" -NOLOGO"
|
|
||||||
LinkerFlags_win32+=" -incremental:no" #
|
|
||||||
LinkerFlags_win32+=" -subsystem:windows" #
|
|
||||||
# add_flag LinkerFlags_win32 "-entry:WinMain" #
|
|
||||||
LinkerFlags_win32+=" -opt:ref" # eliminate functions that are never referenced
|
|
||||||
|
|
||||||
LinkerFlags_osx=""
|
|
||||||
|
|
||||||
LinkerFlags_wasm="--no-entry"
|
|
||||||
LinkerFlags_wasm+=" --export-dynamic" #
|
|
||||||
LinkerFlags_wasm+=" --unresolved-symbols=import-functions" #
|
|
||||||
|
|
||||||
LinkerFlags_linux=""
|
|
||||||
LinkerFlags_raspi="-fuse-ld=lld"
|
|
||||||
|
|
||||||
LinkerFlags_DEBUG="-debug"
|
|
||||||
LinkerFlags_PROD=""
|
|
||||||
|
|
||||||
# Linker Libs
|
|
||||||
|
|
||||||
LinkerLibs_win32="user32.lib kernel32.lib gdi32.lib opengl32.lib"
|
|
||||||
# winmm.lib gdi32.lib dsound.lib Ws2_32.lib Comdlg32.lib Winspool.lib"
|
|
||||||
|
|
||||||
LinkerLibs_osx="-framework OpenGL -framework Cocoa -framework IOKit ${PROJECT_PATH}/src/libs/glfw_osx/lib-universal/libglfw3.a"
|
|
||||||
LinkerLibs_wasm=""
|
|
||||||
LinkerLibs_linux=""
|
|
||||||
LinkerLibs_raspi=""
|
|
||||||
|
|
||||||
# --------------------------------------------
|
# --------------------------------------------
|
||||||
# Varible Selection
|
# Input Flag Settings
|
||||||
|
|
||||||
# Select Platform Variables
|
INPUT_FLAG_UNSET="unset"
|
||||||
|
|
||||||
if [ "${PLATFORM}" == "win32" ]
|
COMPILER=$INPUT_FLAG_UNSET
|
||||||
then
|
MODE=$INPUT_FLAG_UNSET
|
||||||
Compiler=$Compiler_win32
|
PLATFORM=$INPUT_FLAG_UNSET
|
||||||
PlatformEntry=$PlatformEntry_win32
|
ARCH=$INPUT_FLAG_UNSET
|
||||||
CompilerFlags=$CompilerFlags_win32
|
PACKAGE=$INPUT_FLAG_UNSET
|
||||||
CompilerOutput=$CompilerOutput_win32
|
|
||||||
LinkerOutput=$LinkerOutput_win32
|
|
||||||
LinkerFlags=$LinkerFlags_win32
|
|
||||||
LinkerLibs=$LinkerLibs_win32
|
|
||||||
|
|
||||||
elif [ "${PLATFORM}" == "osx" ]
|
# --------------------------------------------
|
||||||
then
|
# Create a local build file if there isn't one
|
||||||
Compiler=$Compiler_osx
|
# using local context to determine defaults
|
||||||
PlatformEntry=$PlatformEntry_osx
|
|
||||||
CompilerFlags=$CompilerFlags_osx
|
|
||||||
CompilerOutput=$CompilerOutput_osx
|
|
||||||
LinkerOutput=$LinkerOutput_osx
|
|
||||||
LinkerFlags=$LinkerFlags_osx
|
|
||||||
LinkerLibs=$LinkerLibs_osx
|
|
||||||
|
|
||||||
if [ "${ARCH}" == "arm64" ]
|
BLD_LOCAL_FILE="${BLD_DIR}/build_local.sh"
|
||||||
|
|
||||||
|
if [ ! -f $BLD_LOCAL_FILE ]
|
||||||
then
|
then
|
||||||
CompilerFlags="${CompilerFlags} -arch arm64"
|
|
||||||
elif [ "${ARCH}" == "intel" ]
|
printf "Creating a build/build_local.sh file for you."
|
||||||
then
|
printf " Path: ${BLD_LOCAL_FILE}"
|
||||||
CompilerFlags="${CompilerFlags} -arch x86_64"
|
printf "This file is excluded in the .gitignore. It is for you to set local compilation targets"
|
||||||
else
|
|
||||||
echo "ERROR: Unrecognized Arch: ${ARCH}"
|
touch $BLD_LOCAL_FILE
|
||||||
exit 0
|
printf "#!/bin/bash" >> $BLD_LOCAL_FILE
|
||||||
|
printf >> $BLD_LOCAL_FILE
|
||||||
|
printf "COMPILER=\"clang\"" >> $BLD_LOCAL_FILE
|
||||||
|
printf "MODE=\"debug\"" >> $BLD_LOCAL_FILE
|
||||||
|
printf "PLATFORM=\"osx\"" >> $BLD_LOCAL_FILE
|
||||||
|
printf "ARCH=\"arm64\"" >> $BLD_LOCAL_FILE
|
||||||
|
printf "PACKAGE=\"false\"" >> $BLD_LOCAL_FILE
|
||||||
|
printf "TEST_FILE=\"\"" >> $BLD_LOCAL_FILE
|
||||||
fi
|
fi
|
||||||
|
|
||||||
elif [ "${PLATFORM}" == "wasm" ]
|
# --------------------------------------------
|
||||||
then
|
# Call Local Build File
|
||||||
Compiler=$Compiler_wasm
|
|
||||||
PlatformEntry=$PlatformEntry_wasm
|
|
||||||
CompilerFlags=$CompilerFlags_wasm
|
|
||||||
CompilerOutput=$CompilerOutput_wasm
|
|
||||||
LinkerOutput=$LinkerOutput_wasm
|
|
||||||
LinkerFlags=$LinkerFlags_wasm
|
|
||||||
LinkerLibs=$LinkerLibs_wasm
|
|
||||||
|
|
||||||
elif [ "${PLATFORM}" == "linux" ]
|
source ${BLD_LOCAL_FILE}
|
||||||
then
|
|
||||||
Compiler=$Compiler_linux
|
|
||||||
PlatformEntry=$PlatformEntry_linux
|
|
||||||
CompilerFlags=$CompilerFlags_linux
|
|
||||||
CompilerOutput=$CompilerOutput_linux
|
|
||||||
LinkerOutput=$LinkerOutput_linux
|
|
||||||
LinkerFlags=$LinkerFlags_linux
|
|
||||||
LinkerLibs=$LinkerLibs_linux
|
|
||||||
|
|
||||||
elif [ "${PLATFORM}" == "raspi" ]
|
# --------------------------------------------
|
||||||
then
|
# Use command line arguments to override local
|
||||||
Compiler=$Compiler_raspi
|
# build file
|
||||||
PlatformEntry=$PlatformEntry_raspi
|
|
||||||
CompilerFlags=$CompilerFlags_raspi
|
if [ "${#OPTS[@]}" -gt "0" ]; then
|
||||||
CompilerOutput=$CompilerOutput_raspi
|
OPTS_COUNT="${#OPTS[@]}"
|
||||||
LinkerOutput=$LinkerOutput_raspi
|
if [ $OPTS_COUNT -lt "4" ] || [ $OPTS_COUNT -gt "5" ]; then
|
||||||
LinkerFlags=$LinkerFlags_raspi
|
printf_r "Error: Incorrect number of arguments supplied"
|
||||||
LinkerLibs=$LinkerLibs_raspi
|
printf " You must either supply all or none of the build script arguments\n"
|
||||||
else
|
|
||||||
echo "Attempting to build for an unknown platform: ${PLATFORM}"
|
|
||||||
print_usage
|
print_usage
|
||||||
exit 0
|
exit 1
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Select Release Mode Variables
|
COMPILER=${OPTS[0]}
|
||||||
|
MODE=${OPTS[1]}
|
||||||
|
PLATFORM=${OPTS[2]}
|
||||||
|
ARCH=${OPTS[3]}
|
||||||
|
|
||||||
if [ "${MODE}" == "debug" ]
|
PACkaGE="false"
|
||||||
then
|
if [ $OPTS_COUNT -eq "5" ]; then
|
||||||
if [ $PLATFORM == "win32" ]
|
if [ "${OPTS[4]}" == "package" ]; then
|
||||||
then
|
PACKAGE="true"
|
||||||
CompilerFlags="${CompilerFlags} ${CompilerFlags_DEBUG_win32}"
|
|
||||||
else
|
else
|
||||||
CompilerFlags="${CompilerFlags} ${CompilerFlags_DEBUG}"
|
printf_r "Error: Invalid package command provided: ${PACKAGE}"
|
||||||
|
printf " You must either supply the 'package' flag or omit it"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
LinkerFlags="${LinkerFlags} ${LinkerFlags_DEBUG}"
|
|
||||||
|
|
||||||
elif [ "${MODE}" == "prod" ]
|
|
||||||
then
|
|
||||||
CompilerFlags="${CompilerFlags} ${CompilerFlags_PROD}"
|
|
||||||
LinkerFlags="${LinkerFlags} ${LinkerFlags_PROD}"
|
|
||||||
|
|
||||||
else
|
|
||||||
echo "Attempting to build for an unknown release mode: ${MODE}"
|
|
||||||
print_usage
|
|
||||||
exit 0
|
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Common Flags
|
|
||||||
CompilerFlags="${CompilerFlags} ${CompilerFlags_common}"
|
|
||||||
|
|
||||||
# --------------------------------------------
|
# --------------------------------------------
|
||||||
# Build Path Construction
|
# Verify valid values for all inputs
|
||||||
#
|
|
||||||
# This determines where the generated executable will
|
|
||||||
# be located. In general, it can be found at
|
|
||||||
# project_path/run_tree/platform/arch/release_mode/lumenarium.exe
|
|
||||||
#
|
|
||||||
# This section also ensures that the path requested actually exists
|
|
||||||
|
|
||||||
BuildDir="${PROJECT_PATH}/run_tree/${PLATFORM}/${ARCH}/${MODE}"
|
ALL_VALID_VALUES="true"
|
||||||
EntryPath="${PROJECT_PATH}/${PlatformEntry}"
|
|
||||||
|
|
||||||
# Exception for wasm, which doesn't care about cpu architecture
|
check_valid_flag () {
|
||||||
if [ $PLATFORM == "wasm" ]
|
local VALID_VALUES_NAME=$1[@]
|
||||||
then
|
local VALID_VALUES=("${!VALID_VALUES_NAME}")
|
||||||
BuildDir="${PROJECT_PATH}/run_tree/${PLATFORM}/${MODE}"
|
local VALUE_GIVEN=$2
|
||||||
|
local VALUE_ID=$3
|
||||||
|
|
||||||
|
if [[ ! " ${VALID_VALUES[*]} " =~ " ${VALUE_GIVEN} " ]]; then
|
||||||
|
printf_r "Error: Invalid ${VALUE_ID} provided: ${VALUE_GIVEN}"
|
||||||
|
printf " Must be one of: "
|
||||||
|
printf_g "${VALID_VALUES[*]}\n"
|
||||||
|
ALL_VALID_VALUES="false"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
check_valid_flag VALID_VALUES_COMPILER $COMPILER "compiler"
|
||||||
|
check_valid_flag VALID_VALUES_MODE $MODE "mode"
|
||||||
|
check_valid_flag VALID_VALUES_PLATFORM $PLATFORM "platform"
|
||||||
|
check_valid_flag VALID_VALUES_ARCH $ARCH "arch"
|
||||||
|
|
||||||
|
if [[ ! " ${VALID_VALUES_PACKAGE[*]} " =~ " ${PACKAGE} " ]]; then
|
||||||
|
printf_r "Error: Invalid package provided: ${PACKAGE}"
|
||||||
|
printf " You must either supply the 'package' flag or omit it"
|
||||||
|
ALL_VALID_VALUES="false"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Make the build directory,
|
if [ "${ALL_VALID_VALUES}" != "true" ]; then
|
||||||
# "-p" flag makes it make the entire tree, and not emit errors if it
|
exit 1
|
||||||
# exists.
|
fi
|
||||||
mkdir -p "${BuildDir}"
|
|
||||||
|
if [ "${COMPILER}" == "clang" ] || [ "${COMPILER}" == "clang++" ]; then
|
||||||
|
LINKER=${COMPILER}
|
||||||
|
elif [ "${COMPILER}" == "msvc" ]; then
|
||||||
|
LINKER="link"
|
||||||
|
fi
|
||||||
|
|
||||||
|
printf "Compiler: "
|
||||||
|
printf_g "${COMPILER}"
|
||||||
|
printf "Mode: "
|
||||||
|
printf_g "${MODE}"
|
||||||
|
printf "Platform: "
|
||||||
|
printf_g "${PLATFORM}"
|
||||||
|
printf "Arch: "
|
||||||
|
printf_g "${ARCH}"
|
||||||
|
printf "Package: "
|
||||||
|
printf_g "${PACKAGE}"
|
||||||
|
|
||||||
# --------------------------------------------
|
# --------------------------------------------
|
||||||
# Compilation
|
# Hooks Identification
|
||||||
|
|
||||||
echo "Building To: ${BuildDir}/${LinkerOutput}"
|
HOOK_PREBUILD="${BLD_DIR}/hook_prebuild.sh"
|
||||||
echo
|
HOOK_POSTBUILD="${BLD_DIR}/hook_postbuild.sh"
|
||||||
pushdir $BuildDir
|
HOOK_PRELINK="${BLD_DIR}/hook_prelink.sh"
|
||||||
|
HOOK_POSTLINK="${BLD_DIR}/hook_postlink.sh"
|
||||||
|
|
||||||
echo "Cleaning: ${CompilerOutput} and ${LinkerOutput}"
|
printf "\nBuild Hooks:\n"
|
||||||
rm -rf ${CompilerOutput} ${LinkerOutput}
|
if [ -f "${HOOK_PREBUILD}" ]; then
|
||||||
|
printf " Pre Build: ${HOOK_PREBUILD##*/}\n"
|
||||||
echo "COMPILING..."
|
|
||||||
echo " COMPILE STRING: $Compiler -o $LinkerOutput $CompilerFlags $EntryPath $LinkerLibs"
|
|
||||||
|
|
||||||
if [ $PLATFORM == "win32" ]
|
|
||||||
then
|
|
||||||
$Compiler \
|
|
||||||
$CompilerFlags \
|
|
||||||
$EntryPath \
|
|
||||||
-link \
|
|
||||||
$LinkerFlags \
|
|
||||||
$LinkerLibs \
|
|
||||||
-OUT:${LinkerOutput}
|
|
||||||
|
|
||||||
elif [ $PLATFORM == "wasm" ]
|
|
||||||
then
|
|
||||||
$Compiler \
|
|
||||||
$CompilerFlags \
|
|
||||||
-o $LinkerOutput \
|
|
||||||
$EntryPath
|
|
||||||
cp \
|
|
||||||
"${PROJECT_PATH}/src/platform/wasm/lumenarium_wasm_imports.js" \
|
|
||||||
./lumenarium_wasm_imports.js
|
|
||||||
else
|
else
|
||||||
$Compiler -o $LinkerOutput $CompilerFlags $EntryPath $LinkerLibs
|
HOOK_PREBUILD=""
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -f "${HOOK_POSTBUILD}" ]; then
|
||||||
|
printf " Post Build: ${HOOK_POSTBUILD##*/}\n"
|
||||||
|
else
|
||||||
|
HOOK_POSTBUILD=""
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -f "${HOOK_PRELINK}" ]; then
|
||||||
|
printf " Pre Link: ${HOOK_PRELINK##*/}\n"
|
||||||
|
else
|
||||||
|
HOOK_PRELINK=""
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -f "${HOOK_POSTLINK}" ]; then
|
||||||
|
printf " Post Link: ${HOOK_POSTLINK##*/}\n"
|
||||||
|
else
|
||||||
|
HOOK_POSTLINK=""
|
||||||
|
fi
|
||||||
|
|
||||||
|
# --------------------------------------------
|
||||||
|
# File Parsing Helpers
|
||||||
|
|
||||||
|
trim() {
|
||||||
|
local var="$*"
|
||||||
|
|
||||||
|
# remove leading whitespace characters
|
||||||
|
var="${var#"${var%%[![:space:]]*}"}"
|
||||||
|
|
||||||
|
# remove trailing whitespace characters
|
||||||
|
var="${var%"${var##*[![:space:]]}"}"
|
||||||
|
|
||||||
|
echo "${var}"
|
||||||
|
}
|
||||||
|
|
||||||
|
load_file_into_lines_array() {
|
||||||
|
FILE=$1
|
||||||
|
local FILE_LINES_RAW=()
|
||||||
|
IFS=$'\r\n'
|
||||||
|
GLOBIGNORE='*'
|
||||||
|
command eval 'FILE_LINES_RAW=($(cat $FILE))'
|
||||||
|
|
||||||
|
FILE_LINES=()
|
||||||
|
for i in "${FILE_LINES_RAW[@]}"; do
|
||||||
|
if [ "${i:0:1}" != "#" ]; then
|
||||||
|
# strip any trailing comments off the end
|
||||||
|
# this lets you do things like:
|
||||||
|
# "compiler>msvc>-FC # full path error"
|
||||||
|
# where you want to explain a flag
|
||||||
|
local LINE=$i
|
||||||
|
local LINE_NO_TRAILING_COMMENT="${LINE% #*}"
|
||||||
|
FILE_LINES+=($LINE_NO_TRAILING_COMMENT)
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
parse_flags_from_selectors() {
|
||||||
|
SELECTORS=()
|
||||||
|
for ((i=1; i<=$#; i+=1)); do
|
||||||
|
SELECTORS+=(${!i})
|
||||||
|
done
|
||||||
|
|
||||||
|
FLAGS=()
|
||||||
|
for i in "${FILE_LINES[@]}"; do
|
||||||
|
LINE=$i
|
||||||
|
FLAG="${LINE##*>}"
|
||||||
|
|
||||||
|
INCLUDE_FLAG="true"
|
||||||
|
while [ "${LINE}" != "${FLAG}" ]; do
|
||||||
|
NEXT_SELECTOR="${LINE%%>*}"
|
||||||
|
LINE="${LINE#*>}"
|
||||||
|
if [[ ! " ${SELECTORS[@]} " =~ " ${NEXT_SELECTOR} " ]]; then
|
||||||
|
INCLUDE_FLAG="false"
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ "${INCLUDE_FLAG}" == "true" ]; then
|
||||||
|
FLAG=$(trim "${FLAG}")
|
||||||
|
FLAG=$(eval "echo $FLAG")
|
||||||
|
FLAGS+=($FLAG)
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
load_file_into_lines_array "${BLD_DIR}/build_flags.sh"
|
||||||
|
|
||||||
|
# --------------------------------------------
|
||||||
|
# Assemble Flags
|
||||||
|
|
||||||
|
parse_flags_from_selectors "compiler" $COMPILER $MODE $PLATFORM $ARCH
|
||||||
|
COMPILER_FLAGS=(${FLAGS[@]})
|
||||||
|
|
||||||
|
parse_flags_from_selectors "compiler" "input" $PLATFORM $ARCH
|
||||||
|
COMPILER_INPUTS=(${FLAGS[@]})
|
||||||
|
|
||||||
|
parse_flags_from_selectors "linker" $MODE $PLATFORM $ARCH
|
||||||
|
LINKER_FLAGS=(${FLAGS[@]})
|
||||||
|
|
||||||
|
parse_flags_from_selectors "linker" "libs" $LINKER $MODE $PLATFORM $ARCH
|
||||||
|
LINKER_LIBRARIES=(${FLAGS[@]})
|
||||||
|
|
||||||
|
parse_flags_from_selectors "linker" "output" $LINKER $MODE $PLATFORM $ARCH
|
||||||
|
LINKER_OUTPUT=(${FLAGS[@]})
|
||||||
|
|
||||||
|
# --------------------------------------------
|
||||||
|
# Create the Run Tree path
|
||||||
|
|
||||||
|
OUT_PATH="${OUT_DIR}/${PLATFORM}/${ARCH}/${MODE}"
|
||||||
|
|
||||||
|
if [ ! -d $OUT_PATH ]; then
|
||||||
|
mkdir -p $OUT_PATH
|
||||||
|
fi
|
||||||
|
|
||||||
|
# --------------------------------------------
|
||||||
|
# Compile The Program
|
||||||
|
|
||||||
|
printf "\nBeginning Compilation...\n"
|
||||||
|
pushdir $OUT_PATH
|
||||||
|
|
||||||
|
if [[ -f ${HOOK_PREBUILD} ]]; then
|
||||||
|
source "${HOOK_PREBUILD}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
COMPILATION_SUCCESS="true"
|
||||||
|
COMPILER_OUTPUT=()
|
||||||
|
FAILED_COMPILES=()
|
||||||
|
for i in "${COMPILER_INPUTS[@]}"; do
|
||||||
|
INPUT="${i}"
|
||||||
|
|
||||||
|
INPUT_FILE="${INPUT##*/}"
|
||||||
|
INPUT_EXTENSION="${INPUT_FILE##*.}"
|
||||||
|
INPUT_NAME="${INPUT_FILE%.*}"
|
||||||
|
OUTPUT_FILE="${INPUT_NAME}_${INPUT_EXTENSION}.o"
|
||||||
|
|
||||||
|
COMPILER_ARGS="-o ${OUTPUT_FILE} -c ${COMPILER_FLAGS[@]} -DPLATFORM_$PLATFORM=1 -DMODE_$MODE=1 -DARCH_$ARCH=1 $INPUT"
|
||||||
|
|
||||||
|
# echo $COMPILER $COMPILER_ARGS
|
||||||
|
eval $COMPILER $COMPILER_ARGS
|
||||||
|
if [ $? -eq 0 ]; then
|
||||||
|
COMPILER_OUTPUT+=(${OUTPUT_FILE})
|
||||||
|
else
|
||||||
|
COMPILATION_SUCCESS="false"
|
||||||
|
FAILED_COMPILES+=(${OUTPUT_FILE})
|
||||||
|
fi
|
||||||
|
|
||||||
|
# TODO: if the output file was a .dll or .lib we don't want to include
|
||||||
|
# those in the final compilation gather
|
||||||
|
done
|
||||||
|
|
||||||
|
printf "\nCompiler Output\n"
|
||||||
|
if [ ${#COMPILER_OUTPUT[@]} -gt 0 ]; then
|
||||||
|
printf " %s \e[32m[SUCCESS]\e[0m\n" "${COMPILER_OUTPUT[@]}"
|
||||||
|
fi
|
||||||
|
if [ ${#FAILED_COMPILES[@]} -gt 0 ]; then
|
||||||
|
printf " %s \e[31m[FAILED]\e[0m\n" "${FAILED_COMPILES[@]}"
|
||||||
|
fi
|
||||||
|
printf "\n"
|
||||||
|
|
||||||
|
if [[ -f ${HOOK_POSTBUILD} ]]; then
|
||||||
|
source "${HOOK_POSTBUILD}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ $COMPILATION_SUCCESS != "true" ]; then
|
||||||
|
printf "Compilation Failed.\n Exiting..."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -f ${HOOK_PRELINK} ]]; then
|
||||||
|
source "${HOOK_PRELINK}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
LINKER_ARGS="-o ${LINKER_OUTPUT} ${COMPILER_OUTPUT[@]} ${LINKER_FLAGS[@]} ${LINKER_LIBRARIES[@]}"
|
||||||
|
|
||||||
|
|
||||||
|
printf "Linking...\n"
|
||||||
|
# echo $LINKER $LINKER_ARGS
|
||||||
|
eval $LINKER $LINKER_ARGS
|
||||||
|
if [ $? -eq 0 ]; then
|
||||||
|
printf " Link: "
|
||||||
|
printf_g "[SUCCEEDED]"
|
||||||
|
else
|
||||||
|
printf "\n Link: "
|
||||||
|
printf_r "[FAILED]"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -f ${HOOK_POSTLINK} ]]; then
|
||||||
|
source "${HOOK_POSTLINK}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo
|
|
||||||
echo "Finished..."
|
|
||||||
popdir
|
popdir
|
||||||
|
|
||||||
|
exit 0
|
|
@ -0,0 +1,87 @@
|
||||||
|
################# COMPILER #################
|
||||||
|
# Compiler: Global
|
||||||
|
|
||||||
|
compiler>input>win32> ${SRC_DIR}/platform/win32/lumenarium_first_win32.c
|
||||||
|
compiler>input>osx> ${SRC_DIR}/platform/osx/lumenarium_first_osx.c
|
||||||
|
compiler>input>raspi> ${SRC_DIR}/platform/raspi/lumenarium_first_raspi.c
|
||||||
|
|
||||||
|
msvc>-nologo
|
||||||
|
msvc>-FC # full path errors
|
||||||
|
msvc>-WX # treat warnings as errors
|
||||||
|
msvc>-W4 # output warning level
|
||||||
|
msvc>-Z7 # generate C compatible debug info
|
||||||
|
# msvc>-Oi # generate intrinsic functions
|
||||||
|
# msvc>-MTd # create a debug multithreaded exe w/ Libcmtd.lib
|
||||||
|
#msvc>-fp:fast # fast floating point model
|
||||||
|
msvc>-wd4505 #
|
||||||
|
msvc>-wd4100 #
|
||||||
|
msvc>-wd4189 #
|
||||||
|
msvc>-wd4702 #
|
||||||
|
msvc>-wd4996 # _CRT_SECURE_NO_WARNINGS
|
||||||
|
|
||||||
|
compiler>wasm>-Wno-writable-strings #
|
||||||
|
compiler>wasm>--target=wasm32 #
|
||||||
|
compiler>wasm>-nostdlib #
|
||||||
|
compiler>wasm>-Wl,--no-entry #
|
||||||
|
compiler>wasm>-Wl,--allow-undefined #
|
||||||
|
compiler>wasm>-Wl,--export-all #
|
||||||
|
|
||||||
|
compiler>clang>linux>-pthread
|
||||||
|
|
||||||
|
compiler>raspi>-pthread
|
||||||
|
compiler>raspi>-lm # link with local system math libraries
|
||||||
|
|
||||||
|
compiler>clang>arm64>-arch arm64
|
||||||
|
|
||||||
|
# Compiler: Debug
|
||||||
|
|
||||||
|
compiler>debug>msvc>win32>-Od #
|
||||||
|
compiler>debug>msvc>win32>-Zi #
|
||||||
|
compiler>debug>msvc>win32>-DDEBUG=1 #
|
||||||
|
# compiler>debug>msvc>win32>-DPRINT_ASSERTS=1
|
||||||
|
|
||||||
|
debug>clang>-O0
|
||||||
|
debug>clang>-g
|
||||||
|
debug>compiler>-DDEBUG=1
|
||||||
|
|
||||||
|
debug>clang>-fsanitize=address
|
||||||
|
|
||||||
|
# Compiler: Prod
|
||||||
|
compiler>release>clang>-O3
|
||||||
|
|
||||||
|
################# LINKER #################
|
||||||
|
|
||||||
|
linker>output>osx>lumenarium
|
||||||
|
linker>output>win32>lumenarium.exe
|
||||||
|
|
||||||
|
linker>win32>-NOLOGO
|
||||||
|
linker>win32>-incremental:no
|
||||||
|
linker>win32>-subsystem:windows
|
||||||
|
linker>win32>-opt:ref # link time optimization - eliminate dead code
|
||||||
|
|
||||||
|
linker>wasm>--no-entry
|
||||||
|
linker>wasm>--export-dynamic
|
||||||
|
linker>wasm>--unresolved-symbols=import-functions
|
||||||
|
|
||||||
|
# TODO: I don't think the build system supports this right now
|
||||||
|
linker>raspi>-fuse-ld=lld
|
||||||
|
|
||||||
|
linker>debug>-debug
|
||||||
|
|
||||||
|
################# LIBRARIES #################
|
||||||
|
|
||||||
|
linker>libs>win32>user32.lib
|
||||||
|
linker>libs>win32>kernel32.lib
|
||||||
|
linker>libs>win32>gdi32.lib
|
||||||
|
linker>libs>win32>opengl32.lib
|
||||||
|
linker>libs>win32>winmm.lib
|
||||||
|
linker>libs>win32>gdi32.lib
|
||||||
|
linker>libs>win32>dsound.lib
|
||||||
|
linker>libs>win32>Ws2_32.lib
|
||||||
|
linker>libs>win32>Comdlg32.lib
|
||||||
|
linker>libs>win32>Winspool.lib
|
||||||
|
|
||||||
|
linker>libs>osx>-framework OpenGL
|
||||||
|
linker>libs>osx>-framework Cocoa
|
||||||
|
linker>libs>osx>-framework IOKit
|
||||||
|
linker>libs>osx>${SRC_DIR}/libs/glfw_osx/lib-universal/libglfw3.a
|
Loading…
Reference in New Issue