MokoMakefile is a Makefile which saves lots of work when setting up an Openmoko build environment.
By automating the setup process of a new Openmoko build environment, it provides an environment which is configured the same for all the existing developers and should therefore be preferred over manual procedures or individual setup procedures.
It brings the same repeatability to build environment creation and maintenance as that which the BitBake scripts bring to OpenEmbedded ease and standardize the process of building OpenEmbedded.

MokoMakefile does not install anything into your system (it can and should be started as normal user). MokoMakefile is a wrapper around all that is required to make it easy to set up and maintain a development environment that fully complies with the setup instructions published by Openmoko.

MokoMakefile is developed by Rod Whitby - it is not an official product of Openmoko (although I would be happy for them to pick it up and use it internally). If there is any discrepancy between the official Openmoko build instructions, and the operation of the MokoMakefile, then you should consider the official instructions to be correct.

The MokoMakefile is able to build both Om2008.8 (org.openmoko.asu.stable, openmoko-asu-image) and "Bleeding Edge" (org.openmoko.dev, openmoko-base-image) images.

MokoMakefile also builds the QEMU-based Neo1973 emulator as part of the build process and has make targets to install the Openmoko images into it and run it. These commands can also be used without downloading and building the whole Openmoko OpenEmbedded distribution. This part is described in Using QEMU with MokoMakefile.

Requirements for building Openmoko

Independent on whether MokoMakefile or a manual process is used to setup an Openmoko build environment, there are several requirements which must be fulfilled in order for the Openmoko build to succeed:

RAM: The build host needs to have at least 512MB of RAM, and about the same amount of swap. Some packages built by OpenEmbedded like busybox are built by compiling all source files into one binary which causes gcc to grow beyond 300MB of size and no part of this memory may be on swap for the compile to finish in predictable time. For busybox, this can be turned off, but turning this off means that busybox will not as well optimized by gcc.

Disk space: You need about 12 GB of available disk space for the Openmoko build to succeed (see below for a tip on how to reduce this).

Time: The initial build takes at least 5 hours (on 2GHz core2duo without multiprocessor optimization) and may take several days on slower machines.

If you forgot anything which OE needs itself, OE will tell you shortly after you start building, but it does not check build dependencies of Openmoko, so you either have to install them before starting or install them after the build failed. OpenEmbedded will continue where it stopped when you restart the build afterwards.

Package requirements by distribution

Your distribution needs to provide these commands in order for OpenEmbedded to start building:

subversion texi2html texinfo help2man

Openmoko needs the development packages (with header files, development libraries and tools) in order to finish building:

ncurses zlib (or libz) OpenSSL GTK++

Because there are bugs in the interaction of QEMU and GCC-4, you'll need a copy of gcc-3.x installed as well.

# On Ubuntu 8.04 and and Debian testing/unstable, the following was required instead of cogito
sudo apt-get install git-core
# Ubuntu links /bin/sh to /bin/dash, but some scripts fail because they use pushd and popd, which dash does not support
sudo dpkg-reconfigure dash
# Select No when it asks you to install dash as /bin/sh.

If you are having problems compiling QEMU and do not need it, you can disable building of QEMU by adding following line to build/conf/local.conf file:

ENABLE_BINARY_LOCALE_GENERATION = "0"

Proxy

Users behind a proxy should ensure that their proxy is configured in their wgetrc file as the http_proxy environment variable is unset by MokoMakefile.

Building Openmoko with MokoMakefile

Preparations

Create your $OMDIR directory (note that you can change ~/moko to any directory you like):

mkdir ~/moko ; cd ~/moko

If you have your ~moko dir mounted from a different file system, be sure to edit /etc/mtab to add the 'exec' permission to the file system, else bitbake will fail with error messages stating that /usr/bin/env is an invalid interpreter.
If you ever want to move your $OMDIR to another location, you must run

make clobber ; make setup

to reinitialize the environment. Yes, this will take a long time, so choose $OMDIR carefully.

MokoMakefile

NOTE: MokoMakefile uses BitBake 1.8.8 which requires python-sqlite2 and sqlite-3.3 or later. Users of SUSE Linux 10.1 can update to the version of openSUSE 10.2

Environment

If you want to make the "Bleeding Edge" (org.openmoko.dev, openmoko-base-image) image instead of the Om2008.8 image, see Distributions, you need to edit your Makefile. Read the top of the Makefile for details.

Building

Before starting a lengthy make process, check the Tips section below for how to make Make multicore aware. You may want to modify the build/conf/local.conf file for your target (emulation/chroot) environment.

make image

Hint: The images build with this command can be found under {$OMDIR}/build/tmp/deploy/glibc/images/neo1973

This will set up the recommended directory structure as described in Building Openmoko from scratch, will download all the required software (from the right places with the right versions), and will immediately start building an image.

Once you have done this, you can choose to continue using the MokoMakefile to initiate your subsequent builds, or you can go into the build directory and run bitbake commands manually. The choice is yours.

Updating the environment

For easy maintenance of your build environment the following commands are available.

1 - To update the MokoMakefile to the latest version:

make update-makefile

Be aware that any changes you previously made to the Makefile (like the git branch to use) are lost when executing update-makefile.

2 - To make sure that any recent changes to the build directory structure have been applied:

make setup

3 - To update the Openmoko repository checkout and the MokoMakefile patches to the latest version:

make update

A quick way to rebuild a new image with the latest updates:

make update-makefile && make setup update image

Build issues

First, make sure that the problem is reproducible after running

make update-makefile && make setup && make update

then run

make clean-package-<foo>

(where you replace <foo> with the name of the package which is failing)

and finally

make image

With luck - you should now have images in your $omdir/build/tmp/deploy/glibc/images/neo1973/ directory.
You can then flash these.

If not, and you can get the error to occur three times in a row after running that sequence of commands (including the update and setup steps) three times, then feel free to report it to rwhitby in #openmoko on IRC.

If you have chronic build problems, cleaning your environment variables and re-running the build from scratch may help. The following script should remove all non-essential variables; you should also manually trim your path to the minimum.

For people with multiple CPU's (or dual-core ones) this small patch might be useful to build things faster.

Edit the local.conf and add the following lines:

PARALLEL_MAKE = "-j 4"
BB_NUMBER_THREADS = "4"

Change the PARALLEL_MAKE and BB_NUMBER_THREADS values to something that suits better if it chokes your machine.

I have some problem with the parallel building, mkfs.jffs failed to build the image because the directory was modify while the building of the fs. patrick.hetu 02:19, 27 May 2008 (UTC)

If you encounter an error related with the qemu-native package and not compiling for the qemu, you can edit the build/conf/local.conf file and add ENABLE_BINARY_LOCALE_GENERATION = "0" line to avoid the error.

To prevent building tons of locales, add a line like this to local.conf:

GLIBC_GENERATE_LOCALES = "en_US.UTF-8 nl_NL.UTF-8"

To not build any binary locales at all, add this to local.conf:

ENABLE_BINARY_LOCALE_GENERATION = "0"

If you want to rebuild the package indexes (for instance, after compiling a new version of a package) without building the whole image, run make build-package-package-index.

User:Wurp will update this to be a little more comprehensible, but maybe it can help someone as-is in the meantime:

If MokoMakefile always fails on some fetch in zlib, just find the binary somewhere, add it to the downloads or sources directory manually (create the .md5 matching file if necessary), and retry.

Make sure you do not have . in your PATH, this causes an "unrecognized option -Qy" error when building g++spec

Useful commands

Here is the list (not complete) of useful MokoMakefile commands (actually make targets) and a short description of each one. These should be run inside $OMDIR directory.

same as make qemu, but uses locally built images instead of official ones.

make run-qemu

runs qemu with usb keyboard (note: qemu must first be built!). This target starts the emulator with some predefined set of options. If you need to start it with other options (enable telnet, etc), see QEMU_command_line.

make build-package-<package name>

buids <package name> package

make update-makefile

updates MokoMakefile

make clean-package-<foo>

cleans the "<foo>" package

make setup

to make sure that any recent changes to the build directory structure have been applied

make update

to update the Openmoko repository checkout and the MokoMakefile patches to the latest version

make setup-machine-om-gta01

setup for GTA01 version of Neo1973

make setup-machine-om-gta02

setup for GTA02 version of FreeRunner

make build-package-package-index

Rebuild the package index

Developing with MokoMakefile

For the following explanations $OMDIR is the directory where there Makefile puts all the stuff.

To make in-tree changes and have them built and used by qemu:

cd $OMDIR/openmoko
quilt new descriptive-patch-name.patch
quilt add trunk/src/name-of-file-to-change # do this for every file you are about to modify
...make the changes...
quilt refresh # this creates a file in $OMDIR/patches/openmoko-HEAD/ and updates the quilt series file there

Note: Do NOT use absolute paths as this confuses quilt and will get you a diff of the file against /dev/null!

To build the changes and have them used by qemu:

make build-qemu
make flash-qemu-local
make run-qemu

If you want to modify applications instead of the openmoko toolchain, this is what you have to do (example: openmoko-messages):

Note: The compile step is only necessary if you already had the package compiled before patching it.

Note: if you just use bitbake openmoko-messages it will remove the sources after building!

Note: You can use the '-f' switch to force a command to be run (e.g. bitbake -f -c compile openmoko-messages to force a compile run.

Then continue with MokoMakefile usage.

If you want to add an application to your openmoko distribution, do this:
All file edits should be done using quilt as described above. That way a patch can easily be submitted to the openmoko project.
First, create a directory that will correspond to your package and edit a .bb file in there:

inherit autotools - The package can be compiled by './configure && make && make install' so we tell MokoMakefile to do it this way.

SRC_URI = ... - This is the download location of the package source. It's imperative that the tar.gz contains a directory called packagename-packageversion (in this case: mycoolpackage-1) so that MokoMakefile can find it automatically or the build will fail.

This is not all. We also need to tell MokoMakfile that it needs to build and include the package in the image. To do this, do

Hello World application

Testimonials

MokoMakefile is recommended by 4 out of 4 new developers on #openmoko, with testimonials such as "For some reason last night I couldn't get my manual install of everything to work (bb complained about my bbpath I think) ... but with your makefile, it works great!", "MokoMakefile rocks!", "Wow this build system is nice - it just seems more polished than my gumstix toolchain buildroot system", "make openmoko-devel-image :) - no magic there", and "I have never been able to get a build to complete in the pure OE environment, whereas Mokomakefile for some reason builds fine."

MokoMakefile is a Makefile which saves lots of work when setting up an Openmoko build environment.
By automating the setup process of a new Openmoko build environment, it provides an environment which is configured the same for all the existing developers and should therefore be preferred over manual procedures or individual setup procedures.
It brings the same repeatability to build environment creation and maintenance as that which the BitBake scripts bring to OpenEmbedded ease and standardize the process of building OpenEmbedded.

MokoMakefile does not install anything into your system (it can and should be started as normal user). MokoMakefile is a wrapper around all that is required to make it easy to set up and maintain a development environment that fully complies with the setup instructions published by Openmoko.

MokoMakefile is developed by Rod Whitby - it is not an official product of Openmoko (although I would be happy for them to pick it up and use it internally). If there is any discrepancy between the official Openmoko build instructions, and the operation of the MokoMakefile, then you should consider the official instructions to be correct.

The MokoMakefile is able to build both Om2008.8 (org.openmoko.asu.stable, openmoko-asu-image) and "Bleeding Edge" (org.openmoko.dev, openmoko-base-image) images.

MokoMakefile also builds the QEMU-based Neo1973 emulator as part of the build process and has make targets to install the Openmoko images into it and run it. These commands can also be used without downloading and building the whole Openmoko OpenEmbedded distribution. This part is described in Using QEMU with MokoMakefile.

Requirements for building Openmoko

Independent on whether MokoMakefile or a manual process is used to setup an Openmoko build environment, there are several requirements which must be fulfilled in order for the Openmoko build to succeed:

RAM: The build host needs to have at least 512MB of RAM, and about the same amount of swap. Some packages built by OpenEmbedded like busybox are built by compiling all source files into one binary which causes gcc to grow beyond 300MB of size and no part of this memory may be on swap for the compile to finish in predictable time. For busybox, this can be turned off, but turning this off means that busybox will not as well optimized by gcc.

Disk space: You need about 12 GB of available disk space for the Openmoko build to succeed (see below for a tip on how to reduce this).

Time: The initial build takes at least 5 hours (on 2GHz core2duo without multiprocessor optimization) and may take several days on slower machines.

If you forgot anything which OE needs itself, OE will tell you shortly after you start building, but it does not check build dependencies of Openmoko, so you either have to install them before starting or install them after the build failed. OpenEmbedded will continue where it stopped when you restart the build afterwards.

Package requirements by distribution

Your distribution needs to provide these commands in order for OpenEmbedded to start building:

subversion texi2html texinfo help2man

Openmoko needs the development packages (with header files, development libraries and tools) in order to finish building:

ncurses zlib (or libz) OpenSSL GTK++

Because there are bugs in the interaction of QEMU and GCC-4, you'll need a copy of gcc-3.x installed as well.

# On Ubuntu 8.04 and and Debian testing/unstable, the following was required instead of cogito
sudo apt-get install git-core
# Ubuntu links /bin/sh to /bin/dash, but some scripts fail because they use pushd and popd, which dash does not support
sudo dpkg-reconfigure dash
# Select No when it asks you to install dash as /bin/sh.

If you are having problems compiling QEMU and do not need it, you can disable building of QEMU by adding following line to build/conf/local.conf file:

ENABLE_BINARY_LOCALE_GENERATION = "0"

Proxy

Users behind a proxy should ensure that their proxy is configured in their wgetrc file as the http_proxy environment variable is unset by MokoMakefile.

Building Openmoko with MokoMakefile

Preparations

Create your $OMDIR directory (note that you can change ~/moko to any directory you like):

mkdir ~/moko ; cd ~/moko

If you have your ~moko dir mounted from a different file system, be sure to edit /etc/mtab to add the 'exec' permission to the file system, else bitbake will fail with error messages stating that /usr/bin/env is an invalid interpreter.
If you ever want to move your $OMDIR to another location, you must run

make clobber ; make setup

to reinitialize the environment. Yes, this will take a long time, so choose $OMDIR carefully.

MokoMakefile

NOTE: MokoMakefile uses BitBake 1.8.8 which requires python-sqlite2 and sqlite-3.3 or later. Users of SUSE Linux 10.1 can update to the version of openSUSE 10.2

Environment

If you want to make the "Bleeding Edge" (org.openmoko.dev, openmoko-base-image) image instead of the Om2008.8 image, see Distributions, you need to edit your Makefile. Read the top of the Makefile for details.

Building

Before starting a lengthy make process, check the Tips section below for how to make Make multicore aware. You may want to modify the build/conf/local.conf file for your target (emulation/chroot) environment.

make image

Hint: The images build with this command can be found under {$OMDIR}/build/tmp/deploy/glibc/images/neo1973

This will set up the recommended directory structure as described in Building Openmoko from scratch, will download all the required software (from the right places with the right versions), and will immediately start building an image.

Once you have done this, you can choose to continue using the MokoMakefile to initiate your subsequent builds, or you can go into the build directory and run bitbake commands manually. The choice is yours.

Updating the environment

For easy maintenance of your build environment the following commands are available.

1 - To update the MokoMakefile to the latest version:

make update-makefile

Be aware that any changes you previously made to the Makefile (like the git branch to use) are lost when executing update-makefile.

2 - To make sure that any recent changes to the build directory structure have been applied:

make setup

3 - To update the Openmoko repository checkout and the MokoMakefile patches to the latest version:

make update

A quick way to rebuild a new image with the latest updates:

make update-makefile && make setup update image

Build issues

First, make sure that the problem is reproducible after running

make update-makefile && make setup && make update

then run

make clean-package-<foo>

(where you replace <foo> with the name of the package which is failing)

and finally

make image

With luck - you should now have images in your $omdir/build/tmp/deploy/glibc/images/neo1973/ directory.
You can then flash these.

If not, and you can get the error to occur three times in a row after running that sequence of commands (including the update and setup steps) three times, then feel free to report it to rwhitby in #openmoko on IRC.

If you have chronic build problems, cleaning your environment variables and re-running the build from scratch may help. The following script should remove all non-essential variables; you should also manually trim your path to the minimum.

For people with multiple CPU's (or dual-core ones) this small patch might be useful to build things faster.

Edit the local.conf and add the following lines:

PARALLEL_MAKE = "-j 4"
BB_NUMBER_THREADS = "4"

Change the PARALLEL_MAKE and BB_NUMBER_THREADS values to something that suits better if it chokes your machine.

I have some problem with the parallel building, mkfs.jffs failed to build the image because the directory was modify while the building of the fs. patrick.hetu 02:19, 27 May 2008 (UTC)

If you encounter an error related with the qemu-native package and not compiling for the qemu, you can edit the build/conf/local.conf file and add ENABLE_BINARY_LOCALE_GENERATION = "0" line to avoid the error.

To prevent building tons of locales, add a line like this to local.conf:

GLIBC_GENERATE_LOCALES = "en_US.UTF-8 nl_NL.UTF-8"

To not build any binary locales at all, add this to local.conf:

ENABLE_BINARY_LOCALE_GENERATION = "0"

If you want to rebuild the package indexes (for instance, after compiling a new version of a package) without building the whole image, run make build-package-package-index.

User:Wurp will update this to be a little more comprehensible, but maybe it can help someone as-is in the meantime:

If MokoMakefile always fails on some fetch in zlib, just find the binary somewhere, add it to the downloads or sources directory manually (create the .md5 matching file if necessary), and retry.

Make sure you do not have . in your PATH, this causes an "unrecognized option -Qy" error when building g++spec

Useful commands

Here is the list (not complete) of useful MokoMakefile commands (actually make targets) and a short description of each one. These should be run inside $OMDIR directory.

same as make qemu, but uses locally built images instead of official ones.

make run-qemu

runs qemu with usb keyboard (note: qemu must first be built!). This target starts the emulator with some predefined set of options. If you need to start it with other options (enable telnet, etc), see QEMU_command_line.

make build-package-<package name>

buids <package name> package

make update-makefile

updates MokoMakefile

make clean-package-<foo>

cleans the "<foo>" package

make setup

to make sure that any recent changes to the build directory structure have been applied

make update

to update the Openmoko repository checkout and the MokoMakefile patches to the latest version

make setup-machine-om-gta01

setup for GTA01 version of Neo1973

make setup-machine-om-gta02

setup for GTA02 version of FreeRunner

make build-package-package-index

Rebuild the package index

Developing with MokoMakefile

For the following explanations $OMDIR is the directory where there Makefile puts all the stuff.

To make in-tree changes and have them built and used by qemu:

cd $OMDIR/openmoko
quilt new descriptive-patch-name.patch
quilt add trunk/src/name-of-file-to-change # do this for every file you are about to modify
...make the changes...
quilt refresh # this creates a file in $OMDIR/patches/openmoko-HEAD/ and updates the quilt series file there

Note: Do NOT use absolute paths as this confuses quilt and will get you a diff of the file against /dev/null!

To build the changes and have them used by qemu:

make build-qemu
make flash-qemu-local
make run-qemu

If you want to modify applications instead of the openmoko toolchain, this is what you have to do (example: openmoko-messages):

Note: The compile step is only necessary if you already had the package compiled before patching it.

Note: if you just use bitbake openmoko-messages it will remove the sources after building!

Note: You can use the '-f' switch to force a command to be run (e.g. bitbake -f -c compile openmoko-messages to force a compile run.

Then continue with MokoMakefile usage.

If you want to add an application to your openmoko distribution, do this:
All file edits should be done using quilt as described above. That way a patch can easily be submitted to the openmoko project.
First, create a directory that will correspond to your package and edit a .bb file in there:

inherit autotools - The package can be compiled by './configure && make && make install' so we tell MokoMakefile to do it this way.

SRC_URI = ... - This is the download location of the package source. It's imperative that the tar.gz contains a directory called packagename-packageversion (in this case: mycoolpackage-1) so that MokoMakefile can find it automatically or the build will fail.

This is not all. We also need to tell MokoMakfile that it needs to build and include the package in the image. To do this, do

Hello World application

Testimonials

MokoMakefile is recommended by 4 out of 4 new developers on #openmoko, with testimonials such as "For some reason last night I couldn't get my manual install of everything to work (bb complained about my bbpath I think) ... but with your makefile, it works great!", "MokoMakefile rocks!", "Wow this build system is nice - it just seems more polished than my gumstix toolchain buildroot system", "make openmoko-devel-image :) - no magic there", and "I have never been able to get a build to complete in the pure OE environment, whereas Mokomakefile for some reason builds fine."