From 90fbbabb34785d7da6f812f91df674e78b17631c Mon Sep 17 00:00:00 2001 From: Cyrill Gorcunov Date: Mon, 11 Feb 2013 19:24:06 +0400 Subject: [PATCH] make: Generate crtools version from Makefile definition This allows us to have a unique place where version lives and what is more important other subsystems (such as docs generation) may reuse version definitions. At moment EXTRA (which corresponds kernels -rc tag) and NAME is not yet used, but I desided to put them in place for future needs. Signed-off-by: Cyrill Gorcunov Signed-off-by: Pavel Emelyanov --- .gitignore | 1 + Makefile | 5 ++++- crtools.c | 3 ++- include/crtools.h | 3 --- scripts/Makefile.version | 23 +++++++++++++++++++++++ 5 files changed, 30 insertions(+), 5 deletions(-) create mode 100644 scripts/Makefile.version diff --git a/.gitignore b/.gitignore index b7cc0da1f..b3f5a0015 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,4 @@ include/syscall.h include/syscall-codes.h protobuf/*.c protobuf/*.h +include/version.h diff --git a/Makefile b/Makefile index c2e5986b2..c78998c06 100644 --- a/Makefile +++ b/Makefile @@ -87,6 +87,8 @@ PROTOBUF-LIB = $(SRC_DIR)/protobuf/protobuf-lib.o export E Q CC ECHO MAKE CFLAGS LIBS ARCH DEFINES MAKEFLAGS export SRC_DIR SYSCALL-LIB SH ARCH_DIR OBJCOPY LDARCH +include scripts/Makefile.version + PROGRAM := crtools OBJS += parasite-syscall.o @@ -144,7 +146,7 @@ ifeq ($(GCOV),1) %.o $(PROGRAM): override CFLAGS += --coverage endif -all: pie +all: pie $(VERSION_HEADER) $(Q) $(MAKE) $(PROGRAM) pie: protobuf $(ARCH) @@ -192,6 +194,7 @@ rebuild: clean: $(E) " CLEAN" + $(Q) $(RM) $(VERSION_HEADER) $(Q) $(RM) -f ./*.o $(Q) $(RM) -f ./*.d $(Q) $(RM) -f ./*.i diff --git a/crtools.c b/crtools.c index 8291850a8..ae02cb5ca 100644 --- a/crtools.c +++ b/crtools.c @@ -21,6 +21,7 @@ #include "files.h" #include "sk-inet.h" #include "net.h" +#include "version.h" struct cr_options opts; @@ -226,7 +227,7 @@ int main(int argc, char *argv[]) opts.handle_file_locks = true; break; case 'V': - pr_msg("Version: %d.%d\n", CRIU_VERSION_MAJOR, CRIU_VERSION_MINOR); + pr_msg("Version: %s\n", version); return 0; case 'h': default: diff --git a/include/crtools.h b/include/crtools.h index a96e3ce98..5225aab23 100644 --- a/include/crtools.h +++ b/include/crtools.h @@ -14,9 +14,6 @@ #define CR_FD_PERM (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH) -#define CRIU_VERSION_MAJOR 0 -#define CRIU_VERSION_MINOR 3 - enum { CR_FD_INVENTORY, /* diff --git a/scripts/Makefile.version b/scripts/Makefile.version new file mode 100644 index 000000000..d0845b901 --- /dev/null +++ b/scripts/Makefile.version @@ -0,0 +1,23 @@ +VERSION_MAJOR := 0 +VERSION_MINOR := 3 +VERSION_SUBLEVEL := +VERSION_EXTRA := +VERSION_NAME := + +CRTOOLSVERSION := $(VERSION_MAJOR)$(if $(VERSION_MINOR),.$(VERSION_MINOR))$(if $(VERSION_SUBLEVEL),.$(VERSION_SUBLEVEL)) + +export VERSION_MAJOR VERSION_MINOR + +VERSION_HEADER := include/version.h + +$(VERSION_HEADER): scripts/Makefile.version + $(E) " GEN " $@ + $(Q) echo "/* Autogenerated, do not edit */" > $(VERSION_HEADER) + $(Q) echo "#ifndef __CR_VERSION_H__" >> $(VERSION_HEADER) + $(Q) echo "#define __CR_VERSION_H__" >> $(VERSION_HEADER) + $(Q) echo "static char version[] = {" >> $(VERSION_HEADER) + $(Q) echo \"$(CRTOOLSVERSION)\" >> $(VERSION_HEADER) + $(Q) echo "};" >> $(VERSION_HEADER) + $(Q) echo "#define CRIU_VERSION_MAJOR " $(VERSION_MAJOR) >> $(VERSION_HEADER) + $(Q) echo "#define CRIU_VERSION_MINOR " $(VERSION_MINOR) >> $(VERSION_HEADER) + $(Q) echo "#endif /* __CR_VERSION_H__ */" >> $(VERSION_HEADER)