#
#       !!!! Do NOT edit this makefile with an editor which replace tabs by spaces !!!!    
#
##############################################################################################
# 
# On command line:
#
# make all = Create project
#
# make clean = Clean project files.
#
# To rebuild project do "make clean" and "make all".
#

##############################################################################################
# Start of default section
#

TRGT = arm-elf-
CC   = $(TRGT)gcc
CP   = $(TRGT)objcopy
AS   = $(TRGT)gcc -x assembler-with-cpp
BIN  = $(CP) -O ihex 

MCU  = arm7tdmi

# List all default C defines here, like -D_DEBUG=1
DDEFS =	

# List all default ASM defines here, like -D_DEBUG=1
DADEFS = 

# List all default directories to look for include files here
DINCDIR = 

# List the default directory to look for the libraries here
DLIBDIR =

# List all default libraries here
DLIBS =

#
# End of default section
##############################################################################################

##############################################################################################
# Start of user section
#

# Define project name here
PROJECT = Debug

# Define linker script file here
LDSCRIPT_RAM   = ./Setup/AT91SAM7S256_RAM.ld
LDSCRIPT_FLASH = ./Setup/AT91SAM7S256_FLASH.ld

# List all user C define here, like -D_DEBUG=1
UDEFS =	\
-DDEBUG=0 \
-DOS_LIBMODE_DP
#-DOS_LIBMODE_D 
#-DOS_LIBMODE_SP
#-DOS_LIBMODE_S
#-DOS_LIBMODE_R
#-DOS_LIBMODE_DT

# Define ASM defines here
UADEFS = 

# List C source files here
SRC  =	\
./Application/Start_LEDBlink.c   	\
./Setup/BSP.c	                    \
./Setup/OS_Error.c	                \
./Setup/RTOSINIT_AT91SAM7S.c 

# List ASM source files here
ASRC =	\
./Setup/Startup.s

# List all user directories here
UINCDIR =	\
./inc

# List the user directory to look for the libraries here
ULIBDIR =

# List all user libraries here
ULIBS =	\
./Lib/osA4LDP.a
#./Lib/osA4LD.a
#./Lib/osA4LSP.a
#./Lib/osA4LS.a
#./Lib/osA4LR.a
#./Lib/osA4LDT.a


# Define optimisation level here
OPT = -O0

#
# End of user defines
##############################################################################################


INCDIR  = $(patsubst %,-I%,$(DINCDIR) $(UINCDIR))
LIBDIR  = $(patsubst %,-L%,$(DLIBDIR) $(ULIBDIR))
DEFS    = $(DDEFS) $(UDEFS)
ADEFS   = $(DADEFS) $(UADEFS)
OBJS    = $(ASRC:.s=.o) $(SRC:.c=.o)
LIBS    = $(DLIBS) $(ULIBS)
MCFLAGS = -mcpu=$(MCU)

ASFLAGS       = $(MCFLAGS) -g -gdwarf-2 -Wa,-amhls=$(<:.s=.lst) $(ADEFS)
CPFLAGS       = $(MCFLAGS) $(OPT) -gdwarf-2 -fomit-frame-pointer -Wall -Wstrict-prototypes -fverbose-asm -Wa,-ahlms=$(<:.c=.lst) $(DEFS)
LDFLAGS_RAM   = $(MCFLAGS) -nostartfiles -T$(LDSCRIPT_RAM) -Wl,-Map=$(PROJECT)_RAM.map,--cref,--no-warn-mismatch $(LIBDIR)
LDFLAGS_FLASH = $(MCFLAGS) -nostartfiles -T$(LDSCRIPT_FLASH) -Wl,-Map=$(PROJECT)_FLASH.map,--cref,--no-warn-mismatch $(LIBDIR)

# Generate dependency information
CPFLAGS += -MD -MP -MF .dep/$(@F).d

#
# makefile rules
#

all: RAM FLASH

RAM: $(OBJS) $(PROJECT)_RAM.elf

FLASH: $(OBJS) $(PROJECT)_FLASH.elf

%o : %c
	@echo "Compiling $<"
	@$(CC) -c $(CPFLAGS) -I . $(INCDIR) $< -o $@

%o : %s
	@echo "Assembling $<"
	@$(AS) -c $(ASFLAGS) $< -o $@

%RAM.elf: $(OBJS)
	@echo "Linking $@"
	@$(CC) $(OBJS) $(LDFLAGS_RAM) $(LIBS) -o $@

%FLASH.elf: $(OBJS)
	@echo "Linking $@"
	@$(CC) $(OBJS) $(LDFLAGS_FLASH) $(LIBS) -o $@

clean:
	-rm -f $(OBJS)
	-rm -f $(PROJECT)_RAM.elf
	-rm -f $(PROJECT)_RAM.map
	-rm -f $(PROJECT)_FLASH.elf
	-rm -f $(PROJECT)_FLASH.map
	-rm -f $(SRC:.c=.c.bak)
	-rm -f $(SRC:.c=.lst)
	-rm -f $(SRC:.c=.o)
	-rm -f $(ASRC:.s=.s.bak)
	-rm -f $(ASRC:.s=.lst)
	-rm -f $(ASRC:.s=.o)
	-rm -fR .dep

# 
# Include the dependency files, should be the last of the makefile
#
-include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)

# *** EOF ***