CROSS =nds32-elf-
CC=$(CROSS)gcc -I./include 
LD = $(CROSS)ld
STRIP = $(CROSS)strip
OBJDUMP = $(CROSS)objdump
NM = $(CROSS)nm
OBJCOPY = $(CROSS)objcopy

VPATH = src tool
CFLAGS = -g -EL -static
LDFLAGS = -mlib=newlib -Tnds32.ld
ASFLAGS = -EL -x assembler-with-cpp

OBJS =  main.o osd.o flcd.o nds32_start.o

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

all: bin bin/osd

bin:
	mkdir -p bin

# $(OBJDUMP) -h -S $@ > $@.text
bin/osd: $(OBJS) 
	$(CC) -o $@ $(CFLAGS) $(OBJS) $(LDFLAGS)
	mkdir -p obj
	mv *.o obj
	$(OBJDUMP) -h -D $@ > $@.text
	$(NM) -B -n $@ > $@.map
	$(OBJCOPY) -S -O binary $@ $@.bin
	
clean:
	rm -rf obj bin *.o *.txt *.bin *.obj
