Write git revision to a header file, then make version.h depend on that file.

This commit is contained in:
Jan Vidar Krey 2010-02-11 01:02:19 +01:00
parent 915cb56448
commit bf1b64db53
2 changed files with 21 additions and 9 deletions

View File

@ -40,7 +40,6 @@ UHUB_PREFIX ?= c:/uhub/
CFLAGS += -mno-cygwin CFLAGS += -mno-cygwin
LDFLAGS += -mno-cygwin LDFLAGS += -mno-cygwin
BIN_EXT ?= .exe BIN_EXT ?= .exe
GIT_REVISION ?= NO
else else
DESTDIR ?= / DESTDIR ?= /
UHUB_CONF_DIR ?= $(DESTDIR)/etc/uhub UHUB_CONF_DIR ?= $(DESTDIR)/etc/uhub
@ -51,7 +50,7 @@ BIN_EXT ?=
endif endif
ifeq ($(SILENT),YES) ifeq ($(SILENT),YES)
MSG_CC=@echo " CC:" $(notdir $^) && MSG_CC=@echo " CC:" $(notdir $<) &&
MSG_LD=@echo " LD:" $(notdir $@) && MSG_LD=@echo " LD:" $(notdir $@) &&
MSG_AR=@echo " AR:" $(notdir $@) && MSG_AR=@echo " AR:" $(notdir $@) &&
else else
@ -71,10 +70,8 @@ endif
ifeq ($(RELEASE),YES) ifeq ($(RELEASE),YES)
CFLAGS += -O3 -DNDEBUG CFLAGS += -O3 -DNDEBUG
GIT_REVISION ?= NO
else else
CFLAGS += -ggdb -DDEBUG CFLAGS += -ggdb -DDEBUG
GIT_REVISION ?= YES
endif endif
ifeq ($(STACK_PROTECT),YES) ifeq ($(STACK_PROTECT),YES)
@ -119,9 +116,9 @@ CFLAGS += -DSSL_SUPPORT
LDLIBS += -lssl LDLIBS += -lssl
endif endif
ifeq ($(GIT_REVISION),YES) GIT_VERSION=$(shell git describe --tags 2>/dev/null || echo "")
CFLAGS += -DGIT_REVISION=\"$(shell git show --abbrev-commit | head -n 1 | cut -f 2 -d " ")\" GIT_REVISION=$(shell git show --abbrev-commit 2>/dev/null | head -n 1 | cut -f 2 -d " " || echo "")
endif OLD_REVISION=$(shell grep GIT_REVISION revision.h 2>/dev/null | cut -f 3 -d " " | tr -d "\"")
# Sources # Sources
libuhub_SOURCES := \ libuhub_SOURCES := \
@ -197,8 +194,10 @@ adcrush_BINARY=adcrush$(BIN_EXT)
admin_BINARY=uhub-admin$(BIN_EXT) admin_BINARY=uhub-admin$(BIN_EXT)
autotest_BINARY=autotest/test$(BIN_EXT) autotest_BINARY=autotest/test$(BIN_EXT)
%.o: %.c .PHONY: revision.h.tmp
$(MSG_CC) $(CC) -c $(CFLAGS) -o $@ $^
%.o: %.c version.h revision.h
$(MSG_CC) $(CC) -c $(CFLAGS) -o $@ $<
all: $(uhub_BINARY) all: $(uhub_BINARY)
@ -214,6 +213,17 @@ $(uhub_BINARY): $(uhub_OBJECTS) $(libuhub_OBJECTS) $(libadc_common_OBJECTS)
autotest.c: $(autotest_SOURCES) autotest.c: $(autotest_SOURCES)
$(shell exotic --standalone $(autotest_SOURCES) > $@) $(shell exotic --standalone $(autotest_SOURCES) > $@)
revision.h.tmp:
@rm -f $@
@echo "/* AUTOGENERATED FILE - DO NOT EDIT */" > $@
@if [ -n '$(GIT_VERSION)' ]; then echo \#define GIT_VERSION \"$(GIT_VERSION)\" >> $@; fi
@if [ -n '$(GIT_REVISION)' ]; then echo \#define GIT_REVISION \"$(GIT_REVISION)\" >> $@; fi
version.h: revision.h
revision.h: revision.h.tmp
@if [ '$(GIT_REVISION)' != '$(OLD_REVISION)' ]; then cat $@.tmp > $@; fi
$(autotest_OBJECTS): autotest.c $(autotest_OBJECTS): autotest.c
$(MSG_CC) $(CC) -c $(CFLAGS) -Isrc -o $@ $< $(MSG_CC) $(CC) -c $(CFLAGS) -Isrc -o $@ $<

View File

@ -1,3 +1,5 @@
#include "revision.h"
#ifndef PRODUCT #ifndef PRODUCT
#define PRODUCT "uHub" #define PRODUCT "uHub"
#endif #endif