CRTOOLSVERSION		:= $(VERSION_MAJOR)$(if $(VERSION_MINOR),.$(VERSION_MINOR))$(if $(VERSION_SUBLEVEL),.$(VERSION_SUBLEVEL))

VERSION_HEADER := 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' ]; then if [ `cat .gitid` = $(GITID) ]; then echo y; fi; fi)
        ifneq ($(GITID_FILE_VALUE),y)
                .PHONY: $(GITID_FILE)
        endif
endif

$(GITID_FILE):
	$(E) "  GEN     " $@
	$(Q) echo "$(GITID)" > $(GITID_FILE)

$(VERSION_HEADER): Makefile scripts/Makefile.version $(GITID_FILE)
	$(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 "#define CRIU_VERSION \"$(CRTOOLSVERSION)\""		>> $(VERSION_HEADER)
	$(Q) echo "#define CRIU_VERSION_MAJOR " $(VERSION_MAJOR)	>> $(VERSION_HEADER)
	$(Q) echo "#define CRIU_VERSION_MINOR " $(VERSION_MINOR)	>> $(VERSION_HEADER)
	$(Q) echo "#define CRIU_GITID \"$(GITID)\""			>> $(VERSION_HEADER)
	$(Q) echo "#endif /* __CR_VERSION_H__ */"			>> $(VERSION_HEADER)

##
## In case if someone add last resort rule
## together with .SUFFIXES not cleaned, this
## will slow down the build procedure
scripts/Makefile.version::
	@true
