joeylib/joeylib/build.sh

284 lines
8.3 KiB
Bash
Executable file

#!/bin/bash -e
#
# 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.
#
# Amiga
# https://github.com/bebbo/amiga-gcc
# m68k-amigaos-gcc -idirafter /home/scott/joey/sdks/amiga/m68k-amigaos/sys-include/machine -c ../src/joey.c
# m68k-amigaos-gcc -idirafter /home/scott/joey/sdks/amiga/m68k-amigaos/sys-include/machine -c ../src/jAmiga.c
# m68k-amigaos-ar rcs libjoeylib.a *.o
# ST
# http://tho-otto.de/crossmint.php
# https://github.com/pmandin/cleancode
# wget http://tho-otto.de/download/mint/m68k-atari-mint-base-20190606-linux.tar.xz
# xz -d m68k-atari-mint-base-20190606-linux.tar.xz
# tar --strip-components=1 -xf ../../stuff/m68k-atari-mint-base-20190606-linux.tar
# m68k-atari-mint-gcc -c ../src/joey.c
# m68k-atari-mint-gcc -c ../src/jST.c
# m68k-atari-ar rcs libjoeylib.a *.o
# 68k Mac
# https://github.com/autc04/Retro68
# Win16
# http://blog.ssokolow.com/archives/2017/10/19/useful-info-on-win16-targeting-compilers-and-a-list-of-resources/
# https://github.com/open-watcom/open-watcom-v2
# ./setup -i -dDstDir=/opt/watcom -dFullCDInstall=1
# DOS
# https://github.com/open-watcom/open-watcom-v2
# OS/2
# https://github.com/open-watcom/open-watcom-v2
SRC="${JOEY}/joeylib/joeylib/src"
BUILD="${JOEY}/joeylib/joeylib/build"
OUT="${JOEY}/sdks/IIgs/ORCA/out/joey"
DEPS="${JOEY}/sdks"
function clearBuild() {
if [[ -d "${BUILD}" ]]; then
rm -rf "${BUILD}"
fi
}
function createBuildAndDist() {
clearBuild
mkdir -p "${BUILD}"
if [[ -d "${DIST}" ]]; then
rm -rf "${DIST}"
fi
mkdir -p "${DIST}"
}
function doIIgsBuild() {
local CADIUS="${JOEY}/sdks/IIgs/cadius/cadius"
local IMPORT="/tmp/IIgs/import.po"
local VOL=Import
local RUNTEST=$1
echo "*** Starting ${DIST}"
if [[ -d "${OUT}" ]]; then
rm -rf "${OUT}"
fi
mkdir -p "${OUT}"
if [[ -d "${DIST}" ]]; then
rm -rf "${DIST}"
fi
mkdir -p "${DIST}"
pushd "${SRC}"
iix assemble +L jIIgs.asm keep=31:/out/joey/jIIgsasm > jIIgs.asm.dis
iix compile jIIgs.c keep=31:/out/joey/jIIgsc
iix compile joey.c keep=31:/out/joey/joey
iix compile test.c keep=31:/out/joey/test
iix -DKeepType=S16 link +L 31:/out/joey/jIIgsc 31:/out/joey/joey 31:/out/joey/jIIgsasm 31:/out/joey/test keep=31:/out/joey/test > test.map
iix dumpobj +D 31:/out/joey/test &> test.dis || true
php "${JOEY}/sdks/IIgs/ntpconverter/ntpconverter.php" *.mod
popd
cp -f "${OUT}/jIIgsc.root" "${DIST}/jIIgsc.root#b10000"
cp -f "${OUT}/jIIgsc.a" "${DIST}/jIIgsc.a#b10000"
cp -f "${OUT}/jIIgsasm.root" "${DIST}/jIIgsasm.root#b10000"
cp -f "${OUT}/jIIgsasm.a" "${DIST}/jIIgsasm.a#b10000"
cp -f "${OUT}/joey.a" "${DIST}/joey.a#b10000"
cp -f "${JOEY}/sdks/IIgs/Tool035#ba0000" "${JOEY}/dist/IIgs/."
cp -f "${JOEY}/sdks/IIgs/Tool222#ba0000" "${JOEY}/dist/IIgs/."
cp -f "${JOEY}/joeylib/scripts/build-IIgs.helper.sh" "${JOEY}/dist/."
if [[ ! -z ${RUNTEST} ]]; then
mkdir -p `dirname ${IMPORT}`
rm "/tmp/IIgs/JLSTATS#040000" 2> /dev/null || true
rm "${IMPORT}" 2> /dev/null || true
cp "${OUT}/test" "${OUT}/Test#b3db03"
cp "${JOEY}/joeylib/joeylib/src/kanga.img" "${OUT}/kanga.img#060000"
cp "${JOEY}/joeylib/joeylib/src/font.img" "${OUT}/font.img#060000"
cp "${JOEY}/joeylib/joeylib/src/font.stn" "${OUT}/font.stn#060000"
cp "${JOEY}/joeylib/joeylib/src/biff.img" "${OUT}/biff.img#060000"
cp "${JOEY}/joeylib/joeylib/src/biff.stn" "${OUT}/biff.stn#060000"
cp "${JOEY}/joeylib/joeylib/src/music.ntp" "${OUT}/music.ntp#D50008"
"${CADIUS}" createvolume "${IMPORT}" ${VOL} 32MB > /dev/null
"${CADIUS}" createfolder "${IMPORT}" ${VOL}/data > /dev/null
"${CADIUS}" addfile "${IMPORT}" ${VOL} "${OUT}/Test#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
"${CADIUS}" addfile "${IMPORT}" ${VOL}/data "${OUT}/kanga.img#060000" > /dev/null
"${CADIUS}" addfile "${IMPORT}" ${VOL}/data "${OUT}/font.img#060000" > /dev/null
"${CADIUS}" addfile "${IMPORT}" ${VOL}/data "${OUT}/font.stn#060000" > /dev/null
"${CADIUS}" addfile "${IMPORT}" ${VOL}/data "${OUT}/biff.img#060000" > /dev/null
"${CADIUS}" addfile "${IMPORT}" ${VOL}/data "${OUT}/biff.stn#060000" > /dev/null
"${CADIUS}" addfile "${IMPORT}" ${VOL}/data "${OUT}/music.ntp#D50008" > /dev/null
pushd "${JOEY}/sdks/IIgs/gsplus"
./GSplus -resizeable -config IIgsTest.cfg || true
popd
echo ""
"${CADIUS}" extractfile "${IMPORT}" ${VOL}/JLSTATS /tmp/IIgs/. > /dev/null
if [[ -e "/tmp/IIgs/JLSTATS#040000" ]]; then
echo ""
cat "/tmp/IIgs/JLSTATS#040000" | tr "\r" "\n" 2> /dev/null
echo ""
fi
fi
}
function doPCBuild() {
local G_CFLAGS="-Wall -D_REENTRANT_ -I${SRC} -I${INSTALLED}/include -c"
echo "*** Starting ${DIST}"
createBuildAndDist
pushd "${BUILD}"
"${CC}" ${CFLAGS} ${G_CFLAGS} -o jSDL2.o "${SRC}/jSDL2.c"
"${CC}" ${CFLAGS} ${G_CFLAGS} -o joey.o "${SRC}/joey.c"
ar x "${INSTALLED}/lib/libSDL2.a"
ar x "${INSTALLED}/lib/libSDL2_mixer.a"
ar x "${INSTALLED}/lib/libmodplug.a"
ar rcs "${DIST}/libjoeylib.a" *.o
popd
cp -f "${JOEY}/joeylib/joeylib/joey.pri" "${JOEY}/dist/."
cp -f "${JOEY}/joeylib/scripts/build-PC.helper.sh" "${JOEY}/dist/."
clearBuild
#***TODO*** Add optional test app execution for Windows (WINE) and Linux here - maybe even a macOS VM
}
ARCH=$1
TEST=$2
if [[ "${ARCH}x" == "x" ]]; then
echo "$0 [arch | \"all\"]"
echo '(Where "arch" is amiga, iigs, linux32, linux64, macos32, macos64, st, windows32, or windows64.)'
exit 0
fi
if [[ "${ARCH}x" == "allx" || "${ARCH}x" == "amigax" ]]; then
DIST="${JOEY}/dist/amiga"
echo "*** Starting ${DIST}"
createBuildAndDist
pushd "${BUILD}"
m68k-amigaos-gcc -c "${SRC}/joey.c"
m68k-amigaos-gcc -c "${SRC}/jAmiga.c"
m68k-amigaos-ar rcs "${DIST}/libjoeylib.a" *.o
popd
clearBuild
#***TODO*** Emulator
fi
if [[ "${ARCH}x" == "allx" || "${ARCH}x" == "iigsx" ]]; then
DIST="${JOEY}/dist/IIgs"
doIIgsBuild ${TEST}
fi
if [[ "${ARCH}x" == "allx" || "${ARCH}x" == "linux64x" ]]; then
CC="gcc"
CFLAGS=""
LDFLAGS=""
DIST="${JOEY}/dist/linux/x64"
INSTALLED="${DEPS}/linux/x64"
doPCBuild
fi
if [[ "${ARCH}x" == "allx" || "${ARCH}x" == "linux32x" ]]; then
CC="gcc"
CFLAGS="-m32"
LDFLAGS=""
DIST="${JOEY}/dist/linux/i386"
INSTALLED="${DEPS}/linux/i386"
doPCBuild
fi
if [[ "${ARCH}x" == "allx" || "${ARCH}x" == "macos32x" ]]; then
CC="o32-clang"
CFLAGS=""
LDFLAGS=""
DIST="${JOEY}/dist/macOS/i386"
INSTALLED="${DEPS}/macOS/i386"
doPCBuild
fi
if [[ "${ARCH}x" == "allx" || "${ARCH}x" == "macos64x" ]]; then
CC="o64-clang"
CFLAGS=""
LDFLAGS=""
DIST="${JOEY}/dist/macOS/x64"
INSTALLED="${DEPS}/macOS/x64"
doPCBuild
fi
if [[ "${ARCH}x" == "allx" || "${ARCH}x" == "stx" ]]; then
DIST="${JOEY}/dist/st"
echo "*** Starting ${DIST}"
createBuildAndDist
pushd "${BUILD}"
m68k-atari-mint-gcc -c "${SRC}/joey.c"
m68k-atari-mint-gcc -c "${SRC}/jST.c"
m68k-atari-mint-ar x "${DEPS}/st/lib/libSDL.a"
m68k-atari-mint-ar x "${DEPS}/st/lib/libSDL_mixer.a"
m68k-atari-mint-ar x "${DEPS}/st/lib/libmikmod.a"
m68k-atari-mint-ar rcs "${DIST}/libjoeylib.a" *.o
popd
clearBuild
#***TODO***
#hatari -c "${JOEY}/sdks/st/hatari.cfg" -d out/
fi
if [[ "${ARCH}x" == "allx" || "${ARCH}x" == "windows64x" ]]; then
CC="x86_64-w64-mingw32-gcc"
CFLAGS=""
LDFLAGS=""
DIST="${JOEY}/dist/windows/x64"
INSTALLED="${DEPS}/windows/x64"
doPCBuild
fi
if [[ "${ARCH}x" == "allx" || "${ARCH}x" == "windows32x" ]]; then
CC="i686-w64-mingw32-gcc"
CFLAGS=""
LDFLAGS=""
DIST="${JOEY}/dist/windows/i386"
INSTALLED="${DEPS}/windows/i386"
doPCBuild
fi
mkdir -p "${JOEY}/dist"
cp -f "${SRC}/joey.h" "${JOEY}/dist/."