62 lines
1.5 KiB
Makefile
62 lines
1.5 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
|
|
TARGET = final
|
|
|
|
SRC_FILES := $(wildcard $(SRC_DIR)/*.c)
|
|
PREP_FILES := $(patsubst $(SRC_DIR)/%.c,$(BUILD_DIR)/%.i,$(SRC_FILES))
|
|
ASM_FILES := $(patsubst $(BUILD_DIR)/%.i,$(BUILD_DIR)/%.S,$(PREP_FILES))
|
|
OBJ_FILES := $(patsubst $(BUILD_DIR)/%.S,$(BUILD_DIR)/%.o,$(ASM_FILES))
|
|
|
|
.PHONY: build
|
|
build: builddir preprocess compile assemble $(BUILD_DIR)/$(TARGET).elf
|
|
|
|
$(BUILD_DIR)/$(TARGET).elf: $(OBJ_FILES)
|
|
$(CC) $(LDFLAGS) $^ -o $@
|
|
|
|
$(BUILD_DIR)/%.i: $(SRC_DIR)/%.c
|
|
$(CC) $(CFLAGS) -E $^ -o $@
|
|
|
|
$(BUILD_DIR)/%.S: $(BUILD_DIR)/%.i
|
|
$(CC) $(CFLAGS) -S $^ -o $@
|
|
|
|
$(BUILD_DIR)/%.o: $(BUILD_DIR)/%.S
|
|
$(CC) $(CFLAGS) -c $^ -o $@
|
|
|
|
.PHONY: builddir
|
|
builddir:
|
|
mkdir $(BUILD_DIR)
|
|
|
|
.PHONY: preprocess
|
|
preprocess: $(PREP_FILES)
|
|
|
|
.PHONY: compile
|
|
compile: preprocess $(ASM_FILES)
|
|
|
|
.PHONY: assemble
|
|
assemble: compile $(OBJ_FILES)
|
|
|
|
.PHONY: clean
|
|
clean:
|
|
rm -rf $(BUILD_DIR)
|