#
# Sega Saturn USB flash cart ROM
# by Anders Montonen, 2012
# Creative Commons Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0)
#
# 2012/07/18 cafe-alpha : made some changes in order to directly run firmware from ROM.
#                         -> ROM_EXE runs from ROM
#                         -> MAIN_EXE runs from HRAM, then calls ROM_EXE
#

CC	=	sh-elf-gcc
AS	=	sh-elf-as
LD	=	sh-elf-ld

# Note: Added -g -Wa,-a,-ad in order to check assembly listings
FLAGS		=	-g -Wa,-a,-ad -Wall -Werror -m2 -Os -fomit-frame-pointer -std=c99
LDFLAGS		=	-nostartfiles --script bart.lnk -Map obj/main_elf.map

ROM_LDFLAGS	=	-nostartfiles --script rom_bart.lnk -Map obj/main_elf_rom.map

FIRMWARE	=	romimage.bin
MAIN_EXE	=	obj/main.bin
ROM_EXE		=	rom_usb.bin

MAIN_OBJ	=	obj/crt0.o	\
				obj/main.o

ROM_OBJ		=	obj/rom_main.o	\
				obj/usb_dev_cart.o	\
				obj/crc.o

all	:	$(FIRMWARE)

$(FIRMWARE)	:	 $(MAIN_EXE) $(ROM_EXE)
		../../../../tools/mkfirm.exe $(MAIN_EXE) $(FIRMWARE) -silent -address 0x06004000 -rom_size 256 -exec_max_size 224 -extra_bin $(ROM_EXE) 0x3F800 1
		../../../../tools/ip_header.exe $(FIRMWARE) -man "ANDERS MONTONEN " -prod "ANTIME-001" -ver "V1.006" -today -dev "R  2" -area "JTUE" -per "J" -title ""


$(MAIN_EXE)	:	$(MAIN_OBJ)
		$(LD) $(LDFLAGS) $(MAIN_OBJ) -o $(MAIN_EXE)

$(ROM_EXE)	:	$(ROM_OBJ)
		$(LD) $(ROM_LDFLAGS) $(ROM_OBJ) -o $(ROM_EXE)

obj/%.o :	%.c
		$(CC) -c $< -o $@ $(FLAGS) > $@.lst

obj/%.o :	%.S
		$(AS) $< -o $@

clean	:
		rm -f obj/*.*

makedir :
		mkdir obj

#
# end of makefile
#
