
all: main.hex

#TARGET = LPC214x
TARGET = LPC23xx
LPC2378_PORT = -DLPC2378_PORTB

CC  = arm-none-eabi-gcc
LD  = arm-none-eabi-ld -v
AR  = arm-none-eabi-ar
AS  = arm-none-eabi-as
CP  = arm-none-eabi-objcopy
OD  = arm-none-eabi-objdump

CFLAGS  = -I./ -I./lpcusb/target/ -I./lpcusb/target/examples/ -c -W -Wall -Os -g -DDEBUG -D$(TARGET) $(LPC2378_PORT) -mcpu=arm7tdmi
ASFLAGS = -ahls -mapcs-32 -Wa,--defsym,$(TARGET)=1 
LFLAGS  = -nostartfiles --warn-common
CPFLAGS = -O ihex
ODFLAGS = -x --syms

main.hex: crt.o halsys.o printf.o console.o main.o lpcusb/target/usbstack.a
	$(CC) -T lpcusb/target/examples/lpc2148-rom.ld $(LFLAGS) $^ -o main.elf -Wl,-Map,main.map
	$(CP) $(CPFLAGS) main.elf main.hex
	$(OD) $(ODFLAGS) main.elf > main.dmp
	$(OD) -d main.elf > main.asm

crt.o: lpcusb/target/examples/crt.s
	$(CC) -c $(ASFLAGS) -Wa,-ahlms=crt.lst lpcusb/target/examples/crt.s -o crt.o

halsys.o: lpcusb/target/examples/halsys.c
	$(CC) -c $(CFLAGS) lpcusb/target/examples/halsys.c -o halsys.o

printf.o: lpcusb/target/examples/printf.c
	$(CC) -c $(CFLAGS) lpcusb/target/examples/printf.c -o printf.o

console.o: lpcusb/target/examples/console.c
	$(CC) -c $(CFLAGS) lpcusb/target/examples/console.c -o console.o

lpcusb/target/usbstack.a:
	make -C lpcusb/target lib

clean:
	rm -f *.hex *.elf *.o *.lst *.dmp *.map *.asm
	make -C lpcusb/target clean

