From af697d4237544e056a421a5ebb8512eb527cd5f4 Mon Sep 17 00:00:00 2001 From: Hubert Denkmair Date: Sun, 17 Apr 2016 13:28:51 +0200 Subject: [PATCH] Makefile improvements (dependency handling, clean target) --- Makefile | 39 +++++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index f7c8d1c..3060809 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,8 @@ -CHIP ?= STM32F072xB -BOARD ?= candleLight +TOOLCHAIN ?= arm-none-eabi- -CC = arm-none-eabi-gcc -OBJCOPY = arm-none-eabi-objcopy -SIZE = arm-none-eabi-size +CC = $(TOOLCHAIN)gcc +OBJCOPY = $(TOOLCHAIN)objcopy +SIZE = $(TOOLCHAIN)size CFLAGS = -c -std=gnu11 -mcpu=cortex-m0 -mthumb -Os CFLAGS += -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -ffreestanding -fno-move-loop-invariants @@ -21,14 +20,23 @@ SRC += $(wildcard system/src/newlib/*.c) SRC += $(wildcard system/src/cortexm/*.c) SRC += $(wildcard system/src/cmsis/*.c) SRC += $(wildcard Middlewares/ST/STM32_USB_Device_Library/Core/Src/*.c) -SRC += system/src/cmsis/startup_stm32f072xb.S +OBJ = $(patsubst %.c,build/$(BOARD)/%.o,$(SRC)) +DEP = $(OBJ:%.o=%.d) + +ASM_SRC = system/src/cmsis/startup_stm32f072xb.S +ASM_OBJ += $(patsubst %.S,build/$(BOARD)/%.asmo,$(ASM_SRC)) +DEP += $(ASM_OBJ:%.asmo=%.d) -OBJECTS = $(patsubst %.c,build/$(BOARD)/%.o,$(SRC)) ELF = build/$(BOARD)/gsusb_$(BOARD).elf BIN = bin/gsusb_$(BOARD).bin all: candleLight cantact +.PHONY : clean +clean: + $(MAKE) BOARD=candleLight board-clean + $(MAKE) BOARD=cantact board-clean + candleLight: $(MAKE) CHIP=STM32F072xB BOARD=candleLight bin @@ -42,11 +50,22 @@ $(BIN): $(ELF) $(OBJCOPY) -O binary $(ELF) $(BIN) $(SIZE) --format=berkeley $(ELF) -$(ELF): $(OBJECTS) +$(ELF): $(OBJ) $(ASM_OBJ) @mkdir -p $(dir $@) - $(CC) $(LDFLAGS) $(OBJECTS) -o $@ + $(CC) $(LDFLAGS) $(OBJ) $(ASM_OBJ) -o $@ + +-include $(DEP) build/$(BOARD)/%.o : %.c @echo $< @mkdir -p $(dir $@) - $(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@ + $(CC) $(CFLAGS) $(INCLUDES) -MMD -c $< -o $@ + +build/$(BOARD)/%.asmo : %.S + @echo $< + @mkdir -p $(dir $@) + $(CC) $(CFLAGS) $(INCLUDES) -MMD -c $< -o $@ + +.PHONY : board-clean +board-clean : + -rm -f $(BIN) $(OBJ) $(ASM_OBJ) $(DEP)