Building your own package for OpenWRT

OpenWRT is a robust and flexible Linux distribution meant for wireless embedded devices. One of the reasons why OpenWRT has become widely popular is that it has a package management system which allows the user to add packages as per the requirements. If someone is into wireless / mesh network research OpenWRT is invaluable. An important part of it could be to create an OpenWRT package out of your own source code. Something worth understanding here is that there are two makefiles which are referred here — the “normal” makefile which is part of your source code and a “special” makefile which is used by the package management system and the buildroot.

As an example, this package was created for some C++ wrapper classes around C socket calls. The source code is available here. It contains the “normal” makefile within it. These are the steps which were carried out :

1. Write the OpenWRT makefile : This is a special makefile which OpenWRT uses. The Makefile is listed and explained at the end of this post. Understanding how to write this makefile is the key to building packages on OpenWRT.

2. Copy this makefile in the appropriate folder : This should be package/<packageName>/Makefile within your buildroot system.

3. make menuconfig : Once the makefile has been placed in the appropriate directory, calling make menuconfig in the buildroot system should show the package in the appropriate section. The package should be selected.

4. make package/<package name>-compile V=99 : This does two things — downloads your package from the URL you specified and compiles the package as well. By default the compilation is done as per the “normal” makefile. You should be able to see the package source code in the dl folder and the compiled images in build_i386/<package-name>.
5. make package/<package name>-install V=99 : This should create the appropriate ipkg package in /bin/packages. Now you can go ahead and port the ipkg to your wrap board and install it using ipkg install <package name>

# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#
# $Id$

include $(TOPDIR)/rules.mk

#These lines concatanate the package name and list the URL location from which the package source code is to be downloaded
PKG_NAME:=commonclasses
PKG_VERSION:=0.1
PKG_RELEASE:=1

PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=http://www.cs.uh.edu/~vivekian/downloads/

#md5 can be computed using the md5sum utility available on linux

PKG_MD5SUM:=6607524493ff74de82cc114e32674d40
PKG_CAT:=zcat

PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)

include $(INCLUDE_DIR)/package.mk

#These lines describe what your package does and its place in the menu config

define Package/commonclasses
SECTION:=net
CATEGORY:=Network
TITLE:=CommonClasses is a group of classes which are C++ wrappers around C socket functions
DESCRIPTION:=\
You can use this in your C++ code \\\
It will make your life easier \\\
It will save you time !
URL:=http://www.cs.uh.edu/~vivekian
endef

#For the compile rules you need to specify the cross compiler which needs to be used :

define Build/Compile
$(MAKE) -C $(PKG_BUILD_DIR) \
CXX="$(TARGET_CROSS)g++"
endef

#These lines describe where your binary images are to be installed – its the equivalent to make install

# This particular package is a library and the installation rules reflect it

define Package/commonclasses/install
$(INSTALL_DIR) $(1)/usr/lib
$(INSTALL_DIR) $(1)/usr/include
$(INSTALL_BIN) $(PKG_BUILD_DIR)/libcppsocket.so $(1)/usr/lib/
$(INSTALL_DATA) $(PKG_BUILD_DIR)/SockException.h $(1)/usr/include/
$(INSTALL_DATA) $(PKG_BUILD_DIR)/Socket.h $(1)/usr/include/
$(INSTALL_DATA) $(PKG_BUILD_DIR)/SocketReaderWriter.h $(1)/usr/include/
$(INSTALL_DATA) $(PKG_BUILD_DIR)/TcpSocket.h $(1)/usr/include/
$(INSTALL_DATA) $(PKG_BUILD_DIR)/UdpSocket.h $(1)/usr/include/
endef

$(eval $(call BuildPackage,commonclasses))

Some Useful Links :

Advertisements

2 thoughts on “Building your own package for OpenWRT

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s