[LEDE-DEV] [PATCH 02/12] uci: patch for static host build

Yousong Zhou yszhou4tech at gmail.com
Sun Mar 5 01:31:33 PST 2017


Signed-off-by: Yousong Zhou <yszhou4tech at gmail.com>
---
 .../uci/patches/0001-build-fix-BUILD_STATIC.patch  | 63 ++++++++++++++++++++++
 ...-redundant-NULL-check-on-return-value-of-.patch | 29 ++++++++++
 ...w-setting-confdir-and-savedir-with-enviro.patch | 58 ++++++++++++++++++++
 3 files changed, 150 insertions(+)
 create mode 100644 package/system/uci/patches/0001-build-fix-BUILD_STATIC.patch
 create mode 100644 package/system/uci/patches/0002-file-remove-redundant-NULL-check-on-return-value-of-.patch
 create mode 100644 package/system/uci/patches/0003-libuci-allow-setting-confdir-and-savedir-with-enviro.patch

diff --git a/package/system/uci/patches/0001-build-fix-BUILD_STATIC.patch b/package/system/uci/patches/0001-build-fix-BUILD_STATIC.patch
new file mode 100644
index 0000000..4a1bfa8
--- /dev/null
+++ b/package/system/uci/patches/0001-build-fix-BUILD_STATIC.patch
@@ -0,0 +1,63 @@
+From 1c109a2247240846a853996d24305d1e3ced2581 Mon Sep 17 00:00:00 2001
+From: Yousong Zhou <yszhou4tech at gmail.com>
+Date: Sat, 4 Mar 2017 21:12:46 +0800
+Subject: [PATCH 1/3] build: fix BUILD_STATIC
+
+ - Build libuci.a in addition to libuci.so
+ - Build uci cli utitlity statically if BUILD_STATIC is enabled
+
+Signed-off-by: Yousong Zhou <yszhou4tech at gmail.com>
+---
+ CMakeLists.txt | 24 ++++++++++++++++--------
+ 1 file changed, 16 insertions(+), 8 deletions(-)
+
+diff --git a/CMakeLists.txt b/CMakeLists.txt
+index a900a15..2df6fa7 100644
+--- a/CMakeLists.txt
++++ b/CMakeLists.txt
+@@ -8,12 +8,7 @@ ADD_DEFINITIONS(-Os -Wall -Werror --std=gnu99 -g3 -I. -DUCI_PREFIX="${CMAKE_INST
+ OPTION(UCI_DEBUG "debugging support" OFF)
+ OPTION(UCI_DEBUG_TYPECAST "typecast debugging support" OFF)
+ OPTION(BUILD_LUA "build Lua binding" ON)
+-
+-IF(BUILD_STATIC)
+-  FIND_LIBRARY(ubox_library NAMES ubox.a)
+-ELSE(BUILD_STATIC)
+-  FIND_LIBRARY(ubox_library NAMES ubox)
+-ENDIF(BUILD_STATIC)
++OPTION(BUILD_STATIC "statically linking uci" OFF)
+ 
+ FIND_PATH(ubox_include_dir libubox/usock.h)
+ 
+@@ -23,13 +18,26 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR} ${ubox_include_dir})
+ 
+ SET(LIB_SOURCES libuci.c file.c util.c delta.c parse.c blob.c)
+ 
++FIND_LIBRARY(ubox NAMES ubox)
++IF(BUILD_STATIC)
++  FIND_LIBRARY(ubox-static NAMES libubox.a)
++ENDIF(BUILD_STATIC)
++
+ ADD_LIBRARY(uci SHARED ${LIB_SOURCES})
+-TARGET_LINK_LIBRARIES(uci ${ubox_library})
+ SET_TARGET_PROPERTIES(uci PROPERTIES OUTPUT_NAME uci)
++TARGET_LINK_LIBRARIES(uci ${ubox})
++
++ADD_LIBRARY(uci-static STATIC ${LIB_SOURCES})
++SET_TARGET_PROPERTIES(uci-static PROPERTIES OUTPUT_NAME uci)
++TARGET_LINK_LIBRARIES(uci-static ${ubox-static})
+ 
+ ADD_EXECUTABLE(cli cli.c)
+ SET_TARGET_PROPERTIES(cli PROPERTIES OUTPUT_NAME uci)
+-TARGET_LINK_LIBRARIES(cli uci)
++IF(BUILD_STATIC)
++  TARGET_LINK_LIBRARIES(cli uci-static ${ubox-static})
++ELSE(BUILD_STATIC)
++  TARGET_LINK_LIBRARIES(cli uci ubox)
++ENDIF(BUILD_STATIC)
+ 
+ ADD_LIBRARY(ucimap STATIC ucimap.c)
+ 
+-- 
+2.6.4
+
diff --git a/package/system/uci/patches/0002-file-remove-redundant-NULL-check-on-return-value-of-.patch b/package/system/uci/patches/0002-file-remove-redundant-NULL-check-on-return-value-of-.patch
new file mode 100644
index 0000000..0f27af1
--- /dev/null
+++ b/package/system/uci/patches/0002-file-remove-redundant-NULL-check-on-return-value-of-.patch
@@ -0,0 +1,29 @@
+From 7e0f33c7b4747a2b48588cc3337b01c19c9b562d Mon Sep 17 00:00:00 2001
+From: Yousong Zhou <yszhou4tech at gmail.com>
+Date: Wed, 27 May 2015 10:30:42 +0800
+Subject: [PATCH 2/3] file: remove redundant NULL check on return value of
+ uci_realloc()
+
+Because the check will be done by uci_realloc itself.
+
+Signed-off-by: Yousong Zhou <yszhou4tech at gmail.com>
+---
+ file.c | 2 --
+ 1 file changed, 2 deletions(-)
+
+diff --git a/file.c b/file.c
+index 7e1e4e6..151a308 100644
+--- a/file.c
++++ b/file.c
+@@ -70,8 +70,6 @@ __private void uci_getln(struct uci_context *ctx, int offset)
+ 
+ 		pctx->bufsz *= 2;
+ 		pctx->buf = uci_realloc(ctx, pctx->buf, pctx->bufsz);
+-		if (!pctx->buf)
+-			UCI_THROW(ctx, UCI_ERR_MEM);
+ 	} while (1);
+ }
+ 
+-- 
+2.6.4
+
diff --git a/package/system/uci/patches/0003-libuci-allow-setting-confdir-and-savedir-with-enviro.patch b/package/system/uci/patches/0003-libuci-allow-setting-confdir-and-savedir-with-enviro.patch
new file mode 100644
index 0000000..801420d
--- /dev/null
+++ b/package/system/uci/patches/0003-libuci-allow-setting-confdir-and-savedir-with-enviro.patch
@@ -0,0 +1,58 @@
+From 8ae26f2c0152c6bd58b7404a400e41405b034cc9 Mon Sep 17 00:00:00 2001
+From: Yousong Zhou <yszhou4tech at gmail.com>
+Date: Sun, 5 Mar 2017 13:43:05 +0800
+Subject: [PATCH 3/3] libuci: allow setting confdir and savedir with
+ environment variables
+
+-p and -P option of uci cli utitlity is not enough for 2 reasons
+
+ - Compile-time default cannot be ignored
+ - CLI_FLAG_NOCOMMIT will be in effect with -P option
+
+Signed-off-by: Yousong Zhou <yszhou4tech at gmail.com>
+---
+ libuci.c | 21 +++++++++++++++++++--
+ 1 file changed, 19 insertions(+), 2 deletions(-)
+
+diff --git a/libuci.c b/libuci.c
+index a9e70e8..19ea20f 100644
+--- a/libuci.c
++++ b/libuci.c
+@@ -24,6 +24,7 @@
+ #include <stdio.h>
+ #include <dlfcn.h>
+ #include <glob.h>
++#include <libubox/utils.h>
+ #include "uci.h"
+ 
+ static const char *uci_errstr[] = {
+@@ -40,8 +41,24 @@ static const char *uci_errstr[] = {
+ #include "uci_internal.h"
+ #include "list.c"
+ 
+-__private const char *uci_confdir = UCI_CONFDIR;
+-__private const char *uci_savedir = UCI_SAVEDIR;
++__private const char *uci_confdir;
++__private const char *uci_savedir;
++
++static const char *uci_getenv_default(const char *var, const char *defval)
++{
++	const char *val;
++
++	val = getenv(var);
++	if (val)
++		return val;
++	else
++		return defval;
++}
++
++static void __constructor uci_dir_init(void) {
++	uci_confdir = uci_getenv_default("UCI_CONFDIR", UCI_CONFDIR);
++	uci_savedir = uci_getenv_default("UCI_SAVEDIR", UCI_SAVEDIR);
++}
+ 
+ /* exported functions */
+ struct uci_context *uci_alloc_context(void)
+-- 
+2.6.4
+
-- 
2.6.4




More information about the Lede-dev mailing list