CROSS = arm-linux-gnueabi-



CC = gcc

CFLAGS = -Wall -Dat91sam7l128 -mcpu=arm7tdmi -marm

LDFLAGS = -nostdlib -Wl,--gc-sections -static
# -Wl,--print-map
#-Wl,--verbose 

LDSCRIPT = flash.lds

TARGET = libhp20b

TARGETPROPER = LibHP20b

TARGETEXT = .bin

SRC = main.c Number.c Decimal.c StandardDef.c Standard.c Core.c HP20b.c HP20b_LCD.c HP20b_Keyboard.c

HEADERS = Architecture.h AT91SAM7L128.h StandardDef.h Number.h Decimal.h Standard.h Core.h HP20b_LCD.h HP20b_Keyboard.h HP20b.h openocd.cfg\
	board/hp-20b-calculator.cfg target/at91sam7l128.cfg

OBJS =	crt0.o $(SRC:.c=.o)

TARFILES = Makefile NMakefile $(LDSCRIPT) crt0.sx $(SRC) $(HEADERS) Report\ HP20bRemix.xcodeproj LibHP20bTest.xcodeproj HP20bRemix.sln LibHP20b.vcxproj LibHP20b.vcxproj.user LibHP20b.vcxproj.filters LibHP20bTest.vcxproj LibHP20bTest.vcxproj.user LibHP20bTest.vcxproj.filters .project .cproject

LIBS = -lgcc

PATH = $(PATH);C:\Program Files\7-Zip;C:\Program Files (x86)\Linaro\gcc-linaro-arm-linux-gnueabi\bin;C:\Program Files (x86)\OpenOCD\0.4.0\bin;

DELCOM = del /q /s 

COMPRESSCOM = cd .. & $(DELCOM) $(TARGETPROPER)\$@ & 7z a -ttar -y $(TARGETPROPER)\$(TARGETPROPER)temp.tar $(TARGETPROPER)\$(TARFILES: = LibHP20b\) & 7z a -tgzip -y $(TARGETPROPER)\$@ $(TARGETPROPER)\$(TARGETPROPER)temp.tar & $(DELCOM) $(TARGETPROPER)\$(TARGETPROPER)temp.tar 
COMPRESSEXT = .tar.gz
.SUFFIXES : .sx .elf

# Microsoft Windows NMake inference rules
.elf$(TARGETEXT) :
	$(CROSS)objcopy -O ihex $< $@

.c.o :
	$(CROSS)$(CC) $(CFLAGS) -c $<

.sx.o :
	$(CROSS)$(CC) $(CFLAGS) -c -x assembler-with-cpp $<

all : $(TARGET)$(TARGETEXT)

compress : $(TARGETPROPER)$(COMPRESSEXT)

.PHONY : flash

flash : $(TARGET)$(TARGETEXT)
	openocd -f openocd.cfg \
	-c "init" \
	-c "write_flash $(TARGET)$(TARGETEXT)" \
	-c "reset" \
	-c "resume" \
	-c "shutdown"

$(TARGET).elf : $(OBJS) $(LDSCRIPT)
	$(CROSS)$(CC) $(LDFLAGS) -T$(LDSCRIPT) -o $(TARGET).elf $(OBJS) $(LIBS)

$(TARGETPROPER)$(COMPRESSEXT) : $(TARFILES)
	$(COMPRESSCOM)

.PHONY : clean
clean :
	rd /q /s Compress Debug Flash & $(DELCOM) *.o *.elf *$(TARGETEXT) ._* *$(COMPRESSEXT)
