Makefile: Generate C file with xemu build info

This commit is contained in:
Matt Borgerson 2020-03-12 02:12:23 -07:00
parent 0a31c7cf28
commit 578e8e087a
3 changed files with 44 additions and 0 deletions

View File

@ -495,6 +495,39 @@ qemu-version.h: FORCE
rm $@.tmp; \ rm $@.tmp; \
fi) fi)
XEMU_DATE := $(shell date -u )
XEMU_COMMIT := $(if $(PKGVERSION),$(PKGVERSION),$(shell \
cd $(SRC_PATH); \
if test -e .git; then \
git rev-parse HEAD 2>/dev/null | tr -d '\n'; \
fi))
XEMU_BRANCH := $(shell \
cd $(SRC_PATH); \
if test -e .git; then \
git symbolic-ref --short HEAD; \
fi)
XEMU_VERSION := $(shell \
cd $(SRC_PATH); \
if test -e .git; then \
git describe --match 'xemu-v*' | cut -c 6- | tr -d '\n'; \
fi)
xemu-version.c: FORCE
$(call quiet-command, (\
printf 'const char *xemu_version = "$(XEMU_VERSION)";\n'; \
printf 'const char *xemu_branch = "$(XEMU_BRANCH)";\n'; \
printf 'const char *xemu_commit = "$(XEMU_COMMIT)";\n'; \
printf 'const char *xemu_date = "$(XEMU_DATE)";\n'; \
) > $@.tmp)
$(call quiet-command, if ! cmp -s $@ $@.tmp; then \
mv $@.tmp $@; \
else \
rm $@.tmp; \
fi)
config-host.h: config-host.h-timestamp config-host.h: config-host.h-timestamp
config-host.h-timestamp: config-host.mak config-host.h-timestamp: config-host.mak
qemu-options.def: $(SRC_PATH)/qemu-options.hx $(SRC_PATH)/scripts/hxtool qemu-options.def: $(SRC_PATH)/qemu-options.hx $(SRC_PATH)/scripts/hxtool

View File

@ -80,6 +80,8 @@ common-obj-$(CONFIG_FDT) += device_tree.o
common-obj-y += qapi/ common-obj-y += qapi/
common-obj-y += xemu-version.o
endif # CONFIG_SOFTMMU endif # CONFIG_SOFTMMU
####################################################################### #######################################################################

9
xemu-version.h Normal file
View File

@ -0,0 +1,9 @@
#ifndef XEMU_VERSION_H
#define XEMU_VERSION_H
extern const char *xemu_version;
extern const char *xemu_branch;
extern const char *xemu_commit;
extern const char *xemu_date;
#endif