添加了一把,还没编译不知道能不能成功。
http://downloads.openwrt.org/docs/buildroot-documentation.html
Extending OpenWrt with more software
This section will only consider the case in which you want to add user-space software.
Package directory
First of all, create a directory under the package directory for your software, for example foo.
Config.in file
Then, create a file named Config.in. This file will contain the portion of options description related to our foo software that will be used and displayed in the configuration tool. It should basically contain :
config BR2_PACKAGE_FOO
tristate "foo - some nice tool"
default m if CONFIG_DEVEL
help
This is a comment that explains what foo is.
If you depend on other software or library inside the Buildroot, it is important that you automatically select these packages in your Config.in. Example if foo depends on bar library:
config BR2_PACKAGE_FOO
tristate "foo - some nice tool"
default m if CONFIG_DEVEL
select BR2_PACKAGE_LIBBAR
help
This is a comment that explains what foo is.
Of course, you can add other options to configure particular things in your software.
Config.in in the package directory
To add your package to the configuration tool, you need to add the following line to package/Config.in, please add it to a section, which fits the purpose of foo:
comment "Networking" source "package/foo/Config.in"
Makefile in the package directory
To add your package to the build process, you need to edit the Makefile in the package/ directory. Locate the lines that look like the following:
package-$(BR2_PACKAGE_FOO) += foo
As you can see, this short line simply adds the target foo to the list of targets handled by OpenWrt Buildroot.
In addition to the default dependencies, you make your package depend on another package (e.g. a library) by adding a line:
foo-compile: bar-compile
The ipkg control file
Additionally, you need to create a control file which contains information about your package, readable by the ipkg package utility. It should be created as file: package/foo/ipkg/foo.control
The file looks like this
1 Package: foo
2 Priority: optional
3 Section: net
4 Maintainer: Foo Software <foo@foosoftware.com>
5 Source: http://foosoftware.com
6 Depends: libbar
7 Description: Package Description
You can skip the usual Version: and Architecture fields, as they will be generated by the make-ipkg-dir.sh script called from your Makefile. The Depends field is important, so that ipkg will automatically fetch all dependend software on your target system.
The real Makefile
Finally, here's the hardest part. Create a file named Makefile. It will contain the Makefile rules that are in charge of downloading, configuring, compiling and installing the software. Below is an example that we will comment afterwards.
1 # $Id: buildroot-documentation.html 2860 2006-01-08 02:17:18Z wbx $
2
3 include $(TOPDIR)/rules.mk
4
5 PKG_NAME:=foo
6 PKG_VERSION:=1.0
7 PKG_RELEASE:=1
8 PKG_MD5SUM:=4584f226523776a3cdd2fb6f8212ba8d
9
10 PKG_SOURCE_URL:=http://www.foosoftware.org/downloads
11 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
12 PKG_CAT:=zcat
13
14 PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)
15 PKG_INSTALL_DIR:=$(PKG_BUILD_DIR)/ipkg-install
16
17 include $(TOPDIR)/package/rules.mk
18
19 $(eval $(call PKG_template,FOO,foo,$(PKG_VERSION)-$(PKG_RELEASE),$(ARCH)))
20
21 $(PKG_BUILD_DIR)/.configured: $(PKG_BUILD_DIR)/.prepared
22 (cd $(PKG_BUILD_DIR); /
23 $(TARGET_CONFIGURE_OPTS) /
24 CFLAGS="$(TARGET_CFLAGS)" /
25 ./configure /
26 --target=$(GNU_TARGET_NAME) /
27 --host=$(GNU_TARGET_NAME) /
28 --build=$(GNU_HOST_NAME) /
29 --prefix=/usr /
30 --sysconfdir=/etc /
31 --with-bar="$(STAGING_DIR)/usr" /
32 );
33 touch $@
34
35 $(PKG_BUILD_DIR)/.built:
36 rm -rf $(PKG_INSTALL_DIR)
37 mkdir -p $(PKG_INSTALL_DIR)
38 $(MAKE) -C $(PKG_BUILD_DIR) /
39 $(TARGET_CONFIGURE_OPTS) /
40 install_prefix="$(PKG_INSTALL_DIR)" /
41 all install
42 touch $@
43
44 $(IPKG_FOO):
46 install -d -m0755 $(IDIR_FOO)/usr/sbin
47 cp -fpR $(PKG_INSTALL_DIR)/usr/sbin/foo $(IDIR_FOO)/usr/sbin
49 $(RSTRIP) $(IDIR_FOO)
50 $(IPKG_BUILD) $(IDIR_FOO) $(PACKAGE_DIR)
51
52 mostlyclean:
53 make -C $(PKG_BUILD_DIR) clean
54 rm $(PKG_BUILD_DIR)/.built
First of all, this Makefile example works for a single binary software. For other software such as libraries or more complex stuff with multiple binaries, it should be adapted. Look at the other Makefile files in the package/directory.
At lines 5-15, a couple of useful variables are defined:
PKG_NAME: The package name, e.g. foo.PKG_VERSION: The version of the package that should be downloaded.PKG_RELEASE: The release number that will be appended to the version number of your ipkg package.PKG_MD5SUM: The md5sum of the software archive.PKG_SOURCE_URL: Space separated list of the HTTP or FTP sites from which the archive is downloaded. It must include the complete path to the directory whereFOO_SOURCEcan be found.PKG_SOURCE: The name of the tarball of your package on the download website of FTP site. As you can seePKG_NAMEandPKG_VERSIONare used.PKG_CAT: The tool needed for extraction of the software archive.PKG_BUILD_DIR: The directory into which the software will be configured and compiled. Basically, it's a subdirectory ofBUILD_DIRwhich is created upon extraction of the tarball.PKG_INSTALL_DIR: The directory into the software will be installed. It is a subdirectory ofPKG_BUILD_DIR.
In Line 3 and 17 we include common variables and routines to simplify the process of ipkg creation. It includes routines to download, verify and extract the software package archives.
Line 19 contains the magic line which automatically creates the ipkg for us.
Lines 21-33 defines a target and associated rules that configures the software. It depends on the previous target (the hidden .prepared file) so that we are sure the software has been uncompressed. In order to configure it, it basically runs the well-known ./configurescript. As we may be doing cross-compilation, target, host and build arguments are given. The prefix is also set to /usr, not because the software will be installed in /usr on your host system, but in the target filesystem. Finally it creates a .configured file to mark the software as configured.
Lines 35-42 defines a target and a rule that compiles the software. This target will create the binary file in the compilation directory, and depends on the software being already configured (hence the reference to the.configured file). Afterwards it installs the resulting binary into the PKG_INSTALL_DIR. It basically runs make install inside the source directory.
Lines 44-50 defines a target and associated rules that create the ipkg package, which can optionally be embedded into the resulting firmware image. It manually installs all files you want to integrate in your resulting ipkg. RSTRIPwill recursevily strip all binaries and libraries. Finally IPKG_BUILD is called to create the package.
Conclusion
As you can see, adding a software to buildroot is simply a matter of writing a Makefile using an already existing example and to modify it according to the compilation process of the software.
If you package software that might be useful for other persons, don't forget to send a patch to OpenWrt developers! Use the mail address: openwrt-devel@openwrt.org
Resources
To learn more about OpenWrt you can visit this website: http://openwrt.org/
本文介绍如何为OpenWrt固件添加新的用户空间软件。主要内容包括创建包目录、配置文件及Makefile规则等步骤,以便将自定义软件整合到OpenWrt Buildroot中。
1529

被折叠的 条评论
为什么被折叠?



