From 1a2815a579be36f7224c8ac07cb021a26bb97280 Mon Sep 17 00:00:00 2001 From: Adrien Bertrand Date: Thu, 14 Jul 2022 13:27:41 +0200 Subject: [PATCH 1/3] makefile: support C files, and fix C++ flags variable name. --- Makefile | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 65ae7f7..0707786 100644 --- a/Makefile +++ b/Makefile @@ -15,9 +15,10 @@ src = $(addprefix src/,\ score.cpp \ ) -SFLAGS = -I. -Isrc -Os -Wall -MD -MP -ggdb3 -mthumb -mfloat-abi=hard -mcpu=cortex-m7 -mfloat-abi=hard -mfpu=fpv5-sp-d16 -SFLAGS += -fno-common -fdata-sections -ffunction-sections -fno-exceptions -CPPFLAGS = -std=c++11 -ffreestanding -fno-rtti -nostdinc -nostdlib -fno-threadsafe-statics +SFLAGS = -I. -Isrc -Os -Wall -MD -MP -ggdb3 -mthumb -mfloat-abi=hard -mcpu=cortex-m7 -mfloat-abi=hard -mfpu=fpv5-sp-d16 +SFLAGS += -fno-common -fdata-sections -ffunction-sections -ffreestanding -nostdinc -nostdlib +CFLAGS = -std=c11 +CXXFLAGS = -std=c++11 -fno-exceptions -fno-rtti -fno-threadsafe-statics LDFLAGS = -Wl,-Ur LDFLAGS += --specs=nosys.specs -nostartfiles -lm @@ -37,9 +38,13 @@ $(BUILD_DIR)/voord.nwa: $(call object_for,$(src)) $(BUILD_DIR)/icon.o @echo "LD $@" $(Q) arm-none-eabi-gcc $(LDFLAGS) $(SFLAGS) $^ -o $@ +$(addprefix $(BUILD_DIR)/,%.o): %.c | $(BUILD_DIR) + @echo "C $^" + $(Q) arm-none-eabi-gcc $(CFLAGS) $(SFLAGS) -c $^ -o $@ + $(addprefix $(BUILD_DIR)/,%.o): %.cpp | $(BUILD_DIR) @echo "CXX $^" - $(Q) arm-none-eabi-g++ $(CPPFLAGS) $(SFLAGS) -c $^ -o $@ + $(Q) arm-none-eabi-g++ $(CXXFLAGS) $(SFLAGS) -c $^ -o $@ $(BUILD_DIR)/icon.nwi: src/icon.png @echo "NWI $<" From d180cb5c63e8a32275ec57d60c4650e7b5a19011 Mon Sep 17 00:00:00 2001 From: Adrien Bertrand Date: Thu, 14 Jul 2022 13:29:09 +0200 Subject: [PATCH 2/3] makefile: -lm needs to be added at the end of the link flags. The problems are visible in other conditions, but this fixes it. --- Makefile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 0707786..499222a 100644 --- a/Makefile +++ b/Makefile @@ -20,7 +20,8 @@ SFLAGS += -fno-common -fdata-sections -ffunction-sections -ffreestanding -nostdi CFLAGS = -std=c11 CXXFLAGS = -std=c++11 -fno-exceptions -fno-rtti -fno-threadsafe-statics LDFLAGS = -Wl,-Ur -LDFLAGS += --specs=nosys.specs -nostartfiles -lm +LDFLAGS += --specs=nosys.specs -nostartfiles +LDFLAGS_END = -lm .PHONY: build build: $(BUILD_DIR)/voord.bin @@ -36,7 +37,7 @@ $(BUILD_DIR)/%.bin: $(BUILD_DIR)/%.nwa $(BUILD_DIR)/voord.nwa: $(call object_for,$(src)) $(BUILD_DIR)/icon.o @echo "LD $@" - $(Q) arm-none-eabi-gcc $(LDFLAGS) $(SFLAGS) $^ -o $@ + $(Q) arm-none-eabi-gcc $(LDFLAGS) $(SFLAGS) $^ $(LDFLAGS_END) -o $@ $(addprefix $(BUILD_DIR)/,%.o): %.c | $(BUILD_DIR) @echo "C $^" From a4a5e1ceef9ac6e5a6cc8eb2b0d8c71b944be07f Mon Sep 17 00:00:00 2001 From: Adrien Bertrand Date: Thu, 14 Jul 2022 13:29:34 +0200 Subject: [PATCH 3/3] makefile: minor cleanup and add an "all" target for IDE compatibility --- Makefile | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 499222a..9bf007c 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,6 @@ Q ?= @ BUILD_DIR = target +NAME = voord define object_for $(addprefix $(BUILD_DIR)/,$(addsuffix .o,$(basename $(1)))) @@ -23,11 +24,14 @@ LDFLAGS = -Wl,-Ur LDFLAGS += --specs=nosys.specs -nostartfiles LDFLAGS_END = -lm +.PHONY: all +all: build + .PHONY: build -build: $(BUILD_DIR)/voord.bin +build: $(BUILD_DIR)/$(NAME).bin .PHONY: run -run: $(BUILD_DIR)/voord.nwa +run: $(BUILD_DIR)/$(NAME).nwa @echo "INSTALL $<" $(Q) nwlink install-nwa $< @@ -35,7 +39,7 @@ $(BUILD_DIR)/%.bin: $(BUILD_DIR)/%.nwa @echo "BIN $@" $(Q) nwlink link-nwa $< $@ -$(BUILD_DIR)/voord.nwa: $(call object_for,$(src)) $(BUILD_DIR)/icon.o +$(BUILD_DIR)/$(NAME).nwa: $(call object_for,$(src)) $(BUILD_DIR)/icon.o @echo "LD $@" $(Q) arm-none-eabi-gcc $(LDFLAGS) $(SFLAGS) $^ $(LDFLAGS_END) -o $@