CC = /usr/local/sh-tools/bin/sh-elf-gcc
AS = /usr/local/sh-tools/bin/sh-elf-as
LD = /usr/local/sh-tools/bin/sh-elf-ld
OBJCPY = /usr/local/sh-tools/bin/sh-elf-objcopy

all: startup_rom_b.o gdb-stub_rom_b.o startup_rom_l.o gdb-stub_rom_l.o startup_b.o gdb-stub_b.o startup_l.o gdb-stub_l.o ../../common/gdb-stub-common_b.o ../../common/gdb-stub-common_l.o
	$(LD) -EB startup_b.o gdb-stub_b.o ../../common/gdb-stub-common_b.o -T memory.def -o gdb-stub_b -Map gdb-stub_b.map
	$(OBJCPY) -O srec gdb-stub_b gdb-stub_b.mot
	$(LD) -EL startup_l.o gdb-stub_l.o ../../common/gdb-stub-common_l.o -T memory.def -o gdb-stub_l -Map gdb-stub_l.map
	$(OBJCPY) -O srec gdb-stub_l gdb-stub_l.mot
	$(LD) -EB startup_rom_b.o gdb-stub_rom_b.o ../../common/gdb-stub-common_b.o -T memory_rom.def -o gdb-stub_rom_b -Map gdb-stub_rom_b.map
	$(OBJCPY) -O binary gdb-stub_rom_b gdb-stub_rom_b.bin
	$(LD) -EL startup_rom_l.o gdb-stub_rom_l.o ../../common/gdb-stub-common_l.o -T memory_rom.def -o gdb-stub_rom_l -Map gdb-stub_rom_l.map
	$(OBJCPY) -O binary gdb-stub_rom_l gdb-stub_rom_l.bin
	cd ../../common; make clean; cd ../sh4a/gdb-stub
../../common/gdb-stub-common_b.o: ../../common/gdb-stub-common.c
	cd ../../common;make sh4a;cd ../sh4a/gdb-stub
../../common/gdb-stub-common_l.o: ../../common/gdb-stub-common.c
	cd ../../common;make sh4a;cd ../sh4a/gdb-stub
startup_b.o : startup.s
	$(AS) -big startup.s -o startup_b.o
startup_l.o : startup.s
	$(AS) -little startup.s -o startup_l.o
startup_rom_b.o : startup.s
	$(AS) --defsym ROM_TARGET=1 -big startup.s -o startup_rom_b.o
startup_rom_l.o : startup.s
	$(AS) --defsym ROM_TARGET=1 --defsym CONFIG_LITTLE_ENDIAN=1 -little startup.s -o startup_rom_l.o
gdb-stub_b.o : gdb-stub.c
	$(CC) -mb -m4-nofpu -c $< -o gdb-stub_b.o -I../../common
gdb-stub_l.o : gdb-stub.c
	$(CC) -ml -m4-nofpu -c $< -o gdb-stub_l.o -I../../common
gdb-stub_rom_b.o : gdb-stub.c
	$(CC) -DROM_TARGET -mb -m4-nofpu -c $< -o gdb-stub_rom_b.o -I../../common
gdb-stub_rom_l.o : gdb-stub.c
	$(CC) -DROM_TARGET -ml -m4-nofpu -c $< -o gdb-stub_rom_l.o -I../../common
clean:
	cd ../../common; make clean; cd ../sh4a/gdb-stub; rm -f *.o gdb-stub_l gdb-stub_b gdb-stub_rom_l gdb-stub_rom_b *.map *.mot *.bin
