[OpenWrt-Devel] uqmi: separate into libuqmi library and uqmi util itself
diff mbox series

Message ID 20190823135749.32764-1-denis281089@gmail.com
State New
Headers show
Series
  • [OpenWrt-Devel] uqmi: separate into libuqmi library and uqmi util itself
Related show

Commit Message

Denis Kalashnikov Aug. 23, 2019, 1:57 p.m. UTC
It is needed to reuse qmi code, e.g. in a modem manager util
which is useful on routers with several cell modems.

Signed-off-by: Denis Kalashnikov <denis281089@gmail.com>

---
 package/network/utils/uqmi/Makefile           | 25 +++++++++-
 .../utils/uqmi/patches/10000-libuqmi.patch    | 46 +++++++++++++++++++
 2 files changed, 70 insertions(+), 1 deletion(-)
 create mode 100644 package/network/utils/uqmi/patches/10000-libuqmi.patch

Patch
diff mbox series

diff --git a/package/network/utils/uqmi/Makefile b/package/network/utils/uqmi/Makefile
index dee4bd051e..49386c9f7a 100644
--- a/package/network/utils/uqmi/Makefile
+++ b/package/network/utils/uqmi/Makefile
@@ -24,7 +24,7 @@  define Package/uqmi
   SECTION:=net
   CATEGORY:=Network
   SUBMENU:=WWAN
-  DEPENDS:=+libubox +libblobmsg-json +kmod-usb-net +kmod-usb-net-qmi-wwan +wwan
+  DEPENDS:=+libubox +libblobmsg-json +kmod-usb-net +kmod-usb-net-qmi-wwan +wwan +libuqmi
   TITLE:=Control utility for mobile broadband modems
 endef
 
@@ -33,6 +33,17 @@  define Package/uqmi/description
   the QMI-protocol.
 endef
 
+define Package/libuqmi
+  SECTION:=libs
+  CATEGORY:=Libraries
+  DEPENDS:=+libubox +kmod-usb-net +kmod-usb-net-qmi-wwan +wwan
+  TITLE:=Control library for mobile broadband modems
+endef
+
+define Package/libuqmi/description
+ Shared library for controlling mobile broadband modems using the QMI-protocol.
+endef
+
 TARGET_CFLAGS += \
 	-I$(STAGING_DIR)/usr/include -ffunction-sections -fdata-sections
 
@@ -41,10 +52,22 @@  TARGET_LDFLAGS += -Wl,--gc-sections
 CMAKE_OPTIONS += \
 	-DDEBUG=1
 
+define Build/InstallDev
+	$(INSTALL_DIR) $(STAGING_DIR)/usr/include/libuqmi
+	$(CP) $(PKG_BUILD_DIR)/*.h $(STAGING_DIR)/usr/include/libuqmi
+	$(CP) $(PKG_BUILD_DIR)/libuqmi.so $(STAGING_DIR)/usr/lib
+endef
+
 define Package/uqmi/install
 	$(INSTALL_DIR) $(1)/sbin
 	$(INSTALL_BIN) $(PKG_BUILD_DIR)/uqmi $(1)/sbin/
 	$(CP) ./files/* $(1)/
 endef
 
+define Package/libuqmi/install
+	$(INSTALL_DIR) $(1)/usr/lib
+	$(CP) $(PKG_BUILD_DIR)/libuqmi.so $(1)/usr/lib
+endef
+
 $(eval $(call BuildPackage,uqmi))
+$(eval $(call BuildPackage,libuqmi))
diff --git a/package/network/utils/uqmi/patches/10000-libuqmi.patch b/package/network/utils/uqmi/patches/10000-libuqmi.patch
new file mode 100644
index 0000000000..b17aecb078
--- /dev/null
+++ b/package/network/utils/uqmi/patches/10000-libuqmi.patch
@@ -0,0 +1,46 @@ 
+Index: uqmi-2019-06-27-1965c713/CMakeLists.txt
+===================================================================
+--- uqmi-2019-06-27-1965c713.orig/CMakeLists.txt
++++ uqmi-2019-06-27-1965c713/CMakeLists.txt
+@@ -8,7 +8,8 @@ ADD_DEFINITIONS(-Os -ggdb -Wall -Werror
+ 
+ SET(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
+ 
+-SET(SOURCES main.c dev.c commands.c qmi-message.c mbim.c)
++SET(SOURCES main.c commands.c)
++SET(LIB_SOURCES dev.c qmi-message.c mbim.c)
+ 
+ FIND_PATH(ubox_include_dir libubox/usock.h)
+ FIND_PATH(blobmsg_json_include_dir libubox/blobmsg_json.h)
+@@ -61,11 +62,15 @@ ADD_CUSTOM_COMMAND(
+ ADD_CUSTOM_TARGET(gen-errors DEPENDS qmi-errors.c)
+ ADD_CUSTOM_TARGET(gen-headers DEPENDS ${service_headers})
+ 
+-ADD_EXECUTABLE(uqmi ${SOURCES} ${service_sources})
++ADD_LIBRARY(uqmi SHARED ${LIB_SOURCES} ${service_sources})
+ ADD_DEPENDENCIES(uqmi gen-headers gen-errors)
+ 
+-TARGET_LINK_LIBRARIES(uqmi ${LIBS})
++ADD_EXECUTABLE(uqmi_bin ${SOURCES})
++TARGET_LINK_LIBRARIES(uqmi_bin ${LIBS} uqmi)
++SET_TARGET_PROPERTIES(uqmi_bin PROPERTIES OUTPUT_NAME uqmi)
+ 
+-INSTALL(TARGETS uqmi
++INSTALL(TARGETS uqmi_bin
+ 	RUNTIME DESTINATION sbin
+ )
++
++INSTALL(TARGETS uqmi LIBRARY DESTINATION /usr/lib)
+Index: uqmi-2019-06-27-1965c713/dev.c
+===================================================================
+--- uqmi-2019-06-27-1965c713.orig/dev.c
++++ uqmi-2019-06-27-1965c713/dev.c
+@@ -353,8 +353,6 @@ int qmi_device_open(struct qmi_dev *qmi,
+ 	struct ustream *us = &qmi->sf.stream;
+ 	int fd;
+ 
+-	uloop_init();
+-
+ 	fd = open(path, O_RDWR | O_EXCL | O_NONBLOCK | O_NOCTTY);
+ 	if (fd < 0)
+ 		return -1;