Openwrt 编译生成ipk包

一、编译时要配置内核,make menuconfig
配置选择Build the OpenWrt SDK 
返回保存,输入make等待编译
1.在编译好的文件中会有/bin/ramips/OpenWrt-SDK-ramips-for-linux-x86_64~~*.tar.bz2文件
2.然后解压这个文件
tar xvf OpenWrt-SDK-ramips-for-linux-x86_64-gcc-4.6-~~*.tar.bz2 --------Tab补齐

二、编译文档
1、进入这个sdk,会看见一个package,在下新建mkdir -p helloworld/src 两个目录
2、切换到src目录,建立helloworld.c  Makefile 两个文件 
3、编辑: 
helloworld.c:
#include<sdtio.h>
int main(void)
{
printf("hello world!\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

4、保存退出,切换到上级目录(helloworld)
5、新建Makefile,内容参考官网
  1. ##############################################  
  2. # OpenWrt Makefile for helloworld program  
  3. #  
  4. #  
  5. # Most of the variables used here are defined in  
  6. # the include directives below. We just need to  
  7. # specify a basic description of the package,  
  8. # where to build our program, where to find  
  9. # the source files, and where to install the  
  10. # compiled program on the router.  
  11. #  
  12. # Be very careful of spacing in this file.  
  13. # Indents should be tabs, not spaces, and  
  14. # there should be no trailing whitespace in  
  15. # lines that are not commented.  
  16. #  
  17. ##############################################  
  18. include $(TOPDIR)/rules.mk  
  19. # Name and release number of this package  
  20. PKG_NAME:=helloworld  
  21. PKG_RELEASE:=1  
  22.   
  23.   
  24. # This specifies the directory where we're going to build the program.   
  25. # The root build directory, $(BUILD_DIR), is by default the build_mipsel  
  26. # directory in your OpenWrt SDK directory  
  27. PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)  
  28.   
  29.   
  30. include $(INCLUDE_DIR)/package.mk  
  31.    
  32. # Specify package information for this program.  
  33. # The variables defined here should be self explanatory.  
  34. # If you are running Kamikaze, delete the DESCRIPTION  
  35. # variable below and uncomment the Kamikaze define  
  36. # directive for the description below  
  37. define Package/helloworld  
  38.         SECTION:=utils  
  39.         CATEGORY:=Utilities  
  40.         TITLE:=Helloworld -- prints a snarky message  
  41. endef  
  42. # Uncomment portion below for Kamikaze and delete DESCRIPTION variable above  
  43. define Package/helloworld/description  
  44.         If you can't figure out what this program does, you're probably  
  45.         brain-dead and need immediate medical attention.  
  46. endef  
  47. # Specify what needs to be done to prepare for building the package.  
  48. # In our case, we need to copy the source files to the build directory.  
  49. # This is NOT the default.  The default uses the PKG_SOURCE_URL and the  
  50. # PKG_SOURCE which is not defined here to download the source from the web.  
  51. # In order to just build a simple program that we have just written, it is  
  52. # much easier to do it this way.  
  53. define Build/Prepare  
  54.         mkdir -p $(PKG_BUILD_DIR)  
  55.         $(CP) ./src/* $(PKG_BUILD_DIR)/  
  56. endef  
  57. # We do not need to define Build/Configure or Build/Compile directives  
  58. # The defaults are appropriate for compiling a simple program such as this one  
  59. # Specify where and how to install the program. Since we only have one file,  
  60. # the helloworld executable, install it by copying it to the /bin directory on  
  61. # the router. The $(1) variable represents the root directory on the router running  
  62. # OpenWrt. The $(INSTALL_DIR) variable contains a command to prepare the install  
  63. # directory if it does not already exist.  Likewise $(INSTALL_BIN) contains the  
  64. # command to copy the binary file from its current location (in our case the build  
  65. # directory) to the install directory.  
  66. define Package/helloworld/install  
  67.         $(INSTALL_DIR) $(1)/bin  
  68.         $(INSTALL_BIN) $(PKG_BUILD_DIR)/helloworld $(1)/bin/  
  69. endef  
  70. # This line executes the necessary commands to compile our program.  
  71. # The above define directives specify all the information needed, but this  
  72. # line calls BuildPackage which in turn actually uses this information to  
  73. # build a package.  
  74. $(eval $(call BuildPackage,helloworld)) 
注意缩进,如果是复制的话若4空格用Tab
保存退出
三、配置文档
1、切换到根目录,即(package上目录) cd ..
2、配置helloworld :   输入vim  .config
   查找helloworld,-------输入/helloworld    回车
   # CONFIG_PACKAGE_helloworld is not set 改成  CONFIG_PACKAGE_helloworld=y 保存退出
3,、编译: make package/helloworld/compile V=s(或者V=99)
4、编译成功,查找该ipk包位置  find -name helloworld*.ipk 
OK !  完成!
   
  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
离线安装OpenWRTIPKOpenWrt Package Kit)通常是在没有网络连接的情况下更新或添加软件的步骤,因为IPK文件含了预编译的软件。下面是基本的离线安装过程: 1. **下载所需IPK文件**: - 首先,你需要知道你要安装的具体IPK的名字以及其版本。访问OpenWRT的软件仓库(如https://downloads.openwrt.org/固件/packages/)找到对应的URL和版本。 - 下载到你的本地存储设备,比如电脑或者USB驱动器。 2. **将IPK文件复制到OpenWRT设备**: - 如果你的OpenWRT设备可以通过USB或SD卡接入电脑,直接将IPK文件复制到相应位置。 - 或者,如果设备支持TFTP传输,你可以设置TFTP服务器并将IPK文件放在服务器上,然后设备通过TFTP进行下载。 3. **配置OpenWRT**: - 登录到OpenWRT的终端或Web界面,进入`opkg`命令行工具。 - 使用`opkg update`(注意这一步通常需要网络,但如果之前已经下载了索引文件,则可以忽略)确保系统知道在哪里查找软件。 - 如果`opkg update`提示没有可用的索引,使用`opkg setsrc`指定你的本地目录作为新的源,例如`opkg setsrc local /path/to/downloaded/ipk/`。 4. **安装IPK**: - 使用`opkg install [package-name]`命令安装你的IPK文件。记得替换`[package-name]`为你要安装的具体名。 5. **确认安装**: - 安装完成后,检查是否成功通过`opkg list-installed`命令查看新安装的是否在列表中。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值