# path to use to find driver sources
DRV_SRCDIR = /opt/ti/ti_ccs6_0/msp430/MSP430ware_1_90_00_30/driverlib/driverlib/MSP430FR5xx_6xx
vpath %.c $(DRV_SRCDIR)

# optional compiler flags
CCOPTS ?= -vmspx --abi=eabi --data_model=restricted --include_path="/opt/ti/ti_ccs6_0/ccsv6/ccs_base/msp430/include" --include_path="/opt/ti/ti_ccs6_0/ccsv6/tools/compiler/msp430_4.3.3/include" --advice:power=all --advice:hw_config=all -g --define=__MSP430FR5969__ --diag_warning=225 --display_error_number --diag_wrap=off --silicon_errata=CPU21 --silicon_errata=CPU22 --silicon_errata=CPU40 --printf_support=minimal   -qq -pdsw225 

# required C preprocessor flags
#    compiler   headers: "/opt/ti/ti_ccs6_0/ccsv6/tools/compiler/msp430_4.3.3/include"
#    device     headers: "/opt/ti/ti_ccs6_0/ccsv6/ccs_base/msp430/include"
#    Grace      headers: "/opt/ti/ti_ccs6_0/grace_3_00_01_59/packages"
#    MSP430ware headers: "/opt/ti/ti_ccs6_0/msp430/MSP430ware_1_90_00_30/driverlib/driverlib/MSP430FR5xx_6xx"
#                      : "/opt/ti/ti_ccs6_0/msp430/MSP430ware_1_90_00_30/driverlib"
CPPFLAGS = -D__MSP430FR5969__ -I "/opt/ti/ti_ccs6_0/ccsv6/tools/compiler/msp430_4.3.3/include" -I "/opt/ti/ti_ccs6_0/grace_3_00_01_59/packages"  -I "/opt/ti/ti_ccs6_0/ccsv6/ccs_base/msp430/include" -I "/opt/ti/ti_ccs6_0/msp430/MSP430ware_1_90_00_30/driverlib/driverlib/MSP430FR5xx_6xx" -I "/opt/ti/ti_ccs6_0/msp430/MSP430ware_1_90_00_30/driverlib"

# the compiler and archiver commands
CC = "/opt/ti/ti_ccs6_0/ccsv6/tools/compiler/msp430_4.3.3/bin/cl430" --abi=eabi -c --obj_directory=objs/  -vmspx --near_data=none --code_model=large --data_model=restricted
AR = "/opt/ti/ti_ccs6_0/ccsv6/tools/compiler/msp430_4.3.3/bin/ar430" rq
RM = rm -f
MKDIR = mkdir -p

# create object sub-directory, if necessary
ifeq (,$(wildcard objs/))
    $(shell $(MKDIR) objs/)
endif

all: grace.lib

# always add power advice options to the Grace generated files 
objs/Grace_init.obj objs/CSL_init.obj objs/PinMux_init.obj objs/CS_A_init.obj objs/InterruptVectors_init.obj objs/System_init.obj objs/WDT_A_init.obj: CCOPTS := $(CCOPTS) --advice:power=all

# supress power advice for driverlib by default; the user can override this by setting project options
 objs/esi.obj objs/timer_b.obj objs/tlv.obj objs/timer_a.obj objs/eusci_b_i2c.obj objs/sfr.obj objs/ram.obj objs/sys.obj objs/rtc_c.obj objs/mpu.obj objs/eusci_a_spi.obj objs/rtc_b.obj objs/eusci_b_spi.obj objs/crc32.obj objs/crc.obj objs/wdt_a.obj objs/aes256.obj objs/ref_a.obj objs/pmm.obj objs/mpy32.obj objs/gpio.obj objs/eusci_a_uart.obj objs/fram.obj objs/lcd_c.obj objs/dma.obj objs/cs.obj objs/adc12_b.obj objs/comp_e.obj:  CCOPTS := --advice:power_severity=suppress $(CCOPTS)

# pattern rule to compile .c source to an object file
objs/%.obj: %.c makefile
	@echo cle430X $< ...
	$(CC) $(CCOPTS) $(CPPFLAGS) "$<"

# rule to combine all objects into the grace.lib library
grace.lib: objs/Grace_init.obj objs/CSL_init.obj objs/PinMux_init.obj objs/CS_A_init.obj objs/InterruptVectors_init.obj objs/System_init.obj objs/WDT_A_init.obj objs/esi.obj objs/timer_b.obj objs/tlv.obj objs/timer_a.obj objs/eusci_b_i2c.obj objs/sfr.obj objs/ram.obj objs/sys.obj objs/rtc_c.obj objs/mpu.obj objs/eusci_a_spi.obj objs/rtc_b.obj objs/eusci_b_spi.obj objs/crc32.obj objs/crc.obj objs/wdt_a.obj objs/aes256.obj objs/ref_a.obj objs/pmm.obj objs/mpy32.obj objs/gpio.obj objs/eusci_a_uart.obj objs/fram.obj objs/lcd_c.obj objs/dma.obj objs/cs.obj objs/adc12_b.obj objs/comp_e.obj
	@ echo are430X $@ $< ...
	$(AR) $@ $^

# clean removes all generated files
clean:
	-$(RM) grace.lib
	-$(RM) "objs/"*.obj

