diff --git a/kernel/Kbuild b/kernel/Kbuild index 71a4665c..a5f2cbff 100644 --- a/kernel/Kbuild +++ b/kernel/Kbuild @@ -73,10 +73,13 @@ mars-objs += \ endif # -# buildtag.h should be regenerated in every build. If a file -# 'DISTVERSION' exists (out-of-tree tarball), its content is -# used as the BUILDTAG. Otherwise, if git is available, the -# git HEAD revision is used instead. +# buildtag.h should be regenerated in every build. +# +# The version is determined by the following preference order: +# 1) environment variable $MARSVERSION +# 2) when git is available: git describe --tags +# 3) if a file 'DISTVERSION' exists (out-of-tree tarball), use its content. +# 4) otherwise "no-buildtag-available" # extra-y += buildtag.h $(obj)/buildtag.h: $(patsubst $(obj)/buildtag.h,,$(wildcard $(obj)/*.[ch])) $(obj)/*/*.[ch] @@ -85,16 +88,19 @@ $(obj)/buildtag.h: $(patsubst $(obj)/buildtag.h,,$(wildcard $(obj)/*.[ch])) $(ob exec > $@;\ /bin/echo -e "/* Automatically generated -- DO NOT EDIT! */";\ cd $(src); \ - if [ -e DISTVERSION ]; then \ - BUILDTAG=$$(cat DISTVERSION); \ + if [ "$$MARSVERSION" != "" ]; then \ + BUILDTAG="$$MARSVERSION"; \ elif git describe --tags >/dev/null 2>&1; then \ BUILDTAG="$$(git describe --tags)"; \ + elif [ -e DISTVERSION ]; then \ + BUILDTAG=$$(cat DISTVERSION); \ else \ BUILDTAG="no-buildtag-available"; \ fi; \ /bin/echo -e "#define BUILDTAG \"$$BUILDTAG\"";\ /bin/echo -e "#define BUILDHOST \"$$USER@`hostname`\"";\ /bin/echo -e "#define BUILDDATE \"$$(date '+%F %T')\"" + cat $@; ifndef CONFIG_MARS # mars_config.h is generated by a simple Kconfig parser (gen_config.pl) @@ -105,7 +111,10 @@ ifndef CONFIG_MARS # extra-y += mars_config.h GEN_CONFIG_SCRIPT := $(src)/../scripts/gen_config.pl +$(obj)/mars_config.h: $(obj)/buildtag.h $(obj)/mars_config.h: $(src)/Kconfig $(GEN_CONFIG_SCRIPT) + $(Q)$(kecho) "MARS: using compiler $($(CC) --version | head -1)" + $(CC) -v $(Q)$(kecho) "MARS: Generating $@" $(Q)set -e; \ if [ ! -x $(GEN_CONFIG_SCRIPT) ]; then \ @@ -113,4 +122,5 @@ $(obj)/mars_config.h: $(src)/Kconfig $(GEN_CONFIG_SCRIPT) /bin/false; \ fi; \ cat $< | $(GEN_CONFIG_SCRIPT) > $@; + cat $@; endif