#
# $Header: /home/ben/.cvs_rep/nds/Debug/arm7/Makefile,v 1.2 2006/10/10 12:06:31 ben Exp $
#

NDSTOOL = ndstool

PREFIX = arm-eabi-
CC = $(PREFIX)gcc
LD = $(PREFIX)ld
AR = $(PREFIX)ar
AS = $(PREFIX)as
OBJCOPY	= $(PREFIX)objcopy

ARCH = -mthumb-interwork

INC_DIRS = $(DEVKITPRO)/libnds/include ../../ndsWifi/include

CFLAGS	= -g -W -Wall -mcpu=arm7tdmi -mtune=arm7tdmi -DARM7\
	 -fomit-frame-pointer\
	-ffast-math\
	$(ARCH) $(addprefix -I,$(INC_DIRS))

THUMB_CFLAGS = -mthumb $(CFLAGS)

ASFLAGS = -g $(ARCH)

LDFLAGS	= -specs=ds_arm7.specs -g $(ARCH) -mno-fpu

LIBS = nds7 dswifi7

LIBDIRS = $(DEVKITPRO)/libnds/lib ../../ndsWifi/lib

# the base name
base_name = debug_tcp

sources = wifi_enabled.c

objects = $(sources:.c=.o)

# the ARM7 and ARM9 binary files
arm7_bin_file = $(base_name).arm7



.PHONY : all
all : $(arm7_bin_file)


arm7_elf_file = $(arm7_bin_file).elf


# The arm7 map file
arm7_map_file = $(subst elf,map,$(arm7_elf_file))


# How to build the ARM binaries stuff
$(arm7_bin_file) : $(arm7_elf_file)
	@$(OBJCOPY) -O binary $< $@


$(arm7_elf_file) : $(objects)
	$(CC) $(LDFLAGS) -Wl,-Map,$(arm7_map_file) $(addprefix -L,$(LIBDIRS)) $(filter %.o,$^) \
		$(addprefix -l,$(LIBS)) -o $@


# Make the object files

%.o : %.c
	@echo building $@ from $<
	$(CC) $(CFLAGS) $< -c -o $@


.PHONY : clean
clean :
	-rm -f *.o
	-rm -f $(arm7_bin_file) $(arm7_elf_file) $(arm7_map_file)


# Generate the dependencies
%.d: %.c
	set -e; $(CC) -MM $(CFLAGS) $< \
		| sed 's|\($*\)\.o[ :]*|\1.o $@ : |g' > $@; \
		[ -s $@ ] || rm -f $@

# include the dependencies files
include $(sources:.c=.d)
