Crosscompile with Optware

From OpenFSG
Jump to: navigation, search


Contents

What is Optware

"The Optware package system was originally created to accompany the Unslung firmware for the NSLU2 (originally the packages were called Unslung packages). It has since been expanded to cover a variety of other platforms. However, much of the documentation hasn't been updated so you may still see references to Unslung and the NSLU2 when the information also applies to other platforms. "

—From http://www.nslu2-linux.org/


Today Optware is also a development environment for all supported platforms. That is including the FSG3v3, FSG3v4, DataTank and Network Drive Pro. All needed toolchains and settings are included. If you develop a package, you can easily compile it for all plattforms. ( All software you like compiled together will be called a package. )


Installing Optware

Possible OS

The Optware Developers normally using GNU/Linux as Host with the preferred Distribution Debian. But it is also possible to run Optware under MS Windows, Mac OS, Unix or other Linux Distributions by using VM software. There is a really good OpenSource VM called VirtualBox. If you don't have Debian GNU/Linux or you don't like to install Optware on your native Debian, you have to install VirtualBox, create a new VM and install Debian on it. Therefore I will only explain using Optware with Debian.

Requirements

Download Optware

Change to a directory where you like to install Optware:

cd /home/myDIR

Anonymous Access

If you only like to test it or have a look of this project you can use the read-only access:

svn co http://svn.nslu2-linux.org/svnroot/optware/trunk optware

This will download Optware into your current directory ( A new directory "optware" will be created. )

Developer Access

If you like to start as a new Developer and like to have the chance of uploading your new packages, you should run:

svn co https://svn.nslu2-linux.org/svnroot/optware/trunk optware

But here you have to create a new key for it.

Installing Optware

After downloading Optware you have to change into the new directory:

cd ./optware

Now we like to create our first target. For every platform, you like to compile your software for, you will have to create a target.

Little <target> list:

FSG3v3: fsg3
FSG3v4: fsg3v4
Datatank: dt2
Network Drive Pro: vt4
make <target>-target
cd ./<target>

Now we are able to compile our first little test-package like "which":

make which
make which-ipk
make which-check

This should work without any trouble. Good luck ;-) But during this first compile there are a few more tasks, which can takes a long time (create directories, create ipkg-utils, create toolchain). But don't worry, this only have to be done once. If you like to test normal build-time of this first packages you can cleanup and do it again:

make which-dirclean
make which
make which-ipk
make which-check

Making your own package

Compile Basics

Most software under GNU/Linux use GNU Autotools for managing the compilation. So the user only has to enter

./configure

for checking the system and search for the needed libraries and tools,

make

for compiling the whole software package with all necessary files and then

make install

to install the software on the system. If you like to crosscompile, there are a lot of settings, that help you to do this. Optware is able to do the whole configuration by interacting with GNU Autotools. You only have to create a template for your package and enter

make mypackage

at your target directory. Than Optware uses the settings from mypackage.mk to

Now a package-file can build with

make mypackage-ipk

which does the following, depending on the settings in mypackage.mk

At last it is possible to check your package with

make mypackage-check

If you like, it is possible to expand the standard checking with your own commands at mypackage.mk.

After creating all this ( mypackage.mk and patches ) you are able to compile your package for all platforms. Only create your target and run:

make mypackage
make mypackage-ipk
make mypackage-check

If you like to upload your package to Optware you only have to upload your template and your patches, no source or binaries.

Create a new template

Optware uses a MasterMakefile, which is able to compile your new package for all platforms, but you have to do some work to get this work. Every package has its own template with suffix ".mk" at the make directory like "mypackage.mk".

To build your package you have to copy "template.mk" to "mypackage.mk":

cp make/template.mk make/mypackage.mk

In this file, all information for compiling your package is contained. The first steps are to replace big <FOO> and little <foo> with your capital and lower case package-name:

sed -i 's/<FOO>/MYPACKAGE/g' make/mypackage.mk
sed -i 's/<foo>/mypackage/g' make/mypackage.mk

To do these first steps with one command you can call:

make make/mypackage.mk

Then create a new source directory:

mkdir sources/mypackage

Edit your template

The main work is to edit the template "mypackage.mk" until it compiles your package without any error for all platforms. First you should follow the current lines of your template and sometimes you'll have a look into other make scripts.

basic settings

<FOO>_SITE=http://$(SOURCEFORGE_MIRROR)/sourceforge/<foo>
<FOO>_VERSION=3.2.1
<FOO>_SOURCE=<foo>-$(<FOO>_VERSION).tar.gz
<FOO>_DIR=<foo>-$(<FOO>_VERSION)
<FOO>_UNZIP=zcat
<FOO>_MAINTAINER=NSLU2 Linux <nslu2-linux@yahoogroups.com>
<FOO>_DESCRIPTION=Describe <foo> here.
<FOO>_SECTION=
<FOO>_PRIORITY=optional
<FOO>_DEPENDS=
<FOO>_SUGGESTS=
<FOO>_CONFLICTS=
<FOO>_IPK_VERSION=1

Specify the URL for source, version, source-filename, directory at package, package-type, your full name and valid email or "NSLU2 Linux <nslu2-linux@yahoogroups.com>", description of your package, section-name ( e.g. lib, admin, tools, ... ), priority, depending packages which have to install before, suggestions, conflicts to installed files of other packages and IPK Version which increments every release.

patches and compiler settings

<FOO>_PATCHES=$(<FOO>_SOURCE_DIR)/configure.patch
<FOO>_CPPFLAGS=
<FOO>_LDFLAGS=
<FOO>_BUILD_DIR=$(BUILD_DIR)/<foo>
<FOO>_SOURCE_DIR=$(SOURCE_DIR)/<foo>
<FOO>_IPK_DIR=$(BUILD_DIR)/<foo>-$(<FOO>_VERSION)-ipk
<FOO>_IPK=$(BUILD_DIR)/<foo>_$(<FOO>_VERSION)-$(<FOO>_IPK_VERSION)_$(TARGET_ARCH).ipk

Specify all files that should be patched before compiling, compiler flags, debugger flags, the directory in which the build is done, the directory which holds all the patches and ipkg control files, the directory in which the ipk is built, the name of the resulting ipk files.

If the compilation of the package requires other packages to be staged first, then do that first:

$(MAKE) <bar>-stage <baz>-stage

You have to specify this line for every required package with accordingly settings or leave it out if there are no required packages.

Now set all flags for "configure" script:

(cd $(@D); \
		$(TARGET_CONFIGURE_OPTS) \
		CPPFLAGS="$(STAGING_CPPFLAGS) $(<FOO>_CPPFLAGS)" \
		LDFLAGS="$(STAGING_LDFLAGS) $(<FOO>_LDFLAGS)" \
		./configure \
		--build=$(GNU_HOST_NAME) \
		--host=$(GNU_TARGET_NAME) \
		--target=$(GNU_TARGET_NAME) \
		--prefix=/opt \
		--disable-nls \
		--disable-static \
	)

If the package uses GNU libtool, you should invoke $(PATCH_LIBTOOL) as shown below to make various patches to it.

$(PATCH_LIBTOOL) $(@D)/libtool

Otherwise leave it out.

If you are building a library, then you need to stage it too.

$(<FOO>_BUILD_DIR)/.staged: $(<FOO>_BUILD_DIR)/.built
	rm -f $@
	$(MAKE) -C $(@D) DESTDIR=$(STAGING_DIR) install
	touch $@

<foo>-stage: $(<FOO>_BUILD_DIR)/.staged

Otherwise leave it out.

Developer Guidlines

For such a great project it is neccessary to give some rules for developers. You should read and do so if you like to work on packages. A list of all guidlines you find here: http://www.nslu2-linux.org/wiki/Optware/PackagingBestPractices

Mark your package ready for testing

"When your package is ready to be looked at by a core developer, add its name to one of the READY_FOR_TESTING lines in the root Makefile. In due course, someone will take a look at what you've done. If it works, and follows the Unslung.PackagingBestPractices, it will be uploaded to the feed. If not, it will be moved to a NEED_TO_BE_FIXED line, and a comment entered in the makefile describing the problem.

—From http://www.nslu2-linux.org/

svn lock Makefile
<edit the Makefile to add your lines>
svn commit -m "package: comments as per guidelines" Makefile

Note regarding Libtool and Libtoolize

"For building most packages, the GNU Libtool and Libtoolize are essential programs that need to be installed on the build system. These two programs interact with the ltmain.sh script included with most program tarballs. There are currently two version streams for these programs, version stream 1.5.x included with most older versions of Debian and Ubuntu etc, this is the version used by the NSLU2 Optware build machines. More recent versions of Ubuntu and other Linux distros have now upgraded Libtool and Libtoolize to the version stream 2.2.x. Unfortunately many Optware packages will not build with this later version. The reason - version stream 2.2.x is not fully backwardly compatible with ltmain.sh scripts from earlier versions. This backward compatibility problem is well documented on the internet, there are may recommended fixes and patches etc, most are not fully explored, some may fix one package but break another. To check the version of Libtool installed type at a console prompt : -

libtool --version

For Optware development it is recommended that the version of Libtool is downgraded to version 1.5.26 or lower, example - with a Ubuntu Intrepid build system install the Ubuntu Hardy version of the libtools.

Another possibility is to upgrade the version of the ltmain.sh script included with the program tarball to a version 2.2.x. This seems to work with some program tarballs but not all. "

—From http://www.nslu2-linux.org/

Links

Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox