openwrt软件包编译
❶ 如何在Openwrt的平台上编译单独一个package
一般来说,在编译时,进行make menuconfig,可以选择你需要编译的包。败搜工具粻甫纲晃蕺浩告彤梗廓会帮助你完成包依赖的处理,包括依赖包的下载以及编译)。 如果要手动编译一个包,则需要自己解决包依赖的问题。例如想编译一个nano的包,可以通过散枯辩命令opkg info nano 来知道包依冲缺赖是什么 。
❷ openwrt怎么编译指定的目标版
编译流程
编译专属于您的设备的特定Openwrt固件以一下五个步骤:
通过Subversion命令获得源代码;
更新(或安装) package feeds[package feeds无法确切翻译,待译吧);
创建一个默认配置以检查编译环境是否搭建好了 (假如需要的话);
用Menuconfig来配置即将编译生成的固件映像文件的配置项;
最后开始编译固件;
❸ 我想为openwrt编译一个软件包,应该怎么办
下面是Makefile中一些约定俗成的目标名称及其含义:
all
编译整个软件包,但不重建任何文档。一般此目标作为默认的终极目标。此目标一般对所有源程序的编译和连接使用"-g"选项,以使最终的可执行程序中包含调试信息。可使用 strip 程序去掉这些调试符号。
clean
清除当前目录下在 make 过程中产生的文件。它不能删除软件包的配置文件,也不能删除 build 时创建的那些文件。
distclean
类似于"clean",但增加删除当前目录下的的配置文件、build 过程产生的文件。
info
产生必要的 Info 文档。
check 或 test
完成所有的自检功能。在执行检查之前,应确保所有程序已经被创建(但可以尚未安装)。为了进行测试,需要实现在程序没有安装的情况下被执行的测试命令。
install
完成程序的编译并将最终的可执行程序、库文件等拷贝到指定的目录。此种安装一般不对可执行程序进行 strip 操作。
install-strip
和"install"类似,但是会对复制到安装目录下的可执行文件进行 strip 操作。
uninstall
删除所有由"install"安装的文件。
installcheck
执行安装检查。在执行安装检查之前,需要确保所有程序已经被创建并且被安装。
installdirs
创建安装目录及其子目录。它不能更改软件的编译目录,而仅仅是创建程序的安装目录。
下面是 Makefile 中一些约定俗成的变量名称及其含义:
这些约定俗成的变量分为三类。第一类代表可执行程序的名字,例如 CC 代表编译器这个可执行程序;第二类代表程序使用的参数(多个参数使用空格分开),例如 CFLAGS 代表编译器执行时使用的参数(一种怪异的做法是直接在 CC 中包含参数);第三类代表安装目录,例如 prefix 等等,含义简单,下面只列出它们的默认值。
AR 函数库打包程序,可创建静态库.a文档。默认是"ar"。
AS 汇编程序。默认是"as"。
CC C编译程序。默认是"cc"。
CXX C++编译程序。默认是"g++"。
CPP C/C++预处理器。默认是"$(CC) -E"。
FC Fortran编译器。默认是"f77"。
PC Pascal语言编译器。默认是"pc"。
YACC Yacc文法分析器。默认是"yacc"。
ARFLAGS 函数库打包程序的命令行参数。默认值是"rv"。
ASFLAGS 汇编程序的命令行参数。
CFLAGS C编译程序的命令行参数。
CXXFLAGS C++编译程序的命令行参数。
CPPFLAGS C/C++预处理器的命令行参数。
FFLAGS Fortran编译器的命令行参数。
PFLAGS Pascal编译器的命令行参数。
YFLAGS Yacc文法分析器的命令行参数。
LDFLAGS 链接器的命令行参数。
prefix /usr/local
exec_prefix $(prefix)
bindir $(exec_prefix)/bin
sbindir $(exec_prefix)/sbin
libexecdir $(exec_prefix)/libexec
datadir $(prefix)/share
sysconfdir $(prefix)/etc
sharedstatedir $(prefix)/com
localstatedir $(prefix)/var
libdir $(exec_prefix)/lib
infodir $(prefix)/info
includedir $(prefix)/include
oldincludedir $(prefix)/include
mandir $(prefix)/man
srcdir 需要编译的源文件所在的目录,无默认值
❹ 如何为现有的openwrt编译一个opkg上没有的软件
这是我去年编辑一个软件时记下的过程,希望对你有所帮助,我也是新手,按照官方提供的教程一步步修改,中间断断续续弄了近两个月,最后总算编译成功了。
一、安装编译环境(以ubuntu10.10为例)
依次输入以下命令:
1.ubuntu开发环境需要的软件:
sudo apt-get install gcc g++ binutils patch bzip2 flex bison make
autoconf gettext texinfo unzip sharutils subversion libncurses5-dev
ncurses-term zlib1g-dev gawk
sudo apt-get update
2.创建目录
mkdir openwrt
3.获取OpenWrt源代码和安装包,更新
svn checkout svn://svn.openwrt.org/openwrt/backfire
cd backfire
./scripts/feeds update -a
./scripts/feeds install -a
4.配置编译选项
make menuconfig
在target system里选择Broadcom BCM63xx,根据需要选择其他的软件,
*:表示该模块直接编译到核心中
M:该模块以被核心支持,可以后再安装
空白:不支持该模块
具体模块的起什么作用需要多google;
5.编译选项配置保存后,开始编译
make V=99
V=99表示输出详细的debug信息;
二、编译准备
1.下载源文件
下载地址:http://ftp.awk.cz/cntlm/ ,最新的版本是0.91rc6;
2.获取md5sum码
进入下载文件目录,在终端里输入
md5sum cntlm-0.91rc6.tar.gz
获得md5验证码:
3.编写makefile文件
在openwrt/backfire目录中的package目录下新建cntlm目录,在cntlm目录下新建文件,命名为makefile,编辑makefile文件,加入如下内容:
---------------------------------------------------------------------------------------------------------------------------
#
# Copyright (C) 2006-2008 OpenWrt.org
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#
include $(TOPDIR)/rules.mk
PKG_NAME:=cntlm
PKG_VERSION:=0.91rc6
PKG_RELEASE:=1
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=http://ftp.awk.cz/cntlm/
PKG_MD5SUM:=
PKG_INSTALL:=1
include $(INCLUDE_DIR)/package.mk
define Package/cntlm
SUBMENU:=Proxy Servers
SECTION:=net
CATEGORY:=Network
TITLE:=Cntlm is a Fast NTLM Authentication Proxy
URL:=http://cntlm.sourceforge.net/
endef
define Package/cntlm/install
$(INSTALL_DIR) $(1)/usr/sbin
$(CP) $(PKG_INSTALL_DIR)/usr/sbin/cntlm $(1)/usr/sbin/
$(INSTALL_DIR) $(1)/usr/share/man/man1
$(CP) $(PKG_INSTALL_DIR)/usr/share/man/man1/$(PKG_NAME).1 $(1)/usr/share/man/man1
$(INSTALL_DIR) $(1)/etc/
$(CP) $(PKG_INSTALL_DIR)/etc/cntlm.conf $(1)/etc/
endef
$(eval $(call BuildPackage,cntlm))
---------------------------------------------------------------------------------------------------------------------------
4.编写patch文件
由于BCM63xx核心是big endian,而我们常用的intel或AMD的cpu都是little
endian的,cntlm虽然能够自己检测编译环境的endian,但我们是在交叉编译环境中编译,cntlm检测出来的还是ubuntu系统的
endian,因此需要设置手动endian为big endian。具体就是将源码文件中的config/endian.c文件的rc设定为0.
将源码文件中的endian.c文件分别复制到a目录下的config目录和b目录下的config目录,打开b目录下的config目录中的endian.c文件,并将其修改为:
-------------------------------------------------------------------------------------------------------------------------
#include <stdio.h>
#include <stdint.h>
int main(int argc, char **argv) {
int rc;
rc = 0;
printf("%s\n", rc ? "little endian" : "big endian");
return rc;
}
---------------------------------------------------------------------------------------------------------------------------
然后保存。
运行:
diff -Naur a/config/endian.c b/config/endian.c >endian.patch
endian.patch文件内容如下:
---------------------------------------------------------------------------------------------------------------------------
--- a/config/endian.c 2007-08-20 07:23:17.000000000 +0800
+++ b/config/endian.c 2010-11-01 18:36:32.000000000 +0800
@@ -1,15 +1,11 @@
#include <stdio.h>
#include <stdint.h>
-uint8_t num[] = { 0xEF, 0xBE };
-/*
- * RC: 1 = LE, 0 = BE
- */
int main(int argc, char **argv) {
int rc;
- rc = (*((uint16_t *)num) == 0xBEEF);
+ rc = 0;
printf("%s\n", rc ? "little endian" : "big endian");
return rc;
---------------------------------------------------------------------------------------------------------------------------
将endian.patch文件复制到package/cntlm/patches/目录下(没有patches目录就新建一个)。
三、编译
1.选定安装包
终端输入:
make menuconfig
在Network——》Proxy Severs中选择cntlm;
2.开始编译
终端输入:
make package/cntlm/compile V=99
中间可能会出现一些提示(Note),可以不用理会。编译完成后在bin/packages目录下可以看到cntlm_0.91rc6-1_brcm63xx.ipk文件啦。
四、补充
上面提到在编译过程中出会现提示(Note),一般如下:
utils.c:1: note: someone does not honour COPTS correctly, passed 0 times
这是由于cntlm源码文件中CFLAG的设置是覆盖而不是续接,与openwrt要求不同,在openwrt一般写成CFLAG += 的方式。可以通过如下修改去除note:
将源码包中的Makefile文件复制到a目录和b目录,打开b目录下的Makefile文件,作如下修改:
CFLAGS+=$(FLAGS)
即增加上面的“+”号,保存。
运行:
diff -Naur a/Makefile b/Makefile > makefile.patch
得到的makefile.patch文件如下:
---------------------------------------------------------------------------------------------------------------------------
--- a/Makefile 2010-04-29 19:18:58.000000000 +0800
+++ b/Makefile 2010-11-09 20:17:33.405177000 +0800
@@ -16,7 +16,7 @@
CC=gcc
VER=`cat VERSION`
OBJS=utils.o ntlm.o xcrypt.o config.o socket.o acl.o auth.o http.o forward.o direct.o scanner.o pages.o main.o
-CFLAGS=$(FLAGS) -std=c99 -Wall -pedantic -O3 -D__BSD_VISIBLE
-D_ALL_SOURCE -D_XOPEN_SOURCE=600 -D_POSIX_C_SOURCE=200112
-D_ISOC99_SOURCE -D_REENTRANT -DVERSION=\"`cat VERSION`\" -g
+CFLAGS+=$(FLAGS) -std=c99 -Wall -pedantic -O3 -D__BSD_VISIBLE
-D_ALL_SOURCE -D_XOPEN_SOURCE=600 -D_POSIX_C_SOURCE=200112
-D_ISOC99_SOURCE -D_REENTRANT -DVERSION=\"`cat VERSION`\" -g
OS=$(shell uname -s)
OSLDFLAGS=$(shell [ $(OS) = "SunOS" ] && echo "-lrt -lsocket -lnsl")
LDFLAGS:=-lpthread $(OSLDFLAGS)
---------------------------------------------------------------------------------------------------------------------------
将makefile.patch文件复制到package/cntlm/patches目录下,重新编译即可。
❺ openwrt怎么选择编译版本
可以参考以下步骤:
开机登陆到支持编译Openwrt的操作系统
3.32位(x86)请执行下列命令:
# apt-get install build-essential asciidoc binutils bzip2 gawk gettext
git libncurses5-dev libz-dev patch unzip zlib1g-dev
64位(x86_64)请执行下列命令:
# apt-get install build-essential asciidoc binutils bzip2 gawk gettext
git libncurses5-dev libz-dev patch unzip zlib1g-dev ia32-libs
lib32gcc1 libc6-dev-i386
❻ 我在openwrt下载了一个官网的.tar.gz软件包,想加到make menuconfig里面去一起编译,能请教一下如何操作吗
你下RPM包,然后系统中解压出来,转换成TXT,在进行编译、
❼ 求助,请问这个板子该如何自己编译openwrt
如薯此果你只是要编译一个自定义的固件(默认带什么软件,不带旦吵什么软件,自定义默认的配置等等),那推荐你用ImageBuilder,简单快速,省心省力 你要是需要自己开发软件包,用OpenWRT的SDK,数迟迅直接出ipk文件 要完全重写就buildroot
❽ openwrt下,请问如何把feeds/packages下的软件包单独编译
make package/autossh/compile
If you find your package doesn’t show up in menuconfig, try the following command to see if you get the correct description:
TOPDIR=$PWD make -C package/<name> DUMP=1 V=99
If you’re just having trouble getting your package to compile, there’s a
few shortcuts you can take. Instead of waiting for make to get to your
package, you can run one of the following:
make package/<name>/clean V=99
make package/<name>/install V=99
Another nice trick is that if the source directory under
build_dir/<arch> is newer than the package directory, it won’t
clobber it by unpacking the sources again. If you were working on a
patch you could simply edit the sources under the
build_dir/<arch>/<source> directory and run the install
command above, when satisfied, the patched sources elsewhere and
diff them with the unpatched sources. A warning though - if you go
modify anything under package/<name> it will remove the old
sources and unpack a fresh .
Other useful targets include:
make package/<name>/prepare V=99
make package/<name>/compile V=99
make package/<name>/configure V=99
❾ 如何在OpenWRT环境下做开发
1、搭建开发环境
首先,在执行make menuconfig后,会出现下图:
其中,图中红框部分是我定制路由器的系统版本,大家可以根据不同的路由器进行不同的选择;绿框部分表示我们需要编译一个SDK开发环境(默认情况下,此项未勾选)。
编译过程中需要通过官网下载很多相关的软件包,所以必须保证能够顺利连上外网。由于下载速度的限制,编译过程大概需要数小时。编译结束后,所有的产品都会放在编译根目录下的bin/yourtarget/. 例如:我所编译的产物都放在./bin/brcm47xx/下,其中文件主要有几类:
(1).bin/.trx 文件: 这些都是在我们所选的target-system的类别之下,针对不同路由器型号、版本编译的路由器固件。这些不同路由器的型号和版本是openwrt预先设置好的,我们不需要更改。至于.bin和.trx的区别,一种说法是,第一次刷路由器的时候,需要用.bin文件,如果需要再升级,则不能再使用.bin文件,而需要用.trx文件。原因是,.bin是将路由器的相关配置信息和.trx封装在一起而生成的封包,也就是说是包含路由器版本信息的.trx。在第一次刷固件的时候,我们需要提供这样的信息,而在后续升级时,则不再需要,用.trx文件即可。
(2)packages文件夹: 里面包含了我们在配置文件里设定的所有编译好的软件包。默认情况下,会有默认选择的软件包。
(3)OpenWrt-SDK.**.tar.bz2: 这个也就是我们定制编译好的OpenWRT SDK环境。我们将用这个来进行OpenWrt软件包的开发。例如,我所编译好的SDK环境包为:/bin/brcm47xx/OpenWrt-SDK-brcm47xx-for-Linux-x86_64-gcc-4.3.3+cs_uClibc-0.9.30.1.tar.bz2
可以从名称上看出,target system是brcm47xx,host system是Linux-x86_64,使用的编译工具以及库是4.3.3+cs_uClibc-0.9.30.1。
(4)md5sums 文件: 这个文件记录了所有我们编译好的文件的MD5值,来保证文件的完整性。因为文件的不完整,很容易将路由器变成“砖头”。
需要主要的是,编译完成后,一定要将编译好的bin目录进行备份(如果里面东西对你很重要的话),因为在下次编译之前,执行make clean 会将bin目录下的所有文件给清除掉!!
2、 更改原有packages
在编译根目录下会有一个dl的目录,这个目录其实是“download”的简写,在编译前期,需要从网络下载的数据包都会放在这个目录下,这些软件包的一个特点就是,会自动安装在所编译的固件中,也就是我们make menuconfig的时候,为固件配置的一些软件包。如果我们需要更改这些源码包,只需要将更改好的源码包打包成相同的名字放在这个目录下,然后开始编译即可。编译时,会将软件包解压到build_dir目录下。
当然,你也可以自己在dl里面创建自己的软件包,然后更改相关的配置文件,让openwrt可以识别这个文件包。
由于我的项目更改的内容是底层的,需要跟固件一起安装。所以,我使用的方法就是直接更改dl目录下软件包,然后重新进行固件编译。感觉类似于Linux的内核编译。反复编过十多次,没有任何问题。
3、 新建自己的packages
对于自己新建的package,而这个package又不需要随固件一起安装,换句话说,就是可以当做一个可选软件包的话。我们可以利用我们的SDK环境来单独编译,编译后会生成一个ipk的文件包。然后利用 opkg install xxx.ipk 来安装这个软件。
下面具体说下,如何编译一个helloword的软件包。
(1)首先,编写helloworld程序
编写helloworld.c
/****************
* Helloworld.c
* The most simplistic C program ever written.
* An epileptic monkey on crack could write this code.
*****************/
#include <stdio.h>
#include <unistd.h>
int main(void)
{
printf("Hell! O' world, why won't my code compile?
");
return 0;
}
编写Makefile文件
# build helloworld executable when user executes "make"
helloworld: helloworld.o
$(CC) $(LDFLAGS) helloworld.o -o helloworld
helloworld.o: helloworld.c
$(CC) $(CFLAGS) -c helloworld.c
# remove object files and executable when user executes "make clean"
clean:
rm *.o helloworld
在这两个文件的目录下,执行make 应该可以生成helloworld的可执行文件。执行helloworld后,能够打印出“Hell! O' world, why won't my code compile?”。 这一步,主要保证我们的源程序是可以正常编译的。下面我们将其移植到OpenWRT上。
(2)将OpenWrt-SDK-brcm47xx-for-Linux-x86_64-gcc-4.3.3+cs_uClibc-0.9.30.1.tar.bz2解压
tar –xvf OpenWrt-SDK-brcm47xx-for-Linux-x86_64-gcc-4.3.3+cs_uClibc-0.9.30.1.tar.bz2
(3)进入SDK
cd OpenWrt-SDK-brcm47xx-for-Linux-x86_64-gcc-4.3.3+cs_uClibc-0.9.30.1
可以看到里面的目录结构跟我们之前source的目录结构基本相同,所需要编译的软件包,需要放置在package目录下
(4)在package目录下创建helloworld目录
cd package
mkdir helloworld
cd helloworld
(5)创建src目录,拷贝 helloworld文件
mkdir src
cp /home/wrt/test/helloworld.c src
cp /home/wrt/test/Makefile src
(6)在helloworld目录下创建Makefile文件
这个Makefile文件是给OpenWRT读的,而之前写的那个Makefile文件是针对helloworld给编译其读的。两个Makefile不在同一层目录下。
touch Makefile
vim Makefile
Makefile文件模板内容如下:
##############################################
# OpenWrt Makefile for helloworld program
#
#
# Most of the variables used here are defined in
# the include directives below. We just need to
# specify a basic description of the package,
# where to build our program, where to find
# the source files, and where to install the
# compiled program on the router.
#
# Be very 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
# Name and release number of this package
PKG_NAME:=helloworld
PKG_RELEASE:=1
# This specifies the directory where we're going to build the program.
# The root 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.
# The variables defined here should be self explanatory.
# If you are running Kamikaze, delete the DESCRIPTION
# variable below and uncomment the Kamikaze define
# directive for the description below
define Package/helloworld
SECTION:=utils
CATEGORY:=Utilities
TITLE:=Helloworld -- prints a snarky message
endef
# Uncomment portion below for Kamikaze and delete DESCRIPTION variable above
define Package/helloworld/description
If you can't figure out what this program does, you're probably
brain-dead and need immediate medical attention.
endef
# Specify what needs to be done to prepare for building the package.
# In our case, we need to the source files to the build directory.
# This is 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.
# In order to just build a simple program that we have just written, it is
# much easier to do it this way.
define Build/Prepare
mkdir -p $(PKG_BUILD_DIR)
$(CP) ./src/* $(PKG_BUILD_DIR)/
endef
# We do not need to define Build/Configure or Build/Compile directives
# The defaults 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,
# the helloworld executable, install it by ing it to the /bin directory on
# the router. 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 the binary file from its current location (in our case the build
# directory) to the install directory.
define Package/helloworld/install
$(INSTALL_DIR) $(1)/bin
$(INSTALL_BIN) $(PKG_BUILD_DIR)/helloworld $(1)/bin/
endef
# This line executes the necessary commands to compile our program.
# The above define directives specify all the information needed, but this
# line calls BuildPackage which in turn actually uses this information to
# build a package.
$(eval $(call BuildPackage,helloworld))
(7)返回到SDK的根目录
执行make进行编译
编译过程会在build_dir目录下完成
编译结果会放在 bin/[yourtarget]/package目录下helloworld_1_bcm47xx.ipk
(8)上传helloworld_1_bcm47xx.ipk
使用sftp软件上传helloworld_1_bcm47xx.ipk至路由器
执行 opkg install helloworld_1_bcm47xx.ipk
输入hello然后按Tab键,发现openwrt中已经有helloworld可执行命令。
执行 helloworld 查看程序的效果。
Hell! O' world, why won't my code compile?
【End】
希望对大家能有帮助 :)
转载
❿ 如何编译OpenWrt
准备工作
在开始编译Openwrt之前需要您做些准备工作;与其他编译过程一样,类似的编译工具和编译环境是必不可少的:
一个构建OpenWrt映像的系统平台,简单说就是准备一个操作系统(比如Ubuntu、Debian等);
确保安装了所需的依赖关系库, (在debian系统中就是安装各种需要的软件包)
OpenWrt源代码副本
首先, 开机登陆到支持编译Openwrt的操作系统(废话了)。实体机或者虚拟机(Vmware 或者 Qemu)里的操作系统都行,这里推荐使用Linux系统。 bsd和mac osx系统也可以编,但不推荐,且未验证是否可编译成功。下文假定您使用的是Debian操作系统,使用 apt-get 来管理包. 替代的选择是 Ubuntu (分支 Kubuntu, Xubuntu 等即可)。
第二步, 就是安装所需要的各种软件包, 包括编译器,解压工具,特定的库等. 这些工作可以简单的通过键入以下命令 (通常需要root 或者是 sudo 权限),以root权限安装下列软件包(可能并不完整,会有提示,提示缺少即装就可以了):
32位(x86)请执行下列命令:
# apt-get install build-essential asciidoc binutils bzip2 gawk gettext \
git libncurses5-dev libz-dev patch unzip zlib1g-dev
64位(x86_64)请执行下列命令(多装了哪些库或软件包呢?请您仔细看一看哦):
# apt-get install build-essential asciidoc binutils bzip2 gawk gettext \
git libncurses5-dev libz-dev patch unzip zlib1g-dev ia32-libs \
lib32gcc1 libc6-dev-i386
参考 本列表中 所列的编译环境所需要软件包或库。
某些依赖的为库或软件包也许操作系统中已经安装过,此时apt-get会作出提示(提示您忽略或重新安装的),别紧张,放轻松些,编译Openwrt不会像编译DD-WRT那样难的(至少本人是体会到了编译DD-WRT的难)。
最后下载一份完整的 Openwrt 源码到编译环境中。关于Openwrt的源代码下载,途径有二,一是通过 svn ,一是通过 git,建议使用 svn ,因为Openwrt主要以 svn 来维护Openwrt系统的版本。另外,请注意Openwrt中不同的分支版本,一个是用得较多的开发快照,俗称 trunk,二是稳定版,俗称 backfire。