joeylib/scripts/build-IIgs.helper.sh
2021-06-14 17:55:25 -05:00

111 lines
3.3 KiB
Bash

# --- HERE BE DRAGONS ---
function buildIIgs() {
TARGET=${JOEY}/sdks/IIgs/ORCA/out/${PROJECT}
GSTARGET=31:/out/${PROJECT}
CADIUS=${JOEY}/sdks/IIgs/cadius/cadius
VOL=Import
WORK=/tmp/IIgs
IMPORT=${WORK}/import.po
# 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}
#***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 > ${PROJECT}.map
# Create a disassembly and linker input listing
iix dumpobj +D ${GSTARGET}/${PROJECT}#b3db03 &> ${PROJECT}.dis || true
echo ${OFILES} > ${PROJECT}.lnk
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
mkdir -p ${JOEY}/builds/${PROJECT}/IIgs/
cp ${IMPORT} ${JOEY}/builds/${PROJECT}/IIgs/${PROJECT}.po
# 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
}