[OpenWrt] Create packages

Source: Internet
Author: User
Tags autoload

[OpenWrt] Create packages

This article turns from: http://blog.chinaunix.net/uid-9688646-id-5083518.html

In fact, most of this article is the official wiki of translation

Http://wiki.openwrt.org/zh-cn/doc/devel/packages to share with you.

One of the things we've tried to do is make porting software to openwrt very easy. If you open the directory (openwrt/package/* or openwrt/feeds/packages/*/*) of a package in openwrt, you will usually find several things:
Package/makefile [Essential]
package/patches/[optional]
package/files/[optional]

The patches directory and the files directory are optional, and the Pactches directory typically includes bug fixes and optimization of executable volume, which typically includes configuration files. You may also see other directories, as long as the makefile file indicates that the directory name can be taken. The first two are conventional and suggest you do the same.

The makefile file is the most critical and generally provides the steps to download, compile, and install the package.

When we open the makefile file here, it's hard to recognize that this is a makefile. Its format is not the same as the general makefile, because its function is different from the ordinary makefile. It is a handy template for writing.

Here, take the Package/bridge/makefile file as an example:

Include $ (topdir)/rules.mk

Pkg_name:=bridge
pkg_version:=1.0.6
Pkg_release:=1

pkg_build_dir:=$ (Build_dir)/bridge-utils-$ (pkg_version)
pkg_source:=bridge-utils-$ (pkg_version). tar.gz
pkg_source_url:= @SF/bridge
pkg_md5sum:=9b7dc52656f5cbec846a7ba3299f73bd
Pkg_cat:=zcat

Include $ (include_dir)/package.mk

Define Package/bridge
Section:=base
Category:=network
Default:=y
Title:=ethernet Bridging Configuration Utility
Description:=ethernet Bridging configuration utility\\\
Manage Ethernet bridging; A way to connect networks together to\\\
form a larger network.
url:=http://bridge.sourceforge.net/
Endef

Define Build/configure
$ (Call Build/configure/default,--with-linux-headers=$ (Linux_dir))
Endef

Define Package/bridge/install
$ (Install_dir) $ (1)/usr/sbin
$ (Install_bin) $ (pkg_build_dir)/brctl/brctl $ (1)/usr/sbin/
Endef

$ (eval $ (call Buildpackage,bridge))

Package variables

Building a software package does not require much work; Most of the work is hidden in other makefiles, and the writing work is abstracted into assigning values to several variables.
Pkg_name-the name of the package, shown in Menuconfig and ipkg
Pkg_version-version of the package, the version of the trunk branch is exactly what we want to download
Pkg_release-This makefile version
Pkg_build_dir-Directory for compiling packages
Pkg_source-the name of the package to download, which is generally composed of pkg_name and pkg_version
Pkg_source_url-Download the link for this package
Pkg_md5sum-MD5 value of the package
Pkg_cat-Method of extracting packages (Zcat, Bzcat, unzip)
Pkg_build_depends-Requires a pre-built package, but only when building this package, not when it is running. Its syntax is the same as the depends below.

The pkg_* variable defines where to download the package, and @SF is a special keyword that represents a download from the SourceForge Web site. Md5sum is used to check that packages downloaded from the Web are intact. Pkg_build_dir defines the decompression path for the package source code.

Notice the last line at the bottom of the sample file above. This is the most critical buildpackage macro. It is defined in the $ (include_dir)/package.mk file. The Buildpackage macro requires only one parameter, which is the name of the package to compile, in this case "bridge". All other information is obtained through macros, which provides an intrinsic simplicity. For example, Buildpackage needs a large string of descriptive information for a software package, and we don't have to pass lengthy arguments to it because we've agreed to describe the information defined in Description macros, and Buildpackage read from inside.
Buildpackage Related macros

package/
Describes the package's information in Menuconfig and ipkg, and can define the following variables:
Section-Package type (not yet in use)
The first-level directory in the category-menuconfig that the package belongs to, such as network
The level two directory that the package belongs to in Submenu-menuconfig, such as Dial-in/up
Title-Package Header
DESCRIPTION-Detailed description of the package
URL-The original location of the software, typically the homepage of the software author
Maintainer-(optional) package maintenance staff
Depends-(optional) dependencies, running other packages that the software relies on

Package/conffiles (optional)

Package needs to copy a list of profiles, one file for a row

Build/prepare (optional)

A set of source code and patching orders, generally do not need.

Build/configure (optional)

If the source code needs to configure and specify some parameters before compiling it, leave these parameters here. Otherwise, you can not define.

Build/compile (optional)

Compile the source code command.

Package/install

Software installation commands, mainly to copy the relevant files to the specified directory, such as configuration files.

Package/preinst

The script that was executed before the software was installed, don't forget to add #!/bin/sh to the first sentence. If the script completes to cancel the installation process, just let it return false.

Package/postinst

The script that is executed after the software is installed, don't forget to add #!/bin/sh in the first sentence.

Package/prerm

The software deletes the script that was executed before, don't forget to add #!/bin/sh in the first sentence. If the script is finished, cancel the deletion process and let it return false directly.

Package/postrm

The script that is executed after the software is deleted, don't forget to add #!/bin/sh in the first sentence.

Some definitions are "package/" prefixes, while others are "build" prefixes. This is because we support an attribute: Building multiple packages from a single source. OpenWrt works on the assumption that a makefile corresponds to a source code, but you can split the compiled program into any number of packages. Because the compilation is only once, it is most appropriate to use the global "build" definition. You can then add a lot of "package/" Definitions and specify the installation method for each package separately. Suggest you go to see dropbear bag, this is a very good demonstration.

Tip: For all variables used in Pre/post, install/removal scripts, you should use the "instead." This is to tell you not to parse the variable for the time being, but to use it as a normal string and instead. -More information


After you have edited the makefile file and placed it in the specified directory, the new package will appear the next time you execute make menuconfig, you can choose this package, save the exit, and use make to compile. Now it's time to successfully transplant a software into the openwrt.
Creating a kernel module package

Kernel modules are a class of installable programs that extend the functionality of the Linux kernel. Kernel module loading occurs after the kernel is loaded (for example, by using the Insmod command).

The Linux source code contains a number of kernel applications. There are 3 options in Menuconfig,
compile into the kernel;
Compiled into a loadable kernel module;
does not compile.

See Fix:customizingthekerneloptions Customizing the kernel options

To include these kernel modules, just make menuconfig select the appropriate kernel module option. (Refer to build Configuration). If you do not find the kernel module you want at make menuconfig, you must add a stanza to a file in the Package/kernel/modules directory. The following is an example extracted from the package/kernel/modules/other.mk.

Define Kernelpackage/loop
Title:=loopback Device Support
Description:=kernel module for loopback device support
kconfig:=$ (Config_blk_dev_loop)
submenu:=$ (Emenu)
autoload:=$ (call Autoload,30,loop)
files:=$ (Modules_dir)/kernel/drivers/block/loop.$ (Linux_kmod_suffix)
Endef
$ (eval $ (call Kernelpackage,loop))


Additionally, you can add kernel modules that are not part of the Linux source package. In this case, the kernel module is placed in the package/directory, the same as the usual package. The Package/makefile file uses the KERNELPACKAGE/XXX definition instead of package/xxx.

This is an example of package/madwifi/makefile:
#
# Copyright (C) 2006 openwrt.org
#
# This are free software, licensed under the GNU general public License v2.
# See/license for more information.
#
# $Id $

Include $ (topdir)/rules.mk
Include $ (include_dir)/kernel.mk

Pkg_name:=madwifi
pkg_version:=0.9.2
Pkg_release:=1

pkg_source:=$ (Pkg_name)-$ (pkg_version). tar.bz2
pkg_source_url:= @SF/$ (pkg_name)
Pkg_md5sum:=a75baacbe07085ddc5cb28e1fb43edbb
Pkg_cat:=bzcat

pkg_build_dir:=$ (Kernel_build_dir)/$ (pkg_name)-$ (pkg_version)

Include $ (include_dir)/package.mk

Rate_control:=sample

Ifeq ($ (ARCH), MIPS)
Hal_target:=mips-be-elf
endif
Ifeq ($ (ARCH), Mipsel)
Hal_target:=mips-le-elf
endif
Ifeq ($ (ARCH), i386)
Hal_target:=i386-elf
endif
Ifeq ($ (ARCH), ARMEB)
Hal_target:=xscale-be-elf
endif
Ifeq ($ (ARCH), PowerPC)
Hal_target:=powerpc-be-elf
endif

Bus:=pci
Ifneq ($ (config_linux_2_4_ar531x),)
Bus:=ahb
endif
Ifneq ($ (Config_linux_2_6_aruba),)
BUS:=PCI AHB # no suitable HAL for AHB yet.
endif

bus_modules:=
Ifeq ($ (findstring ahb,$ (bus)), AHB)
bus_modules+=$ (Pkg_build_dir)/ath/ath_ahb.$ (Linux_kmod_suffix)
endif
Ifeq ($ (findstring pci,$ (bus)), PCI)
bus_modules+=$ (Pkg_build_dir)/ath/ath_pci.$ (Linux_kmod_suffix)
endif

madwifi_autoload:= \
WLAN \
WLAN_SCAN_AP \
Wlan_scan_sta \
Ath_hal \
ath_rate_$ (Rate_control) \
WLAN_ACL \
WLAN_CCMP \
Wlan_tkip \
WLAN_WEP \
Wlan_xauth

Ifeq ($ (findstring ahb,$ (bus)), AHB)
Madwifi_autoload + + ATH_AHB
endif
Ifeq ($ (findstring pci,$ (bus)), PCI)
Madwifi_autoload + + Ath_pci
endif

Define Kernelpackage/madwifi
  submenu:=wireless Drivers
  default:=y if LINUX_2_6_BRCM |  LIN Ux_2_6_aruba |  linux_2_4_ar531x |  Linux_2_6_xscale, m if all
  Title:=driver for Atheros wireless CHI Psets
  description:=\
This package contains a driver for Atheros 802.11a/b/g.
  Chipsets: madwifi.org/
  version:=$ (linux_version) +$ (pkg_version)-$ (BOARD)-$ (pkg_release)
  files:= \
  $ (Pkg_build_dir)/ath/ath_hal.$ (linux_kmod_suffix) \
  $ (bus_modules) \
  $ (pkg_build_dir)/ ath_rate/$ (Rate_control)/ath_rate_$ (Rate_control). $ (Linux_kmod_suffix) \
  $ (pkg_build_dir)/net80211/ wlan*.$ (linux_kmod_suffix)
  autoload:=$ (call autoload,50,$ (madwifi_autoload))
Endef

Madwifi_makeopts=-C $ (pkg_build_dir) \
Path= "$ (target_path)" \
Arch= "$ (linux_karch)" \
Cross_compile= "$ (target_cross)" \
Target= "$ (hal_target)" \
Toolprefix= "$ (kernel_cross)" \
Toolpath= "$ (kernel_cross)" \
Kernelpath= "$ (linux_dir)" \
ldopts= "" \
Ath_rate= "ath_rate/$ (rate_control)" \
Domulti=1

Ifeq ($ (findstring ahb,$ (bus)), AHB)
Define BUILD/COMPILE/AHB
$ (make) $ (madwifi_makeopts) bus= "AHB" all
Endef
endif

Ifeq ($ (findstring pci,$ (bus)), PCI)
Define Build/compile/pci
$ (make) $ (madwifi_makeopts) bus= ' PCI ' all
Endef
endif

Define Build/compile
$ (call BUILD/COMPILE/AHB)
$ (call Build/compile/pci)
Endef

Define Build/installdev
$ (Install_dir) $ (staging_dir)/usr/include/madwifi
$ (CP) $ (pkg_build_dir)/include $ (staging_dir)/usr/include/madwifi/
$ (Install_dir) $ (staging_dir)/usr/include/madwifi/net80211
$ (CP) $ (pkg_build_dir)/net80211/*.h $ (staging_dir)/usr/include/madwifi/net80211/
Endef

Define Kernelpackage/madwifi/install
$ (Install_dir) $ (1)/ETC/INIT.D
$ (Install_dir) $ (1)/lib/modules/$ (linux_version)
$ (Install_dir) $ (1)/usr/sbin
$ (install_bin)./files/madwifi.init $ (1)/etc/init.d/madwifi
$ (CP) $ (pkg_build_dir)/tools/{madwifi_multi,80211debug,80211stats,athchans,athctrl,athdebug,athkey,athstats, Wlanconfig} $ (1)/usr/sbin/
Endef

$ (eval $ (call Kernelpackage,madwifi

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.