From 2605c7e82e092e8c479f33038b6ac326d5a8a4da Mon Sep 17 00:00:00 2001 From: Scott Duensing Date: Thu, 12 Jan 2023 21:31:03 -0600 Subject: [PATCH] Linux builds working. --- buildTest.sh | 2 +- helpers/GCC.helper | 111 ++++++++++++++++++++++++++++++++++++++ helpers/SDL2.helper | 5 ++ joeybuild.sh | 69 ++++++++++++------------ sampleProject/build.start | 3 ++ targets/IIgs.target | 2 +- targets/Linux.target | 46 +++++++++++++--- targets/MacOS.target | 6 +-- targets/Windows.target | 6 +-- 9 files changed, 202 insertions(+), 48 deletions(-) create mode 100644 helpers/GCC.helper diff --git a/buildTest.sh b/buildTest.sh index e62279e..0133a4a 100644 --- a/buildTest.sh +++ b/buildTest.sh @@ -14,4 +14,4 @@ tSudo chown -R test:test /home/test/build tSudo chmod ugo+rwx /home/test/build tSudo chmod ugo+rw /home/test/build/* -./joeybuild.sh build /home/test/build +./joeybuild.sh build test diff --git a/helpers/GCC.helper b/helpers/GCC.helper new file mode 100644 index 0000000..a27257d --- /dev/null +++ b/helpers/GCC.helper @@ -0,0 +1,111 @@ +#!/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. +# + + +function assembleGCC() { + local ARCH=$1 + local PASS=$2 + local LOG=$3 + local AFILES=(${*:4}) + local OFILES="" + local FILE= + local O= + + # Assemble ASM files and generate object list. + for FILE in "${AFILES[@]}"; do + O=${G_TEMP}/${FILE%.*} + OFILES="${OFILES} ${O}" + # as + #gcc -static -nostdlib -nostartfiles ${FILE} -o ${O} + done + + echo ${OFILES} +} + + +function compileGCC() { + local ARCH=$1 + local PASS=$2 + local LOG=$3 + local CFILES=(${*:4}) + local OFILES="" + local FILE= + local O= + + rm -rf "${G_TEMP}" || true + mkdir -p "${G_TEMP}" + + # Compile C files and generate object list. + for FILE in "${CFILES[@]}"; do + O=${G_TEMP}/$(basename ${FILE%.*}).o + OFILES="${OFILES} ${O}" + ${CC} ${CFLAGS} -c ${FILE} -o ${O} + done + + echo ${OFILES} +} + + +function linkGCC() { + local OS=$1 + local ARCH=$2 + local PASS=$3 + local EXT=$4 + local LOG=$5 + local OFILES=(${*:6}) + local LIB="${G_EHOME}/dist/${OS}-${ARCH}/${PASS}" + local DIR=${G_BUILD_RESULTS}/${OS}-${ARCH}/${PASS} + + mkdir -p ${DIR} + + ${LD} ${CFLAGS} -o ${DIR}/${G_BUILD_PROJECT}${EXT} ${OFILES[@]} ${LIB}/libjoeylib.a ${LDFLAGS} +} + + +function packageGCC() { + local OS=$1 + local ARCH=$2 + local PASS=$3 + local LOG=$4 + local DFILES=(${*:5}) + local DIR=${G_BUILD_RESULTS}/${OS}-${ARCH}/${PASS}/data + local FILE= + local O= + local EXTENSION= + + #***TODO*** Maybe copy source code for everything to the disk in DEBUG so there are symbols to view? + + mkdir -p ${DIR} + + # Copy game data. + for FILE in "${DFILES[@]}"; do + # Data conversion. + EXTENSION="${FILE##*.}" + case ${EXTENSION,,} in + *) + O=${DIR}/$(basename ${FILE}) + cp -f ${FILE} ${O} + ;; + esac + done +} diff --git a/helpers/SDL2.helper b/helpers/SDL2.helper index 6e07431..9c6a28f 100644 --- a/helpers/SDL2.helper +++ b/helpers/SDL2.helper @@ -23,10 +23,15 @@ function buildJoeyLibSDL2() { + local PASS=$1 + rm -rf ${G_DIST} mkdir -p ${G_DIST} pushd ${G_DIST} + if [[ "${PASS}" == "debug" ]]; then + ${CC} ${CFLAGS} -I${G_SRC}/3rdparty/memwatch -o memwatch.o ${G_SRC}/3rdparty/memwatch/memwatch.c + fi ${CC} ${CFLAGS} -o jPixBuf.o ${G_SRC}/jPixBuf.c ${CC} ${CFLAGS} -o jSDL2.o ${G_SRC}/jSDL2.c ${CC} ${CFLAGS} -o joey.o ${G_SRC}/joey.c diff --git a/joeybuild.sh b/joeybuild.sh index 9e24229..4881e97 100755 --- a/joeybuild.sh +++ b/joeybuild.sh @@ -94,7 +94,8 @@ function delBuildUser() { function doBuild() { - local SOURCE=$1 + local USERNAME=$1 + local SOURCE=/home/"${USERNAME}/build" local LINE= local FILE= local EXTENSION= @@ -109,8 +110,6 @@ function doBuild() { local PASS= local PROJECT_TYPE= - set -x - pushd "${SOURCE}" # Are there old results to clean up? @@ -169,6 +168,11 @@ function doBuild() { for TEMP in ${LINE}; do if [[ -z ${TARGET} ]]; then TARGET=${TEMP} + call RESULT ${TARGET} enabled + if [[ ${RESULT} -ne 1 ]]; then + # Target is not enabled, stop. + break + fi else for PASS in "debug" "release"; do tBoldBox tPURPLE "Building \"${G_BUILD_PROJECT}\" ${TARGET} ${TEMP} (${PASS})..." @@ -201,6 +205,27 @@ function doBuild() { done < build.start + # Compress the results. + tar cJf build.temp results + tSudo chown ${USERNAME}:${USERNAME} build.temp + + # Erase everything except the temp file. + rm -rf "${G_BUILD_RESULTS}" + for FILE in $(ls -1); do + if [[ -f "${FILE}" ]]; then + if [[ "${FILE}" != "build.temp" ]]; then + rm "${FILE}" + fi + else + if [[ -d "${FILE}" ]]; then + rm -r "${FILE}" + fi + fi + done + + # Signal JoeyDev we're done. + mv build.temp build.tar.bz2 + popd tTrim TEMP "${G_BUILD_PLATFORMS}" @@ -225,7 +250,7 @@ function doInstall() { # Start build server on reboot. if [[ ! -f /etc/rc.local ]]; then echo "#!/bin/bash" | tSudo tee /etc/rc.local > /dev/null - echo "cd ${G_HOME}" | tSudo tee -a /etc/rc.local > /dev/null + echo "cd ${G_EHOME}" | tSudo tee -a /etc/rc.local > /dev/null echo "sudo -u $(logname) ${BASH_SOURCE[0]} server &> /dev/null &" | tSudo tee -a /etc/rc.local > /dev/null echo "exit 0" | tSudo tee -a /etc/rc.local > /dev/null fi @@ -318,7 +343,7 @@ function startup() { #set +x tBoldBox tGREEN "${G_TITLE} Options" echo "${NAME} add USER PASS" - echo "${NAME} build SRC" + echo "${NAME} build USER" echo "${NAME} del USER" echo "${NAME} install" echo "${NAME} rebuild" @@ -338,7 +363,7 @@ function startBuildServer() { local USERNAME= local FILE= - cd ${G_HOME} + cd ${G_EHOME} # Log startup. echo "$(date) - Startup ${0}" >> "${LOG}" @@ -376,42 +401,18 @@ function startBuildServer() { chmod go-rwx "${USERNAME}/build" # Handle building JoeyLib Applications. - if [[ -f "${USERNAME}/build/build.application" ]]; then + if [[ -f "${USERNAME}/build/build.start" ]]; then # Are there old reults to clean up? if [[ -f build.tar.bz2 ]]; then rm build.tar.bz2 fi - doBuild /home/"${USERNAME}/build" + doBuild ${USERNAME} - pushd "${USERNAME}/build" + # Log it. + echo "$(date) - Compiled ${G_BUILD_PROJECT} for ${USERNAME} on ${G_BUILD_PLATFORMS}" >> joeybuild.log - # Compress the results. - tar cJf build.temp results - chown ${USERNAME}:${USERNAME} build.temp - - # Erase everything except the temp file. - rm -rf "${G_BUILD_RESULTS}" - for FILE in $(ls -1); do - if [[ -f "${FILE}" ]]; then - if [[ "${FILE}" != "build.temp" ]]; then - rm "${FILE}" - fi - else - if [[ -d "${FILE}" ]]; then - rm -r "${FILE}" - fi - fi - done - - # Signal JoeyDev we're done. - mv build.temp build.tar.bz2 - - # Log it. - echo "$(date) - Compiled ${G_BUILD_PROJECT} for ${USERNAME} on ${G_BUILD_PLATFORMS}" >> joeybuild.log - - popd fi done diff --git a/sampleProject/build.start b/sampleProject/build.start index c4f4878..4a35f5a 100644 --- a/sampleProject/build.start +++ b/sampleProject/build.start @@ -1,3 +1,6 @@ application Warehouse IIgs 65816 +Linux i386 x86_64 +Windows i686 x86_64 +MacOS i386 x86_64 aarch64 diff --git a/targets/IIgs.target b/targets/IIgs.target index a088c17..91507f8 100644 --- a/targets/IIgs.target +++ b/targets/IIgs.target @@ -133,7 +133,7 @@ function compile() { function enabled() { - echo 1 + echo 0 } diff --git a/targets/Linux.target b/targets/Linux.target index b1052ca..ff9aabc 100644 --- a/targets/Linux.target +++ b/targets/Linux.target @@ -26,7 +26,8 @@ M_SDL2_TAG=97a5e744497ff7cc93edc5119d67cad3ee86dd57 M_TRIPLE="x86_64-linux-gnu" -source helpers/SDL2.helper +source ${G_EHOME}/helpers/SDL2.helper +source ${G_EHOME}/helpers/GCC.helper function architectures() { @@ -35,10 +36,14 @@ function architectures() { function assemble() { - local -n AFILES=$1 + local ARCH=$1 local PASS=$2 local LOG=$3 + local AFILES=(${*:4}) + setCompiler ${ARCH} ${PASS} + assembleGCC ${ARCH} ${PASS} ${LOG} "${AFILES[@]}" + unSetCompiler } @@ -58,18 +63,33 @@ function buildJoeyLib() { fi setCompiler ${ARCH} ${PASS} - buildJoeyLibSDL2 + buildJoeyLibSDL2 ${PASS} unSetCompiler } function compile() { - local -n CFILES=$1 + local ARCH=$1 local PASS=$2 local LOG=$3 + local CFILES=(${*:4}) + setCompiler ${ARCH} ${PASS} + + if [[ "${ARCH}" == "i386" ]]; then + export CFLAGS="-m32 -Wall -D_REENTRANT_" + else + export CFLAGS="-Wall -D_REENTRANT_" + fi + + setCompiler ${ARCH} ${PASS} + compileGCC ${ARCH} ${PASS} ${LOG} "${CFILES[@]}" + unSetCompiler + + unSetCompiler } + function enabled() { echo 1 } @@ -94,18 +114,32 @@ function install() { function link() { - local -n OFILES=$1 + local ARCH=$1 local PASS=$2 local LOG=$3 + local OFILES=(${*:4}) + if [[ "${ARCH}" == "i386" ]]; then + export CFLAGS="-m32" + else + export CFLAGS= + fi + + export LDFLAGS="-lm -ldl -lpthread" + + setCompiler ${ARCH} ${PASS} + linkGCC Linux ${ARCH} ${PASS} "" ${LOG} "${OFILES[@]}" + unSetCompiler } function package() { - local -n DFILES=$1 + local ARCH=$1 local PASS=$2 local LOG=$3 + local DFILES=(${*:4}) + packageGCC Linux ${ARCH} ${PASS} ${LOG} "${DFILES[@]}" } diff --git a/targets/MacOS.target b/targets/MacOS.target index 8391726..ac832f5 100644 --- a/targets/MacOS.target +++ b/targets/MacOS.target @@ -25,7 +25,7 @@ M_TRIPLE= -source helpers/SDL2.helper +source ${G_EHOME}/helpers/SDL2.helper function architectures() { @@ -53,7 +53,7 @@ function buildJoeyLib() { fi setCompiler ${ARCH} ${PASS} - buildJoeyLibSDL2 + buildJoeyLibSDL2 ${PASS} unSetCompiler } @@ -95,7 +95,7 @@ function compile() { } function enabled() { - echo 1 + echo 0 } diff --git a/targets/Windows.target b/targets/Windows.target index 1ceb1f9..a2bf92f 100644 --- a/targets/Windows.target +++ b/targets/Windows.target @@ -26,7 +26,7 @@ M_SDL2_TAG=97a5e744497ff7cc93edc5119d67cad3ee86dd57 M_TRIPLE= -source helpers/SDL2.helper +source ${G_EHOME}/helpers/SDL2.helper function architectures() { @@ -54,7 +54,7 @@ function buildJoeyLib() { fi setCompiler ${ARCH} ${PASS} - buildJoeyLibSDL2 ${M_TRIPLE} + buildJoeyLibSDL2 ${PASS} unSetCompiler } @@ -67,7 +67,7 @@ function compile() { } function enabled() { - echo 1 + echo 0 }