From bf11a41c8822e299c132426ed1b2680c8e89696b Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Sun, 9 May 2021 11:42:45 +0200 Subject: [PATCH] Makefile: Build file names with version suffix --- mk/libopencm3.mk | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/mk/libopencm3.mk b/mk/libopencm3.mk index 61137c3..7267523 100644 --- a/mk/libopencm3.mk +++ b/mk/libopencm3.mk @@ -1,9 +1,10 @@ ## -## This file is part of the libopencm3 project. +## The original file was part of the libopencm3 project. ## ## Copyright (C) 2009 Uwe Hermann ## Copyright (C) 2010 Piotr Esden-Tempski ## Copyright (C) 2013 Frantisek Burian +## Copyright (C) 2021 Harald Welte ## ## This library is free software: you can redistribute it and/or modify ## it under the terms of the GNU Lesser General Public License as published by @@ -19,6 +20,8 @@ ## along with this library. If not, see . ## +GIT_VERSION=$(shell git describe --tags --dirty) + # Be silent per default, but 'make V=1' will show all compiler calls. ifneq ($(V),1) Q := @ @@ -145,6 +148,9 @@ LDLIBS += -Wl,--start-group -lc -lgcc -lnosys -Wl,--end-group .SECONDEXPANSION: .SECONDARY: +BINARY_VER = $(BINARY)-$(GIT_VERSION) + + all: elf elf: $(BINARY).elf @@ -152,10 +158,10 @@ bin: $(BINARY).bin hex: $(BINARY).hex srec: $(BINARY).srec list: $(BINARY).list -GENERATED_BINARIES=$(BINARY).elf $(BINARY).bin $(BINARY).hex $(BINARY).srec $(BINARY).list $(BINARY).map +GENERATED_BINARIES=$(BINARY_VER).elf $(BINARY_VER).bin $(BINARY_VER).hex $(BINARY_VER).srec $(BINARY_VER).list $(BINARY_VER).map -images: $(BINARY).images -flash: $(BINARY).flash +images: $(BINARY_VER).images +flash: $(BINARY_VER).flash # Either verify the user provided LDSCRIPT exists, or generate it. ifeq ($(strip $(DEVICE)),) @@ -173,6 +179,20 @@ ifeq (,$(wildcard $@)) $(MAKE) -C $(OPENCM3_DIR) endif +.PHONY: $(BINARY).elf $(BINARY).bin $(BINARY).hex $(BINARY).srec $(BINARY).list $(BINARY).map +$(BINARY).elf: $(BINARY_VER).elf $(BINARY).map + ln -sf $< $@ +$(BINARY).bin: $(BINARY_VER).bin + ln -sf $^ $@ +$(BINARY).hex: $(BINARY_VER).hex + ln -sf $^ $@ +$(BINARY).srec: $(BINARY_VER).srec + ln -sf $^ $@ +$(BINARY).list: $(BINARY_VER).list + ln -sf $^ $@ +$(BINARY).map: $(BINARY_VER).map + ln -sf $^ $@ + # Define a helper macro for debugging make errors online # you can type "make print-OPENCM3_DIR" and it will show you # how that ended up being resolved by all of the included @@ -218,6 +238,8 @@ print-%: clean: @printf " CLEAN\n" $(Q)$(RM) $(GENERATED_BINARIES) generated.* $(OBJS) $(OBJS:%.o=%.d) + $(Q)$(RM) $(BINARY)-*.{elf,bin,hex,srec,list,map} + $(Q)$(RM) $(BINARY).{elf,bin,hex,srec,list,map} stylecheck: $(STYLECHECKFILES:=.stylecheck) styleclean: $(STYLECHECKFILES:=.styleclean)