TARGET		:=	dsptest
BUILD		:=	
SOURCES		:=	.
INCLUDE		:=	include

#---------------------------------------------------------------------------------
# options for code generation
#---------------------------------------------------------------------------------

MACHDEP = -DGEKKO -mcpu=750 -meabi -mhard-float
CFLAGS = -O2 -Wall $(MACHDEP) $(INCLUDES)

#CFLAGS	:=	-O3 -Wa,-mregnames -Wall $(INCLUDE)
#ASFLAGS	:=	-Wa,-mregnames $(INCLUDE)

LDFLAGS	=	$(MACHDEP) -mogc -Wl,-Map,$(notdir $@).map

PREFIX	:=	powerpc-gekko-
LIBS	:=	-logc -lm -lbba

#---------------------------------------------------------------------------------
# no real need to edit anything past this point unless you need to add additional
# rules for different file extensions
#---------------------------------------------------------------------------------

export OUTPUT	:=	$(CURDIR)/$(TARGET)

export VPATH	:=	$(foreach dir,$(SOURCES),$(CURDIR)/$(dir))

export CC		:=	$(PREFIX)gcc
export CXX		:=	$(PREFIX)g++
export AR		:=	$(PREFIX)ar
export OBJCOPY	:=	$(PREFIX)objcopy
#---------------------------------------------------------------------------------
# use CXX for linking C++ projects, CC for standard C
#---------------------------------------------------------------------------------
export LD	:=	$(CXX)
#export LD	:=	$(CC)

#---------------------------------------------------------------------------------
# automatically build a list of object files for our project
#---------------------------------------------------------------------------------
CFILES		:=	$(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
CPPFILES	:=	$(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
sFILES		:=	$(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
SFILES		:=	$(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.S)))
BINFILES		:=	$(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.bin)))

export OFILES	:= $(CPPFILES:.cpp=.o)
# $(CFILES:.c=.o) $(sFILES:.s=.o) $(SFILES:.S=.o)
#export OFILES	:=	gx_demo.o spaceship.o texture.o incbin.o
#---------------------------------------------------------------------------------
# build a list of include paths
#---------------------------------------------------------------------------------
export INCLUDES	:=	$(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
					$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
					-I$(CURDIR)/$(BUILD) \
					-I$(CURDIR)/$(INCLUDE)

#---------------------------------------------------------------------------------
# build a list of library paths
#---------------------------------------------------------------------------------
export LIBPATHS	:=	$(foreach dir,$(LIBDIRS),-L$(dir)/lib)

$(OUTPUT).dol: $(OUTPUT).elf
	@echo output ... $(notdir $@)
	@$(OBJCOPY)  -O binary $< $@

$(OUTPUT).elf: $(OFILES)
	@echo "Making"
	@echo $^
	@$(LD)  $^ $(LDFLAGS) $(LIBPATHS) $(LIBS) -o $@	

DEPENDS	:=	$(OFILES:.o=.d)

%.bin: %.S
	gdtool -c $< -o $@

%.h: %.bin
	bin2c $< >$@

clean:
	@rm -fr *.o *.bin dsp_test.h *.elf


#---------------------------------------------------------------------------------
%.o : %.cpp dsp_test.h
	@echo $(notdir $<)
	@$(CXX) -MMD $(CFLAGS) -o $@ -c $<

#---------------------------------------------------------------------------------
%.o : %.c
	@echo $(notdir $<)
	@$(CC) -MMD $(CFLAGS) -o $@ -c $<

#---------------------------------------------------------------------------------
#%.o : %.S
#	@echo $(notdir $<)
#	@$(CC) -MMD $(CFLAGS) -D_LANGUAGE_ASSEMBLY -c $< -o $@

#%.o : %.s
#	@echo $(notdir $<)
#	@$(CC) -MMD $(CFLAGS) -D_LANGUAGE_ASSEMBLY -c $< -o $@



-include $(DEPENDS)

