diff --git a/Makefile b/Makefile index 6d09b653..1d5e7170 100644 --- a/Makefile +++ b/Makefile @@ -24,6 +24,12 @@ CFLAGS += -I$(TOP) CFLAGS += $(CPPFLAGS) VPATH = $(TOPSRC) +TCC_GIT_HASH=$(shell git rev-parse > /dev/null 2>&1 && git rev-parse --short HEAD || echo no) + +ifneq ($(TCC_GIT_HASH),no) + CFLAGS += -DTCC_GIT_HASH=\"$(TCC_GIT_HASH)\" +endif + ifdef CONFIG_WIN32 CFG = -win ifneq ($(CONFIG_static),yes) diff --git a/tcc.c b/tcc.c index bd9ce2fa..e7c3e26a 100644 --- a/tcc.c +++ b/tcc.c @@ -149,7 +149,13 @@ static const char help2[] = ; static const char version[] = - "tcc version "TCC_VERSION" (" + "tcc version "TCC_VERSION +#ifdef TCC_GIT_HASH + " - " TCC_GIT_HASH +#else + " - unknown hash" +#endif + " (" #ifdef TCC_TARGET_I386 "i386" #elif defined TCC_TARGET_X86_64