您的位置:首页 > 运维架构

Ubus移植到openwrt

2015-08-13 08:43 513 查看
ubus移植到openwrt

环境为Ubuntu12.04,交叉编译工具为mipsel-openwrt-linux-gcc

首先参考杰哥的链接:
openwrt ubus 移植到ARM上 http://blog.csdn.net/h893529689/article/details/46873451 openwrt libubox 移植到ARM上 http://blog.csdn.net/h893529689/article/details/46861201  
弄清楚依赖关系
要编译ubus,需要libubox,libubox又需要json-c。
 
源码为libubox-2014-08-04-dffbc09baf71b294185a36048166d00066d433b5.tar.gz,这个库依赖json-c 库,所以要先移植json-c库(json-c-0.11.tar.gz)。  
json-c移植
具体步骤如下:
1. 解压源码
2. 编辑config.h.in 文件,一定要去掉下面两行内容,红色字体为要删除的
/*Define to rpl_malloc if the replacement function should be used. */
#undefmalloc
/*Define to rpl_realloc if the replacement function should be used. */
#undefrealloc
3.  ./configure --host=mipsel-openwrt-linux  --prefix=/home/yang/lib_mips/json-c
4.  make
5 . make install
执行以上几个步骤,即可生成头文件和库文件到/home/yang/lib_mips/json-c中
  
libubox的移植
由于libubox没有configure之类的,需要用cmake生成Makefile,cmake如果没有,请自行安装。
具体的步骤如下:
1. 解压libubox源码
2. 修改CMakeList.txt文件,在文件最开始处加上如下几句(不要怀疑,就是最开始处):
红色字体为要添加的
#告知当前使用的是交叉编译方式,必须配置
SET(CMAKE_SYSTEM_NAMELinux)
#指定C交叉编译器,必须配置
#或交叉编译器使用绝对地址
SET(CMAKE_C_COMPILER"mipsel-openwrt-linux-gcc")
#指定C++交叉编译器
SET(CMAKE_CXX_COMPILER"mipsel-openwrt-linux-g++")
include_directories("/home/yang/lib_mips/json-c/include/json-c")
include_directories("/home/yang/lib_mips/json-c/include")
link_directories("/home/yang/lib_mips/json-c/lib")
 
3. cmake
4. make
5.修改文件cmake_install.cmake,
红色的要修改的
# Set the installprefix
IF(NOT DEFINEDCMAKE_INSTALL_PREFIX)
  SET(CMAKE_INSTALL_PREFIX"/home/yang/lib_mips/libubox")
6. make install
执行以上几个步骤,即可生成头文件和库文件到/home/yang/lib_mips/libubox中
 
好,开始编译ubus
源码为ubus-2014-09-17-4c4f35cf2230d70b9ddd87638ca911e8a563f2f3.tar.gz,具体的步骤如下:
1.解压源码
2.修改CMakeList.txt,
首先,在开头加上如下几句,可以看到它依赖libubox。
红色的为要添加的
#告知当前使用的是交叉编译方式,必须配置
SET(CMAKE_SYSTEM_NAMELinux)
#指定C交叉编译器,必须配置
#或交叉编译器使用绝对地址
SET(CMAKE_C_COMPILER"mipsel-openwrt-linux-gcc")
#指定C++交叉编译器
SET(CMAKE_CXX_COMPILER"mipsel-openwrt-linux-g++")
INCLUDE_DIRECTORIES(/home/yang/lib_mips/json-c/include/json-c)
INCLUDE_DIRECTORIES(/home/yang/lib_mips/json-c/include)
LINK_DIRECTORIES(/home/yang/lib_mips/json-c/lib)
 
INCLUDE_DIRECTORIES(/home/yang/lib_mips/libubox/include/libubox)
INCLUDE_DIRECTORIES(/home/yang/lib_mips/libubox/include)
LINK_DIRECTORIES(/home/yang/lib_mips/libubox/lib)
 
LINK_DIRECTORIES(/home/yang/lib_mips/uiot_libs)
然后,修改以下几行其中的内容
红色的为要修改的
#find_library(jsonNAMES json-c json)
ADD_EXECUTABLE(clicli.c)
SET_TARGET_PROPERTIES(cliPROPERTIES OUTPUT_NAME ubus)
TARGET_LINK_LIBRARIES(cliubus ubox blobmsg_json json-c)
3.cmake .
4.make
5.在源码根目录即可生成库和可执行文件
ubusd 为ubus服务
ubus 为ubus客户端
6. 修改文件cmake_install.cmake
红色的要修改的
# Set the installprefix
IF(NOT DEFINEDCMAKE_INSTALL_PREFIX)
  SET(CMAKE_INSTALL_PREFIX"/home/yang/lib_mips/libubus")
ENDIF(NOT DEFINEDCMAKE_INSTALL_PREFIX)
6. 修改lua目录下的cmake_install.cmake
将其中的/usr/local/lib  全部替换成/home/yang/lib_mips/libubus
7. make install
执行以上几个步骤,即可生成头文件和库文件到/home/yang/lib_mips/libubus中

完成!

 
 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ubus 移植