Hi,
On 10/04/2017 10:28 AM, Jan Kiszka wrote:
+
+$(GEN_VERSION_H): $(top_srcdir)/Makefile.in FORCE
+ $(call filechk,version)
+
+CLEANFILES += $(GEN_VERSION_H)
+
$(top_builddir)/%.o: $(top_srcdir)/%.c
@$(MKDIR_P) $(shell dirname $@)/
$(AM_V_CC)$(GNUEFI_CC) $(efi_cppflags) $(efi_cflags) -c $< -o $@
@@ -168,6 +192,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); \
@@ -189,3 +215,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..4c25d9c 100644
--- a/tools/bg_setenv.c
+++ b/tools/bg_setenv.c
@@ -15,6 +15,9 @@
#include "env_api.h"
#include "ebgenv.h"
#include "uservars.h"
+#include "version.h"
+
+#define VERSION_KEY 1000
Why are we needing a special define for the version key, when all the
other parameters don't need this.
I think we should be consistent here. If we change the style here, then
a separate patch would be useful.
Because all the other switches have a character as key that can also be
used as an abbreviation of the long parameter name. --version has no
such thing, so the key has to be a "non-printable" value.
Ok and you wanted to avoid magic numbers in the code. Maybe change it to
'V'.
Claudius
static char doc[] =
"bg_setenv/bg_printenv - Environment tool for the EFI Boot Guard";
@@ -38,10 +41,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", VERSION_KEY, 0, 0, "Print version"},
{0}};
static struct argp_option options_printenv[] = {
{"verbose", 'v', 0, 0, "Be verbose"},
+ {"version", VERSION_KEY, 0, 0, "Print version"},
{0}};
struct arguments {
@@ -311,6 +316,9 @@ static error_t parse_opt(int key, char *arg,
struct argp_state *state)
/* Set user-defined variable(s) */
set_uservars(arg);
break;
+ case VERSION_KEY:
+ 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 */
Claudius
Thanks,
Jan
--
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-54 Fax: (+49)-8142-66989-80 Email: [email protected]
--
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/1fd7b958-0ff0-2778-8e5f-8e155e5995a5%40siemens.com.
For more options, visit https://groups.google.com/d/optout.