382 lines
11 KiB
Bash
382 lines
11 KiB
Bash
#!/bin/bash
|
|
|
|
#
|
|
# JoeyBuild
|
|
# Copyright (C) 2018-2023 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.
|
|
#
|
|
|
|
|
|
M_IIGS="${G_EHOME}/cross/gsos-wdc-orca"
|
|
M_CADIUS="${M_IIGS}/cadius/cadius"
|
|
M_TARGET="${M_IIGS}/ORCA/out/build" # Target directory as seen by Linux
|
|
M_GSTARGET="31:/out/build" # Target directory as seen by Golden Gate
|
|
|
|
|
|
export GOLDEN_GATE=${M_IIGS}/ORCA
|
|
|
|
|
|
function architectures() {
|
|
echo "65816"
|
|
}
|
|
|
|
|
|
function assemble() {
|
|
local ARCH=$1
|
|
local PASS=$2
|
|
local LOG=$3
|
|
local AFILES=(${*:4})
|
|
local OFILES=""
|
|
local FILE=
|
|
local O=
|
|
|
|
setCompiler
|
|
|
|
# Assemble ASM files and generate object list.
|
|
for FILE in "${AFILES[@]}"; do
|
|
O=${FILE%.*}
|
|
OFILES="${OFILES} ${M_GSTARGET}/${O}"
|
|
iix assemble ${FILE} keep=${M_GSTARGET}/${O} >> ${LOG} 2>&1
|
|
done
|
|
|
|
unSetCompiler
|
|
|
|
echo ${OFILES}
|
|
}
|
|
|
|
|
|
function buildJoeyLib() {
|
|
local ARCH=$1
|
|
local PASS=$2
|
|
local OUT=${GOLDEN_GATE}/out/joey
|
|
|
|
setCompiler
|
|
|
|
rm -rf ${G_DIST}
|
|
mkdir -p ${G_DIST}
|
|
pushd ${G_DIST}
|
|
|
|
rm -rf ${OUT} || true
|
|
mkdir -p ${OUT}
|
|
|
|
pushd ${G_SRC}
|
|
if [[ "${PASS}" == "debug" ]]; then
|
|
# Add JOEY_DEBUG flag.
|
|
cp joey.h joey.h.original
|
|
sed -i "1i #define JOEY_DEBUG" joey.h
|
|
fi
|
|
|
|
iix assemble jIIgs.asm keep=31:/out/joey/jIIgsasm 1>&2
|
|
iix compile jIIgs.c keep=31:/out/joey/jIIgsc 1>&2
|
|
iix compile joey.c keep=31:/out/joey/joey 1>&2
|
|
|
|
if [[ "${PASS}" == "debug" ]]; then
|
|
# Remove JOEY_DEBUG.
|
|
rm joey.h
|
|
mv joey.h.original joey.h
|
|
fi
|
|
popd
|
|
|
|
cp -f "${OUT}/jIIgsc.root" "jIIgsc.root#b10000"
|
|
cp -f "${OUT}/jIIgsc.a" "jIIgsc.a#b10000"
|
|
cp -f "${OUT}/jIIgsasm.root" "jIIgsasm.root#b10000"
|
|
cp -f "${OUT}/jIIgsasm.a" "jIIgsasm.a#b10000"
|
|
cp -f "${OUT}/joey.a" "joey.a#b10000"
|
|
cp -f "${M_IIGS}/Tool222#ba0000" .
|
|
|
|
popd
|
|
|
|
unSetCompiler
|
|
}
|
|
|
|
|
|
function compile() {
|
|
local ARCH=$1
|
|
local PASS=$2
|
|
local LOG=$3
|
|
local CFILES=(${*:4})
|
|
local OFILES=""
|
|
local FILE=
|
|
local O=
|
|
|
|
setCompiler
|
|
|
|
rm -rf "${M_TARGET}" || true
|
|
mkdir -p "${M_TARGET}"
|
|
|
|
# Compile C files and generate object list.
|
|
for FILE in "${CFILES[@]}"; do
|
|
O=${FILE%.*}
|
|
OFILES="${OFILES} ${M_GSTARGET}/${O}"
|
|
iix compile ${FILE} keep=${M_GSTARGET}/${O} >> ${LOG} 2>&1
|
|
done
|
|
|
|
unSetCompiler
|
|
|
|
echo ${OFILES}
|
|
}
|
|
|
|
|
|
function enabled() {
|
|
echo 1
|
|
}
|
|
|
|
|
|
function friendlyName() {
|
|
echo "Apple IIgs"
|
|
}
|
|
|
|
|
|
function install() {
|
|
local ARCH=$1
|
|
local PASS=$2
|
|
local RESULT=
|
|
local O=
|
|
|
|
# We only need to do this once, so we ignore the debug pass.
|
|
if [[ "${PASS}" == "debug" ]]; then
|
|
return
|
|
fi
|
|
|
|
mkdir -p "${M_IIGS}/ORCA"
|
|
chmod 777 "${M_IIGS}/ORCA"
|
|
|
|
mkdir -p ${G_EHOME}/.ssh
|
|
cp -f "${CONFIG_GOLDEN_GATE_PUBLIC_KEY}" ${G_EHOME}/.ssh/id_rsa.pub
|
|
cp -f "${CONFIG_GOLDEN_GATE_PRIVATE_KEY}" ${G_EHOME}/.ssh/id_rsa
|
|
touch ${G_EHOME}/.ssh/authorized_keys
|
|
touch ${G_EHOME}/.ssh/known_hosts
|
|
touch ${G_EHOME}/.ssh/config
|
|
chmod go-w ${G_EHOME}
|
|
chmod 700 ${G_EHOME}/.ssh
|
|
chmod 600 ${G_EHOME}/.ssh/id_rsa
|
|
chmod 644 ${G_EHOME}/.ssh/id_rsa.pub
|
|
chmod 644 ${G_EHOME}/.ssh/authorized_keys
|
|
chmod 644 ${G_EHOME}/.ssh/known_hosts
|
|
chmod 644 ${G_EHOME}/.ssh/config
|
|
|
|
if [[ ! -e "${M_IIGS}/jfsDrive.img" ]]; then
|
|
O=${M_IIGS}/mountORCA.sh
|
|
echo "#!/bin/bash" > "${O}"
|
|
echo "IIGS=${M_IIGS}" >> "${O}"
|
|
echo "if ! mount | grep \${IIGS}/ORCA | grep -q jfs; then" >> "${O}"
|
|
echo -e "\tfsck.jfs -a \${IIGS}/jfsDrive.img" >> "${O}"
|
|
echo -e "\tsudo mount -t jfs \${IIGS}/jfsDrive.img \${IIGS}/ORCA" >> "${O}"
|
|
echo -e "\techo MOUNT=\${IIGS}/ORCA >> \${IIGS}/lastMount.cfg" >> "${O}"
|
|
echo "fi" >> "${O}"
|
|
chmod +x "${O}"
|
|
O=${M_IIGS}/unmountORCA.sh
|
|
echo "#!/bin/bash" > "${O}"
|
|
echo "IIGS=${M_IIGS}" >> "${O}"
|
|
echo "if [[ -e \${IIGS}/lastMount.cfg ]]; then" >> "${O}"
|
|
echo -e "\tsource \${IIGS}/lastMount.cfg" >> "${O}"
|
|
echo -e "\tsudo umount \${MOUNT}" >> "${O}"
|
|
echo -e "\trm \${IIGS}/lastMount.cfg" >> "${O}"
|
|
echo "fi" >> "${O}"
|
|
chmod +x "${O}"
|
|
fallocate -l 32M "${M_IIGS}/jfsDrive.img"
|
|
mkfs.jfs -O -q -L IIgs "${M_IIGS}/jfsDrive.img"
|
|
fi
|
|
|
|
"${M_IIGS}/mountORCA.sh"
|
|
tSudo chown $(id -ru):$(id -rg) "${M_IIGS}/ORCA/."
|
|
|
|
if [[ ! -d GoldenGate ]]; then
|
|
ssh-keygen -F gitlab.com || ssh-keyscan gitlab.com > ${G_EHOME}/.ssh/known_hosts
|
|
git config --global credential.helper cache
|
|
git clone https://${CONFIG_GOLDEN_GATE_USER_NAME}:${CONFIG_GOLDEN_GATE_PASSWORD}@gitlab.com/GoldenGate/GoldenGate.git
|
|
fi
|
|
|
|
if [[ ! -f "${M_IIGS}/iix" ]]; then
|
|
pushd GoldenGate
|
|
git submodule init
|
|
git submodule update
|
|
mkdir -p build
|
|
cd build
|
|
cmake -DCMAKE_INSTALL_PREFIX=$(pwd)/installed .. 1>&2
|
|
make 1>&2
|
|
make install 1>&2
|
|
mkdir -p ${M_IIGS}
|
|
cp -f bin/{iix,dumpobj,opus-extractor} "${M_IIGS}/."
|
|
cd installed
|
|
msiextract "${G_EHOME}/${CONFIG_GOLDEN_GATE_MSI}"
|
|
find -name ".*" -delete
|
|
cp -rf GoldenGate/* "${M_IIGS}/ORCA/."
|
|
popd
|
|
fi
|
|
|
|
isoinfo -i "${CONFIG_OPUS_SOFTWARE_ISO}" -x /FOR_EMUL/BYTEWORK.S\;1 > BYTEWORKS
|
|
"${M_IIGS}/opus-extractor" -v BYTEWORKS "${M_IIGS}/ORCA"
|
|
rm BYTEWORKS
|
|
|
|
tFetchGitHubRelease RESULT byteworksinc ORCA-C 2mg
|
|
"${M_IIGS}/opus-extractor" -v -s / ${RESULT} "${M_IIGS}/ORCA"
|
|
|
|
export PATH=${G_ORIGINAL_PATH}:${M_IIGS}
|
|
pushd ${GOLDEN_GATE}
|
|
for O in etc/* ; do iix chtyp -t txt "${O}" ; done
|
|
for O in lib/* ; do if [ -f "${O}" ] ; then iix chtyp -t lib "${O}" ; fi ; done
|
|
for O in usr/lib/lib* ; do iix chtyp -t lib "${O}" ; done
|
|
for O in usr/lib/tmac/* ; do iix chtyp -t txt "${O}" ; done
|
|
for O in bin/* ; do iix chtyp -t exe "${O}" ; done
|
|
for O in usr/bin/* ; do iix chtyp -t exe "${O}" ; done
|
|
for O in usr/local/bin/* ; do iix chtyp -t exe "${O}" ; done
|
|
for O in Languages/* ; do if [ -f "${O}" ] ; then iix chtyp -t exe "${O}" ; fi ; done ;
|
|
for O in Utilities/Help/* ; do if [ -f "${O}" ] ; then iix chtyp -t txt "${O}" ; fi ; done ;
|
|
for O in Utilities/* ; do if [ -f "${O}" ] ; then iix chtyp -t exe "${O}" ; fi ; done ;
|
|
for O in Libraries/* ; do if [ -f "${O}" ] ; then iix chtyp -t lib "${O}" ; fi ; done ;
|
|
for O in Libraries/AInclude/* ; do if [ -f "${O}" ] ; then iix chtyp -t txt "${O}" ; fi ; done ;
|
|
for O in Libraries/APWCInclude/* ; do if [ -f "${O}" ] ; then iix chtyp -t txt "${O}" ; fi ; done ;
|
|
for O in Libraries/AppleUtil/* ; do if [ -f "${O}" ] ; then iix chtyp -t txt "${O}" ; fi ; done ;
|
|
for O in Libraries/ORCACDefs/* ; do if [ -f "${O}" ] ; then iix chtyp -l cc "${O}" ; fi ; done ;
|
|
for O in Libraries/ORCAInclude/* ; do if [ -f "${O}" ] ; then iix chtyp -l asm "${O}" ; fi ; done ;
|
|
for O in Libraries/RInclude/* ; do if [ -f "${O}" ] ; then iix chtyp -l rez "${O}" ; fi ; done ;
|
|
for O in Libraries/Tool.Interface/* ; do if [ -f "${O}" ] ; then iix chtyp -l pascal "${O}" ; fi ; done ;
|
|
for O in Libraries/GSoftDefs/* ; do if [ -f "${O}" ] ; then iix chtyp -t 0x5e -a 0x8007 "${O}" ; fi ; done ;
|
|
for O in Libraries/ORCAPascalDefs/* ; do if [ -f "${O}" ] ; then iix chtyp -t 0x5e -a 0x8009 "${O}" ; fi ; done ;
|
|
for O in Libraries/m2defs/* ; do if [ -f "${O}" ] ; then iix chtyp -t 0x5e -a 0x8006 "${O}" ; fi ; done ;
|
|
popd
|
|
export PATH=${G_ORIGINAL_PATH}
|
|
|
|
if [[ ! -d cadius ]]; then
|
|
git clone https://skunkworks.kangaroopunch.com/mirrors/cadius.git
|
|
pushd cadius
|
|
make 1>&2
|
|
mkdir -p "${M_IIGS}/cadius"
|
|
cp -f bin/release/cadius "${M_IIGS}/cadius/."
|
|
popd
|
|
fi
|
|
|
|
if [[ ! -e "${M_IIGS}/ntpconverter/ntpconverter.php" ]]; then
|
|
tDownload http://ninjaforce.com/downloads/ntpsources.zip
|
|
unzip ntpsources.zip ntpconverter*
|
|
mkdir -p "${M_IIGS}/ntpconverter"
|
|
mv -f ntpconverter*.php "${M_IIGS}/ntpconverter/."
|
|
fi
|
|
|
|
if [[ ! -e "${M_IIGS}/Tool222#ba0000" ]]; then
|
|
tDownload http://www.ninjaforce.com/downloads/ninjatrackerplus_tool222_v1.4.2mg
|
|
"${M_CADIUS}" extractfile ninjatrackerplus_tool222_v1.4.2mg NTP.TOOL222V1.4/SYSTEM/TOOLS/TOOL222 .
|
|
cp -f "TOOL222#BA0000" "${M_IIGS}/Tool222#ba0000"
|
|
fi
|
|
|
|
"${M_IIGS}/unmountORCA.sh"
|
|
|
|
if [[ ! -e "${M_IIGS}/jfsDrive.img.backup.tar.bz2" ]]; then
|
|
tar cjf "${M_IIGS}/jfsDrive.img.backup.tar.bz2" "${M_IIGS}/jfsDrive.img"
|
|
fi
|
|
}
|
|
|
|
|
|
function link() {
|
|
local ARCH=$1
|
|
local PASS=$2
|
|
local LOG=$3
|
|
local OFILES=(${*:4})
|
|
local LIB="${G_EHOME}/dist/IIgs-65816/${PASS}"
|
|
|
|
setCompiler
|
|
|
|
# We need a local copy of JoeyLib to link.
|
|
cp -f "${LIB}/jIIgsc.a#b10000" "${M_TARGET}/jIIgsc.a"
|
|
cp -f "${LIB}/jIIgsc.root#b10000" "${M_TARGET}/jIIgsc.root"
|
|
cp -f "${LIB}/jIIgsasm.a#b10000" "${M_TARGET}/jIIgsasm.a"
|
|
cp -f "${LIB}/jIIgsasm.root#b10000" "${M_TARGET}/jIIgsasm.root"
|
|
cp -f "${LIB}/joey.a#b10000" "${M_TARGET}/joey.a"
|
|
iix chtyp -t obj ${M_GSTARGET}/jIIgsc.a
|
|
iix chtyp -t obj ${M_GSTARGET}/jIIgsc.root
|
|
iix chtyp -t obj ${M_GSTARGET}/jIIgsasm.a
|
|
iix chtyp -t obj ${M_GSTARGET}/jIIgsasm.root
|
|
iix chtyp -t obj ${M_GSTARGET}/joey.a
|
|
|
|
# Add our library files to OFILES
|
|
OFILES+=("${M_GSTARGET}/jIIgsc ${M_GSTARGET}/joey ${M_GSTARGET}/jIIgsasm")
|
|
|
|
# Link.
|
|
iix -DKeepType=S16 link ${OFILES[@]} keep=${M_GSTARGET}/${G_BUILD_PROJECT}#b3db03 >> ${LOG} 2>&1
|
|
|
|
rm -f *.sym || true
|
|
|
|
unSetCompiler
|
|
}
|
|
|
|
|
|
function package() {
|
|
local ARCH=$1
|
|
local PASS=$2
|
|
local LOG=$3
|
|
local DFILES=(${*:4})
|
|
local DIR=${G_BUILD_RESULTS}/IIgs-65816/${PASS}
|
|
local DISK=${DIR}/${G_BUILD_PROJECT}.po
|
|
local LIB="${G_EHOME}/dist/IIgs-65816/${PASS}"
|
|
local FILE=
|
|
local O=
|
|
local EXTENSION=
|
|
|
|
setCompiler
|
|
|
|
mkdir -p ${DIR}
|
|
|
|
#***TODO*** Maybe copy source code for everything to the disk in DEBUG so there are symbols to view?
|
|
|
|
# Create disk image, setting known file types
|
|
${M_CADIUS} createvolume ${DISK} ${G_BUILD_PROJECT} 32MB
|
|
${M_CADIUS} createfolder ${DISK} ${G_BUILD_PROJECT}/data
|
|
${M_CADIUS} addfile ${DISK} ${G_BUILD_PROJECT} ${M_TARGET}/${G_BUILD_PROJECT}#b3db03
|
|
${M_CADIUS} addfile ${DISK} ${G_BUILD_PROJECT}/data ${LIB}/Tool222#ba0000
|
|
|
|
# Copy game data.
|
|
for FILE in "${DFILES[@]}"; do
|
|
# Data conversion.
|
|
EXTENSION="${FILE##*.}"
|
|
case ${EXTENSION,,} in
|
|
mod)
|
|
php "${M_IIGS}/ntpconverter/ntpconverter.php" "${FILE}"
|
|
O=${M_TARGET}/$(basename -s .mod ${FILE}).ntp#060000
|
|
mv -f ${FILE} ${O}
|
|
${M_CADIUS} addfile ${DISK} ${G_BUILD_PROJECT}/data ${O}
|
|
rm ${O}
|
|
;;
|
|
|
|
*)
|
|
O=${M_TARGET}/$(basename ${FILE})#060000
|
|
cp -f ${FILE} ${O}
|
|
${M_CADIUS} addfile ${DISK} ${G_BUILD_PROJECT}/data ${O}
|
|
rm ${O}
|
|
;;
|
|
esac
|
|
done
|
|
|
|
unSetCompiler
|
|
}
|
|
|
|
|
|
function setCompiler() {
|
|
export PATH=${G_ORIGINAL_PATH}:${M_IIGS}
|
|
# Be sure we can silently sudo. (Not tSudo - for mountORCA)
|
|
tSudo
|
|
"${M_IIGS}/mountORCA.sh" &> /dev/null
|
|
}
|
|
|
|
|
|
function unSetCompiler() {
|
|
# Be sure we can silently sudo. (Not tSudo - for unmountORCA)
|
|
tSudo
|
|
"${M_IIGS}/unmountORCA.sh" &> /dev/null
|
|
export PATH=${G_ORIGINAL_PATH}
|
|
}
|