summaryrefslogtreecommitdiff
path: root/Makefile
diff options
context:
space:
mode:
authorjaseg <git-bigdata-wsl-arch@jaseg.de>2020-10-12 20:15:41 +0200
committerjaseg <git-bigdata-wsl-arch@jaseg.de>2020-10-12 20:15:41 +0200
commite16ec19e3a445c1156c990ed71628fb183332be9 (patch)
treeaf95b48f15f35665342f5aba76625df3849927d2 /Makefile
downloadfenris-master.tar.gz
fenris-master.tar.bz2
fenris-master.zip
Initial commitHEADmaster
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile160
1 files changed, 160 insertions, 0 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..d51d2c1
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,160 @@
+
+########################################################################################################################
+# Dependency directories
+########################################################################################################################
+
+CMSIS_DEVICE_DIR ?= lib/cmsis_device
+CMSIS_CORE_DIR ?= lib/cmsis_core
+HAL_DIR ?= lib/hal_driver
+MUSL_DIR ?= lib/musl
+
+########################################################################################################################
+# Sources
+########################################################################################################################
+
+C_SOURCES := src/main.c
+C_SOURCES += src/cobs.c
+C_SOURCES += src/clocks.c
+C_SOURCES += src/bootloader.c
+C_SOURCES += src/interrupts.c
+C_SOURCES += src/system_stm32f3xx.c
+C_SOURCES += config/fe_config.c
+
+MUSL_SOURCES += string/strlen.c
+
+C_SOURCES += $(addprefix $(MUSL_DIR)/src/,$(MUSL_SOURCES))
+
+CXX_SOURCES +=
+
+BUILDDIR ?= build
+BINARY := fenris_f302r8tx.elf
+LDSCRIPT := stm32f302r8tx.ld
+
+########################################################################################################################
+# Build parameters
+########################################################################################################################
+
+PREFIX ?= arm-none-eabi-
+
+DEBUG ?= 1
+
+CC := $(PREFIX)gcc
+CXX := $(PREFIX)g++
+LD := $(PREFIX)gcc
+AR := $(PREFIX)ar
+AS := $(PREFIX)as
+SIZE := $(PREFIX)size
+NM := $(PREFIX)nm
+OBJCOPY := $(PREFIX)objcopy
+OBJDUMP := $(PREFIX)objdump
+GDB := $(PREFIX)gdb
+
+HOST_CC ?= $(HOST_PREFIX)gcc
+HOST_CXX ?= $(HOST_PREFIX)g++
+HOST_LD ?= $(HOST_PREFIX)gcc
+HOST_AR ?= $(HOST_PREFIX)ar
+HOST_AS ?= $(HOST_PREFIX)as
+HOST_OBJCOPY ?= $(HOST_PREFIX)objcopy
+HOST_OBJDUMP ?= $(HOST_PREFIX)objdump
+
+PYTHON3 ?= python3
+DOT ?= dot
+
+CMSIS_DIR_ABS := $(abspath $(CMSIS_DIR))
+
+ARCH_FLAGS ?= -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16
+SYSTEM_FLAGS ?= -nostdlib -ffreestanding -nostartfiles
+
+CFLAGS += -Iinclude -Iconfig
+CFLAGS += -I$(BUILDDIR)
+CFLAGS += -I$(CMSIS_DEVICE_DIR)/Include -I$(CMSIS_CORE_DIR)/Include
+CFLAGS += -I$(abspath include/musl_include_shims)
+
+CFLAGS += -Os -std=gnu11 -g -DSTM32F302x8 -DSTM32F3 -DDEBUG=$(DEBUG)
+CFLAGS += $(ARCH_FLAGS) $(SYSTEM_FLAGS)
+CFLAGS += -fno-common -ffunction-sections -fdata-sections
+
+# for musl
+CFLAGS += -Dhidden=
+
+CXXFLAGS += -Os -g
+CXXFLAGS += $(ARCH_FLAGS) $(SYSTEM_FLAGS)
+CXXFLAGS += -fno-common -ffunction-sections -fdata-sections
+CXXFLAGS += -Wall -Wextra -Wshadow -Wundef -Wredundant-decls
+CXXFLAGS += -I.
+
+LDFLAGS += $(ARCH_FLAGS) $(SYSTEM_FLAGS)
+
+LIBS += -lgcc
+LDFLAGS += -Wl,--gc-sections
+
+LINKMEM_FLAGS ?= --trim-stubs=startup_stm32f302x8.o --trace-sections .isr_vector --highlight-subdirs $(BUILDDIR)
+
+OBJS := $(addprefix $(BUILDDIR)/,$(C_SOURCES:.c=.o) $(CXX_SOURCES:.cpp=.o))
+
+ALL_OBJS := $(OBJS)
+ALL_OBJS += $(BUILDDIR)/startup_stm32f302x8.o
+
+########################################################################################################################
+# Rules
+########################################################################################################################
+
+all: binsize
+
+.PHONY: binsize
+binsize: $(BUILDDIR)/$(BINARY) $(BUILDDIR)/$(BINARY:.elf=-symbol-sizes.pdf)
+ $(LD) -T$(LDSCRIPT) $(LDFLAGS) -Wl,--print-memory-usage -o /dev/null $(ALL_OBJS) $(LIBS)
+ @echo
+ @echo "▐▬▬▬▌ SyMbOL sIzE HiGhScORe LiSt ▐▬▬▬▌"
+ $(NM) --print-size --size-sort --radix=d $< | tail -n 20
+
+$(BUILDDIR)/generated: ; mkdir -p $@
+
+.PRECIOUS: $(BUILDDIR)/$(BINARY)
+$(BUILDDIR)/$(BINARY) $(BUILDDIR)/$(BINARY:.elf=.map) &: $(ALL_OBJS)
+ $(LD) -T$(LDSCRIPT) $(LDFLAGS) -o $@ -Wl,-Map=$(BUILDDIR)/$(BINARY:.elf=.map) $^ $(LIBS)
+
+build/$(BINARY:.elf=-symbol-sizes.dot): $(ALL_OBJS)
+ $(PYTHON3) tools/linkmem.py $(LINKMEM_FLAGS) $(LD) -T$(LDSCRIPT) $(LDFLAGS) $^ $(LIBS) > $@
+
+%.pdf: %.dot
+ $(DOT) -T pdf $< -o $@
+
+%.dot: %.elf
+ r2 -a arm -qc 'aa;agRd' $< 2>/dev/null >$@
+
+$(BUILDDIR)/%.o: %.s
+ mkdir -p $(@D)
+ $(CC) $(COMMON_CFLAGS) $(CFLAGS) $(INT_CFLAGS) -o $@ -c $<
+
+$(BUILDDIR)/src/%.o: src/%.c
+ mkdir -p $(@D)
+ $(CC) $(COMMON_CFLAGS) $(CFLAGS) $(INT_CFLAGS) -o $@ -c $<
+
+$(BUILDDIR)/src/%.o: src/%.cpp
+ mkdir -p $(@D)
+ $(CXX) $(CXXFLAGS) -o $@ -c $<
+
+$(BUILDDIR)/generated/%.o: $(BUILDDIR)/generated/%.c
+ mkdir -p $(@D)
+ $(CC) $(COMMON_CFLAGS) $(CFLAGS) $(INT_CFLAGS) -o $@ -c $<
+
+$(BUILDDIR)/%.o: %.c
+ mkdir -p $(@D)
+ $(CC) $(COMMON_CFLAGS) $(CFLAGS) $(EXT_CFLAGS) -o $@ -c $<
+
+clean:
+ rm -rf $(BUILDDIR)/src
+ rm -rf $(BUILDDIR)/generated
+ rm -f $(BUILDDIR)/$(BINARY)
+ rm -f $(BUILDDIR)/$(BINARY:.elf=.map)
+ rm -f $(BUILDDIR)/$(BINARY:.elf=-symbol-sizes.dot)
+ rm -f $(BUILDDIR)/$(BINARY:.elf=-symbol-sizes.pdf)
+ rm -f $(BUILDDIR)/tools/freq_meas_test
+
+mrproper: clean
+ rm -rf build
+
+.PHONY: clean mrproper
+
+-include $(OBJS:.o=.d)