joeylib/scripts/build-IIgs.helper.sh
2021-09-16 18:35:59 -05:00

153 lines
4.6 KiB
Bash

#
# JoeyLib
# Copyright (C) 2018-2019 Scott Duensing <scott@kangaroopunch.com>
#
# 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.
#
# --- HERE BE DRAGONS ---
function buildIIgs() {
TARGET=${JOEY}/sdks/IIgs/ORCA/out/${PROJECT}
GSTARGET=31:/out/${PROJECT}
CADIUS=${JOEY}/sdks/IIgs/cadius/cadius
VOL=${PROJECT}
WORK=/tmp/IIgs
IMPORT=${WORK}/import.po
DEBUG=.
# Clean up target and working directories
if [ -d ${TARGET} ]; then
rm -rf ${TARGET}
fi
mkdir -p ${TARGET}
if [ -d ${WORK} ]; then
rm -rf ${WORK}
fi
mkdir -p ${WORK}
# Where to put debugging information?
if [[ ! -z ${RESULTS} ]]; then
mkdir ${RESULTS}/IIgs
DEBUG=${RESULTS}/IIgs
fi
#***TODO*** Add image and music conversion.
# Automatically copy converted images, stencils, and audio so they
# no longer need to be specified in the build script.
# We temporarily need a local copy of the joey header
cp -f ${JOEY}/dist/joey.h .
# Make a list of files to compile, iterate over them
CFILES=($(ls -1 *.c))
OFILES=""
for F in "${CFILES[@]}"; do
O=${F%.*}
OFILES="${OFILES} ${GSTARGET}/${O}"
echo "Compiling ${F}..."
iix compile ${F} keep=${GSTARGET}/${O}
done
# Clean up
rm joey.h
echo "Linking ${PROJECT}..."
# We need a local copy of joeylib to link
cp -f ${JOEY}/dist/IIgs/jIIgsc.a#b10000 ${TARGET}/jIIgsc.a
cp -f ${JOEY}/dist/IIgs/jIIgsc.root#b10000 ${TARGET}/jIIgsc.root
cp -f ${JOEY}/dist/IIgs/jIIgsasm.a#b10000 ${TARGET}/jIIgsasm.a
cp -f ${JOEY}/dist/IIgs/jIIgsasm.root#b10000 ${TARGET}/jIIgsasm.root
cp -f ${JOEY}/dist/IIgs/joey.a#b10000 ${TARGET}/joey.a
iix chtyp -t obj ${GSTARGET}/jIIgsc.a
iix chtyp -t obj ${GSTARGET}/jIIgsc.root
iix chtyp -t obj ${GSTARGET}/jIIgsasm.a
iix chtyp -t obj ${GSTARGET}/jIIgsasm.root
iix chtyp -t obj ${GSTARGET}/joey.a
# Add our library files to OFILES
OFILES="${GSTARGET}/jIIgsc ${GSTARGET}/joey ${GSTARGET}/jIIgsasm ${OFILES}"
# Link our program and create a map file
iix -DKeepType=S16 link +L ${OFILES} keep=${GSTARGET}/${PROJECT}#b3db03 > ${DEBUG}/${PROJECT}.map
# Create a disassembly and linker input listing
iix dumpobj +D ${GSTARGET}/${PROJECT}#b3db03 &> ${DEBUG}/${PROJECT}.dis || true
echo ${OFILES} > ${DEBUG}/${PROJECT}.lnk
# Clean up SYM files
CFILES=($(ls -1 *.c))
for F in "${CFILES[@]}"; do
O=${F%.*}.sym
if [[ -e ${O} ]]; then
rm ${O}
fi
done
echo "Creating disk image..."
# Be sure our work directories exists
mkdir -p ${WORK}/{data,source}
# Create disk image, setting known file types
${CADIUS} createvolume ${IMPORT} ${VOL} 32MB > /dev/null
${CADIUS} createfolder ${IMPORT} ${VOL}/data > /dev/null
${CADIUS} addfile ${IMPORT} ${VOL} ${TARGET}/${PROJECT}#b3db03 > /dev/null
${CADIUS} addfile ${IMPORT} ${VOL}/data ${JOEY}/dist/IIgs/Tool035#ba0000 > /dev/null
${CADIUS} addfile ${IMPORT} ${VOL}/data ${JOEY}/dist/IIgs/Tool222#ba0000 > /dev/null
for F in "${DATA[@]}"; do
N=${WORK}/data/`basename ${F}`#060000
cp -f ${F} ${N}
${CADIUS} addfile ${IMPORT} ${VOL}/data ${N} > /dev/null
rm ${N}
done
# If they asked for source to be copied to the image, copy it and set the type
for S in "${SOURCE[@]}"; do
for F in `ls -1 ${S}`; do
tr "\n" "\r" < ${F} > ${WORK}/source/${F}#040000
${CADIUS} addfile ${IMPORT} ${VOL} ${F}#040000 > /dev/null
rm ${WORK}/source/${F}#040000
done
done
if [[ -z ${RESULTS} ]]; then
mkdir -p ${JOEY}/builds/${PROJECT}/IIgs/
cp ${IMPORT} ${JOEY}/builds/${PROJECT}/IIgs/${PROJECT}.po
else
cp ${IMPORT} ${RESULTS}/IIgs/${PROJECT}.po
fi
# Did they ask for GSPlus to be executed?
if [ ! -z $1 ]; then
# Launch GSPlus
pushd ${JOEY}/sdks/IIgs/gsplus
./GSplus -resizeable -config IIgsTest.cfg || true
popd
# Extract and display the results of the run
${CADIUS} extractfile ${IMPORT} ${VOL}/JLSTATS ${WORK}/. > /dev/null
if [ -e ${WORK}/JLSTATS#040000 ]; then
echo ""
cat ${WORK}/JLSTATS#040000 | tr "\r" "\n" 2> /dev/null
echo ""
fi
fi
}