# JoeyLib toolchain environment.
#
# Source this file before invoking make:
#   source toolchains/env.sh
#
# All build commands resolve cross-compilers and assemblers exclusively
# from toolchains/ regardless of what is installed on the host. The
# Makefiles reference these variables by name; never hardcode paths.

JOEY_TOOLCHAINS="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
export JOEY_TOOLCHAINS

# ------------------------------------------------------------------------
# IIgs (llvm-mos w65816: clang + llvm-mc + link816)
#
# LLVM816_ROOT is the toolchain root (clang / llvm-mc / link816 plus the
# prebuilt runtime + MAME + ROMs). clang-build.sh drives compile/assemble/
# link. It is vendored under toolchains/iigs/llvm-mos by install.sh -- a
# git clone of the 65816-llvm-mos repo with tools/ + runtime built via the
# repo's own setup.sh. Override LLVM816_ROOT to point at a different copy.
# ------------------------------------------------------------------------

: "${LLVM816_ROOT:=${JOEY_TOOLCHAINS}/iigs/llvm-mos}"
export LLVM816_ROOT
export IIGS_CLANG_BUILD="${JOEY_TOOLCHAINS}/iigs/clang-build.sh"
# merlin32 assembles the NinjaTrackerPlus audio replayer (third-party asm).
export IIGS_AS="${JOEY_TOOLCHAINS}/iigs/merlin32/bin/merlin32"
# Alias used by the top-level Makefile's HAVE_IIGS probe (`[ -x $IIGS_CC ]`).
export IIGS_CC="${IIGS_CLANG_BUILD}"

# ------------------------------------------------------------------------
# Amiga
# ------------------------------------------------------------------------

export AMIGA_PREFIX="${JOEY_TOOLCHAINS}/amiga/gcc"
export AMIGA_CC="${AMIGA_PREFIX}/bin/m68k-amigaos-gcc"
export AMIGA_AR="${AMIGA_PREFIX}/bin/m68k-amigaos-ar"
export AMIGA_LD="${AMIGA_PREFIX}/bin/m68k-amigaos-ld"
# vasm is invoked only for ptplayer.asm (third-party Devpac/vasm
# syntax). JoeyLib's own .s files are GAS syntax and go through
# AMIGA_CC -> m68k-amigaos-as (binutils, GPL) instead.
export AMIGA_AS="${JOEY_TOOLCHAINS}/amiga/vasm/bin/vasmm68k_mot"
export AMIGA_NDK="${AMIGA_PREFIX}/m68k-amigaos/sys-include"
export AMIGA_PTPLAYER="${JOEY_TOOLCHAINS}/amiga/ptplayer"

# ------------------------------------------------------------------------
# Atari ST
# ------------------------------------------------------------------------

export ST_PREFIX="${JOEY_TOOLCHAINS}/atarist/gcc"
export ST_CC="${ST_PREFIX}/bin/m68k-atari-mint-gcc"
export ST_AR="${ST_PREFIX}/bin/m68k-atari-mint-ar"
export ST_LD="${ST_PREFIX}/bin/m68k-atari-mint-ld"
# Atari ST .s files are GAS syntax and assembled via ST_CC ->
# m68k-atari-mint-as (binutils, GPL). No vasm dependency.

# ------------------------------------------------------------------------
# DOS
# ------------------------------------------------------------------------

export DOS_PREFIX="${JOEY_TOOLCHAINS}/dos/djgpp"
export DOS_CC="${DOS_PREFIX}/bin/i586-pc-msdosdjgpp-gcc"
export DOS_AR="${DOS_PREFIX}/bin/i586-pc-msdosdjgpp-ar"
export DOS_LD="${DOS_PREFIX}/bin/i586-pc-msdosdjgpp-ld"
# DJGPP's DOS-target utilities live under the i586-...-msdosdjgpp
# sysroot bin, not the host bin that holds the cross-gcc.
export DOS_STUBEDIT="${DOS_PREFIX}/i586-pc-msdosdjgpp/bin/stubedit"
export DOS_STUBIFY="${DOS_PREFIX}/i586-pc-msdosdjgpp/bin/stubify"
export DOS_EXE2COFF="${DOS_PREFIX}/i586-pc-msdosdjgpp/bin/exe2coff"
export DOS_AS="${JOEY_TOOLCHAINS}/dos/nasm/bin/nasm"
export DOS_CWSDPMI="${JOEY_TOOLCHAINS}/dos/cwsdpmi/bin/bin"
export DOS_CWSDSTUB="${DOS_CWSDPMI}/CWSDSTUB.EXE"
export DOS_EMBED_DPMI="${JOEY_TOOLCHAINS}/dos/embed-dpmi.sh"

# ------------------------------------------------------------------------
# PATH augmentation (in case sub-tools shell out unprefixed names)
# ------------------------------------------------------------------------

PATH="${AMIGA_PREFIX}/bin:${ST_PREFIX}/bin:${DOS_PREFIX}/bin:${JOEY_TOOLCHAINS}/iigs/merlin32/bin:${JOEY_TOOLCHAINS}/amiga/vasm/bin:${JOEY_TOOLCHAINS}/dos/nasm/bin:${PATH}"
export PATH
