Skip to content

Instantly share code, notes, and snippets.

@Earnestly
Last active May 18, 2025 05:43

Revisions

  1. Earnestly revised this gist Nov 9, 2018. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions makepkg_overview.rst
    Original file line number Diff line number Diff line change
    @@ -118,7 +118,7 @@ Example
    # Because I don't do any error handling, just bail if any command fails for
    # any reason.
    set +o errexit
    set -o errexit
    startdir=$PWD
    srcdir=$startdir/src
    @@ -154,8 +154,8 @@ Example
    cat <<! > .PKGINFO
    pkgname = antimicro-git
    pkgver = $pkgver-$pkgrel
    pkgdesc = Map keyboard and mouse actions to gamepad buttons, inspired by qjoypad.
    url = https://github.com/Ryochan7/antimicro
    pkgdesc = map keyboard and mouse actions to gamepad buttons, inspired by qjoypad
    url = https://github.com/AntiMicro/antimicro
    builddate = $(date -u +%s)
    packager = Unknown Packager
    size = $(du -sb --apparent-size "$pkgdir" | awk '{print $1}')
    @@ -176,4 +176,4 @@ Example
    # Test.
    cd "$startdir"
    namcap antimicro-git-"$pkgver"-"$pkgrel"-"$arch".pkg.tar.xz
    namcap -m antimicro-git-"$pkgver"-"$pkgrel"-"$arch".pkg.tar.xz
  2. Earnestly revised this gist Dec 21, 2017. 1 changed file with 18 additions and 16 deletions.
    34 changes: 18 additions & 16 deletions makepkg_overview.rst
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,7 @@ Introduction
    ------------

    This is a terse document covering the anatomy of a package built for the pacman
    package manager.
    package manager.

    The following example commands can mostly run verbatim to manually create a
    package without makepkg.
    @@ -38,7 +38,7 @@ package()
    maintain appropriate permissions while not actually running as root. That
    is, the facade of root permission is maintained so long real root privilege
    is not needed.

    .. code-block:: sh
    mkdir pkg
    @@ -88,7 +88,7 @@ cross-checked when using the ``-Qk`` option.
    Bsdtar is then used to generate the ``.MTREE`` file. This disables !all of the
    attributes and then enables a selected few.
    When creating the mtree, the ``.PKGINFO`` file needs to be first in the
    When creating the mtree, the ``.PKGINFO`` file needs to be first in the
    archive.
    .. code-block:: sh
    @@ -113,16 +113,16 @@ Example
    .. code-block:: sh
    #!/usr/bin/env bash
    #!/bin/sh --
    # Basic makepkg which just creates a package for antimicro, built from git.
    # Because I don't do any error handling, just bail if any command fails for
    # any reason.
    set +e
    set +o errexit
    startdir="$PWD"
    srcdir="$startdir"/src
    pkgdir="$startdir"/pkg
    startdir=$PWD
    srcdir=$startdir/src
    pkgdir=$startdir/pkg
    # The pkgrel just indicates the version of the build itself, independent of
    # the pkgver, although a pkgver bump resets the pkgrel to 1.
    @@ -136,10 +136,12 @@ Example
    # Build.
    mkdir -p "$srcdir"
    cd "$srcdir"
    git clone git://github.com/Ryochan7/antimicro --depth 1
    git clone https://github.com/AntiMicro/antimicro
    cd antimicro
    pkgver="$(git describe | sed 's/-/.r/; s/-/./')" # No hyphens allowed in the version.
    # No hyphens allowed in the version.
    pkgver=$(git describe --long --tags | sed 's/^v//; s/\([^-]*-g\)/r\1/; s/-/./g')
    cmake -DMAKE_INSTALL_PREFIX=/usr -DUSE_SDL2=ON
    make
    @@ -149,16 +151,16 @@ Example
    # Package.
    cd "$pkgdir"
    cat <<EOF > .PKGINFO
    cat <<! > .PKGINFO
    pkgname = antimicro-git
    pkgver = $pkgver-$pkgrel
    pkgdesc = Map keyboard and mouse actions to gamepad buttons, inspired by qjoypad.
    url = https://github.com/Ryochan7/antimicro
    builddate = $(date -u '+%s')
    builddate = $(date -u +%s)
    packager = Unknown Packager
    size = $(du -sb --apparent-size "$pkgdir" | awk '{print $1}')
    arch = $arch
    license = GPL3
    license = GPL
    conflict = antimicro
    provides = antimicro
    depend = libxtst
    @@ -167,11 +169,11 @@ Example
    depend = libxkbcommon-x11
    makedepend = cmake
    makedepend = qt5-tools
    EOF
    !
    fakeroot -- env LANG=C bsdtar -czf .MTREE --format=mtree --options='!all,use-set,type,uid,gid,mode,time,size,md5,sha256,link' .PKGINFO *
    fakeroot -- env LANG=C bsdtar -cf - .MTREE .PKGINFO * | xz -c -z - > "$startdir"/antimicro-git-"$pkgver-$pkgrel-$arch".pkg.tar.xz
    fakeroot -- env LANG=C bsdtar -cf - .MTREE .PKGINFO * | xz -c -z - > "$startdir"/antimicro-git-"$pkgver"-"$pkgrel"-"$arch".pkg.tar.xz
    # Test.
    cd "$startdir"
    namcap antimicro-git-"$pkgver-$pkgrel-$arch".pkg.tar.xz
    namcap antimicro-git-"$pkgver"-"$pkgrel"-"$arch".pkg.tar.xz
  3. Earnestly revised this gist Sep 21, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion makepkg_overview.rst
    Original file line number Diff line number Diff line change
    @@ -81,7 +81,7 @@ PKGBUILD, almost exactly. Keys with multiple entries are simply repeated.
    EOF
    An mtree is essentially a way to generate a map of a directory structure with
    all kinds of attributes included, such as permissions, acls, etc. This allows
    all kinds of attributes included, such as permissions, uids, etc. This allows
    pacman to easily know what the attributes should be so that any issues can be
    cross-checked when using the ``-Qk`` option.
  4. Earnestly revised this gist Sep 9, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion makepkg_overview.rst
    Original file line number Diff line number Diff line change
    @@ -170,7 +170,7 @@ Example
    EOF
    fakeroot -- env LANG=C bsdtar -czf .MTREE --format=mtree --options='!all,use-set,type,uid,gid,mode,time,size,md5,sha256,link' .PKGINFO *
    fakeroot -- env LANG=C bsdtar -cf - .MTREE .PKGINFO * | xz -c -z - > ../antimicro-git-"$pkgver-$pkgrel-$arch".pkg.tar.xz
    fakeroot -- env LANG=C bsdtar -cf - .MTREE .PKGINFO * | xz -c -z - > "$startdir"/antimicro-git-"$pkgver-$pkgrel-$arch".pkg.tar.xz
    # Test.
    cd "$startdir"
  5. Earnestly revised this gist Aug 27, 2015. 1 changed file with 8 additions and 5 deletions.
    13 changes: 8 additions & 5 deletions makepkg_overview.rst
    Original file line number Diff line number Diff line change
    @@ -124,7 +124,10 @@ Example
    srcdir="$startdir"/src
    pkgdir="$startdir"/pkg
    # The pkgrel just indicates the version of the build itself, independent of
    # the pkgver, although a pkgver bump resets the pkgrel to 1.
    pkgrel=1
    arch=$(uname -m)
    # Check for all dependencies. This command will return any which are
    # missing, each one on a newline.
    @@ -136,7 +139,7 @@ Example
    git clone git://github.com/Ryochan7/antimicro --depth 1
    cd antimicro
    pkgver="$(git describe | sed 's/-/.r/; s/-/./')"
    pkgver="$(git describe | sed 's/-/.r/; s/-/./')" # No hyphens allowed in the version.
    cmake -DMAKE_INSTALL_PREFIX=/usr -DUSE_SDL2=ON
    make
    @@ -148,13 +151,13 @@ Example
    cd "$pkgdir"
    cat <<EOF > .PKGINFO
    pkgname = antimicro-git
    pkgver = "$pkgver"-"$pkgrel"
    pkgver = $pkgver-$pkgrel
    pkgdesc = Map keyboard and mouse actions to gamepad buttons, inspired by qjoypad.
    url = https://github.com/Ryochan7/antimicro
    builddate = $(date -u '+%s')
    packager = Unknown Packager
    size = $(du -sb --apparent-size "$pkgdir" | awk '{print $1}')
    arch = $(uname -m)
    arch = $arch
    license = GPL3
    conflict = antimicro
    provides = antimicro
    @@ -167,8 +170,8 @@ Example
    EOF
    fakeroot -- env LANG=C bsdtar -czf .MTREE --format=mtree --options='!all,use-set,type,uid,gid,mode,time,size,md5,sha256,link' .PKGINFO *
    fakeroot -- env LANG=C bsdtar -cf - .MTREE .PKGINFO * | xz -c -z - > ../antimicro-git-"$pkgver"-"$pkgrel"-x86_64.pkg.tar.xz
    fakeroot -- env LANG=C bsdtar -cf - .MTREE .PKGINFO * | xz -c -z - > ../antimicro-git-"$pkgver-$pkgrel-$arch".pkg.tar.xz
    # Test.
    cd "$startdir"
    namcap antimicro-git-"$pkgver"-"$pkgrel"-x86_64.pkg.tar.xz
    namcap antimicro-git-"$pkgver-$pkgrel-$arch".pkg.tar.xz
  6. Earnestly revised this gist Aug 27, 2015. 1 changed file with 6 additions and 3 deletions.
    9 changes: 6 additions & 3 deletions makepkg_overview.rst
    Original file line number Diff line number Diff line change
    @@ -124,6 +124,8 @@ Example
    srcdir="$startdir"/src
    pkgdir="$startdir"/pkg
    pkgrel=1
    # Check for all dependencies. This command will return any which are
    # missing, each one on a newline.
    pacman -T cmake qt5-tools libxtst qt5-base sdl2 libxkbcommon-x11
    @@ -134,6 +136,7 @@ Example
    git clone git://github.com/Ryochan7/antimicro --depth 1
    cd antimicro
    pkgver="$(git describe | sed 's/-/.r/; s/-/./')"
    cmake -DMAKE_INSTALL_PREFIX=/usr -DUSE_SDL2=ON
    make
    @@ -145,7 +148,7 @@ Example
    cd "$pkgdir"
    cat <<EOF > .PKGINFO
    pkgname = antimicro-git
    pkgver = 2.13.r1.g862577c-1
    pkgver = "$pkgver"-"$pkgrel"
    pkgdesc = Map keyboard and mouse actions to gamepad buttons, inspired by qjoypad.
    url = https://github.com/Ryochan7/antimicro
    builddate = $(date -u '+%s')
    @@ -164,8 +167,8 @@ Example
    EOF
    fakeroot -- env LANG=C bsdtar -czf .MTREE --format=mtree --options='!all,use-set,type,uid,gid,mode,time,size,md5,sha256,link' .PKGINFO *
    fakeroot -- env LANG=C bsdtar -cf - .MTREE .PKGINFO * | xz -c -z - > ../antimicro-git-2.13.r1.g862577c-1-x86_64.pkg.tar.xz
    fakeroot -- env LANG=C bsdtar -cf - .MTREE .PKGINFO * | xz -c -z - > ../antimicro-git-"$pkgver"-"$pkgrel"-x86_64.pkg.tar.xz
    # Test.
    cd "$startdir"
    namcap antimicro-git-2.13.r1.g862577c-1-x86_64.pkg.tar.xz
    namcap antimicro-git-"$pkgver"-"$pkgrel"-x86_64.pkg.tar.xz
  7. Earnestly revised this gist May 23, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion makepkg_overview.rst
    Original file line number Diff line number Diff line change
    @@ -43,7 +43,7 @@ package()
    mkdir pkg
    cd src/program
    fakeroot -- make DESTDIR=pkg/ install
    fakeroot -- make DESTDIR=../../pkg install
    Metadata
  8. Earnestly revised this gist May 23, 2015. 1 changed file with 10 additions and 8 deletions.
    18 changes: 10 additions & 8 deletions makepkg_overview.rst
    Original file line number Diff line number Diff line change
    @@ -16,16 +16,16 @@ Building

    build()
    This is used for the creation and generation of needful resources and
    files. This function will create the ``src/`` directory which is referred to
    via the ``$srcdir`` variable.
    files. This function will create the ``src`` directory which is referred
    to via the ``$srcdir`` variable.

    A typical procedure for most projects might look like this:

    .. code-block:: sh
    mkdir src
    # Extract the source into src/
    cd src/
    # Extract the source into src
    cd src
    ./configure --prefix=/usr
    make
    @@ -57,7 +57,7 @@ PKGBUILD, almost exactly. Keys with multiple entries are simply repeated.

    .. code-block:: sh
    cd pkg/
    cd pkg
    cat << EOF > .PKGINFO
    pkgname = $pkgname
    pkgver = $pkgver-$pkgrel
    @@ -93,7 +93,7 @@ archive.
    .. code-block:: sh
    cd pkg/
    cd pkg
    fakeroot -- env LANG=C bsdtar -czf .MTREE --format=mtree --options='!all,use-set,type,uid,gid,mode,time,size,md5,sha256,link' .PKGINFO *
    Package
    @@ -104,7 +104,7 @@ again as with everything during the package phase.
    .. code-block:: sh
    cd pkg/
    cd pkg
    fakeroot -- env LANG=C bsdtar -cf - .MTREE .PKGINFO * | xz -c -z - > $pkgname-$pkgver-$pkgrel-$arch.tar.xz
    @@ -116,7 +116,9 @@ Example
    #!/usr/bin/env bash
    # Basic makepkg which just creates a package for antimicro, built from git.
    set +e
    # Because I don't do any error handling, just bail if any command fails for
    # any reason.
    set +e
    startdir="$PWD"
    srcdir="$startdir"/src
  9. Earnestly revised this gist May 4, 2015. 1 changed file with 1 addition and 12 deletions.
    13 changes: 1 addition & 12 deletions makepkg_overview.rst
    Original file line number Diff line number Diff line change
    @@ -11,20 +11,9 @@ The following example commands can mostly run verbatim to manually create a
    package without makepkg.


    Preamble
    Building
    --------

    pkgver()
    If present, the output (stdout) of this function will become the new
    ``pkgver=``, this updates the PKGBUILD in-place. An illegal pkgver will be
    rejected and makepkg will exit.

    prepare()
    Any patches or alterations needed before the main build is done here.

    Build
    -----

    build()
    This is used for the creation and generation of needful resources and
    files. This function will create the ``src/`` directory which is referred to
  10. Earnestly revised this gist Apr 16, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion makepkg_overview.rst
    Original file line number Diff line number Diff line change
    @@ -45,7 +45,7 @@ Installation
    ------------

    package()
    The separation of build and install happens here. Fakeroot is used to
    The separation of build and installation happens here. Fakeroot is used to
    maintain appropriate permissions while not actually running as root. That
    is, the facade of root permission is maintained so long real root privilege
    is not needed.
  11. Earnestly revised this gist Apr 16, 2015. 1 changed file with 8 additions and 7 deletions.
    15 changes: 8 additions & 7 deletions makepkg_overview.rst
    Original file line number Diff line number Diff line change
    @@ -27,8 +27,8 @@ Build

    build()
    This is used for the creation and generation of needful resources and
    files. This function will create the src/ directory which is referred to
    via the "$srcdir" variable.
    files. This function will create the ``src/`` directory which is referred to
    via the ``$srcdir`` variable.

    A typical procedure for most projects might look like this:

    @@ -61,9 +61,9 @@ Metadata
    --------

    The meat of the data pacman depends on is now generated, this includes a simple
    key value pair file called .PKGINFO and an "mtree", the .MTREE.
    key value pair file called ``.PKGINFO`` and an "mtree", the ``.MTREE``.

    A .PKGINFO is just a simple collection of what one would express in the
    A ``.PKGINFO`` is just a simple collection of what one would express in the
    PKGBUILD, almost exactly. Keys with multiple entries are simply repeated.

    .. code-block:: sh
    @@ -94,12 +94,13 @@ PKGBUILD, almost exactly. Keys with multiple entries are simply repeated.
    An mtree is essentially a way to generate a map of a directory structure with
    all kinds of attributes included, such as permissions, acls, etc. This allows
    pacman to easily know what the attributes should be so that any issues can be
    cross-checked when using the `-Qk` option.
    cross-checked when using the ``-Qk`` option.
    Bsdtar is then used to generate the .MTREE file. This disables !all of the
    Bsdtar is then used to generate the ``.MTREE`` file. This disables !all of the
    attributes and then enables a selected few.
    The .PKGINFO needs to be first.
    When creating the mtree, the ``.PKGINFO`` file needs to be first in the
    archive.
    .. code-block:: sh
  12. Earnestly revised this gist Apr 16, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion makepkg_overview.rst
    Original file line number Diff line number Diff line change
    @@ -37,7 +37,7 @@ build()
    mkdir src
    # Extract the source into src/
    cd src/
    configure --prefix=/usr
    ./configure --prefix=/usr
    make
  13. Earnestly revised this gist Apr 12, 2015. 1 changed file with 0 additions and 9 deletions.
    9 changes: 0 additions & 9 deletions makepkg_overview.rst
    Original file line number Diff line number Diff line change
    @@ -169,15 +169,6 @@ Example
    depend = libxkbcommon-x11
    makedepend = cmake
    makedepend = qt5-tools
    makepkgopt = strip
    makepkgopt = docs
    makepkgopt = !libtool
    makepkgopt = !staticlibs
    makepkgopt = emptydirs
    makepkgopt = zipman
    makepkgopt = purge
    makepkgopt = !upx
    makepkgopt = !debug
    EOF
    fakeroot -- env LANG=C bsdtar -czf .MTREE --format=mtree --options='!all,use-set,type,uid,gid,mode,time,size,md5,sha256,link' .PKGINFO *
  14. Earnestly revised this gist Apr 10, 2015. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion makepkg_overview.rst
    Original file line number Diff line number Diff line change
    @@ -132,7 +132,8 @@ Example
    srcdir="$startdir"/src
    pkgdir="$startdir"/pkg
    # Check for all dependencies.
    # Check for all dependencies. This command will return any which are
    # missing, each one on a newline.
    pacman -T cmake qt5-tools libxtst qt5-base sdl2 libxkbcommon-x11
    # Build.
  15. Earnestly revised this gist Apr 10, 2015. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion makepkg_overview.rst
    Original file line number Diff line number Diff line change
    @@ -125,14 +125,16 @@ Example
    #!/usr/bin/env bash
    # Basic makepkg which just creates a package for antimicro, built from git.
    # Assumes all dependencies are available.
    set +e
    startdir="$PWD"
    srcdir="$startdir"/src
    pkgdir="$startdir"/pkg
    # Check for all dependencies.
    pacman -T cmake qt5-tools libxtst qt5-base sdl2 libxkbcommon-x11
    # Build.
    mkdir -p "$srcdir"
    cd "$srcdir"
  16. Earnestly revised this gist Apr 10, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion makepkg_overview.rst
    Original file line number Diff line number Diff line change
    @@ -78,7 +78,7 @@ PKGBUILD, almost exactly. Keys with multiple entries are simply repeated.
    license = $license
    builddate = $(date -u '+%s')
    size = $(du -sb --apparent-size . | awk '{print $1}')
    size = $(du -sb --apparent-size | awk '{print $1}')
    arch = $(uname -m)
  17. Earnestly revised this gist Apr 10, 2015. 1 changed file with 2 additions and 4 deletions.
    6 changes: 2 additions & 4 deletions makepkg_overview.rst
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,5 @@
    A Brief Tour of the Makepkg Process
    ===================================
    What Makes a Pacman Package
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    A Brief Tour of the Makepkg Process: What Makes a Pacman Package
    ================================================================

    Introduction
    ------------
  18. Earnestly revised this gist Apr 10, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion makepkg_overview.rst
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    A Brief Tour of the Makepkg Process
    ===================================
    What Makes a Pacman Package
    ---------------------------
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~

    Introduction
    ------------
  19. Earnestly revised this gist Apr 10, 2015. 1 changed file with 0 additions and 2 deletions.
    2 changes: 0 additions & 2 deletions makepkg_overview.rst
    Original file line number Diff line number Diff line change
    @@ -185,5 +185,3 @@ Example
    # Test.
    cd "$startdir"
    namcap antimicro-git-2.13.r1.g862577c-1-x86_64.pkg.tar.xz
    # Done.
  20. Earnestly revised this gist Apr 10, 2015. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions makepkg_overview.rst
    Original file line number Diff line number Diff line change
    @@ -35,6 +35,7 @@ build()
    A typical procedure for most projects might look like this:

    .. code-block:: sh
    mkdir src
    # Extract the source into src/
    cd src/
    @@ -52,6 +53,7 @@ package()
    is not needed.

    .. code-block:: sh
    mkdir pkg
    cd src/program
    fakeroot -- make DESTDIR=pkg/ install
    @@ -67,6 +69,7 @@ A .PKGINFO is just a simple collection of what one would express in the
    PKGBUILD, almost exactly. Keys with multiple entries are simply repeated.

    .. code-block:: sh
    cd pkg/
    cat << EOF > .PKGINFO
    pkgname = $pkgname
    @@ -101,6 +104,7 @@ attributes and then enables a selected few.
    The .PKGINFO needs to be first.
    .. code-block:: sh
    cd pkg/
    fakeroot -- env LANG=C bsdtar -czf .MTREE --format=mtree --options='!all,use-set,type,uid,gid,mode,time,size,md5,sha256,link' .PKGINFO *
    @@ -111,6 +115,7 @@ All that remains is to generate a tarball of our package. We use fakeroot
    again as with everything during the package phase.
    .. code-block:: sh
    cd pkg/
    fakeroot -- env LANG=C bsdtar -cf - .MTREE .PKGINFO * | xz -c -z - > $pkgname-$pkgver-$pkgrel-$arch.tar.xz
    @@ -119,6 +124,7 @@ Example
    -------
    .. code-block:: sh
    #!/usr/bin/env bash
    # Basic makepkg which just creates a package for antimicro, built from git.
    # Assumes all dependencies are available.
  21. Earnestly created this gist Apr 10, 2015.
    183 changes: 183 additions & 0 deletions makepkg_overview.rst
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,183 @@
    A Brief Tour of the Makepkg Process
    ===================================
    What Makes a Pacman Package
    ---------------------------

    Introduction
    ------------

    This is a terse document covering the anatomy of a package built for the pacman
    package manager.

    The following example commands can mostly run verbatim to manually create a
    package without makepkg.


    Preamble
    --------

    pkgver()
    If present, the output (stdout) of this function will become the new
    ``pkgver=``, this updates the PKGBUILD in-place. An illegal pkgver will be
    rejected and makepkg will exit.

    prepare()
    Any patches or alterations needed before the main build is done here.

    Build
    -----

    build()
    This is used for the creation and generation of needful resources and
    files. This function will create the src/ directory which is referred to
    via the "$srcdir" variable.

    A typical procedure for most projects might look like this:

    .. code-block:: sh
    mkdir src
    # Extract the source into src/
    cd src/
    configure --prefix=/usr
    make
    Installation
    ------------

    package()
    The separation of build and install happens here. Fakeroot is used to
    maintain appropriate permissions while not actually running as root. That
    is, the facade of root permission is maintained so long real root privilege
    is not needed.

    .. code-block:: sh
    mkdir pkg
    cd src/program
    fakeroot -- make DESTDIR=pkg/ install
    Metadata
    --------

    The meat of the data pacman depends on is now generated, this includes a simple
    key value pair file called .PKGINFO and an "mtree", the .MTREE.

    A .PKGINFO is just a simple collection of what one would express in the
    PKGBUILD, almost exactly. Keys with multiple entries are simply repeated.

    .. code-block:: sh
    cd pkg/
    cat << EOF > .PKGINFO
    pkgname = $pkgname
    pkgver = $pkgver-$pkgrel
    pkgdesc = $pkgdesc
    url = $url
    license = $license
    builddate = $(date -u '+%s')
    size = $(du -sb --apparent-size . | awk '{print $1}')
    arch = $(uname -m)
    depend = libfoo
    depend = libbar
    depend = libbaz
    makedepend = buildlibfoo
    makedepend = buildlibbar
    makedepend = buildlibbaz
    EOF
    An mtree is essentially a way to generate a map of a directory structure with
    all kinds of attributes included, such as permissions, acls, etc. This allows
    pacman to easily know what the attributes should be so that any issues can be
    cross-checked when using the `-Qk` option.
    Bsdtar is then used to generate the .MTREE file. This disables !all of the
    attributes and then enables a selected few.
    The .PKGINFO needs to be first.
    .. code-block:: sh
    cd pkg/
    fakeroot -- env LANG=C bsdtar -czf .MTREE --format=mtree --options='!all,use-set,type,uid,gid,mode,time,size,md5,sha256,link' .PKGINFO *
    Package
    -------
    All that remains is to generate a tarball of our package. We use fakeroot
    again as with everything during the package phase.
    .. code-block:: sh
    cd pkg/
    fakeroot -- env LANG=C bsdtar -cf - .MTREE .PKGINFO * | xz -c -z - > $pkgname-$pkgver-$pkgrel-$arch.tar.xz
    Example
    -------
    .. code-block:: sh
    #!/usr/bin/env bash
    # Basic makepkg which just creates a package for antimicro, built from git.
    # Assumes all dependencies are available.
    set +e
    startdir="$PWD"
    srcdir="$startdir"/src
    pkgdir="$startdir"/pkg
    # Build.
    mkdir -p "$srcdir"
    cd "$srcdir"
    git clone git://github.com/Ryochan7/antimicro --depth 1
    cd antimicro
    cmake -DMAKE_INSTALL_PREFIX=/usr -DUSE_SDL2=ON
    make
    # Installation.
    mkdir -p "$pkgdir"
    fakeroot -- make DESTDIR="$pkgdir" install
    # Package.
    cd "$pkgdir"
    cat <<EOF > .PKGINFO
    pkgname = antimicro-git
    pkgver = 2.13.r1.g862577c-1
    pkgdesc = Map keyboard and mouse actions to gamepad buttons, inspired by qjoypad.
    url = https://github.com/Ryochan7/antimicro
    builddate = $(date -u '+%s')
    packager = Unknown Packager
    size = $(du -sb --apparent-size "$pkgdir" | awk '{print $1}')
    arch = $(uname -m)
    license = GPL3
    conflict = antimicro
    provides = antimicro
    depend = libxtst
    depend = qt5-base
    depend = sdl2
    depend = libxkbcommon-x11
    makedepend = cmake
    makedepend = qt5-tools
    makepkgopt = strip
    makepkgopt = docs
    makepkgopt = !libtool
    makepkgopt = !staticlibs
    makepkgopt = emptydirs
    makepkgopt = zipman
    makepkgopt = purge
    makepkgopt = !upx
    makepkgopt = !debug
    EOF
    fakeroot -- env LANG=C bsdtar -czf .MTREE --format=mtree --options='!all,use-set,type,uid,gid,mode,time,size,md5,sha256,link' .PKGINFO *
    fakeroot -- env LANG=C bsdtar -cf - .MTREE .PKGINFO * | xz -c -z - > ../antimicro-git-2.13.r1.g862577c-1-x86_64.pkg.tar.xz
    # Test.
    cd "$startdir"
    namcap antimicro-git-2.13.r1.g862577c-1-x86_64.pkg.tar.xz
    # Done.