You don't need to start with the SDK, you can also start with the OpenWrt sources; the difference is mostly that the sources will build the compiler while the SDK already comes with the compiler. It's actually easier to use the sources, it just takes a little longer.
As for the package makefile, the real trick is understanding just how much OpenWrt's buildroot system does for you. This is not your traditional makefile, the goal is not to describe how each piece of the source is run through the compiler, and what optimization flags are used; there's already a makefile included with the source that does all that. All that you need to do is tell OpenWrt where to download the sources and a brief description of what they are for the ipkg entry. The actual compile is done by passing control over to whatever structure already exists within the source.
Compiling a typical linux application from source generally looks like this:
1. Extract the sources into a temporary directory.
- is the source a tar.bz2? tar jxvf source.tar.bz2
- is the source a tar.gz? tar zxvf source.tar.gz
2. Configure the source
- if the source has a "configure" script, run it: ./configure
3. Compile the source
- make
OpenWrt knows this pattern, you don't need to specify it. Hence the package Makefile can be simplified down to the following:
include $(TOPDIR)/rules.mk
# name of package
# version number of the sources you're using
# how many times you've released a package based on the above version number
PKG_NAME:=mypackage
PKG_VERSION:=1.0
PKG_RELEASE:=1
# name of the sources; using variables from above for the version
# server directory containing the above source file (assuming it's not already found in the local dl directory)
# md5sum to avoid corrupted downloads
PKG_SOURCE:=mypackage-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=http://example.com/download/sources
PKG_MD5SUM:=12345678901234567890
# sources will be unpacked into this directory (you shouldn't need to change this)
PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)
include $(INCLUDE_DIR)/package.mk
# Metadata; information about what the package is for the ipkg listings
# to keep things simple, a number of fields have been left at their defaults
# and are not shown here.
define Package/mypackage
TITLE:=one line description of mypackage
MAINTAINER:=Your email address <user@example.com>
endef
define Package/mypackage/description
A very long description of what mypackage is and why anyone would ever want to install it.
Features:
- the ability to illustrate an openwrt package makefile
- more features
endef
# We'll use the OpenWrt defaults to configure and compile the package. Otherwise we'd need to define
# Build/Configure - commands to invoke a configure (or similar) script
# Build/Compile - commands used to run make or otherwise build the source
define Package/mypackage/install
# Now that we have the source compiled (magic huh?) we need to copy files out of the source
# directory and into our ipkg file. These are shell commands, so make sure you start the lines
# with a TAB. $(1) here represents the root filesystem on the router.
# make a directory for the config
$(INSTALL_DIR) $(1)/etc/mypackage/
# copy the config
$(INSTALL_CONF) $(PKG_BUILD_DIR)/mypackage.conf $(1)/etc/mypackage
# make a directory for some random data files required by mypackage
$(INSTALL_DIR) $(1)/usr/share/mypackage
# copy the data files
$(INSTALL_DATA) $(PKG_BUILD_DIR)/data/* $(1)/usr/share/mypackage
# copy the binary
$(INSTALL_BIN) $(PKG_BUILD_DIR)/mypackage $(1)/usr/bin
endef
This makefile would then be saved as "package/mypackage/Makefile".