Package Management


Midori includes a basic package management system called MLZ that is designed specifically for the needs of small devices. This chapter introduces the MLZ package management system and describes the following:

MLZ is much simpler than general-purpose package management systems like RPM and Debian. General-purpose package management systems can create modules that may be installed on a variety of different runtime systems. MLZ depends on the Midori build system to ensure that its packages can be bundled into a Flash ROM for a specific runtime target. In particular, MLZ packages have the following advantages:

Each Midori Flash ROM image is a runtime image that contains a collection of MLZ packages. The Midori build system assembles the package into the final Flash ROM image. The MLZ package management system is a wrapper system that mediates between the Midori build system and each package's internal build system. For example, the Midori software release includes both a configured Linux 2.4 kernel and an XFree86 4.x distribution. From the perspective of the Midori build system, these are just two more MLZ packages. But both of these packages have very different internal build systems. The MLZ package management system allows the Midori build system to manage these package's internal build systems and generate a single Flash ROM image.

Creating Packages

Creating an MLZ package is a matter of integrating the internal package's build system with the Midori build system.

MLZ packages are stored in the apps directory and follow these conventions:

format
MLZ files are stored in .tar.gz format.

unpacking
MLZ package files must unpack into their own directory.

file name
Each MLZ package must have a file name with the form name-n.mlz, with n being an MLZ-based version number to distinguish different package files. So for vim-3.0, the first MLZ package file name would be vim-3.0-1.mlz.

build file (required)
Each package must contain an executable script named build.

Note: We strongly recommend that each build script uses the standard build functions described in build.txt.

CONFIG file (required)
Each MLZ package must contain a CONFIG file which sets build variables. These build variables can be overwritten by the top-level config file.

source files
An MLZ file can contain a collection of source files or a single .tar.gz archive file containing source files.

Modifying Packages

After an MLZ package is created, it can be subsequently modified with software patches. Midori uses the now common strategy of keeping the original package sources together with the patches and the scripts necessary to automatically apply those patches during the build process.

For example, suppose we have a package called foo-6.18 and we get a source patch from its original author. Rather than apply the source patch to the original sources we put the patch file in a special directory with a script to run it. The sections below elaborate on how this is done.

Start from a working build.

Before setting off to customize packages, it's best to start from a working build. Create a ".precious" file in the cache/build directory of the package you want to change ("cache/build/foo-6.18/" in our example) to protect your changes from being erased by the build scripts and experiment until you have your changes the way you want them.

Keeping a copy of what the directory originally contained (before customizing) would make it easy to "diff", of course.

Make a place for customized package sources.

After the first time Midori is installed and compiled, you will find a directory called "cache/build/mlbuild-0.2/buildscripts/" (or perhaps a later version). "cd" to this directory and run the "setup" script, passing the full path of the directory where you will keep your customized package sources:
	cd  cache/build/mlbuild-0.2/buildscripts/
	./setup  /usr/local/ml_custom

Note: Be sure to edit the MIDORI variable in the new "Makefile.vars" file to point to the top of your Midori tree.

Unpack the package where you can modify it.

We'll begin with the package foo-6.18_ML2.4.mlz in our Midori "apps" directory, as it would be if we had been building Midori with this package included.

Go to your custom directory and from there untar the package you wish to customize:

	cd  /usr/local/ml_custom
	tar  -xzvf  /usr/local/midori/apps/foo-6.18_ML2.4.mlz
Then add the package name and version to the "PACKAGES" variable in the main Makefile ("/usr/local/ml_custom/foo-6.18/Makefile" in our example) to read:
	PACKAGES=foo-6.18

This is where the changes which you decide to keep will be stored, under this custom directory.

Create the package-compatible patch.

Typically, packages invoke default procedures for unpacking the tar-ball and applying any patches. The default is to untar while in the "cache/build/$PACKAGE" directory ("cache/build/foo-6.18/" in this example). Patches are also run from that same current working directory by default. Read through the "build" script first to see if the package you want to modify is doing anything different. Look for functions named "ml_unpack" and "ml_patchit". If either is not present, its default will be used. If they do exist, look for the default function embedded in their code ("ml_unpack_default" and "ml_patchit_default"). As long as the default behavior is being used, you will be able to create a patch in the following way. Otherwise, things would be more complicated. "cd" to the package directory and untar the tar-ball. Then move it to a different name (possibly with a ".orig" extension). Then untar it again. Now, manually apply your patches or changes to the recently untar'd sources. From the package directory then, "diff" between the .orig sources and the ones you've modified to produce the patch:
	cd  /usr/local/ml_custom/foo-6.18
	tar  -xzvf  foo-6.18.tar.gz
	mv  -f  foo-6.18  foo-6.18.orig
	tar  -xzvf  foo-6.18.tar.gz

	(Here, apply your changes or patches.)

	cd  /usr/local/ml_custom/foo-6.18
	diff -urN  foo-6.18.orig  foo-6.18  >  my_change.patch

Be sure to name the file with the ".patch" ending. If it's very large and you want to save space, you can gzip it (leaving the name with a ".patch.gz" ending). Those names are automatically applied with "patch" by the default build function "ml_patchit_default".

One step more: In order for your patch file to be included in the package you must add it to the "SOURCE" list in the package's Makefile:

	SOURCE=CONFIG VERSION foo-6.18.tar.gz my_change.patch
After that, you can clean up by removing the directories which were untarred to make the patch ("foo-6.18.orig/" and "foo-6.18/"). Leaving them there won't hurt anything though. Since they're not listed in the SOURCE variable, they won't be included in the .mlz file.

Change the build script, if necessary.

If the package is not using the default functions for unpacking and patching the sources, then the build script may need changes for applying your patch.

Another reason for changing the build script would be if you wanted to make some sort of change dynamic, something which could only be determined at build-time (like a timestamp, for example).

Rebuild the package.

While in the top directory of your custom tree ("/usr/local/ml_custom"), do a "make". This should overwrite the corresponding .mlz file under the Midori "apps/" directory with your modified one.

If you put a ".precious" file in the package directory in "cache/build/", now is the time to remove it.

The next "make" done in the top of the Midori tree should then unpack your modified package into "cache/build" and build it with your changes included.

Adding Packages

autoloaded by default

Removing Packages