PREFIX=/usr/local
TARGET=sh-elf

CC=$(PREFIX)/bin/$(TARGET)-gcc
LD=$(PREFIX)/bin/$(TARGET)-ld
AS=$(PREFIX)/bin/$(TARGET)-as
AR=$(PREFIX)/bin/$(TARGET)-ar
OBJCOPY=$(PREFIX)/bin/$(TARGET)-objcopy

ASFLAGS = -little -I../sub

CFLAGS = -ml -m4-single-only -O2
LDFLAGS = -nostartfiles -nodefaultlibs -ml -Wl,-oformat,binary,-Ttext,8c010000

#OBJCOPYFLAGS = --strip-all --set-start=0x8c010000 --change-section-address text=0x8c010000


%.srec : %.bin
	dcsrec.exe $^ $@

#%.bin : %.elf
#	$(OBJCOPY) $(OBJCOPYFLAGS) -O binary $^ $@



.PHONY : all
all : test.srec


test.bin : main.o donut.o ../sub/Cache.o ../sub/XMat4x4.o ../sub/Serial.o ../sub/std.o ../sub/Exception.o ../sub/BrowseVideoMemory.o ../sub/Render.o ../sub/Screen.o ../sub/SuperStrip.o
	$(CC) $(LDFLAGS) $^ -o $@


.PHONY : dist
dist : all cleantemp


.PHONY : cleantemp
cleantemp : 
	@-rm *.o


.PHONY : cleandist
cleandist :
	@-rm *.elf
	@-rm *.bin
	@-rm *.srec


.PHONY : clean
clean : cleantemp cleandist
