openwrt加入leveldb包編譯

coding夢想_起點發表於2020-10-23

升級openwrt的cmake工具版本

  • 由於標準openwrt發行版沒有帶leveldb包,需要自己加入,首先openwrt 的cmake 版本必須在3.1.13版本往上。升級cmake方法,修改openwrt/tools/cmake/Makefile如下,同時刪掉patchs目錄
#
# Copyright (C) 2006-2014 OpenWrt.org
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#
include $(TOPDIR)/rules.mk

PKG_NAME:=cmake
PKG_VERSION:=3.1.3

PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=http://www.cmake.org/files/v3.1/
PKG_MD5SUM:=5697a77503bb5636f4b4057dcc02aa32

HOST_BUILD_PARALLEL:=1
HOST_CONFIGURE_PARALLEL:=1

include $(INCLUDE_DIR)/host-build.mk

HOST_CONFIGURE_VARS :=

HOST_CONFIGURE_ARGS := \
    --prefix=$(STAGING_DIR_HOST) \
    $(if $(MAKE_JOBSERVER),--parallel="$(MAKE_JOBSERVER)")

$(eval $(call HostBuild))

配置leveldb包

  • 新建包目錄以及feeds/packages/libs/leveldb/Makefile檔案,內容如下,
    同時新建feeds/packages/libs/leveldb/patches,放入對應的補丁檔案,命名為100-downgrade-cmake-version.patch
include $(TOPDIR)/rules.mk

PKG_NAME:=leveldb
PKG_VERSION:=1.22
PKG_RELEASE:=1
PKG_INSTALL:=1

PKG_SOURCE:=$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=https://github.com/google/leveldb/archive/
PKG_MD5SUM:=e1dbde14dcda1b58b49f0c214464fdd9
PKG_BUILD_PARALLEL:=1

include $(INCLUDE_DIR)/package.mk
include $(INCLUDE_DIR)/cmake.mk

define Package/leveldb/Default
  SUBMENU:=database
  TITLE:=(leveldb)A key/value database library
  URL:=https://code.google.com/p/leveldb/
  MAINTAINER:=code.google.com
endef

define Package/leveldb
  DEPENDS:=+snappy
  SECTION:=libs
  CATEGORY:=Libraries
  SUBMENU:=database
  TITLE:=A fast and lightweight key/value database library
  URL:=https://code.google.com/p/leveldb/
  DEPENDS:=+libstdcpp +libpthread
  DEFAULT:=y
endef

CMAKE_OPTIONS += \
    -DCMAKE_BUILD_TYPE=Release \
    -DBUILD_SHARED_LIBS=ON

TARGET_CFLAGS += \
    -D_GLIBCXX_USE_C99

define Package/leveldb/Default/description
A fast and lightweight key/value database library
endef

define Build/Compile
  $(call Build/Compile/Default)
endef

define Package/leveldb/install
  $(MAKE) $(PKG_JOBS) -C $(PKG_BUILD_DIR) DESTDIR="$(1)" install
endef

$(eval $(call BuildPackage,leveldb))

leveldb補丁patches檔案

Index: leveldb-1.22/CMakeLists.txt
===================================================================
--- leveldb-1.22.orig/CMakeLists.txt
+++ leveldb-1.22/CMakeLists.txt
@@ -2,7 +2,7 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file. See the AUTHORS file for names of contributors.
-cmake_minimum_required(VERSION 3.9)
+cmake_minimum_required(VERSION 3.1.13)
# Keep the version below in sync with the one in db.h
project(leveldb VERSION 1.22.0 LANGUAGES C CXX)
  • 由於leveldb使用C++實現,C語言是無法直接呼叫的,好在leveldb已經實現了C繫結,參考原始碼目錄下的c_test.c檔案的呼叫API

相關文章