Receipt
5.1
A SliTaz package is built by cook from a receipt: a small shell
file that says where the source is, how to compile it and which files
go into the package. This page takes a first receipt from the empty
template to an installed package, with the habits of the wok. The
reference is the
Cookutils manual
and its page on receipts v2;
the Handbook shows the first commands in
Build your own.
Before you start
As root, install cookutils and prepare /home/slitaz:
# spk-add cookutils
# cook setup
On x86_64, check that /etc/slitaz/cook.conf says ARCH="x86_64"
(see the Handbook). cook setup makes an empty wok, enough for your
own packages. To work on official packages, or to read hundreds of
real receipts, clone the cooking wok instead (needs mercurial):
# cook setup --wok
A package in the wok
Each package is a directory of /home/slitaz/wok:
receipt: the receipt, the only file you must write;stuff/: patches and extra files, seen as$stuffin the receipt. Patches listed instuff/patches/series, one per line, are applied before the build;description.txt: an optional long description, shipped in the package.
cook adds, while it works:
source/: the unpacked source,$srcin the receipt;install/: whatmake installwrote,$install(or$DESTDIR);taz/: the package tree.
After a good cook only taz/ stays (KEEP_BUILD_TREE="yes" in
cook.conf keeps the others). The source tarball goes to
/home/slitaz/src, the package to /home/slitaz/packages, the log to
/home/slitaz/log/<package>.log.
A first receipt
cook new makes the directory and an empty receipt:
# cook new hello
/home/slitaz/wok/hello/receipt is a v2 receipt:
# SliTaz package receipt v2.
PACKAGE="hello"
VERSION=""
CATEGORY=""
SHORT_DESC=""
MAINTAINER=""
LICENSE=""
WEB_SITE=""
TARBALL="$PACKAGE-$VERSION.tar.gz"
WGET_URL="$TARBALL"
BUILD_DEPENDS=""
# Rules to configure and make the package.
compile_rules()
{
./configure $CONFIGURE_ARGS && make && make install
}
# Rules to gen a SliTaz package suitable for Tazpkg.
genpkg_rules()
{
copy @std @dev
DEPENDS=""
}
cook new hello --interactive asks for the fields one by one. Filled
in for GNU Hello:
# SliTaz package receipt v2.
PACKAGE="hello"
VERSION="2.12"
CATEGORY="misc"
SHORT_DESC="The GNU Hello program."
MAINTAINER="you@example.org"
LICENSE="GPL3"
WEB_SITE="https://www.gnu.org/software/hello/"
TARBALL="$PACKAGE-$VERSION.tar.gz"
WGET_URL="https://ftp.gnu.org/gnu/$PACKAGE/$TARBALL"
BUILD_DEPENDS=""
# Rules to configure and make the package.
compile_rules()
{
./configure --prefix=/usr $CONFIGURE_ARGS &&
make &&
make DESTDIR=$DESTDIR install
}
# Rules to gen a SliTaz package suitable for Tazpkg.
genpkg_rules()
{
copy @std
DEPENDS=""
}
What to know about it:
- The header. "receipt v2" on the first line: one receipt can make
several packages (
SPLIT=, see the receipts v2 page). Without "v2", cook reads it the old way. - The fields.
PACKAGE,VERSION,CATEGORY,SHORT_DESC,MAINTAINERandWEB_SITEmust be set.CATEGORYis one of the listPKGS_CATEGORIESin/etc/slitaz/slitaz.conf. BuildTARBALLandWGET_URLfrom$PACKAGEand$VERSION: a new release is then a one-line change. - compile_rules runs inside the source directory.
$CONFIGURE_ARGSand the compiler flags come fromcook.conf. Install into$DESTDIR, never into the system, and chain the commands with&&: a failedmakemust stop the cook. - genpkg_rules copies from
$installinto$fs, the root of the package.copy @stdtakes the programs, libraries and data, and leaves out the developer files, man pages, documentation and translations;copy @devtakes the headers, static libraries and.pcfiles.copyalso takes file names and directories (copy bin/ hello.conf). - DEPENDS lists the packages needed to run it, BUILD_DEPENDS
those needed to build it (the
-devpackages). In a v2 receipt, setDEPENDSingenpkg_rulesfor each package, as the template does: split packages do not inherit aDEPENDSset at the top.
Every other variable (PROVIDE, CONFIG_FILES, SUGGESTED,
TAGS, COOKOPTS...) and every helper function is in the
Cookutils manual.
For a package built on i486 and x86_64, or only one of them, see
Multi-arch.
Cook it
Check the syntax first: a receipt is a shell script.
# sh -n /home/slitaz/wok/hello/receipt
# cook hello --getsrc
# cook hello
--getsrc only downloads the source: a quick check of WGET_URL. The
cook itself downloads the source if needed, installs the build
dependencies in a throw-away layer, compiles, strips the binaries and
packs. When the receipt has no checksum, the cook prints a
TARBALL_SHA256="..." line: paste it into the receipt, and the next
cooks check the tarball. Then, as root:
# spk-add /home/slitaz/packages/hello-2.12-x86_64.tazpkg
$ hello
Hello, world!
On i486 the file is hello-2.12.tazpkg. cook never installs what it
builds: that is your call, and your test.
When it fails
Read the end of the log, not the first error you see:
# tail -40 /home/slitaz/log/hello.log
The "Debug information" block at the end tells the step that broke:
compile_rules, or genpkg_rules when the files were not where the
receipt looked for them. Then:
cook hello --continuerunscompile_rulesagain on the source already unpacked, after you changed the receipt;cook hello --packrunsgenpkg_rulesagain without compiling;cook doctor hellochecks the receipt, the build dependencies and the last log;cook hello --cleanremovessource/,install/andtaz/.
The usual causes:
- "foo.h: No such file or directory": add
foo-devtoBUILD_DEPENDS. - "ERROR: copy from the empty $install" or "ERROR: empty
package": the install step did not write into
$DESTDIR, a command failed without&&to stop it, orgenpkg_ruleslooked for files in the wrong place. Look intoinstall/to see what is there. - It cooks on your machine, but not on the build host: your system
has a
-devpackage that the receipt does not list. The build host only installs whatBUILD_DEPENDSasks for. Cook it once in a clean chroot, see Building in a chroot.
Habits of the wok
- One package per task, the lightest program that does the job,
and the name of its source in lowercase. Modules take the name of
their language:
python-,perl-... See Forge on the site. - The main package stays small. Headers and static libraries go
into a
-devpackage (copy @devin a split), man pages and documentation are left out or go into a-docsplit, translations into-lang. - A working default setup. Ship a configuration that runs as it
is, list it in
CONFIG_FILESso an upgrade keeps the user's changes, and put examples in/usr/share/examples. - Plain shell. No macros, no clever tricks: anyone who opens the receipt must see what it does. Comment what is not obvious, such as why a patch exists.
- Copy from
$install, not from$src. Fill$installincompile_rulesand pack from there: the build host does not always keepsource/when it packs.
Share it
When the package builds and works, post the receipt on the forum for review. A developer pushes it to the wok; the build host then cooks it on both architectures and publishes it on the mirror. See Contribute to SliTaz.
Links
- Cookutils manual and receipts v2.
- Handbook: Build your own.
- The cooking wok: thousands of receipts to learn from.
- cook.slitaz.org: the build host, its logs and its broken packages.
- Repology: the versions packaged by other distributions.