Skip to content
Search openEuler

    Browse this documentation

    Your first RPM with rpmbuild on openEuler — a minimal spec built end to end (including the gotcha that %{?dist} expands to empty on openEuler)

    Evidence on this page comes from the container track (E2, build-type) — openeuler/openeuler:latest (online repos, 2026-11-05): toolchain installation, minimal-spec build, installing and running the home-grown RPM, release-tag observation. Raw log: evidence/logs/openeuler-rpmbuild-intro.log.

    Five minutes end to end (the verified command surface)

    Section titled “Five minutes end to end (the verified command surface)”
    Terminal window
    dnf -y install rpm-build # rpmbuild --version → RPM version 4.18.2
    mkdir -p ~/rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS}

    The minimal spec (~/rpmbuild/SPECS/hello.spec, an equivalent form of the one verified on this page):

    Name: hello-euler
    Version: 1.0
    Release: 1%{?dist}
    Summary: minimal rpm
    License: MIT
    %description
    minimal test package
    %files
    /usr/bin/hello-euler
    %install
    mkdir -p %{buildroot}/usr/bin
    echo '#!/bin/sh
    echo hello openEuler' > %{buildroot}/usr/bin/hello-euler
    chmod +x %{buildroot}/usr/bin/hello-euler

    Building and verifying (verified output):

    $ rpmbuild -ba ~/rpmbuild/SPECS/hello.spec
    … ~/rpmbuild/RPMS/aarch64/hello-euler-1.0-1.aarch64.rpm
    $ dnf -y install ~/rpmbuild/RPMS/*/*.rpm
    $ rpm -q hello-euler && /usr/bin/hello-euler
    hello-euler-1.0-1.aarch64
    hello openEuler

    A package from a local file:// path installs directly through dnf’s default trust path — for distributing internal tools that is already a usable minimal loop; external distribution is what needs signing (see the end).

    A finding from testing: %{?dist} expands to empty

    Section titled “A finding from testing: %{?dist} expands to empty”

    The artifact name is hello-euler-1.0-1.aarch64.rpm — the release is a bare 1, with no .oe2403sp4 suffix (in testing, rpm -q --qf '%{RELEASE}\n' printed 1). Compare against an official package (dnf-4.16.2-10.oe2403sp4):

    • openEuler’s official build environment injects the %dist macro at build time (.oe2403sp4); on ordinary containers/machines this macro is not preset, and %{?dist} quietly expands to empty;
    • to replicate the official style (internal packages recognizable at a glance by distro and SP), declare it explicitly in ~/.rpmmacros:
    %dist .oe2403sp4

    The value of this gotcha: it gives “should internal packages carry a release tag” a clear decision point — without one (the default), the same spec can be reused across distros; with one, it must be edited manually on version upgrades (or managed centrally via a macro file).

    1. Run the full rpmbuild -ba chain on a spec before committing it to the repo (both BUILD→RPMS and SRPMS produced) — running only -bb hides SRPM reproducibility problems;
    2. %files uses an absolute-path whitelist, never wildcarded big directories (packing in something that should not be there is the most common internal-package accident);
    3. The License field is mandatory (even the minimal spec above has one) — openEuler’s official packages follow Mulan PSL v2 and other licenses; internal packages fill in their actual license, and a false License is a compliance mine.
    • Signing home-grown RPMs (rpmsign + a self-built GPG + import on the distribution side) not tested in this environment (a prerequisite for external distribution, queued for a later batch);
    • Dissecting openEuler’s official spec structure (the spec ecosystem on src-openEuler/Gitee, Mulan PSL license headers) left for a deep-dive page;
    • mock/scm packaging workflows not covered (this page is the minimal loop).