From: Jan Kiszka <[email protected]> Generate a version string, either using the VERSION file for git-less build or information obtained from the git tree. VERSION needs to be updated on each release.
Signed-off-by: Jan Kiszka <[email protected]> --- Changes in v3: - fixed dependency of bg_setenv build on version.h - reordered version.h section in Makefile.am (no functional change) .gitignore | 1 + Makefile.am | 35 +++++++++++++++++++++++++++++++++++ VERSION | 1 + gen_version_h | 28 ++++++++++++++++++++++++++++ main.c | 3 ++- tools/bg_setenv.c | 6 ++++++ 6 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 VERSION create mode 100755 gen_version_h diff --git a/.gitignore b/.gitignore index cad1f4a..6433560 100644 --- a/.gitignore +++ b/.gitignore @@ -78,3 +78,4 @@ Makefile.in /Makefile /tools/tests/Makefile .deps/ +version.h diff --git a/Makefile.am b/Makefile.am index c7dcb10..b11366d 100644 --- a/Makefile.am +++ b/Makefile.am @@ -36,6 +36,33 @@ ARFLAGS = cr EXTRA_DIST = autogen.sh README LICENSE CLEANFILES = +define filechk + $(AM_V_at)set -e; \ + echo ' CHK $@'; \ + mkdir -p $(dir $@); \ + $(filechk_$(1)) < $< > [email protected]; \ + if [ -r $@ ] && cmp -s $@ [email protected]; then \ + rm -f [email protected]; \ + else \ + echo ' UPD $@'; \ + mv -f [email protected] $@; \ + fi +endef + +# +# Version header +# +define filechk_version + $(top_srcdir)/gen_version_h $(top_srcdir)/ +endef + +GEN_VERSION_H := $(top_builddir)/version.h + +$(GEN_VERSION_H): $(top_srcdir)/Makefile.in FORCE + $(call filechk,version) + +CLEANFILES += $(GEN_VERSION_H) + # # Static libraries # @@ -168,6 +195,8 @@ $(top_builddir)/drivers/watchdog/%.o: $(top_srcdir)/drivers/watchdog/%.S @$(MKDIR_P) $(shell dirname $@)/ $(AM_V_CC)$(GNUEFI_CC) $(efi_cppflags) $(efi_cflags) -c $< -o $@ +$(top_builddir)/main.o: $(GEN_VERSION_H) + $(efi_solib): $(efi_objects) $(AM_V_CCLD)$(LD) $(efi_ldflags) $(efi_objects) \ -o $@ -lefi -lgnuefi $(shell $(CC) $(CFLAGS) -print-libgcc-file-name); \ @@ -178,6 +207,8 @@ $(efi_loadername): $(efi_solib) -j .dynsym -j .rel -j .rela -j .reloc -j .init_array \ --target=efi-app-$(ARCH) $< $@ +$(top_builddir)/tools/bg_setenv-bg_setenv.o: $(GEN_VERSION_H) + bg_printenvdir = $(top_srcdir) bg_printenv: $(bg_setenv) @@ -189,3 +220,7 @@ CLEANFILES += bg_printenv # Tests depend on libraries being built - start with "." SUBDIRS = . tools/tests + +FORCE: + +.PHONY: FORCE diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..085135e --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +v0.1 diff --git a/gen_version_h b/gen_version_h new file mode 100755 index 0000000..f917fe0 --- /dev/null +++ b/gen_version_h @@ -0,0 +1,28 @@ +#!/bin/sh +# +# EFI Boot Guard +# +# Copyright (c) Siemens AG, 2017 +# +# Authors: +# Jan Kiszka <[email protected]> +# +# This work is licensed under the terms of the GNU GPL, version 2. See +# the COPYING file in the top-level directory. +# + +echo "/* Auto-generated - leave alone and don't commit! */" +echo "" + +cd "$1" > /dev/null + +if ! git rev-parse 2>/dev/null; then + version="`cat VERSION`" +else + describe="`git describe --long --dirty --match "v[0-9].[0-9]*"`" + version="`echo $describe | sed -e 's/\([^-]*\)-\(.*\)/\1 (\2)/'`" +fi + +cd - > /dev/null + +echo "#define EFIBOOTGUARD_VERSION \"$version\"" diff --git a/main.c b/main.c index e796450..5bf38df 100644 --- a/main.c +++ b/main.c @@ -18,6 +18,7 @@ #include <pci/header.h> #include <bootguard.h> #include <configuration.h> +#include "version.h" extern const unsigned long init_array_start[]; extern const unsigned long init_array_end[]; @@ -104,7 +105,7 @@ EFI_STATUS efi_main(EFI_HANDLE image_handle, EFI_SYSTEM_TABLE *system_table) this_image = image_handle; InitializeLib(this_image, system_table); - Print(L"\nEFI Boot Guard\n"); + Print(L"\nEFI Boot Guard %s\n", L""EFIBOOTGUARD_VERSION); status = uefi_call_wrapper(BS->OpenProtocol, 6, this_image, diff --git a/tools/bg_setenv.c b/tools/bg_setenv.c index 6f7f8f9..424b442 100644 --- a/tools/bg_setenv.c +++ b/tools/bg_setenv.c @@ -15,6 +15,7 @@ #include "env_api.h" #include "ebgenv.h" #include "uservars.h" +#include "version.h" static char doc[] = "bg_setenv/bg_printenv - Environment tool for the EFI Boot Guard"; @@ -38,10 +39,12 @@ static struct argp_option options_setenv[] = { {"uservar", 'x', "KEY=VAL", 0, "Set user-defined string variable. For " "setting multiple variables, use this " "option multiple times."}, + {"version", 'V', 0, 0, "Print version"}, {0}}; static struct argp_option options_printenv[] = { {"verbose", 'v', 0, 0, "Be verbose"}, + {"version", 'V', 0, 0, "Print version"}, {0}}; struct arguments { @@ -311,6 +314,9 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) /* Set user-defined variable(s) */ set_uservars(arg); break; + case 'V': + printf("EFI Boot Guard %s\n", EFIBOOTGUARD_VERSION); + exit(0); case ARGP_KEY_ARG: /* too many arguments - program terminates with call to * argp_usage with non-zero return code */ -- 2.12.3 -- You received this message because you are subscribed to the Google Groups "EFI Boot Guard" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/efibootguard-dev/bb032320-56cb-bcac-3b07-d16a19ec91db%40siemens.com. For more options, visit https://groups.google.com/d/optout.
