On 10/04/2017 10:43 AM, Jan Kiszka wrote:
On 2017-10-04 10:36, Claudius Heine wrote:
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'.

Is "-V" a common abbreviation for version? I don't get your suggestion yet.

Yes:

$ ping -v
Usage: ping [-aAbBdDfhLnOqrRUvV64] [-c count] [-i interval] [-I interface]
[-m mark] [-M pmtudisc_option] [-l preload] [-p pattern] [-Q tos]
            [-s packetsize] [-S sndbuf] [-t ttl] [-T timestamp_option]
            [-w deadline] [-W timeout] [hop1 ...] destination
Usage: ping -6 [-aAbBdDfhLnOqrRUvV] [-c count] [-i interval] [-I interface]
             [-l preload] [-m mark] [-M pmtudisc_option]
             [-N nodeinfo_option] [-p pattern] [-Q tclass] [-s packetsize]
             [-S sndbuf] [-t ttl] [-T timestamp_option] [-w deadline]
$ ping -V
ping utility, iputils-s20161105



--
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/dc4fa168-b54b-8937-2a2e-2b666b8fc086%40siemens.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to