From: Andreas Reichel <[email protected]>

For API refactoring, storage backend should be configurable.
Add --with-env-backend configure option to specify the c-file
with the backend implementation.

Signed-off-by: Andreas Reichel <[email protected]>
---
 Makefile.am                   |  6 +++---
 configure.ac                  | 46 ++++++++++++++++++++++++++-----------------
 env/env_api_fat.c             |  1 +
 include/env_api.h             |  4 +---
 tools/tests/Makefile          | 20 ++++++++++---------
 tools/tests/test_partitions.c |  1 +
 6 files changed, 45 insertions(+), 33 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index 0ec6fe6..6fa7d82 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -42,7 +42,7 @@ CLEANFILES =
 lib_LIBRARIES = libebgenv.a libenv_api.a
 
 libebgenv_a_SOURCES = \
-       env/env_api_fat.c \
+       env/@[email protected] \
        tools/ebgpart.c \
        swupdate-adapter/ebgenv.c
 
@@ -55,7 +55,7 @@ libebgenv_a_CFLAGS = \
 
 libenv_api_a_SOURCES = \
        tools/ebgpart.c \
-       env/env_api_fat.c
+       env/@[email protected]
 
 libenv_api_a_CFLAGS = \
        $(AM_CFLAGS)
@@ -196,7 +196,7 @@ all-local: bg_printenv build_tests
 
 build_tests:
        make -C $(top_srcdir)/tools/tests build-tests \
-       BUILDDIR=$(BUILDDIR) SRCDIR=$(SRCDIR)
+       ENV_API=@env_api_file@ BUILDDIR=$(BUILDDIR) SRCDIR=$(SRCDIR)
 
 .PHONY: check
 check:
diff --git a/configure.ac b/configure.ac
index 80dd365..e235341 100644
--- a/configure.ac
+++ b/configure.ac
@@ -5,6 +5,7 @@
 #
 # Authors:
 #  Claudius Heine <[email protected]>
+#  Andreas Reichel <[email protected]>
 #
 # This work is licensed under the terms of the GNU GPL, version 2.  See
 # the COPYING file in the top-level directory.
@@ -14,10 +15,10 @@
 #
 
 AC_INIT([efibootguard],
-        [0.1.0],
-        [],
-        [efibootguard],
-        [])
+       [0.1.0],
+       [],
+       [efibootguard],
+       [])
 
 AC_CONFIG_SRCDIR([bootguard.c])
 AC_CONFIG_MACRO_DIR([m4])
@@ -92,15 +93,15 @@ SET_ARCH(IA64, ia64*)
 ARCH=$(echo $host | sed "s/\(-\).*$//")
 
 AM_COND_IF(ARCH_I686, [
-        ARCH=ia32
-        MACHINE_TYPE_NAME=ia32])
+       ARCH=ia32
+       MACHINE_TYPE_NAME=ia32])
 
 AM_COND_IF(ARCH_I586, [
-        ARCH=ia32
-        MACHINE_TYPE_NAME=ia32])
+       ARCH=ia32
+       MACHINE_TYPE_NAME=ia32])
 
 AM_COND_IF(ARCH_X86_64, [
-        MACHINE_TYPE_NAME=x64])
+       MACHINE_TYPE_NAME=x64])
 
 AC_SUBST([ARCH])
 AC_SUBST([MACHINE_TYPE_NAME])
@@ -134,24 +135,33 @@ AC_TYPE_UINT16_T
 AC_TYPE_UINT32_T
 AC_TYPE_UINT8_T
 
+AC_ARG_WITH([env-backend],
+           AS_HELP_STRING([--with-env-backend=STRING],
+                          [define the environment backend, defaults to 
"env_api_fat"]),
+           [ ENV_API_FILE="$withval" ],
+           [ ENV_API_FILE="env_api_fat" ])
+
+AC_SUBST([env_api_file], [${ENV_API_FILE}])
 # 
------------------------------------------------------------------------------
 AC_CONFIG_FILES([
-        Makefile
+       Makefile
 ])
 
 AC_OUTPUT
 AC_MSG_RESULT([
-        $PACKAGE_NAME $VERSION
+       $PACKAGE_NAME $VERSION
 
-        arch:                    $ARCH
-        machine type:            $MACHINE_TYPE_NAME
+       arch:                    $ARCH
+       machine type:            $MACHINE_TYPE_NAME
 
-        prefix:                  ${prefix}
+       prefix:                  ${prefix}
        exec_prefix:             ${exec_prefix}
-        libexecdir:              ${libexecdir}
-        libdir:                  ${libdir}
+       libexecdir:              ${libexecdir}
+       libdir:                  ${libdir}
+
+       efi libs:                ${GNUEFI_LIBS}
+       efi lds:                 ${GNUEFI_LDS_DIR}
 
-        efi libs:                ${GNUEFI_LIBS}
-        efi lds:                 ${GNUEFI_LDS_DIR}
+       environment backend:     ${ENV_API_FILE}.c
 ])
 
diff --git a/env/env_api_fat.c b/env/env_api_fat.c
index f282a3f..93b85a1 100644
--- a/env/env_api_fat.c
+++ b/env/env_api_fat.c
@@ -11,6 +11,7 @@
  */
 
 #include "env_api.h"
+#include "ebgpart.h"
 #include "test-interface.h"
 
 const char *tmp_mnt_dir = "/tmp/mnt-XXXXXX";
diff --git a/include/env_api.h b/include/env_api.h
index 70727e9..83c7123 100644
--- a/include/env_api.h
+++ b/include/env_api.h
@@ -26,9 +26,7 @@
 #include <fcntl.h>
 #include <sys/file.h>
 #include <sys/mount.h>
-
-#include "ebgpart.h"
-
+#include "config.h"
 #include <zlib.h>
 #include "envdata.h"
 
diff --git a/tools/tests/Makefile b/tools/tests/Makefile
index 5486585..f0f5087 100644
--- a/tools/tests/Makefile
+++ b/tools/tests/Makefile
@@ -46,6 +46,8 @@ LIBS = -lcmocka \
        $(BUILDDIR)/libebgenv.a \
        -lz
 
+ENV_API ?= env_api_fat
+
 # Test recipes shall run everytime independent of already built files.
 # A simple way to achieve this is to depend on files that don't exist
 # by changing their extension with Makefile's string functions.
@@ -53,20 +55,20 @@ LIBS = -lcmocka \
 # dependency recipes.
 # All targets' '.target' extensions get removed within the target recipes.
 #
-OBJS_test_partitions = test_partitions.O env_api_fat.O ebgpart.O
-OBJS_test_environment = test_environment.O env_api_fat.O ebgpart.O
-OBJS_test_api = test_api.O env_api_fat.O ebgenv.O
+OBJS_test_partitions = test_partitions.O $(ENV_API).O ebgpart.O
+OBJS_test_environment = test_environment.O $(ENV_API).O ebgpart.O
+OBJS_test_api = test_api.O $(ENV_API).O ebgenv.O
 
-MOCKOBJS_test_partitions = env_api_fat ebgpart
-MOCKOBJS_test_environment = env_api_fat
-MOCKOBJS_test_api = env_api_fat
+MOCKOBJS_test_partitions = $(ENV_API) ebgpart
+MOCKOBJS_test_environment = $(ENV_API) 
+MOCKOBJS_test_api = $(ENV_API) 
 
 # Define symbols to be stripped dependent on target and object file name
 # MOCKOBJS_SYMBOLS_objectname-targetname = symbolname1 symbolname2 ...
 
-MOCKOBJS_SYMBOLS_env_api_fat-test_partitions = probe_config_file
-MOCKOBJS_SYMBOLS_env_api_fat-test_environment = oldenvs configparts fopen 
fclose fread fwrite feof mount_partition
-MOCKOBJS_SYMBOLS_env_api_fat-test_api = bgenv_init bgenv_write bgenv_close 
bgenv_get_latest bgenv_get_by_index bgenv_get_oldest
+MOCKOBJS_SYMBOLS_$(ENV_API)-test_partitions = probe_config_file
+MOCKOBJS_SYMBOLS_$(ENV_API)-test_environment = oldenvs configparts fopen 
fclose fread fwrite feof mount_partition
+MOCKOBJS_SYMBOLS_$(ENV_API)-test_api = bgenv_init bgenv_write bgenv_close 
bgenv_get_latest bgenv_get_by_index bgenv_get_oldest
 MOCKOBJS_SYMBOLS_ebgpart-test_partitions = ped_device_probe_all 
ped_device_get_next ped_disk_next_partition
 
 TEST_TARGETS = test_partitions.target test_environment.target test_api.target
diff --git a/tools/tests/test_partitions.c b/tools/tests/test_partitions.c
index c6865e4..4387ecd 100644
--- a/tools/tests/test_partitions.c
+++ b/tools/tests/test_partitions.c
@@ -17,6 +17,7 @@
 #include <setjmp.h>
 #include <cmocka.h>
 #include "env_api.h"
+#include "ebgpart.h"
 #include "test-interface.h"
 
 static PedDevice ped_devices[32] = {0};
-- 
2.14.1

-- 
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/20170921132111.29035-6-andreas.reichel.ext%40siemens.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to