#************************************************************************/
#* CQBBEL GNU CC Common Control Software / (C) Toshio MURAI 2011- 2013	*/
#*      This is Free Software;   You can redistribute this software     */
#*      and/or modify it under the terms of the GNU General Public      */
#*      License version 3, or (at your option) any later version.       */
#************************************************************************/

#*******	CPU Dependent Part		*************************/
PAHT=/usr/local/arm/bin/arm-eabi-
CFLAGS= -O2
ARCH=-mcpu=cortex-m3 -mthumb
LIBGCC=/usr/local/arm/lib/gcc/arm-eabi/4.7.3/thumb/libgcc.a
OBJECTNAME=CQBBEL

#*******	Common Part		*********************************/
CC = $(PAHT)gcc $(ARCH)
AS = $(PAHT)as  $(ARCH)
LD = $(PAHT)ld
OBJCOPY = $(PAHT)objcopy

#OBJECTS=vect.o crt0.o main.o rvect.o
OBJECTS=vect.o crt0.o main.o

$(OBJECTNAME).out:  $(OBJECTS)
	$(LD) -T memory.x -Map $(OBJECTNAME).map $(OBJECTS) $(LIBGCC) -o $(OBJECTNAME).out 
# -O srec	MOTOROLA S FORMAT
	$(OBJCOPY) -O srec $(OBJECTNAME).out $(OBJECTNAME).srec
#	$(OBJCOPY) -O srec $(OBJECTNAME).out $(OBJECTNAME).mot
#	$(OBJCOPY) -O srec $(OBJECTNAME).out $(OBJECTNAME).mhx
# -O ihex	INTEL HEX FORMAT
#	$(OBJCOPY) -O ihex $(OBJECTNAME).out $(OBJECTNAME).ihex
#	$(OBJCOPY) -O ihex $(OBJECTNAME).out $(OBJECTNAME).hex
# -O binary	Binary Format
#	$(OBJCOPY) -O binary $(OBJECTNAME).out $(OBJECTNAME).bin

crt0.o : crt0.s
	$(CC) -c crt0.s 
#	$(AS) crt0.s -o crt0.o

main.o: ../main.c macro.h io.h
	$(CC) $(CFLAGS) -c -I. ../main.c 

vect.o: vect.c
#	$(AS) vect.s -o vect.o
	$(CC) -c vect.c 

rvect.o: rvect.c
	$(CC) -c rvect.c 

clean:
	rm -f *.o CQBBEL* crt0-template.s

crt0-template.s: ../crt0-template.c
	$(CC) $(CFLAGS) -I. -S ../crt0-template.c
