Skip to content

Instantly share code, notes, and snippets.

@abrasive
Created October 16, 2024 22:39
Show Gist options
  • Select an option

  • Save abrasive/359439d2bb4bafde976a138b910915d5 to your computer and use it in GitHub Desktop.

Select an option

Save abrasive/359439d2bb4bafde976a138b910915d5 to your computer and use it in GitHub Desktop.
basic makefile for an stm32 target
PROJ=token
OUT=out
FILES=init startup_stm32f10x_cl touch usb
OBJS=$(addprefix $(OUT)/,$(addsuffix .o,$(FILES)))
default: $(OUT)/$(PROJ).elf
$(shell mkdir -p $(OUT))
-include $(OBJS:.o=.d)
CFLAGS=-ggdb3 -O2 -mcpu=cortex-m3 -mthumb -mno-thumb-interwork -nostdlib -Iinc --std=gnu11
CFLAGS+=-ffunction-sections -fdata-sections -Wl,--gc-sections
CC=arm-none-eabi-gcc
$(OUT)/%.elf: $(OUT)/main_%.o $(OBJS) linker.ld
$(CC) $(OBJS) $(COMMON_OBJS) $< $(CFLAGS) $(LDFLAGS) -T linker.ld -o $@
$(OUT)/%.o: %.s
$(CC) -c $(CFLAGS) $< -o $@
$(OUT)/%.o: %.c
$(CC) -MMD -c $(CFLAGS) $< -o $@
clean:
rm -f $(OUT)/*
.DELETE_ON_ERROR:
.PHONY: clean default
.SECONDARY:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment