diff --git a/Makefile.cfg b/Makefile.cfg index 1af48ae1cba00b652b0d3b0db5e42c2e91348d61..1f31fcda13a04618b243c28e64806d11a6b2d62b 100644 --- a/Makefile.cfg +++ b/Makefile.cfg @@ -45,6 +45,9 @@ endif # Set these variables to fit your system: +# Set it to 'yes' to display git commit id beside the version +GIT_COMMIT_ID := yes + # The target directory where the Test Executor will be installed to: TTCN3_DIR := ${TOP}/Install diff --git a/common/.gitignore b/common/.gitignore index 1a5ba15b2cd0c7ddb7fa0ced96865637d6803383..2d1233e9375ff7d41c4b2ba382670838d4ed0c04 100644 --- a/common/.gitignore +++ b/common/.gitignore @@ -14,3 +14,4 @@ pattern_uni.output config_preproc_p.output config_preproc_p.tab.cc config_preproc_p.tab.hh +git_version.c diff --git a/common/Makefile b/common/Makefile index f8989dec488950bf0b358a31c4d186c1f6782e0d..6c86b4e1bbcc00f3fe7a9d17d1f96e8c3e676105 100644 --- a/common/Makefile +++ b/common/Makefile @@ -26,6 +26,26 @@ TOP := .. include $(TOP)/Makefile.cfg +# Generating git_version.c according to GIT_COMMIT_ID +ifeq ($(GIT_COMMIT_ID), yes) + $(shell echo -e "// this file was generated by make\n#include \"version_internal.h\"\n\nchar const *const GIT_COMMIT_ID = \"$$(git describe --always --dirty --match 'NOT A TAG')\";" > git_version.c.tmp; \ + if [ ! -f git_version.c.tmp ]; then \ + echo -e "// this file was generated by make\n#include \"version_internal.h\"\n\nchar const *const GIT_COMMIT_ID = \"\";" > git_version.c.tmp; \ + fi; \ + if diff -q git_version.c.tmp git_version.c >/dev/null 2>&1; then \ + rm git_version.c.tmp; \ + else \ + mv git_version.c.tmp git_version.c; \ + fi) +else + $(shell echo -e "// this file was generated by make\n#include \"version_internal.h\"\n\nchar const *const GIT_COMMIT_ID = \"\";" > git_version.c.tmp; \ + if diff -q git_version.c.tmp git_version.c >/dev/null 2>&1; then \ + rm git_version.c.tmp; \ + else \ + mv git_version.c.tmp git_version.c; \ + fi) +endif + TARGETS := # The origin of GENERATED_SOURCES @@ -35,7 +55,7 @@ GENERATED_SOURCES := pattern_la.cc pattern_p.cc pattern_uni.cc config_preproc_la # Sources in the CVS -STATIC_SOURCES := memory.c new.cc userinfo.c path.c config_preproc.cc Quadruple.cc \ +STATIC_SOURCES := git_version.c memory.c new.cc userinfo.c path.c config_preproc.cc Quadruple.cc \ Path2.cc ModuleVersion.cc JSON_Tokenizer.cc UnicharPattern.cc openssl_version.c ifndef MINGW diff --git a/common/version_internal.h b/common/version_internal.h index 1af7cd7617c34be05b691d5103ba0c3746a1d3b9..e334c98670191e514cee1340f6abca3d60638e3b 100644 --- a/common/version_internal.h +++ b/common/version_internal.h @@ -286,4 +286,7 @@ /* For prefixing the above messages. Default value: empty string. */ #define COMMENT_PREFIX +/ * For include git commit id in version printouts */ +extern char const *const GIT_COMMIT_ID; + #endif diff --git a/compiler2/Makefile b/compiler2/Makefile index ba9a9e4dff6f0a3d12d4cfbc87a61d875a21a150..6f88256f85f3e3f07d8eae1aaaa4c3cbef24906c 100644 --- a/compiler2/Makefile +++ b/compiler2/Makefile @@ -121,7 +121,7 @@ ifdef REGEX_DIR endif COMPILER_COMMON_OBJECTS := $(COMMON_OBJECTS) \ -$(addprefix ../common/, new.o pattern_la.o pattern_p.o pattern_uni.o Quadruple.o \ +$(addprefix ../common/, git_version.o new.o pattern_la.o pattern_p.o pattern_uni.o Quadruple.o \ ModuleVersion.o JSON_Tokenizer.o UnicharPattern.o openssl_version.o) ifeq ($(USAGE_STATS), yes) diff --git a/compiler2/main.cc b/compiler2/main.cc index 01e3c19d4688e54eb3ceeab051122fbdcbf948bf..c191b41fda09652aa50144c471c292a955c9eab4 100644 --- a/compiler2/main.cc +++ b/compiler2/main.cc @@ -977,6 +977,10 @@ int main(int argc, char *argv[]) "Compiled with: " C_COMPILER_VERSION "\n", stderr); fputs("Using ", stderr); fputs(openssl_version_str(), stderr); + if (strlen(GIT_COMMIT_ID)) { + fputs("\nCommit id: ", stderr); + fputs(GIT_COMMIT_ID, stderr); + } fputs("\n\n" COPYRIGHT_STRING "\n\n", stderr); #ifdef LICENSE print_license_info(); diff --git a/core/Makefile b/core/Makefile index 7620b928e0521b6e85456e4a08b2c0e7e8c5df02..a9972a9cd7c006c853fccc78c95b5c0fed1a60e5 100644 --- a/core/Makefile +++ b/core/Makefile @@ -160,7 +160,7 @@ PROFMERGE_OBJECTS := ProfMerge_main.o ProfilerTools.profmerge.o \ COMMON_OBJECTS := $(addprefix ../common/, memory.o pattern_la.o pattern_p.o \ config_preproc.o config_preproc_la.o config_preproc_p.tab.o \ path.o pattern_uni.o Quadruple.o NetworkHandler.o Path2.o \ - ModuleVersion.o JSON_Tokenizer.o UnicharPattern.o) + ModuleVersion.o JSON_Tokenizer.o UnicharPattern.o git_version.o) ifeq ($(DEBUG), yes) COMMON_OBJECTS += ../common/new.o diff --git a/core/Parallel_main.cc b/core/Parallel_main.cc index ce627f92e7d00409fc6bf08a2c6fdb7a919f85cb..cce5b5eff4a6e23b49c7529997fcaa5ecdd5b927 100644 --- a/core/Parallel_main.cc +++ b/core/Parallel_main.cc @@ -175,8 +175,12 @@ static boolean process_options(int argc, char *argv[], int& ret_val, fputs("TTCN-3 Host Controller (parallel mode)\n" "Version: " VERSION_STRING "\n" "Build date (Base Library): " __DATE__ " " __TIME__ "\n" - "Base Library was compiled with: " C_COMPILER_VERSION "\n\n" - COPYRIGHT_STRING "\n\n", stderr); + "Base Library was compiled with: " C_COMPILER_VERSION, stderr); + if (strlen(GIT_COMMIT_ID)) { + fputs("\nCommit id: ", stderr); + fputs(GIT_COMMIT_ID, stderr); + } + fputs("\n\n" COPYRIGHT_STRING "\n\n", stderr); #ifdef LICENSE print_license_info(); putc('\n', stderr); diff --git a/core/Single_main.cc b/core/Single_main.cc index 1af929246b358967b59b6b6216a3c1cf677617d8..28913c0560b29f328be1d6a75bca9bf21436752f 100644 --- a/core/Single_main.cc +++ b/core/Single_main.cc @@ -185,8 +185,12 @@ int main(int argc, char *argv[]) fputs("TTCN-3 Test Executor (single mode)\n" "Version: " VERSION_STRING "\n" "Build date (Base Library): " __DATE__ " " __TIME__ "\n" - "Base Library was compiled with: " C_COMPILER_VERSION "\n\n" - COPYRIGHT_STRING "\n\n", stderr); + "Base Library was compiled with: " C_COMPILER_VERSION, stderr); + if (strlen(GIT_COMMIT_ID)) { + fputs("\nCommit id: ", stderr); + fputs(GIT_COMMIT_ID, stderr); + } + fputs("\n\n" COPYRIGHT_STRING "\n\n", stderr); #ifdef LICENSE print_license_info(); putc('\n', stderr);