Files
system76-embedded-controller/src/arch/avr/toolchain.mk
Tim Crawford 01be30f107 Only support building a single board at a time
As a follow up to c461e20df3 ("make: Remove version from build output
path"), only support building a single version of a single board by
default. The build directory can still be specified by passing `BUILD`.

Fixes running the `clean` target when `BUILD` is a custom value or
`BOARD` isn't set.

Fixes: b03c960b4f ("make: Reduce build output")
Signed-off-by: Tim Crawford <tcrawford@system76.com>
2023-10-12 12:49:43 -06:00

50 lines
1.3 KiB
Makefile

# SPDX-License-Identifier: GPL-3.0-only
CC = avr-gcc -mmcu=$(EC_VARIANT)
CFLAGS += -MMD -Os -fstack-usage -Wall -Werror \
-Wl,--gc-sections -Wl,-u,vfprintf -lprintf_flt
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105523
_gcc_version = $(shell avr-gcc --version 2>/dev/null)
ifneq ($(findstring 12.,$(_gcc_version)),)
CFLAGS += --param=min-pagesize=0
else ifneq ($(findstring 13.,$(_gcc_version)),)
CFLAGS += --param=min-pagesize=0
endif
OBJCOPY = avr-objcopy
OBJ=$(sort $(patsubst src/%.c,$(BUILD)/%.o,$(SRC)))
# Run EC rom in simulator
sim: $(BUILD)/ec.elf
simavr $< --mcu $(EC_VARIANT)
# Convert from Intel Hex file to binary file
$(BUILD)/ec.rom: $(BUILD)/ec.ihx
@echo " OBJCOPY $(subst $(BUILD)/,,$@)"
mkdir -p $(@D)
$(OBJCOPY) -I ihex -O binary --gap-fill 0xFF $< $@
# Convert from ELF file to Intel Hex file
$(BUILD)/ec.ihx: $(BUILD)/ec.elf
@echo " OBJCOPY $(subst $(BUILD)/,,$@)"
mkdir -p $(@D)
$(OBJCOPY) -j .text -j .data -O ihex $< $@
# Link object files into ELF file
$(BUILD)/ec.elf: $(OBJ)
@echo " LINK $(subst $(BUILD)/,,$@)"
mkdir -p $(@D)
$(CC) -o $@ $^
# Compile C files into object files
$(BUILD)/%.o: src/%.c $(INCLUDE)
@echo " CC $(subst $(BUILD)/,,$@)"
mkdir -p $(@D)
$(CC) $(CFLAGS) -o $@ -c $<
# Add dependency rules
DEP = $(OBJ:%.o=%.d)
-include $(DEP)