Files
stm32-falling-sand/Makefile
2024-08-03 11:54:31 +02:00

44 lines
1.0 KiB
Makefile

CC = arm-none-eabi-gcc
CFLAGS = -mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16
CFLAGS += -Wall -Werror -Wpedantic -Wextra
# Remove unused code and data; https://gcc.gnu.org/onlinedocs/gnat_ugn/Compilation-options.html
CFLAGS += -ffunction-sections -fdata-sections
# Don't include memcpy
CFLAGS += -fno-builtin
# "-fno-common ... specifies that the compiler places uninitialized global variables in the BSS section of the object file."
CFLAGS += -fno-common
DEBUG ?= 1
ifeq ($(DEBUG), 0)
# Optimize for size
CFLAGS += -Os
else
CFLAGS += -O0 -g3 -ggdb
endif
LDFLAGS = -T link.ld -nostartfiles -nostdlib --specs nano.specs -lc -lgcc -Wl,--gc-sections -Wl,-Map=$@.map
SRC_DIR = src
BUILD_DIR = build
SRC_FILES := $(wildcard $(SRC_DIR)/*.c)
PREP_FILES := $(patsubst $(SRC_DIR)/%.c,$(BUILD_DIR)/%.i,$(SRC_FILES))
.PHONY: build
build: builddir preprocess
$(BUILD_DIR)/%.i: $(SRC_DIR)/%.c
$(CC) $(CFLAGS) -E $^ -o $@
.PHONY: builddir
builddir:
mkdir $(BUILD_DIR)
.PHONY: preprocess
preprocess: $(PREP_FILES)
.PHONY: clean
clean:
rm -rf $(BUILD_DIR)