How to compile your application

In this short indtroduction we will show how to cross compile an application.

First of all you need to install the SDK* on your pc get it.

NOTE: On this external website you can found a more detailed article on this topic.

Directory structure

In the top level of the SDK directory tree you find the directory package. Change to the directory package and create a directory with the name of your application. Change to the newly created directory and create two additional directories src and files. In this example we wish to compile a simple helloworld application.

cd package
mkdir helloworld
cd helloworld
mkdir src
mkdir files

The Makefile

Copy the source file of your application into the directory package/helloworld/src, configuration files and script files should be copied to package/helloworld/files and in package/helloworld, the following Makefile has to be created:

#helloworld makefile
include $(TOPDIR)/rules.mk
 
PKG_NAME:=helloworld
PKG_RELEASE:=1
PKG_VERSION:=0.1
 
PKG_BUILD_DEPENDS:=
 
include $(INCLUDE_DIR)/package.mk
 
define Package/helloworld
  SECTION:=utils
  CATEGORY:=Utilities
  DEPENDS:=@TARGET_etrax
  TITLE:=Yet Another Helloworld Application
endef
 
define Package/helloworld/description
 This is helloworld :p
endef
 
define Build/Prepare
	mkdir -p $(PKG_BUILD_DIR)
	$(CP) ./src/* $(PKG_BUILD_DIR)/
endef
 
define Build/Compile
	$(MAKE) -C $(PKG_BUILD_DIR) \
		$(TARGET_CONFIGURE_OPTS) \
		CFLAGS="$(TARGET_CFLAGS)"
endef
 
define Package/helloworld/install
	$(INSTALL_DIR) $(1)/usr/bin
	$(INSTALL_BIN) $(PKG_BUILD_DIR)/helloworld $(1)/usr/bin/
endef
 
$(eval $(call BuildPackage,helloworld))

This build the package: bin/packages/$PKG_NAME_$PKG_VERSION-$PKG_RELEASE.ipk in this case: bin/packages/helloworld_1.0-1.ipk.

Some other inforation on:

  • PKG_BUILD_DEPENDS: this is a host application depends
  • DEPENDS: this is the package depends on remote host, for example DEPENDS:=@TARGET_ETRAX libz +libqslite2 means:
    1. The target architecture is ONLY ETRAX
    2. Show this package in make menuconfig only if libz has been previous selected
    3. If this package is selected require libsqlite2 to be compile
  • CATEGORY: This choice the package category inside make menuconfig

Source code

As previous declared the source code should be copied iside package/helloworld/src, for the our application helloworld this folder should contain:

File main.c:

#include <stdio.h>
 
void main (void) {
     hello();
}

File hello.c:

#include <stdio.h>
 
void hello (void) {
     printf("Yet another helloworld application :D\n ");
}

File Makefile:

#Change application name
PROGS     = helloworld
 
INSTDIR   = $(prefix)/usr/bin
INSTMODE  = 0755
INSTOWNER = root
INSTGROUP = root
 
#change obj list for this application
OBJS = main.o hello.o 
 
all: $(PROGS)
$(PROGS): $(OBJS)
	$(CC) $(CFLAGS) $(LDFLAGS) $^ $(LDLIBS) -o $@
	$(STRIP) $@
 
install: $(PROGS)
	$(INSTALL) -d $(INSTDIR)
	$(INSTALL) -m $(INSTMODE) -o $(INSTOWNER) -g $(INSTGROUP) $(PROGS) $(INSTDIR)
 
clean:
	rm -f $(PROGS) *.o core

NOTE: On this external website you can found a more detailed article on this topic.

Compiling it

Now you should run make menuconfig and select your new package inside appropriate category before run make.
With the own example you will obtain:

The application selected with * are installed by default inside generated image; the application selected with M are compiled as packages that can be installed with opkg.
The compiled packages can be found inside openwrt/bin directory.

documentation/sdk/build_your_app.txt · Last modified: 2010/02/06 11:02 (external edit)
CC Attribution-Noncommercial-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0