Packaging¶
Overview¶
Creating a package involves the following steps:
Initialize package directories
Configure metadata and upstream source in Makefile
Generate MANIFEST file (source checksums)
Configure distribution-specific packaging
Build the package
Creating Packages¶
Initialize a packaging skeleton:
./common/init_pkg.sh -n yourpackage
This creates the following structure:
foo/
├── buildenv -> ../common/buildenv
├── debian/ # Debian packaging files
│ ├── changelog
│ ├── compat
│ ├── control # Package metadata and dependencies
│ ├── rules # Build instructions
│ └── ...
├── rpm/
│ └── component.spec # RPM spec file
├── Makefile # Package metadata and build configuration
└── MANIFEST # Checksums of upstream sources
Building Packages¶
First, go in the package directory:
cd yourpackage
Building the .rpm
Package:
make rpm_chroot DIST=el9 # Replace 'el9' with target distro
tree *out
out/
└── yourpackage-0.0.1-1.amk+el9.noarch.rpm
Building the .deb
Package:
make deb_chroot DIST=trixie # Replace 'trixie' with target distro
tree out
out/
└── yourpackage_0.0.1-1~amk+deb13_all.deb
Clean:
# Clean everything
make clean
# Clean, but retain upstream source download
make clean KEEP_CACHE=true
Makefile Setup¶
Package Metadata¶
The Makefile contains package metadata and upstream source configuration:
# Package name
NAME = mk-sh-skel
# Version
VERSION = 1.0.0
# URL of the project
URL = https://github.com/kakwa/mk-sh-skel
# Revision number
RELEASE = 1
# Description
DESCRIPTION = "Description of the package"
# License of the package
LICENSE = "MIT"
# URL to upstream source
URL_SRC = $(URL)/archive/$(VERSION).tar.gz
Sources Recovery & Preparation¶
From there, you can add the upstream source recovery.
Using wget + checksum tool:
# Example of source recovery url
URL_SRC=$(URL)/archive/$(VERSION).tar.gz
# Basic source archive recovery
$(SOURCE_ARCHIVE): $(SOURCE_DIR) $(CACHE) Makefile MANIFEST
@$(WGS) -u $(URL_SRC) -o $(SOURCE_ARCHIVE)
Using git + checksum tool:
# Git URL
URL=https://github.com/kakwa/mk-sh-skel
# Revision
REVISION=dac9e68d96d5d7de9854728dd08f7824d1376eb2
# Example of git source recovery
$(SOURCE_ARCHIVE): $(SOURCE_DIR) $(CACHE) Makefile MANIFEST
@$(GS) -u $(URL) -o $(SOURCE_ARCHIVE) -r $(REVISION)
It is also possible to manually tweak the archive if necessary (leveraging $(SOURCE_DIR)
and $(SOURCE_TAR_CMD)
):
# Example of upstream debian/ packaging removal
# note the switch -o -> -O in $(WGS)
$(SOURCE_ARCHIVE): $(SOURCE_DIR) $(CACHE) Makefile MANIFEST
@$(WGS) -u $(URL_SRC) -O $(NAME)-$(VERSION).tar.gz
@tar -vxf $(CACHE_DIR)/$(NAME)-$(VERSION).tar.gz -C $(SOURCE_DIR) --strip-components=1
@rm -rf $(SOURCE_DIR)/debian
@$(SOURCE_TAR_CMD)
Skipping Version¶
If you want to disable the build for a given distribution/version, add the following:
# Skip builds for Debian < 9, All RHEL versions, Fedora > 40, Ubuntu <= 18.4
SKIP=<:deb:9 >=:el:0 >:fc:40 <=:ubu:18.4
Generating the MANIFEST¶
After configuring the Makefile, and whenever you update the upstream version, (re)generate the MANIFEST file:
make manifest
This downloads the upstream source and creates a MANIFEST file with checksums to ensure upstream is not doing something iffy.
Version Specific Packaging¶
If necessary, you can override any packaging file on a per distribution basis. Simply use the <FILE>.dist.<DIST>
to override a default <FILE>
.
For example:
debian/control # will be used as default
debian/control.dist.buster # will be used if build is called with DIST=buster
External Packaging Documentation¶
The rest of the work is pretty much .deb
or .rpm
vanilla packaging (with a bit of templating).
Follow the packaging documentation of each ecosystems and the usual standards:
Filesystem Layout: Filesystem Hierarchy Standard
Debian Reference: Debian Policy Manual
Debian/Ubuntu (.deb) Packaging: Debian New Maintainers’ Guide
Fedora/RHEL/CentOS (.rpm) Packaging: Fedora Packaging Guidelines
openSUSE (.rpm) Packaging: openSUSE Packaging Guide
Also, take inspiration from existing packages:
Fedora: Fedora Packaging Sources (search a package, then click the Files menu).
Debian: Debian Package Search (search a package, then look for the *.debian.tar.xz Download on the right).