diff --git a/Makefile b/Makefile index ac7376c7f..99991d0e2 100644 --- a/Makefile +++ b/Makefile @@ -6,11 +6,6 @@ export __nmk_dir include $(__nmk_dir)/include.mk include $(__nmk_dir)/macro.mk -# -# Import tools versions early -# so subsequents may refer them. -include Makefile.versions - # # To build host helpers. HOSTCC ?= gcc @@ -140,6 +135,44 @@ endif CFLAGS += $(WARNINGS) $(DEFINES) +# +# Version headers. +include Makefile.versions + +VERSION_HEADER := $(SRC_DIR)/criu/include/version.h +GITID_FILE := .gitid +GITID := $(shell if [ -d ".git" ]; then git describe; fi) + +ifeq ($(GITID),) + GITID := 0 +else + GITID_FILE_VALUE := $(shell if [ -f '$(GITID_FILE)' ]; then if [ `cat '$(GITID_FILE)'` = $(GITID) ]; then echo y; fi; fi) + ifneq ($(GITID_FILE_VALUE),y) + .PHONY: $(GITID_FILE) + endif +endif + +$(GITID_FILE): + $(call msg-gen, $@) + $(Q) echo "$(GITID)" > $(GITID_FILE) + +$(VERSION_HEADER): Makefile.versions $(GITID_FILE) + $(call msg-gen, $@) + $(Q) echo "/* Autogenerated, do not edit */" > $@ + $(Q) echo "#ifndef __CR_VERSION_H__" >> $@ + $(Q) echo "#define __CR_VERSION_H__" >> $@ + $(Q) echo "#define CRIU_VERSION \"$(CRIU_VERSION)\"" >> $@ + $(Q) echo "#define CRIU_VERSION_MAJOR " $(CRIU_VERSION_MAJOR) >> $@ + $(Q) echo "#define CRIU_VERSION_MINOR " $(CRIU_VERSION_MINOR) >> $@ +ifneq ($(CRIU_VERSION_SUBLEVEL),) + $(Q) echo "#define CRIU_VERSION_SUBLEVEL " $(CRIU_VERSION_SUBLEVEL) >> $@ +endif +ifneq ($(CRIU_VERSION_EXTRA),) + $(Q) echo "#define CRIU_VERSION_EXTRA " $(CRIU_VERSION_EXTRA) >> $@ +endif + $(Q) echo "#define CRIU_GITID \"$(GITID)\"" >> $@ + $(Q) echo "#endif /* __CR_VERSION_H__ */" >> $@ + # # Protobuf images first, they are not depending # on anything else. @@ -153,9 +186,9 @@ $(eval $(call gen-built-in,images)) # # But note that we're already included # the nmk so we can reuse it there. -criu/%: images/built-in.o +criu/%: images/built-in.o $(VERSION_HEADER) $(Q) $(MAKE) -C criu $@ -criu: images/built-in.o +criu: images/built-in.o $(VERSION_HEADER) $(Q) $(MAKE) -C criu all .PHONY: criu @@ -188,6 +221,7 @@ clean: subclean mrproper: subclean $(Q) $(MAKE) $(build)=images $@ $(Q) $(MAKE) -C criu $@ + $(Q) $(RM) $(VERSION_HEADER) $(Q) $(RM) cscope.* $(Q) $(RM) tags TAGS .PHONY: mrproper diff --git a/criu/Makefile b/criu/Makefile index 19989547a..6f3da08c0 100644 --- a/criu/Makefile +++ b/criu/Makefile @@ -79,10 +79,6 @@ endif # msg-* printing include $(__nmk_dir)/msg.mk -# -# Version header file. -include Makefile.version - # # Configure variables. include Makefile.config diff --git a/criu/Makefile.version b/criu/Makefile.version deleted file mode 100644 index 123487b5c..000000000 --- a/criu/Makefile.version +++ /dev/null @@ -1,38 +0,0 @@ -include $(__nmk_dir)msg.mk - -VERSION_HEADER := include/version.h -GITID_FILE := ../.gitid -GITID := $(shell if [ -d "../.git" ]; then cd .. && git describe; fi) - -ifeq ($(GITID),) - GITID := 0 -else - GITID_FILE_VALUE := $(shell if [ -f '$(GITID_FILE)' ]; then if [ `cat '$(GITID_FILE)'` = $(GITID) ]; then echo y; fi; fi) - ifneq ($(GITID_FILE_VALUE),y) - .PHONY: $(GITID_FILE) - endif -endif - -$(GITID_FILE): - $(call msg-gen, $@) - $(Q) echo "$(GITID)" > $(GITID_FILE) - -$(VERSION_HEADER): ../Makefile.versions $(GITID_FILE) - $(call msg-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 "#define CRIU_VERSION \"$(CRIU_VERSION)\"" >> $(VERSION_HEADER) - $(Q) echo "#define CRIU_VERSION_MAJOR " $(CRIU_VERSION_MAJOR) >> $(VERSION_HEADER) - $(Q) echo "#define CRIU_VERSION_MINOR " $(CRIU_VERSION_MINOR) >> $(VERSION_HEADER) -ifneq ($(CRIU_VERSION_SUBLEVEL),) - $(Q) echo "#define CRIU_VERSION_SUBLEVEL " $(CRIU_VERSION_SUBLEVEL) >> $(VERSION_HEADER) -endif -ifneq ($(CRIU_VERSION_EXTRA),) - $(Q) echo "#define CRIU_VERSION_EXTRA " $(CRIU_VERSION_EXTRA) >> $(VERSION_HEADER) -endif - $(Q) echo "#define CRIU_GITID \"$(GITID)\"" >> $(VERSION_HEADER) - $(Q) echo "#endif /* __CR_VERSION_H__ */" >> $(VERSION_HEADER) - -Makefile.version: - @true