#!/bin/bash # # JoeyBuild # Copyright (C) 2018-2023 Scott Duensing # # This software is provided 'as-is', without any express or implied # warranty. In no event will the authors be held liable for any damages # arising from the use of this software. # # Permission is granted to anyone to use this software for any purpose, # including commercial applications, and to alter it and redistribute it # freely, subject to the following restrictions: # # 1. The origin of this software must not be misrepresented; you must not # claim that you wrote the original software. If you use this software # in a product, an acknowledgment in the product documentation would be # appreciated but is not required. # 2. Altered source versions must be plainly marked as such, and must not be # misrepresented as being the original software. # 3. This notice may not be removed or altered from any source distribution. # M_TRIPLE= source ${G_EHOME}/helpers/SDL2.helper source ${G_EHOME}/helpers/GCC.helper function architectures() { echo "i386 x86_64 aarch64" } function assemble() { local ARCH=$1 local PASS=$2 local LOG=$3 local AFILES=(${*:4}) setCompiler ${ARCH} ${PASS} assembleGCC ${ARCH} ${PASS} ${LOG} "${AFILES[@]}" unSetCompiler } function buildJoeyLib() { local ARCH=$1 local PASS=$2 export CFLAGS="-Wall -D_REENTRANT_ -I${G_INSTALLED}/include -c" export LDFLAGS="-lm -ldl -lpthread" if [[ "${PASS}" == "debug" ]]; then export CFLAGS="-DJOEY_DEBUG ${CFLAGS}" fi setCompiler ${ARCH} ${PASS} buildJoeyLibSDL2 ${PASS} unSetCompiler } function buildMacOSXToolchain() { local SDK=$1 local XCODE=$2 local PLATFORM=$3 if [[ ! -d osxcross ]]; then git clone https://skunkworks.kangaroopunch.com/mirrors/osxcross.git fi if [[ ! -f cross/${PLATFORM}/toolchain.cmake ]]; then pushd osxcross # Do we have an existing SDK tarball? if [[ ! -f "../${SDK}" ]]; then # Nope. Build tarball and keep for later. ./tools/gen_sdk_package_pbzx.sh "../${XCODE}" mv -f MacOSX* "../${SDK}" fi # Put tarball in place. cp -f "../${SDK}" tarballs/. # Build SDK. UNATTENDED=1 ./build.sh # Build compiler runtime. if [[ -d /usr/lib/llvm-10/lib/clang/10.0.0/lib/darwin ]]; then tSudo rm -rf /usr/lib/llvm-10/lib/clang/10.0.0/lib/darwin fi tSudo ENABLE_COMPILER_RT_INSTALL=1 ./build_compiler_rt.sh # Move results into cross compiler location. mkdir -p ../cross/${PLATFORM} mv -f target/* ../cross/${PLATFORM} tSudo mv -f /usr/lib/llvm-10/lib/clang/10.0.0/lib/darwin ../cross/${PLATFORM}/. # Tidy up for next build. ./cleanup.sh rm -f tarballs/* popd fi } function compile() { local ARCH=$1 local PASS=$2 local LOG=$3 local CFILES=(${*:4}) export CFLAGS="-Wall -D_THREAD_SAFE" setCompiler ${ARCH} ${PASS} compileGCC ${ARCH} ${PASS} ${LOG} "${CFILES[@]}" unSetCompiler } function enabled() { echo 1 } function friendlyName() { echo "Modern MacOS" } function install() { local ARCH=$1 local PASS=$2 # Debug is the first pass, so build our toolchains then. if [[ "${ARCH}" == "aarch64" ]]; then if [[ "${PASS}" == "debug" ]]; then buildMacOSXToolchain "${CONFIG_MACOS_SDK_11_3}" "${CONFIG_XCODE_12_5_1_XIP}" macos-apple fi SDL2_TAG=97a5e744497ff7cc93edc5119d67cad3ee86dd57 else if [[ "${PASS}" == "debug" ]]; then buildMacOSXToolchain "${CONFIG_MACOS_SDK_10_13}" "${CONFIG_XCODE_9_4_1_XIP}" macos-intel fi SDL2_TAG=25f9ed87ff6947d9576fc9d79dee0784e638ac58 fi setCompiler ${ARCH} ${PASS} buildSDL2 ${SDL2_TAG} ${M_TRIPLE} unSetCompiler } function link() { local ARCH=$1 local PASS=$2 local LOG=$3 local OFILES=(${*:4}) export CFLAGS="-Wall -D_THREAD_SAFE" if [[ "${ARCH}" == "aarch64" ]]; then export LDFLAGS="-lm -liconv -Wl,-framework,CoreAudio -Wl,-framework,AudioToolbox -Wl,-weak_framework,CoreHaptics -Wl,-weak_framework,GameController -Wl,-framework,ForceFeedback -lobjc -Wl,-framework,CoreVideo -Wl,-framework,Cocoa -Wl,-framework,Carbon -Wl,-framework,IOKit -Wl,-weak_framework,QuartzCore -Wl,-weak_framework,Metal" else export LDFLAGS="-lm -liconv -Wl,-framework,CoreAudio -Wl,-framework,AudioToolbox -Wl,-framework,ForceFeedback -lobjc -Wl,-framework,CoreVideo -Wl,-framework,Cocoa -Wl,-framework,Carbon -Wl,-framework,IOKit -Wl,-weak_framework,QuartzCore -Wl,-weak_framework,Metal" fi setCompiler ${ARCH} ${PASS} linkGCC MacOS ${ARCH} ${PASS} "" "" ${LOG} "${OFILES[@]}" unSetCompiler } function package() { local ARCH=$1 local PASS=$2 local LOG=$3 local DFILES=(${*:4}) packageGCC MacOS ${ARCH} ${PASS} ${LOG} "${DFILES[@]}" } function setCompiler() { local ARCH=$1 local PASS=$2 local CROSS= if [[ "${ARCH}" == "aarch64" ]]; then M_TRIPLE="${ARCH}-apple-darwin20.4" CROSS=macos-apple else M_TRIPLE="${ARCH}-apple-darwin17" CROSS=macos-intel fi export PATH=${G_EHOME}/cross/${CROSS}/bin:${G_ORIGINAL_PATH} export LD_LIBRARY_PATH=${G_EHOME}/cross/${CROSS}/lib tSudo ln -sf ${G_EHOME}/cross/${CROSS}/darwin/ /usr/lib/llvm-10/lib/clang/10.0.0/lib/. export CC=${M_TRIPLE}-clang export LD=${M_TRIPLE}-c++ export AR=${M_TRIPLE}-ar } function unSetCompiler() { export CC= export LD= export AR= export LD_LIBRARY_PATH= export PATH=${G_ORIGINAL_PATH} }