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)
	$(Q) echo "#define CRIU_GITID \"$(GITID)\""			>> $(VERSION_HEADER)
	$(Q) echo "#endif /* __CR_VERSION_H__ */"			>> $(VERSION_HEADER)

Makefile.version:
	@true
