diff --git a/tools/acrn-crashlog/acrnprobe/Makefile b/tools/acrn-crashlog/acrnprobe/Makefile index 8c5ff1e3c..0952e5b94 100644 --- a/tools/acrn-crashlog/acrnprobe/Makefile +++ b/tools/acrn-crashlog/acrnprobe/Makefile @@ -1,3 +1,6 @@ +MAJOR_VERSION=1 +MINOR_VERSION=0 + BASEDIR := $(shell pwd) LIBS = -lpthread -lxml2 -lcrypto -lrt -lsystemd -ltelemetry @@ -10,7 +13,7 @@ LDFLAGS += $(LIBS) -Wl,--gc-sections TARGET = $(BUILDDIR)/acrnprobe/bin/acrnprobe -all: check_dirs $(TARGET) +all: include/version.h check_dirs $(TARGET) $(BUILDDIR)/acrnprobe/obj/%.o:%.c $(CC) -c $(CFLAGS) $< -o $@ @@ -35,6 +38,9 @@ $(BUILDDIR)/acrnprobe/bin/acrnprobe: $(BUILDDIR)/acrnprobe/obj/main.o \ clean: @echo "Clean objects and binaries" + @if [ -e include/version.h ]; then \ + $(RM) -f include/version.h; \ + fi @if [ -d $(BUILDDIR)/acrnprobe/obj ]; then \ find $(BUILDDIR)/acrnprobe/obj -name "*.o" -exec $(RM) {} \; 2>&1 || exit 0; \ fi @@ -45,6 +51,19 @@ clean: $(RM) -r $(BUILDDIR)/acrnprobe/obj ; \ fi +include/version.h: + touch include/version.h + @COMMIT=`git log -1 --pretty=format:%h . 2>/dev/null`;\ + DIRTY=`git diff --name-only $(BASEDIR)`;\ + if [ -n "$$DIRTY" ];then PATCH="$$COMMIT-dirty";else PATCH="$$COMMIT";fi;\ + TIME=`date "+%Y-%m-%d %H:%M:%S"`;\ + cat $(BASEDIR)/../license_header > include/version.h;\ + echo "#define AP_MAJOR_VERSION $(MAJOR_VERSION)" >> include/version.h;\ + echo "#define AP_MINOR_VERSION $(MINOR_VERSION)" >> include/version.h;\ + echo "#define AP_BUILD_VERSION "\""$$PATCH"\""" >> include/version.h;\ + echo "#define AP_BUILD_TIME "\""$$TIME"\""" >> include/version.h;\ + echo "#define AP_BUILD_USER "\""$(USER)"\""" >> include/version.h + check_dirs: @if [ ! -d $(BUILDDIR)/acrnprobe/bin ]; then \ mkdir -p $(BUILDDIR)/acrnprobe/bin ; \ diff --git a/tools/acrn-crashlog/acrnprobe/main.c b/tools/acrn-crashlog/acrnprobe/main.c index e9d1fdc3e..f077144d5 100644 --- a/tools/acrn-crashlog/acrnprobe/main.c +++ b/tools/acrn-crashlog/acrnprobe/main.c @@ -20,10 +20,10 @@ #include "event_handler.h" #include "channels.h" #include "log_sys.h" +#include "version.h" #define CONFIG_INSTALL "/usr/share/defaults/telemetrics/acrnprobe.xml" #define CONFIG_CUSTOMIZE "/etc/acrnprobe.xml" -#define VERSION "1.0" void usage(void) { @@ -79,7 +79,10 @@ int main(int argc, char *argv[]) usage(); return 0; case 'V': - printf(VERSION "\n"); + printf("version is %d.%d-%s, build by %s@%s\n", + AP_MAJOR_VERSION, AP_MINOR_VERSION, + AP_BUILD_VERSION, AP_BUILD_USER, + AP_BUILD_TIME); return 0; case '?': usage(); diff --git a/tools/acrn-crashlog/license_header b/tools/acrn-crashlog/license_header new file mode 100644 index 000000000..f0b28cfd2 --- /dev/null +++ b/tools/acrn-crashlog/license_header @@ -0,0 +1,5 @@ +/* + * Copyright (C) <2018> Intel Corporation + * SPDX-License-Identifier: BSD-3-Clause + */ + diff --git a/tools/acrn-crashlog/usercrash/Makefile b/tools/acrn-crashlog/usercrash/Makefile index b4c75c443..baaac212c 100644 --- a/tools/acrn-crashlog/usercrash/Makefile +++ b/tools/acrn-crashlog/usercrash/Makefile @@ -1,4 +1,7 @@ -all: check_obj usercrash_s usercrash_c debugger +MAJOR_VERSION=1 +MINOR_VERSION=0 + +all: include/version.h check_obj usercrash_s usercrash_c debugger CURRDIR := $(shell pwd) INCLUDE += -I $(CURRDIR)/include/ @@ -30,6 +33,19 @@ debugger: $(BUILDDIR)/usercrash/obj/debugger.o \ $(BUILDDIR)/usercrash/obj/%.o:%.c $(CC) $(CFLAGS) $(INCLUDE) -o $@ -c $< +include/version.h: + touch include/version.h + @COMMIT=`git log -1 --pretty=format:%h . 2>/dev/null`;\ + DIRTY=`git diff --name-only $(CURRDIR)`;\ + if [ -n "$$DIRTY" ];then PATCH="$$COMMIT-dirty";else PATCH="$$COMMIT";fi;\ + TIME=`date "+%Y-%m-%d %H:%M:%S"`;\ + cat $(CURRDIR)/../license_header > include/version.h;\ + echo "#define UC_MAJOR_VERSION $(MAJOR_VERSION)" >> include/version.h;\ + echo "#define UC_MINOR_VERSION $(MINOR_VERSION)" >> include/version.h;\ + echo "#define UC_BUILD_VERSION "\""$$PATCH"\""" >> include/version.h;\ + echo "#define UC_BUILD_TIME "\""$$TIME"\""" >> include/version.h;\ + echo "#define UC_BUILD_USER "\""$(USER)"\""" >> include/version.h + check_obj: @if [ ! -d $(BUILDDIR)/usercrash/bin ]; then \ mkdir -p $(BUILDDIR)/usercrash/bin ; \ @@ -41,6 +57,9 @@ check_obj: .PHONY:clean clean: @echo "Clean objects and binaries" + @if [ -e include/version.h ]; then \ + $(RM) -f include/version.h; \ + fi @if [ -d $(BUILDDIR)/usercrash/obj ]; then \ find $(BUILDDIR)/usercrash/obj -name "*.o" -exec $(RM) {} \; 2>&1 || exit 0; \ fi diff --git a/tools/acrn-crashlog/usercrash/client.c b/tools/acrn-crashlog/usercrash/client.c index 5089c2aa0..c8e22c0eb 100644 --- a/tools/acrn-crashlog/usercrash/client.c +++ b/tools/acrn-crashlog/usercrash/client.c @@ -30,6 +30,7 @@ #include "packet.h" #include "log_sys.h" #include "protocol.h" +#include "version.h" /** * Usercrash works as C/S model: usercrash_c works as usercrash client to @@ -185,7 +186,10 @@ int main(int argc, char *argv[]) if (argc > 1) { if (strcmp(argv[1], "-v") == 0) { - printf("usercrash_c version is 1.0\n"); + printf("version is %d.%d-%s, build by %s@%s\n", + UC_MAJOR_VERSION, UC_MINOR_VERSION, + UC_BUILD_VERSION, UC_BUILD_USER, + UC_BUILD_TIME); return 0; } if (strcmp(argv[1], "-h") == 0) { diff --git a/tools/acrn-crashlog/usercrash/debugger.c b/tools/acrn-crashlog/usercrash/debugger.c index d454dfe5f..0d89becf3 100644 --- a/tools/acrn-crashlog/usercrash/debugger.c +++ b/tools/acrn-crashlog/usercrash/debugger.c @@ -10,6 +10,7 @@ #include #include "crash_dump.h" #include "log_sys.h" +#include "version.h" /** * Debugger can work without server when uses "debugger pid" commands to @@ -33,7 +34,10 @@ int main(int argc, char *argv[]) if (argc > 1) { if (strcmp(argv[1], "-v") == 0) { - printf("debugger version is 1.0\n"); + printf("version is %d.%d-%s, build by %s@%s\n", + UC_MAJOR_VERSION, UC_MINOR_VERSION, + UC_BUILD_VERSION, UC_BUILD_USER, + UC_BUILD_TIME); return 0; } if (strcmp(argv[1], "-h") == 0) { diff --git a/tools/acrn-crashlog/usercrash/server.c b/tools/acrn-crashlog/usercrash/server.c index b6b2c63d7..7c7a38820 100644 --- a/tools/acrn-crashlog/usercrash/server.c +++ b/tools/acrn-crashlog/usercrash/server.c @@ -42,6 +42,7 @@ #include "packet.h" #include "protocol.h" #include "log_sys.h" +#include "version.h" #define FILE_PATH_LEN_MAX 256 @@ -389,7 +390,10 @@ int main(int argc, char *argv[]) while ((opt = getopt(argc, argv, "vh")) != -1) { switch (opt) { case 'v': - printf("usercrash_s version is 1.0\n"); + printf("version is %d.%d-%s, build by %s@%s\n", + UC_MAJOR_VERSION, UC_MINOR_VERSION, + UC_BUILD_VERSION, UC_BUILD_USER, + UC_BUILD_TIME); break; case 'h': print_usage();