# https://sourceforge.net/projects/acme-crossass/
ACME=acme

# https://github.com/mach-kernel/cadius
CADIUS=cadius

# note: flags set to decrunch backwards
EXOMIZER=exomizer mem -lnone -P23 -q

BUILDDIR=build
DISKVOLUME=ANCHORMAN
LOADER=$(BUILDDIR)/LOADER.SYSTEM\#FF2000
EXE=$(BUILDDIR)/ANCHORMAN\#064800
COMPRESSED1=src/AUXOBJ.6000.87FF.X
COMPRESSED2=src/OBJ.0800.47FF.X
COMPRESSED3=src/OBJ.6000.B8FF.X
SOURCES=$(wildcard src/*.a) $(COMPRESSED1) $(COMPRESSED2) $(COMPRESSED3)
RES=$(wildcard res/*) $(wildcard ../common/res/*)
BUILDDISK=$(BUILDDIR)/$(DISKVOLUME).po

.PHONY: clean mount all

$(BUILDDISK): $(EXE) $(LOADER) $(RES)

$(LOADER): $(SOURCES) | $(BUILDDIR)
	$(ACME) src/loader.a
	$(CADIUS) REPLACEFILE "$(BUILDDISK)" "/$(DISKVOLUME)/" "$(LOADER)" -C
	@touch "$@"

$(EXE): $(SOURCES) | $(BUILDDIR)
	$(ACME) src/anchorman.a
	$(CADIUS) REPLACEFILE "$(BUILDDISK)" "/$(DISKVOLUME)/" "$(EXE)" -C
	@touch "$@"

$(RES): $(BUILDDIR)
	$(CADIUS) REPLACEFILE "$(BUILDDISK)" "/$(DISKVOLUME)/" "$@" -C
	@touch "$@"

$(COMPRESSED1):
	$(EXOMIZER) src/AUXOBJ.6000.87FF@0x0800 -o "$@"

$(COMPRESSED2):
	$(EXOMIZER) src/OBJ.0800.47FF@0x0800 -o "$@"

$(COMPRESSED3):
	$(EXOMIZER) src/OBJ.6000.B8FF@0x6000 -o "$@"

mount: $(BUILDDISK)
	@open "$(BUILDDISK)"

clean:
	rm -rf "$(BUILDDIR)"

$(BUILDDIR):
	mkdir -p "$@"
	$(CADIUS) CREATEVOLUME "$(BUILDDISK)" "$(DISKVOLUME)" 140KB -C

all: clean mount

.NOTPARALLEL:
