[LEDE-DEV] [PATCH 03/12] uci: add host build

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


Signed-off-by: Yousong Zhou <yszhou4tech at gmail.com>
---
 package/system/uci/Makefile                | 15 ++++++++++++++-
 package/system/uci/files/lib/config/uci.sh | 31 ++++++++++++++++--------------
 2 files changed, 31 insertions(+), 15 deletions(-)

diff --git a/package/system/uci/Makefile b/package/system/uci/Makefile
index b4d019c..dc6b363 100644
--- a/package/system/uci/Makefile
+++ b/package/system/uci/Makefile
@@ -9,7 +9,7 @@
 include $(TOPDIR)/rules.mk
 
 PKG_NAME:=uci
-PKG_RELEASE:=1
+PKG_RELEASE:=2
 
 PKG_SOURCE_URL=$(LEDE_GIT)/project/uci.git
 PKG_SOURCE_PROTO:=git
@@ -24,7 +24,10 @@ PKG_MAINTAINER:=Felix Fietkau <nbd at nbd.name>
 
 PKG_BUILD_PARALLEL:=0
 
+HOST_BUILD_DEPENDS:=libubox/host
+
 include $(INCLUDE_DIR)/package.mk
+include $(INCLUDE_DIR)/host-build.mk
 include $(INCLUDE_DIR)/cmake.mk
 
 # set to 1 to enable debugging
@@ -58,6 +61,10 @@ CMAKE_OPTIONS = \
 	-DLUAPATH=/usr/lib/lua \
 	$(if $(DEBUG),-DUCI_DEBUG=ON)
 
+CMAKE_HOST_OPTIONS += \
+	-DBUILD_STATIC=ON \
+	-DBUILD_LUA=OFF \
+
 define Package/libuci/install
 	$(INSTALL_DIR) $(1)/lib
 	$(CP) $(PKG_BUILD_DIR)/libuci.so* $(1)/lib/
@@ -83,6 +90,12 @@ define Build/InstallDev
 	$(CP) $(PKG_BUILD_DIR)/libucimap.a $(1)/usr/lib
 endef
 
+define Host/Install
+	$(INSTALL_DIR) $(STAGING_DIR_HOST)/sbin
+	$(INSTALL_BIN) $(HOST_BUILD_DIR)/uci $(STAGING_DIR_HOST)/sbin/uci
+endef
+
 $(eval $(call BuildPackage,uci))
 $(eval $(call BuildPackage,libuci))
 $(eval $(call BuildPackage,libuci-lua))
+$(eval $(call HostBuild))
diff --git a/package/system/uci/files/lib/config/uci.sh b/package/system/uci/files/lib/config/uci.sh
index 50891a6..d716723 100644
--- a/package/system/uci/files/lib/config/uci.sh
+++ b/package/system/uci/files/lib/config/uci.sh
@@ -19,6 +19,9 @@
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 
 CONFIG_APPEND=
+UCI="${UCI:-/sbin/uci}"
+UCI_STATE_DIR="${IPKG_INSTROOT}/var/state}"
+
 uci_load() {
 	local PACKAGE="$1"
 	local DATA
@@ -37,7 +40,7 @@ uci_load() {
 		export ${NO_EXPORT:+-n} CONFIG_SECTION=
 	fi
 
-	DATA="$(/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} ${LOAD_STATE:+-P /var/state} -S -n export "$PACKAGE" 2>/dev/null)"
+	DATA="$($UCI ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} ${LOAD_STATE:+-P "$UCI_STATE_DIR"} -S -n export "$PACKAGE" 2>/dev/null)"
 	RET="$?"
 	[ "$RET" != 0 -o -z "$DATA" ] || eval "$DATA"
 	unset DATA
@@ -48,9 +51,9 @@ uci_load() {
 
 uci_set_default() {
 	local PACKAGE="$1"
-	/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -q show "$PACKAGE" > /dev/null && return 0
-	/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} import "$PACKAGE"
-	/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} commit "$PACKAGE"
+	$UCI ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -q show "$PACKAGE" > /dev/null && return 0
+	$UCI ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} import "$PACKAGE"
+	$UCI ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} commit "$PACKAGE"
 }
 
 uci_revert_state() {
@@ -58,7 +61,7 @@ uci_revert_state() {
 	local CONFIG="$2"
 	local OPTION="$3"
 
-	/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -P /var/state revert "$PACKAGE${CONFIG:+.$CONFIG}${OPTION:+.$OPTION}"
+	$UCI ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -P "$UCI_STATE_DIR" revert "$PACKAGE${CONFIG:+.$CONFIG}${OPTION:+.$OPTION}"
 }
 
 uci_set_state() {
@@ -68,7 +71,7 @@ uci_set_state() {
 	local VALUE="$4"
 
 	[ "$#" = 4 ] || return 0
-	/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -P /var/state set "$PACKAGE.$CONFIG${OPTION:+.$OPTION}=$VALUE"
+	$UCI ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -P "$UCI_STATE_DIR" set "$PACKAGE.$CONFIG${OPTION:+.$OPTION}=$VALUE"
 }
 
 uci_toggle_state() {
@@ -82,11 +85,11 @@ uci_set() {
 	local OPTION="$3"
 	local VALUE="$4"
 
-	/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} set "$PACKAGE.$CONFIG.$OPTION=$VALUE"
+	$UCI ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} set "$PACKAGE.$CONFIG.$OPTION=$VALUE"
 }
 
 uci_get_state() {
-	uci_get "$1" "$2" "$3" "$4" "/var/state"
+	uci_get "$1" "$2" "$3" "$4" ""$UCI_STATE_DIR""
 }
 
 uci_get() {
@@ -96,7 +99,7 @@ uci_get() {
 	local DEFAULT="$4"
 	local STATE="$5"
 
-	/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} ${STATE:+-P $STATE} -q get "$PACKAGE${CONFIG:+.$CONFIG}${OPTION:+.$OPTION}"
+	$UCI ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} ${STATE:+-P $STATE} -q get "$PACKAGE${CONFIG:+.$CONFIG}${OPTION:+.$OPTION}"
 	RET="$?"
 	[ "$RET" -ne 0 ] && [ -n "$DEFAULT" ] && echo "$DEFAULT"
 	return "$RET"
@@ -108,9 +111,9 @@ uci_add() {
 	local CONFIG="$3"
 
 	if [ -z "$CONFIG" ]; then
-		export ${NO_EXPORT:+-n} CONFIG_SECTION="$(/sbin/uci add "$PACKAGE" "$TYPE")"
+		export ${NO_EXPORT:+-n} CONFIG_SECTION="$($UCI add "$PACKAGE" "$TYPE")"
 	else
-		/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} set "$PACKAGE.$CONFIG=$TYPE"
+		$UCI ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} set "$PACKAGE.$CONFIG=$TYPE"
 		export ${NO_EXPORT:+-n} CONFIG_SECTION="$CONFIG"
 	fi
 }
@@ -120,7 +123,7 @@ uci_rename() {
 	local CONFIG="$2"
 	local VALUE="$3"
 
-	/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} rename "$PACKAGE.$CONFIG=$VALUE"
+	$UCI ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} rename "$PACKAGE.$CONFIG=$VALUE"
 }
 
 uci_remove() {
@@ -128,10 +131,10 @@ uci_remove() {
 	local CONFIG="$2"
 	local OPTION="$3"
 
-	/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} del "$PACKAGE.$CONFIG${OPTION:+.$OPTION}"
+	$UCI ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} del "$PACKAGE.$CONFIG${OPTION:+.$OPTION}"
 }
 
 uci_commit() {
 	local PACKAGE="$1"
-	/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} commit $PACKAGE
+	$UCI ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} commit $PACKAGE
 }
-- 
2.6.4




More information about the Lede-dev mailing list