##############################################################
# Makefile for ADUC7000 MCU                                  #
# Makefile was adapted from J.Lynch                          #
# Modifcations:                                              #
# * Support for ram and flash run                            #
# * Output format is binary and ihex                         #
# * Choose debug or release configuration                    #
# * Several smaller cleanups                                 #
#                                                            #
# (C) 13.01.2008 Tilo Lutz, TiloLutz@gmx.de                  #
#                                                            #
##############################################################

# Set to "yes" if program should run from Ram instead of Flash
RAM_RUN=no

# Set to "yes" if program should contains debug information and no
# code optimization.
DEBUG=yes

# Set to yes to allow GNU99 C Code
GNU99=no

# External objects (header) files
ADDOBJECTS=uart.o

##############################################################
# No modifications should be needed beyond this line         #
##############################################################

# variables 
CC      = arm-elf-gcc
LD      = arm-elf-ld -v
AR      = arm-elf-ar
AS      = arm-elf-as
CP      = arm-elf-objcopy
OD	    = arm-elf-objdump

CFLAGS  = -I./ -c -fno-common -std=gnu99 -mcpu=arm7tdmi
ifeq ($(DEBUG),yes) # Set debug compiler options
	CFLAGS += -O0 -g
else
	CFLAGS += -O2
endif
ifeq ($(GNU99),yes) # Allow gnu99 Syntax
	CFLAGS += -std=gnu99
endif

AFLAGS  = -ahls -mapcs-32 -o crt.o
LFLAGS  =  -Map main.map
ifeq ($(RAM_RUN),yes) # Select memory layout
	LFLAGS += -Taduc-ram.cmd
else
	LFLAGS += -Taduc-flash.cmd
endif

ODFLAGS	= -x --syms

OBJECTS = crt.o irq.o main.o
OBJECTS += $(ADDOBJECTS)

#make target called by Eclipse  (Project -> Build Project)
all:  main.out
	@ echo "...copying"
	$(CP) $(CPFLAGS) main.out main.bin
	$(CP) --output-target=binary main.out main.bin
	$(CP) --output-target=ihex main.out main.hex
	$(OD) $(ODFLAGS) main.out > main.dmp

main.out: $(OBJECTS)  
	@ echo "..linking"
	$(LD) $(LFLAGS) -o main.out $(OBJECTS) libgcc.a

crt.o: crt.s
	@ echo ".assembling crt.s"
	$(AS) $(AFLAGS) crt.s > crt.lst

main.o: main.c
	@ echo ".compiling main.c"
	$(CC) $(CFLAGS) main.c
	
irq.o: irq.c
	@ echo ".compiling irq.c"
	$(CC) $(CFLAGS) irq.c

# make target called by Eclipse (Project -> Clean ...)
clean:
	-rm -f $(OBJECTS) crt.lst main.out main.bin main.hex main.map main.dmp
