怎么创建openwrt软件包

  介绍

本篇内容介绍了“怎么创建openwrt软件包”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!

方法一

1,生成SDK

让menuconfig选上“构建openwrt SDK”,然后保存,退出。再做一次。
完成之后,在bin/ramips/目录下会生成SDK的压缩文件:
openwrt - SDK - ramips rt305x_gcc - 4.8 - linaro_uclibc 0.9.33.2.linux x86_64.tar.bz2

2,安装SDK

把上面生成的openwrt - SDK - ramips rt305x_gcc - 4.8 - linaro_uclibc 0.9.33.2.linux x86_64.tar。bz2解获取压到别的目录下

3,创建helloworld项目

其实,这里可以是任意我们想要加入的程序,库等。这里就以helloword为例。
在任意路径下,创建helloword项目。比如这里还是在~/Workspace/OpeWRT目录下。
,

<>之前,美元cd  ~/Workspace/OpenWRT   美元,mkdir  helloword   美元,cd  helloword   美元,touch  helloword.c  Makefile

在~/Workspace/OpenWRT目录下创建了helloword目录,并生成helloword.c与Makefile文件。   
如下为helloworld.c的内容:   以前

<> # include  & lt; stdio.h>   ,   int  main ()   {   ,,,printf(“却;能够is  my  hello 词! \ n");   ,,,return  0;   }

Makefile的内容:

 helloworld : helloworld.o
  ,,,(CC)美元,美元(LDFLAGS), helloworld.o  -o  helloworld
  
  helloworld.o : helloworld.c
  ,,,(CC)美元,美元(CFLAGS), -c  helloworld.c
  
  clean :
  ,,,rm  * .o  helloworld 

自己使一下确保程序没有问题,一定要注意tab键空格。   
,

4,创建helloworld包

进入OpenWrt/包/并在该目录下创建helloworld目录,并进入该目录。

<>之前,美元cd  ~/Workspace/OpenWrt/OpenWrt-SDK/包   美元,mkdir  helloworld   美元,cd  helloworld

将我们第三步写的程序复制到这个目录下来,更名为src。再新建一个Makefile文件。

<>之前,美元cp  -r  . ./. ./. ./helloworld  src   美元,touch  Makefile

整个过程下来,包目录结构如下:

<>之前包   |——helloworld   | - - - |,,还以为,Makefile   |,,,,,src   |,,,,,,,|——helloworld.c   |,,,,,,,”——Makefile   ”——,Makefile

Makefile文件如下:

 include  (TOPDIR)/rules.mk美元
  
  PKG_NAME:=helloworld
  PKG_RELEASE:=1
  
  PKG_BUILD_DIR:=(BUILD_DIR)/(PKG_NAME)美元
  
  include  (INCLUDE_DIR)/package.mk美元
  
  define 包/helloworld
  部分:=跑龙套
  类别:=实用程序
  标题:=Hello 世界! ! !
  取决于:=+ libwebsockets  + libsqlite3  + libjson-c
  endef
  
  define 包/helloworld/描述
  这# 39;s  my  first  package 演示。
  endef
  
  define 构建/准备
  mkdir  -p  $ (PKG_BUILD_DIR)
  (CP),美元。/src/*, (PKG_BUILD_DIR)/美元
  endef
  
  define 包/helloworld/安装
  (INSTALL_DIR),(1)美元/usr/sbin
  $ (INSTALL_BIN), (PKG_BUILD_DIR)/(PKG_NAME)美元,美元(1)/usr/sbin
  endef
  
  (eval 美元(call  BuildPackage helloworld)) 

让j - 1 V=s成功了。生成了helloworld_1_ramips_24kec。ipk。
,

5,试验helloworld

通过把有WinSCP ipk上能到openwrt根目录下的/tmp

 cd /tmp
  opkg  install  helloworld_1_ramips_24kec。ipk 

用这命令查看helloworld安装的路径:

 which  helloworld 

在/bin/路径下

 cd /bin
  helloworld 

方法二

1,创建helloworld项目

把方法一创建helloworld文件夹复制到openwrt根目录下的包。

2,选择helloworld项目

 make  menuconfig 

实用工具——》helloworld勾选上并保存退出   

<>以前make  -j3  V=s

如果要单独编译模块:   

<>以前make 包/helloworld/编译   make 包/helloworld/安装

3,试验helloworld

 cd /bin
  helloworld 

4,后续开发

把新helloworld文件替换旧hellworld文件

重新编译

 make 包/helloworld/编译

在openwrt目录的。/build_dir/target-mipsel_24kec + dsp_uClibc-0.9.33.2/helloworld/ipkg-ramips_24kec/helloworld/bin下找到重新生成的helloworld文件,重新替换路由器/bin下面的helloworld。

怎么创建openwrt软件包