#
# Makefile for the MidiSynth module
# 24/8/2022
# uses gccsdk 4.7.4

CC = gcc
CFLAGS = -mmodule -c -Wall -mthrowback -O2 -mpoke-function-name
AS = gcc
ASFLAGS = -mmodule -c -mthrowback
LD = gcc
LDFLAGS = -mmodule
CMHG = cmunge
MFLAGS = -tgcc -32bit -throwback

# listings
#CFLAGS += -fverbose-asm -save-temps
#CFLAGS += -fverbose-asm -S
#LDFLAGS += -Wl,-Map=map
#MFLAGS += -s s.modhdr

MHDR = modhdr

C_OBJ = o.module o.kbd o.midi o.queue o.store o.tables o.SoundSet
A_OBJ = o.buffer o.fft o.fmull

H_SRC = h.instrument h.kbd h.main h.midi h.queue \
        h.store h.midi_spec h.$(MHDR)

# Select 'c' or assembler synth sample generator code.
# assembler is a bit faster (not much).
# 'c' is easier to modify.
A_OBJ += o.synth-s
#C_OBJ += o.synth-c

OBJS = o.$(MHDR) $(A_OBJ) $(C_OBJ)

# Link          
MidiSynth: $(OBJS)
	$(LD) $(LDFLAGS) -o $@ $(OBJS)

# Module Header
h.$(MHDR) o.$(MHDR): cmhg.$(MHDR)
	$(CMHG) $(MFLAGS) -d h.$(MHDR) -o o.$(MHDR) $<

# Compile
$(C_OBJ): o.%: c.%
	$(CC) $(CFLAGS) $<

# Assemble
$(A_OBJ): o.%: s.%
	$(AS) $(ASFLAGS) $<

# Headers
$(C_OBJ): $(H_SRC)

$(OBJS): Makefile

clean:
	wipe h.$(MHDR) ~C~V
	wipe o ~C~V


