openwrt sdk 添加軟件包 Makefile 寫法

參考 https://openwrt.org/start?id=docs/guide-developer/packages ,英文稍好點的本身看吧,我寫出來也就是方便,英文很差的人看。html

軟件包的來源,有幾種來源。git , sourceforge.net , 或是某軟件本身的網站下載。 也支持 svn 什麼的,不經常使用的就不介紹了git

1, git 下載github

PKG_NAME:=dkjson PKG_VERSION:=2.5 PKG_RELEASE:=3 PKG_SOURCE_URL:=https://github.com/LuaDist/dkjson.git
PKG_SOURCE_PROTO:=git PKG_SOURCE_VERSION:=e72ba0c9f5d8b8746fc306f6189a819dbb5cd0be

首選是 git 地址 https://github.com/LuaDist/dkjson.git 而後是版本號 e72ba0c9f5d8b8746fc306f6189a819dbb5cd0bejson

你們都知道git 提交之後,會生成這個吧。 git log 能夠查看到。小程序

2, http https 下載app

PKG_NAME:=mpg123 PKG_VERSION:=1.25.10 PKG_RELEASE:=1 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.bz2 PKG_SOURCE_URL:=@SF/mpg123 PKG_HASH:=6c1337aee2e4bf993299851c70b7db11faec785303cfca3a5c3eb5f329ba7023

表示從 SF 也就是 https://sourceforge.net/ 上面下載,把版本號拼上來下載地址就是 ide

https://downloads.sourceforge.net/mpg123/mpg123-1.25.10.tar.bz2svn

PKG_NAME:=mpd PKG_VERSION:=0.20.20 PKG_RELEASE:=1 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.xz PKG_SOURCE_URL:=http://www.musicpd.org/download/mpd/0.20/
PKG_HASH:=a9e458c6e07cdf62649de7722e1e5a7f13aa82eeb397bfbbebc07cf5cf273584

沒有放到 sf.net 的 從本身的網站下載oop

PKG_HASH 是 sha256 測試

3, 配置說明信息

define Package/libev SECTION:=libs CATEGORY:=Libraries TITLE:=High-performance event loop URL:=http://software.schmorp.de/pkg/libev.html
  DEPENDS:=+zlib +libpthread endef

在 make menuconfig 哪一個選擇項目裏面出現,以及說明信息。

4, configure 編譯附加指令

CONFIGURE_ARGS += \ --enable-shared \ --enable-static \

編譯出來 動態庫, 靜態庫。

功能介紹

表示在哪一個選項包裏面
define Package/cJSON

描述
define Package/cJSON/description

編譯配置
define Build/Configure

編譯前
define Build/Prepare

編譯
define Build/Compile

安裝
define Package/cJSON/install

安裝到 dev 通常是頭文件和 靜態庫 動態庫
define Build/InstallDev

有幾個不是必須的,若是 不寫就是用默認的

例:添加一個 cJSON 包

# # This is free software, licensed under the GNU General Public License v2. # See /LICENSE for more information. # https://github.com/DaveGamble/cJSON.git
# include $(TOPDIR)/rules.mk PKG_NAME:=cJSON #包名 PKG_VERSION:=1.7.7 #版本 PKG_RELEASE:=1 PKG_MAINTAINER:=DaveGamble #做者 PKG_SOURCE_PROTO:=git #git PKG_SOURCE_URL:=https://github.com/DaveGamble/cJSON.git #git 地址
PKG_MIRROR_HASH:=9fe484dd954f6c573fee367ecea5aadfb743bee0a9d6aa917c29528b73fa5fa3 #自動生成的不用管 PKG_SOURCE_VERSION:=787d651e8131c6394c6ff844f108e1a53012949f #git 提交記錄 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.xz #在 dl 中保存的文件名 PKG_SOURCE_SUBDIR:=$(PKG_NAME)-$(PKG_VERSION) PKG_LICENSE:=MIT #許可證 PKG_LICENSE_FILES:=LICENSE #許可證文件 include $(INCLUDE_DIR)/package.mk define Package/cJSON SECTION:=net CATEGORY:=Network TITLE:=cJSON URL:=https://github.com/DaveGamble
 endef define Package/cJSON/description Ultralightweight JSON parser in ANSI C. endef define Build/InstallDev #安裝頭文件 靜態庫 動態庫什麼的 $(INSTALL_DIR) $(1)/usr/include $(CP) $(PKG_BUILD_DIR)/cJSON.h $(1)/usr/include/ $(INSTALL_DIR) $(1)/usr/lib $(CP) $(PKG_BUILD_DIR)/libcjson.{a,so*} $(1)/usr/lib/ endef define Package/cJSON/install #安裝到 固件中的 動態庫 可執行程序 $(INSTALL_DIR) $(1)/usr/bin $(INSTALL_BIN) $(PKG_BUILD_DIR)/cJSON_test $(1)/usr/bin $(INSTALL_DIR) $(1)/usr/lib $(CP) $(PKG_BUILD_DIR)/libcjson.so.* $(1)/usr/lib/ $(CP) $(PKG_BUILD_DIR)/libcjson_utils.so.* $(1)/usr/lib/ endef $(eval $(call BuildPackage,cJSON))

另一個 cmake 版

# # This is free software, licensed under the GNU General Public License v2. # See /LICENSE for more information. # https://github.com/DaveGamble/cJSON.git
# include $(TOPDIR)/rules.mk PKG_NAME:=cJSON PKG_VERSION:=1.7.7 PKG_RELEASE:=1 PKG_MAINTAINER:=DaveGamble PKG_SOURCE_PROTO:=git PKG_SOURCE_URL:=https://github.com/DaveGamble/cJSON.git
PKG_MIRROR_HASH:=9fe484dd954f6c573fee367ecea5aadfb743bee0a9d6aa917c29528b73fa5fa3 PKG_SOURCE_VERSION:=787d651e8131c6394c6ff844f108e1a53012949f PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.xz PKG_SOURCE_SUBDIR:=$(PKG_NAME)-$(PKG_VERSION) PKG_LICENSE:=MIT PKG_LICENSE_FILES:=LICENSE include $(INCLUDE_DIR)/package.mk include $(INCLUDE_DIR)/cmake.mk #添加 cmake define Package/cJSON SECTION:=net CATEGORY:=Network TITLE:=cJSON URL:=https://github.com/DaveGamble
endef define Package/cJSON/description Ultralightweight JSON parser in ANSI C. endef 
#cmake 參數 CMAKE_OPTIONS
+= -DENABLE_CJSON_UTILS=On \ -DENABLE_CJSON_TEST=On \ -DBUILD_SHARED_AND_STATIC_LIBS=On\ -DCMAKE_INSTALL_PREFIX=/usr define Build/InstallDev $(INSTALL_DIR) $(1)/usr/include $(CP) $(PKG_INSTALL_DIR)/usr/include/cjson $(1)/usr/include/ $(INSTALL_DIR) $(1)/usr/lib $(CP) $(PKG_INSTALL_DIR)/usr/lib/libcjson.{a,so*} $(1)/usr/lib/ endef define Package/cJSON/install $(INSTALL_DIR) $(1)/usr/bin $(INSTALL_BIN) $(PKG_BUILD_DIR)/cJSON_test $(1)/usr/bin $(INSTALL_DIR) $(1)/usr/lib $(CP) $(PKG_INSTALL_DIR)/usr/lib/libcjson.so.* $(1)/usr/lib/ $(CP) $(PKG_INSTALL_DIR)/usr/lib/libcjson_utils.so.* $(1)/usr/lib/ endef $(eval $(call BuildPackage,cJSON))

cmake 的編譯仍是比較簡單的。

寫了一個 測試 cjson 的小程序 

 1 #include <stdio.h>
 2 #include <cjson/cJSON.h>
 3 
 4 int main(int argc, char **argv)  5 {  6     cJSON *root;  7     
 8     root = cJSON_CreateObject();  9     cJSON_AddStringToObject(root, "VER",       "1.0"); 10     cJSON_AddStringToObject(root, "IP",        "127.0.0.1"); 11     cJSON_AddStringToObject(root, "DATE",      "2018"); 12     
13     printf("cjson: %s", cJSON_PrintUnformatted(root)); 14  cJSON_Delete(root); 15     return 0; 16 }

Makefile 工程

include $(TOPDIR)/rules.mk # Name, version and release number # The name and version of your package are used to define the variable to point to the build directory of your package: $(PKG_BUILD_DIR) PKG_NAME:=cjson_hello PKG_VERSION:=1.0 PKG_RELEASE:=1 include $(INCLUDE_DIR)/package.mk # Package definition; instructs on how and where our package will appear in the overall configuration menu ('make menuconfig') define Package/cjson_hello SECTION:=examples CATEGORY:=Examples TITLE:=cjson_hello, World! DEPENDS:=+cJSON endef # Package description; a more verbose description on what our package does define Package/cjson_hello/description A simple "Hello, world!" -application. endef define Build/Prepare mkdir -p $(PKG_BUILD_DIR) cp ./src/* $(PKG_BUILD_DIR) $(Build/Patch) endef define Package/cjson_hello/install $(INSTALL_DIR) $(1)/usr/bin $(INSTALL_BIN) $(PKG_BUILD_DIR)/cjson_hello $(1)/usr/bin endef $(eval $(call BuildPackage,cjson_hello))

只須要添加這行 引用 庫 就能夠了 DEPENDS:=+cJSON , openwrt 真的是太方便了,這點比 yocto 易用。

看測試截圖

相關文章
相關標籤/搜索