mspbsldump/Makefile

85 lines
1.9 KiB
Makefile
Raw Permalink Normal View History

2022-04-09 01:48:43 +00:00
default: all
PREFIX ?= msp430-
ifeq ($(CC),cc)
CC := gcc
endif
CC := $(PREFIX)$(CC)
OBJCOPY ?= $(PREFIX)objcopy
GDB ?= $(PREFIX)gdb
SIZE ?= $(PREFIX)size
PYTHON3 ?= python3
MCU ?= msp430fr5994
#MCU ?= msp430fr5962
CFLAGS = $(patsubst %,-I%,$(INCLUDE)) -mmcu=$(MCU) -Os \
-Werror=implicit-function-declaration -Werror=return-type \
-Werror=maybe-uninitialized \
-ffunction-sections -fdata-sections -g -ffreestanding -flto
LDFLAGS = -Wl,--cref #-Wl,--gc-sections -nostartfiles #-Wl,--print-gc-sections
SZFLAGS ?= -x --format=SysV
MSP430WARE_DIR ?= $(HOME)/ti/msp430/MSP430Ware_3_80_14_01
LIBMSP430_PATH := /usr/lib
MSPDEBUG_BIN := mspdebug
MSPDEBUG = LD_LIBRARY_PATH="$(LIBMSP430_PATH):$$LD_LIBRARY_PATH" $(MSPDEBUG_BIN) tilib
-include config.mk
MSP430WARE_DRIVER := $(MSP430WARE_DIR)/driverlib/driverlib/MSP430FR5xx_6xx
INCLUDE := include/ $(MSP430WARE_DRIVER)/
LIBSRC := cs dma eusci_a_uart gpio hspll mtif pmm sfr sysctl timer_a tlv uups wdt_a
SOURCES := $(wildcard src/*.c) $(wildcard src/*.S) \
$(patsubst %,$(MSP430WARE_DRIVER)/%.c,$(LIBSRC))
LDSCRIPT := $(MCU).ld
OBJECTS := $(patsubst $(MSP430WARE_DRIVER)/%,obj/%.o,$(patsubst src/%,obj/%.o,$(SOURCES)))
%/:
@mkdir -v "$@"
bin/main.elf: $(OBJECTS) $(LDSCRIPT)
@[ -d bin/ ] || mkdir -vp "bin/"
$(CC) -o "$@" $(OBJECTS) $(CFLAGS) $(LDFLAGS) -T $(LDSCRIPT) "-Wl,-Map=$@.map"
@$(SIZE) $(SZFLAGS) "$@"
bin/main.bin: bin/main.elf
$(OBJCOPY) -O binary "$<" "$@"
obj/%.o: src/%
@[ -d obj/ ] || mkdir -vp "obj/"
$(CC) -c -o "$@" "$<" $(CFLAGS)
obj/%.o: $(MSP430WARE_DRIVER)/%
@[ -d obj/ ] || mkdir -vp "obj/"
$(CC) -c -o "$@" "$<" $(CFLAGS)
all: bin/main.bin
clean:
@$(RM) -v bin/* obj/*
mspdebug:
$(MSPDEBUG)
load: bin/main.elf
$(MSPDEBUG) reset 'load bin/main.elf' reset
dbg: bin/main.elf
$(MSPDEBUG) reset 'load bin/main.elf' 'sym import bin/main.elf' 'gdb 3333' run
gdb: bin/main.elf
$(GDB) -ex 'target remote localhost:3333' bin/main.elf
.PHONY: default all clean hogs