diff --git a/Makefile b/Makefile index 1370d799cc4b9976644ef9d35fa93bf8ab02f8ae..c674c1066a7b2f9c3cd3e5250e0135d590f024ab 100644 --- a/Makefile +++ b/Makefile @@ -193,7 +193,7 @@ arflags-gnu-y := $(ARFLAGS) asflags-gnu-y := $(ASFLAGS) cflags-gnu-y := $(CFLAGS) cxxflags-gnu-y := $(CXXFLAGS) -cppflags-gnu-y := $(CPPFLAGS) +cppflags-gnu-y := $(CPPFLAGS) -D GIT_COMMIT=$(shell cd . && printf "%d" 0x$(shell git rev-parse --short HEAD)) cpuflags-gnu-y := dbgflags-gnu-y := $(DBGFLAGS) libflags-gnu-y := $(foreach LIB,$(LIBS),-l$(LIB)) @@ -325,7 +325,7 @@ ifeq ($(target_type),lib) all: $(target) $(project).lss $(project).sym else ifeq ($(target_type),elf) -all: prebuild $(target) $(project).lss $(project).sym $(project).hex $(project).bin postbuild +all: getver prebuild $(target) $(project).lss $(project).sym $(project).hex $(project).bin postbuild endif endif @@ -497,3 +497,8 @@ dfu: AVRDUDE_FLAGS = -p $(AVRDUDE_DEV) -c flip2 -U application:w:$(TARGET):e flash: $(TARGET) avrdude $(AVRDUDE_FLAGS) +# get git version +getver: +# $(eval GIT_COMMIT = $(shell printf "%d" 0x$(shell git rev-parse --short HEAD))) + @echo 'GIT_COMMIT = $(GIT_COMMIT)' + diff --git a/src/main.c b/src/main.c index de021dae859058e929611101e9d0c393fa734192..e6e5a33478e7bfc2af93f905f7e35013089dd521 100644 --- a/src/main.c +++ b/src/main.c @@ -86,7 +86,10 @@ read_data: break; case 'V': //check version - printf("V%u.%u\n", BOARD_VER_MAJOR, BOARD_VER_MINOR); + #define STRING2(x) #x + #define STRING(x) STRING2(x) + #pragma message "GIT_COMMIT = " STRING(GIT_COMMIT) + printf("V%u.%u.%lu\n", BOARD_VER_MAJOR, BOARD_VER_MINOR, GIT_COMMIT); break; default: