Openwrt 编译添加模块 Package

3.  添加模块

一般我们需要建立自己的模块(package),在编译固件时可以选择是否将自己的模块编译到固件中去。

3.1. 建立package

最终helloword文件目录结构为:

helloword/
├──Makefile
└── src
   ├── helloworld.c
   └── Makefile

在./openwrt/trunk/package/utils/目录下新建helloword文件夹。

然后在helloword文件夹下新建src文件夹。

3.2. 在src目录下编写helloworld程序

在src目录下,编写helloworld.c

#include<stdio.h>
int main(void)
{
<span style="white-space:pre">	</span>printf("Helloworld\n");
<span style="white-space:pre">	</span>return 0;
}

在src目录下编写Makefile文件,注意Makefile文件格式,尤其是Tab制表符缩进

helloworld:helloworld.o
<span style="white-space:pre">	</span>$(CC) $(LDFLAGS) helloworld.o -o helloworld
helloworld.o:helloworld.c
<span style="white-space:pre">	</span>$(CC) $(CFLAGS) -c helloworld.c
clean:
<span style="white-space:pre">	</span>rm *.o helloworld

3.3. 在helloworld目录下创建Makefile文件

这个Makefile文件是给OpenWRT读的,而之前写的那个Makefile文件是针对helloworld给编译其读的。两个Makefile不在同一层目录下。注意Makefile文件格式,尤其是Tab制表符缩进

##############################################
#OpenWrt Makefile for helloworld program
#
#
# Mostof the variables used here are defined in
# theinclude directives below. We just need to
#specify a basic description of the package,
#where to build our program, where to find
# thesource files, and where to install the
#compiled program on the router.
#
# Bevery careful of spacing in this file.
#Indents should be tabs, not spaces, and
#there should be no trailing whitespace in
#lines that are not commented.
#
##############################################
include$(TOPDIR)/rules.mk
# Nameand release number of this package
PKG_NAME:=helloworld
PKG_RELEASE:=1

# Thisspecifies the directory where we're going to build the program.
# Theroot build directory, $(BUILD_DIR), is by default the build_mipsel
#directory in your OpenWrt SDK directory
PKG_BUILD_DIR:= $(BUILD_DIR)/$(PKG_NAME)

include$(INCLUDE_DIR)/package.mk

#Specify package information for this program.
# Thevariables defined here should be self explanatory.
# Ifyou are running Kamikaze, delete the DESCRIPTION
#variable below and uncomment the Kamikaze define
#directive for the description below
definePackage/helloworld
SECTION:=utils
CATEGORY:=Utilities
TITLE:=Helloworld-- prints a snarky message
endef

#Uncomment portion below for Kamikaze and delete DESCRIPTION variable above
definePackage/helloworld/description
If youcan't figure out what this program does, you're probably
brain-deadand need immediate medical attention.
endef

#Specify what needs to be done to prepare for building the package.
# Inour case, we need to copy the source files to the build directory.
# Thisis NOT the default. The default uses the PKG_SOURCE_URL and the
#PKG_SOURCE which is not defined here to download the source from the web.
# Inorder to just build a simple program that we have just written, it is
# mucheasier to do it this way.
defineBuild/Prepare
<span style="white-space:pre">	</span>mkdir -p $(PKG_BUILD_DIR)
<span style="white-space:pre">	</span>$(CP) ./src/* $(PKG_BUILD_DIR)/
endef

# Wedo not need to define Build/Configure or Build/Compile directives
# Thedefaults are appropriate for compiling a simple program such as this one

#Specify where and how to install the program. Since we only have one file,
# thehelloworld executable, install it by copying it to the /bin directory on
# therouter. The $(1) variable represents the root directory on the router running
#OpenWrt. The $(INSTALL_DIR) variable contains a command to prepare the install
#directory if it does not already exist. Likewise $(INSTALL_BIN) contains the
#command to copy the binary file from its current location (in our case the build
#directory) to the install directory.
definePackage/helloworld/install
<span style="white-space:pre">	</span>$(INSTALL_DIR) $(1)/bin
<span style="white-space:pre">	</span>$(INSTALL_BIN) $(PKG_BUILD_DIR)/helloworld $(1)/bin/
endef

$(eval$(call BuildPackage,helloworld))

3.4 helloworld模块

在trunk目录下,敲make menuconfig

选择Utilities

在Utilities中选择就可以看到helloworld,选择该模块就可以将helloword模块编译到固件中去。

在trunk目录下make重新编译固件后

编译结果会放在 bin/[yourtarget]/package目录下helloworld_1_xx.ipk,

也可能在bin/[yourtarget]/package的子目录下。可以通过find . –name hello*命令来查找编译好的模块helloworld。

时间: 2024-07-28 12:35:27

Openwrt 编译添加模块 Package的相关文章

Nginx重新编译添加模块

找到安装nginx的源码根目录,如果没有的话下载新的源码 http://nginx.org tar xvzf nginx-1.3.2.tar.gz 查看ngixn版本极其编译参数 /usr/local/nginx/sbin/nginx -V 进入nginx源码目录 cd nginx-1.3.2 以下是重新编译的代码和模块 ./configure --prefix=/usr/local/nginx--with-http_stub_status_module --with-http_ssl_modu

OpenWRT添加模块 Makefile和Config.in

添加模块编译 在网上找了一下,很多关于编译Openwrt系统的资料,不过这些事情芯片厂商提供的开发包都已经办得妥妥了,但是没有找到系统介绍的资料,添加一个包的介绍有不多,其中有两个很有参考价值: http://blog.csdn.net/lj627889343/article/details/7997463 http://kamikaze.openwrt.org/docs/openwrt.html#x1-460002.1.2 详细步骤如下: 在package目录下创建模块目录my_module,

动态编译添加php模块

注意:转载请注明出处:http://www.programfish.com/blog/?p=85 在很多时候我们用linux里搭建web服务器的时候会需要编译安装php套件,而在编译安装后可能又会需要添加一些编译安装时没有指定要编译进去的模块,例如如下情况: mysql.so 或mysqli.so .mbstring.so  zlib.so 等模块. 这里提示一下: 如果你有安装过phpmyadmin而且在安装配置好之后打开首页是空白的,那么很有可能就是你的php没有mysql和mbstring

windows环境下使用apxs编译添加apache模块

windows环境下使用apxs编译添加apache模块 简介说明:本文使用mod_limitipconn模块为例. 环境: windows7 x86系统 apache 2.4.18 目标: 在windows环境下,利用mod_limitipconn0.24源码.apxs为apache2.4.18添加mod_limitipconn模块. 分析: limitipconn模块最新版已经支持apache2.4了.但是没有编译好的对应版本.因此需要自己动手编译模块.在windows下要实现这个目标,需要

安装成功的nginx,如何添加未编译安装模块(非覆盖安装http_image_filter_module)

背景:1.做了图片上传小项目.2.图片上传,需要多图管理.3.图片上传,需要存储到Fastdfs.4.Fastdfs上的图片,和Nginx结合.5.Nginx从Fastdfs获得的图片,需要使用缩略图.a.在不需要缩略图,小图的情况下,可以使用原图.b.需要缩略图的情况下,指定目标宽度和高度,获得指定宽度和高度的缩略图. 关键的几个参考资料1.安装成功的nginx如何添加未编译安装模块http://blog.csdn.net/gebitan505/article/details/17612845

centos-nginx添加模块(无需重新编译)

$ wget http://nginx.org/download/nginx-1.3.2.tar.gz $ tar xvzf nginx-1.3.2.tar.gz #查看ngixn版本极其编译参数 $ /usr/local/nginx/sbin/nginx -V nginx version: nginx/1.3.2 TLS SNI support disabled configure arguments: --prefix=/usr/local/nginx --with-http_stub_st

Nginx 编译,添加未编译安装模块ngx_cache_purge

Nginx 编译,添加未编译安装模块ngx_cache_purge 官网下载nginx及第三方ngx_cache_purge 模块 http://wiki.nginx.org/Install http://labs.frickle.com/nginx_ngx_cache_purge/ 编译与安装 Blockquote ./configure \ –prefix=/usr/local/nginx-1.8.0 \ –sbin-path=/usr/sbin/nginx \ –conf-path=/et

Nginx 动态添加模块

Nginx动态添加模块 1.首先查看现在已经编译的模块 /usr/local/nginx/sbin/nginx -V 2.下载需要编译的模块 wget https://github.com/yaoweibin/nginx_tcp_proxy_module/archive/master.zip 新模块:--add-module=/data/package/nginx_tcp_proxy_module-master/ #模块存放路径 3.进入nginx安装目录 进行重新编译,需要加上之前已经编译过的

OpenWRT 编译过程

一.使用Ubuntu编译OpenWRT源码 第一步:安装基础软件 sudo apt-get install subversion g++ zlib1g-dev build-essential git python rsync man-db sudo apt-get install libncurses5-dev gawk gettext unzip file libssl-dev wget zip time 第二步:克隆代码 git clone https://git.openwrt.org/o