NAME	= gdb_sample
CC      = m68k-coff-gcc
CXX     = m68k-coff-g++

# set the VARIANT environment var to pick your type, else defaults to RAM
# you can change the default by changing which one of these you set
ifeq "$(strip $(VARIANT))" ""
  VARIANT=ram_mode
# VARIANT=rom_mode
endif

# jaguar is always 68k
CPU_VARIANT=MC68000

# pattern match the variant to set the compiler flags

ifeq "$(VARIANT)" "ram_mode"
  NEW_INSTRUCTIONS=
  SIMINFO=
  MACTEST=
  LINKER_SCRIPT=jaguar-ram.ld

else
ifeq "$(VARIANT)" "rom_mode"
  NEW_INSTRUCTIONS=
  SIMINFO=
  MACTEST=
  LINKER_SCRIPT=jaguar-rom.ld
  
else
	@echo "Missing variant configuration"
	@exit 1
endif
endif

# no debug
#CFLAGS = -m68000 -O1 -D$(CPU_VARIANT) $(NEW_INSTRUCTIONS) -fomit-frame-pointer
#LDFLAGS = -m68000 -Wl,-s -Wl,-n -T$(LINKER_SCRIPT) -Wl,-Map=$(basename $@).map

# debug versions
CFLAGS = -m68000 -g -D$(CPU_VARIANT) $(NEW_INSTRUCTIONS)
LDFLAGS = -m68000 -g -Wl,-n -T$(LINKER_SCRIPT) -Wl,-Map=$(basename $@).map

## Feel free to edit below this point to create your own makefile project!

all: test.cof

test.cof: foo.o jagstart.o
	$(CC) $(LDFLAGS) -o $@ $^

foo.o: foo.c
	$(CC) $(CFLAGS) -Wall $< -c -o $@

jagstart.o: jagstart.s
	$(CC) $(CFLAGS) -Wall $< -c -o $@

# This clean rule can only be used with a properly setup Cygwin environment. Sorry.
.PHONY : clean
clean:
	rm -f *.cof *.o *.map core *.d

.PHONY : distclean
distclean:
	rm -f *.cof *.o *.map core *.d *.\$$\$$\$$ *.d@

