xref: /haiku/docs/develop/packages/BuildingPackages.rst (revision 3376ed1a72dc862faea22f98e4610bcf83760749)
103d384bbSLeorize=================
203d384bbSLeorizeBuilding Packages
303d384bbSLeorize=================
403d384bbSLeorize
503d384bbSLeorizeThis page provides information regarding the package building process. The first
603d384bbSLeorizesection documents building a package with the low level command ``package``. The
703d384bbSLeorizesecond section refers to building packages with the ``haikuporter`` tool.
803d384bbSLeorize
903d384bbSLeorizeBuilding a Package with the "package" Command
1003d384bbSLeorize=============================================
1103d384bbSLeorizeThe package file format is specified in detail in a `separate document`_. This
1203d384bbSLeorizesection presents information from the perspective of how to build a package file
1303d384bbSLeorizewith the ``package`` command.
1403d384bbSLeorize
1503d384bbSLeorize.. _separate document: FileFormat.rst
1603d384bbSLeorize
1703d384bbSLeorizeAn hpkg file is an archive file (just like tar or zip files) that additionally
1803d384bbSLeorizecontains package meta information in a separate section of the file. When
1903d384bbSLeorizebuilding an hpkg file via the ``package`` command the meta information must be
2003d384bbSLeorizeprovided via a ``.PackageInfo`` file. For convenience, the file itself is added
2103d384bbSLeorizeto the archive as well and can be extracted later, but it will be ignored by
2203d384bbSLeorizepackagefs.
2303d384bbSLeorize
2403d384bbSLeorizeThe ``.PackageInfo`` file must be located in the top directory that is archived.
2503d384bbSLeorizeA ``package`` invocation usually looks like that::
2603d384bbSLeorize
2703d384bbSLeorize  package create -C foo-4.5.26-1 foo-4.5.26-1-x86.hpkg
2803d384bbSLeorize
2903d384bbSLeorizeor (packaging a gcc2 build from within the folder)::
3003d384bbSLeorize
3103d384bbSLeorize  cd foo-4.5.26-1
3203d384bbSLeorize  package create ../foo-4.5.26-1-x86_gcc2.hpkg
3303d384bbSLeorize
3403d384bbSLeorizeThe argument of the ``-C`` option specifies the directory whose contents to
3503d384bbSLeorizearchive (by default the current directory), the remaining argument is the path
3603d384bbSLeorizeof the package file to be built.
3703d384bbSLeorize
3803d384bbSLeorizeThe .PackageInfo
3903d384bbSLeorize----------------
4003d384bbSLeorizeThe contents of the ``.PackageInfo`` adheres to a restricted driver settings
4103d384bbSLeorizesyntax. It consists of name-value pairs, following this simple grammar::
4203d384bbSLeorize
4303d384bbSLeorize  package_info	::= attribute*
4403d384bbSLeorize  attribute	::= name value_list
4503d384bbSLeorize  value_list	::= value | ( "{" value* "}" )
4603d384bbSLeorize  value		::= value_item+ ( '\n' | ';' )
4703d384bbSLeorize
4803d384bbSLeorize``name`` can be one of the attribute names defined below. ``value_item`` is
4903d384bbSLeorizeeither an unquoted string not containing any whitespace characters or a string
5003d384bbSLeorizeenclosed in quotation marks (``"`` or ``'``) which can contain whitespace and
5103d384bbSLeorizealso escaped characters (using ``\``).
5203d384bbSLeorize
5303d384bbSLeorizeThe supported attributes are:
5403d384bbSLeorize
5503d384bbSLeorize- ``name``: The name of the package, not including the package version. Must
5603d384bbSLeorize  only contain ``entity_name_char`` characters.
5703d384bbSLeorize
5803d384bbSLeorize  ::
5903d384bbSLeorize
6003d384bbSLeorize    entity_name_char	::= any character but '-', '/', '=', '!', '<', '>', or whitespace
6103d384bbSLeorize
6203d384bbSLeorize- ``version``: The version of the package. The string must have the ``version``
6303d384bbSLeorize  format (see the `Version Strings`_ section).
6403d384bbSLeorize- ``architecture``: The system architecture the package has been built for. Can
6503d384bbSLeorize  be either of:
6603d384bbSLeorize
6703d384bbSLeorize  - ``any``: Any architecture (e.g. a documentation package).
6803d384bbSLeorize  - ``x86``: Haiku x86, built with gcc 4.
6903d384bbSLeorize  - ``x86_gcc2``: Haiku x86, built with gcc 2.
7003d384bbSLeorize
7103d384bbSLeorize- ``summary``: A short (one-line) description of the package.
7203d384bbSLeorize- ``description``: A longer description of the package.
7303d384bbSLeorize- ``vendor``: The name of the person/organization publishing this package.
7403d384bbSLeorize- ``packager``: The name and e-mail address of person that created this package
7503d384bbSLeorize  (e.g. "Peter Packman <peter.packman@example.com>").
7603d384bbSLeorize- ``copyrights``: A list of copyrights applying to the software contained in
7703d384bbSLeorize  this package.
7803d384bbSLeorize- ``licenses``: A list of names of the licenses applying to the software
7903d384bbSLeorize  contained in this package.
8003d384bbSLeorize- ``urls``: A list of URLs referring to the packaged software's project home
8103d384bbSLeorize  page. The list elements can be regular URLs or email-like named URLs (e.g.
8203d384bbSLeorize  "Project Foo <http://foo.example.com>").
8303d384bbSLeorize- ``source-urls``: A list of URLs referring to the packaged software's source
8403d384bbSLeorize  code or build instructions. Elements have the same format as those of
8503d384bbSLeorize  ``urls``.
8603d384bbSLeorize- ``flags``: A list of boolean flags applying to the package. Can contain any
8703d384bbSLeorize  of the following:
8803d384bbSLeorize
8903d384bbSLeorize  - ``approve_license``: This package's license requires approval (i.e. must be
9003d384bbSLeorize    shown to and acknowledged by user before installation).
9103d384bbSLeorize  - ``system_package``: This is a system package (i.e. lives under
9203d384bbSLeorize    "/boot/system").
9303d384bbSLeorize
9403d384bbSLeorize- ``provides``: A list of entities provided by this package. The list elements
9503d384bbSLeorize  must have the following format::
9603d384bbSLeorize
9703d384bbSLeorize    entity	::= entity_name [ "=" version_ref ] [ ( "compat" | "compatible" ) ">=" version_ref ]
9803d384bbSLeorize    entity_name	::= [ entity_type ":" ] entity_name_char+
9903d384bbSLeorize    entity_type	::= "lib" | "cmd" | "app" | "add_on"
10003d384bbSLeorize
10103d384bbSLeorize  See the `Version Strings`_ section for the ``version_ref`` definition.
10203d384bbSLeorize  The first ``version_ref`` specifies the version of the provided entity. It
10303d384bbSLeorize  can be omitted e.g. for abstract resolvables like "web_browser". The
10403d384bbSLeorize  ``version_ref`` after the "compat"/"compatible" string specifies the oldest
10503d384bbSLeorize  version the resolvable is backwards compatible with.
10603d384bbSLeorize  The ``entity_type`` specifies the type of entity provided: a library ("lib"),
10703d384bbSLeorize  a command line program ("cmd"), an application ("app"), or an add-on
10803d384bbSLeorize  ("add-on").
10903d384bbSLeorize- ``requires``: A list of entities required by this package. The list elements
11003d384bbSLeorize  must have the following format::
11103d384bbSLeorize
11203d384bbSLeorize    required_entity	::= entity_name [ version_operator version_ref [ "base" ] ]
11303d384bbSLeorize    version_operator	::= "<" | "<=" | "==" | "!=" | ">=" | ">"
11403d384bbSLeorize
11503d384bbSLeorize  See the `Version Strings`_ section for the ``version_ref`` definition. If
11603d384bbSLeorize  "base" is specified, the specified entity is the base package for this
11703d384bbSLeorize  package. The package manager shall ensure that this package is installed in
11803d384bbSLeorize  the same installation location as its base package.
11903d384bbSLeorize- ``supplements``: A list of entities that are supplemented by this package
12003d384bbSLeorize  (i.e. this package will automatically be selected for installation if the
12103d384bbSLeorize  supplemented entities are already installed). The list elements must have the
12203d384bbSLeorize  ``required_entity`` format.
12303d384bbSLeorize- ``conflicts``: A list of entities that this package conflicts with (i.e. only
12403d384bbSLeorize  one of both can be installed at any time). The list elements must have the
12503d384bbSLeorize  ``required_entity`` format.
12603d384bbSLeorize- ``freshens``: A list of entities that are being freshened by this package
12703d384bbSLeorize  (i.e. this package will patch one or more files of the package(s) that provide
12803d384bbSLeorize  this entity). The list elements must have the ``required_entity`` format.
12903d384bbSLeorize- ``replaces``: A list of entities that are being replaced by this package (used
13003d384bbSLeorize  if the name of a package changes, or if a package has been split). The list
13103d384bbSLeorize  elements must have the ``entity_name`` format.
13203d384bbSLeorize- ``global-writable-files``: A list of global writable file infos. The list
13303d384bbSLeorize  elements must have the following format::
13403d384bbSLeorize
13503d384bbSLeorize    global_writable_file_info	::= path [ "directory" ] [ "keep-old" | "manual" | "auto-merge" ]
13603d384bbSLeorize
13703d384bbSLeorize  ``path`` is the relative path of the writable file or directory, starting with
13803d384bbSLeorize  "settings/" or any other writable directory. If the "directory" keyword is
13903d384bbSLeorize  given, the path refers to a directory. If no other keyword is given after the
14003d384bbSLeorize  path respectively after the "directory" keyword, the file or directory is not
14103d384bbSLeorize  included in the package. It will be created by the software or by the user.
14203d384bbSLeorize  If a keyword is given, the file or directory (a default version) is included
14303d384bbSLeorize  in the package and it will be extracted on package activation. The keyword
14403d384bbSLeorize  specifies what shall happen when the package is updated and a previous default
14503d384bbSLeorize  version of the file or directory has been modified by the user:
14603d384bbSLeorize
14703d384bbSLeorize  - "keep-old": Indicates that the software can read old files and the
14803d384bbSLeorize    user-modified file or directory should be kept.
14903d384bbSLeorize  - "manual": Indicates that the software may not be able to read an older file
15003d384bbSLeorize    and the user may have to manually adjust it.
15103d384bbSLeorize  - "auto-merge": Indicates that the file format is simple text and a three-way
15203d384bbSLeorize    merge shall be attempted (not applicable for directories).
15303d384bbSLeorize
15403d384bbSLeorize- ``user-settings-files``: A list of user settings file infos. The list elements
15503d384bbSLeorize  must have the following format::
15603d384bbSLeorize
15703d384bbSLeorize    user_settings_file_info	::= path [ "directory" | "template" template_path ]
15803d384bbSLeorize
15903d384bbSLeorize  ``path`` is the relative path of the settings file or directory, starting with
16003d384bbSLeorize  "settings/". It is not included in the package. However, if ``template_path``
16103d384bbSLeorize  is specified, it is a path to a file included in the package that can serve as
16203d384bbSLeorize  a template for the settings file. It doesn't imply any automatic action on
16303d384bbSLeorize  package activation, though. If the "directory" keyword is given, the path
16403d384bbSLeorize  refers to a settings directory (typical when a program creates multiple
16503d384bbSLeorize  settings files).
16603d384bbSLeorize- ``users``: A list of specifications for Unix users the packaged software
16703d384bbSLeorize  requires. The list elements must have the following format::
16803d384bbSLeorize
16903d384bbSLeorize    user:	::= name [ "real-name" real_name ] "home" home_path [ "shell" shell_path ] [ "groups" group+ ]
17003d384bbSLeorize
17103d384bbSLeorize  ``name`` is the name of the Unix user, ``real_name``, if specified, the real
17203d384bbSLeorize  name of the user, ``home_path`` the path to the user's home directory,
173e9c3e80cSAlexander G. M. Smith  ``shell_path`` the path to the user's shell, and ``group+`` is a list of the
174e9c3e80cSAlexander G. M. Smith  names of Unix groups the user is a member of (first one is their primary
175e9c3e80cSAlexander G. M. Smith  group). If the respective components are not specified, ``name`` is also
176e9c3e80cSAlexander G. M. Smith  used as the user's real name, "/bin/bash" is the path of the user's shell,
177e9c3e80cSAlexander G. M. Smith  and the user will belong to the default user group.
17803d384bbSLeorize- ``groups``: A list of names of Unix groups the packaged software requires.
17903d384bbSLeorize- ``post-install-scripts``: A list of paths of files included in the package,
18003d384bbSLeorize  which shall be executed on package activation. Each path must start with
181a22fa0c9SAlexander G. M. Smith  "boot/post-install/". All the files in that directory are also run on first
182*3376ed1aSAlexander G. M. Smith  boot after installing or copying the OS to a new disk.  As an odd bonus,
183*3376ed1aSAlexander G. M. Smith  they're also run when you boot the installer disc, and the installer copies
184*3376ed1aSAlexander G. M. Smith  some of the resulting settings data to the new install too.  So try to
185*3376ed1aSAlexander G. M. Smith  handle being run twice.
186a22fa0c9SAlexander G. M. Smith- ``pre-uninstall-scripts``: A list of paths of files included in the package,
187a22fa0c9SAlexander G. M. Smith  which shall be executed on package deactivation. For consistency, each path
188a22fa0c9SAlexander G. M. Smith  should start with "boot/pre-uninstall/".
18903d384bbSLeorize
19003d384bbSLeorizeVersion Strings
19103d384bbSLeorize---------------
19203d384bbSLeorizeVersions strings are used in three contexts: For the package version, for
19303d384bbSLeorizeresolvable versions (``provides``), and in dependency version expressions
19403d384bbSLeorize(``requires``, ``supplements``, ``conflicts``, ``freshens``). They are
19503d384bbSLeorizestructurally identical, with the exception that the former requires a revision
19603d384bbSLeorizecomponent (``version``), while the latter two don't (``version_ref``)::
19703d384bbSLeorize
19803d384bbSLeorize  version	::= major [ "." minor [ "." micro ] ] [ "~" pre_release ] "-" revision
19903d384bbSLeorize  version_ref	::= major [ "." minor [ "." micro ] ] [ "~" pre_release ] [ "-" revision ]
20003d384bbSLeorize  major		::= alphanum_underline+
20103d384bbSLeorize  minor		::= alphanum_underline+
20203d384bbSLeorize  micro		::= alphanum_underline_dot+
20303d384bbSLeorize  pre_release	::= alphanum_underline_dot+
20403d384bbSLeorize  revision	::= positive_non_zero_integer
20503d384bbSLeorize
20603d384bbSLeorizeThe meaning of the major, minor, and micro version parts is vendor specific. A
20703d384bbSLeorizetypical, but not universal (!), convention is to increment the major version
20803d384bbSLeorizewhen breaking binary compatibility (i.e. version a.d.e is backwards compatible
20903d384bbSLeorizeto version a.b.c for all b.c <= d.e), to increment the minor version when adding
21003d384bbSLeorizenew features (in a binary compatible way), and to increment the micro version
21103d384bbSLeorizefor bug fix releases. There are, however, projects that use different
21203d384bbSLeorizeconventions which don't imply that e.g. version 1.4 is backwards compatible with
21303d384bbSLeorizeversion 1.2. Which convention is used is important for the packager to know, as
21403d384bbSLeorizeit is required for a correct declaration of the compatibility versions for the
21503d384bbSLeorizeprovided resolvables. The compatibility version specifies the oldest version the
21603d384bbSLeorizeprovided resolvable is backwards compatible with, thus implying the version
21703d384bbSLeorizerange requested by a dependent package the resolvable can satisfy. When
21803d384bbSLeorizefollowing the aforementioned convention a resolvable of version 2.4.3 should
21903d384bbSLeorizehave compatibility version 2 (or, semantically virtually identical, 2.0.0).
22003d384bbSLeorizeNot following the convention 2.4 may be correct instead. If no compatibility
22103d384bbSLeorizeversion is specified, the resolvable can only satisfy dependency constraints
22203d384bbSLeorizewith an exactly matching version.
22303d384bbSLeorize
22403d384bbSLeorizeThe pre-release part of the version string has special semantics for comparison.
22503d384bbSLeorizeUnlike minor and micro its presence makes the version older. E.g. version
22603d384bbSLeorizeR1.0~alpha1 is considered to be older than version R1.0. When both version
22703d384bbSLeorizestrings have a pre-release part, that part is compared naturally after the micro
22803d384bbSLeorizepart (R1.0.1~alpha1 > R1.0 > R1.0~beta1 > R1.0~alpha2).
22903d384bbSLeorize
23003d384bbSLeorizeThe revision part of the version string is assigned by the packager (not by the
23103d384bbSLeorizevendor). It allows to uniquely identify updated packages of the same vendor
23203d384bbSLeorizeversion of a software.
23303d384bbSLeorize
23403d384bbSLeorizePackage File Names
23503d384bbSLeorize------------------
23603d384bbSLeorizeA package file name should have the following form::
23703d384bbSLeorize
23803d384bbSLeorize  file_name	::= name "-" version "-" architecture ".hpkg"
23903d384bbSLeorize
24003d384bbSLeorizeExample package file
24103d384bbSLeorize--------------------
24203d384bbSLeorize::
24303d384bbSLeorize
24403d384bbSLeorize  name			example
24503d384bbSLeorize  version		42.17-12
24603d384bbSLeorize  architecture		x86_gcc2
24703d384bbSLeorize  summary		"This is an example package file"
24803d384bbSLeorize  description		"Haiku has a very powerful package management system. Really, you should try it!
24903d384bbSLeorize  it even supports muliline strings in package descriptions"
25003d384bbSLeorize  packager		"John Doe <test@example.com>"
25103d384bbSLeorize  vendor		"Haiku Project"
25203d384bbSLeorize  licenses {
25303d384bbSLeorize  	"MIT"
25403d384bbSLeorize  }
25503d384bbSLeorize  copyrights {
25603d384bbSLeorize  	"Copyright (C) 1812-2013 by John Doe <test@example.com>"
25703d384bbSLeorize  }
25803d384bbSLeorize  provides {
25903d384bbSLeorize  	example = 42.17-12
26003d384bbSLeorize  	cmd:example = 3.1
26103d384bbSLeorize  }
26203d384bbSLeorize  requires {
26303d384bbSLeorize  	haiku >= r1~alpha4_pm_hrev46213-1
26403d384bbSLeorize  	lib:libpython2.6 >= 1.0
26503d384bbSLeorize  }
26603d384bbSLeorize  urls {
26703d384bbSLeorize  	"http://example.com/"
26803d384bbSLeorize  }
26903d384bbSLeorize  global-writable-files {
27003d384bbSLeorize  	"settings/example/configurationFile" keep-old
27103d384bbSLeorize  	"settings/example/servers" directory keep-old
27203d384bbSLeorize  }
27303d384bbSLeorize  source-urls {
27403d384bbSLeorize  	"Download <http://example.com/source.zip>"
27503d384bbSLeorize  }
27603d384bbSLeorize
27703d384bbSLeorizeBuilding a Package with "haikuporter"
27803d384bbSLeorize=====================================
27903d384bbSLeorize``haikuporter`` is a high level tool for building packages. As input it reads a
28003d384bbSLeorizebuild recipe file for a certain version of a software (aka port) and produces
28103d384bbSLeorizeone or more packages, as declared in the recipe. A recipe specifies package
28203d384bbSLeorizerequirements similar to how it is done in a ``.PackageInfo`` file. When asked to
28303d384bbSLeorizebuild a port, ``haikuporter`` resolves the respective dependencies and
28403d384bbSLeorizerecursively builds all not-yet-built ports required for the requested port.
28503d384bbSLeorize``haikuporter`` itself and a large library of recipe files are hosted at
28603d384bbSLeorizeHaikuPorts_. A detailed `documentation for haikuporter`_ and the
28703d384bbSLeorize`recipe format`_ can also be found there.
28803d384bbSLeorize
28903d384bbSLeorize.. _HaikuPorts: https://github.com/haikuports/
29003d384bbSLeorize
29103d384bbSLeorize.. _documentation for haikuporter:
29203d384bbSLeorize   https://github.com/haikuports/haikuports/wiki/HaikuPorterForPM
29303d384bbSLeorize
29403d384bbSLeorize.. _recipe format:
29503d384bbSLeorize   https://github.com/haikuports/haikuports/wiki/HaikuPorter-BuildRecipes
296