# makfile configuration
NAME = pmsa

CSOURCES = main.c ../utils/uuart.o\
		../uart/delay.c ../utils/b2d.c ../uart/dco.c ../utils/str2bin.c
#		../utils/bin2hexS.c \

ASOURCES =

CPU = msp430f1232

CFLAGS       = -mmcu=${CPU} -O2 -Wall -g -DTARGET_FREQ=2000000 -DDCODEBUG=0
ASFLAGS      = -mmcu=${CPU} -x assembler-with-cpp -D_GNU_ASSEMBLER_ -c

#switch the compiler (for the internal make rules)
CC	= msp430-gcc
AS	= msp430-gcc

OBJECTS         = ${CSOURCES:.c=.o} ${ASOURCES:.s=.o}

.PHONY: all FORCE clean download

#all should be the first target. it's built when make is run without args
all: ${NAME}.elf ${NAME}.a43 ${NAME}.lst

#confgigure the next line if you want to use the serial download
download: download-jtag
#download: download-bsl

#additional rules for files
${NAME}.elf: ${OBJECTS}
	${CC} -mmcu=${CPU} -o $@ ${OBJECTS}

${NAME}.a43: ${NAME}.elf
	msp430-objcopy -O ihex $^ $@

${NAME}.lst: ${NAME}.elf
	msp430-objdump -dSt $^ >$@

clean:
	rm -f ${NAME}.elf ${NAME}.a43 ${NAME}.lst ${OBJECTS}

#automatic collection of dependencies in the source files.
#it's only updated the first time, after that it must be done maually
#with "make depend"
#the dependecies are included from a separate file:

#target to update the file, it's removed first
depend: dependencies.in
#depend: rmdepend dependencies.in
#remove the file
#rmdepend:
#	rm dependencies.in
#build the file that contains the dependencies. no deps in this rule.
#if there were deps it would be rebuilt every chnage, which is unneded:
dependencies.in:
	#rm dependencies.in
	$(CC) -MM ${CFLAGS} ${CSOURCES} > dependencies.in
	#$(CC) -MM ${ASFLAGS} ${ASOURCES} >> dependencies.in

-include dependencies.in

#dummy target as dependecy if something has to be build everytime
FORCE:

