From f030dfda420c9cd7b1fde797cb91ba08599b0f9a Mon Sep 17 00:00:00 2001 From: Petr Písař Date: May 30 2023 11:35:23 +0000 Subject: GNU Hello tutorial: All depenencies, configure options, handle info dir The complete hello.spec was reported not building because of missing texinfo. The real problem is an automagic dependency on info package. If info is installed, %{_infodir}/dir is generated. Otherwise, %{_infodir}/dir is not generated, yet hello.info is correctly installed. This commit fixes this by a conditional removal of %{_infodir}/dir. This commit also adds BuildRequires on bash, coreutils, glibc-common, and sed. They are used, but were not declared. This commit also explicitly enabled NLS support and disables RPATH feature, to be in line current Fedora packaging custom to support native languages and not rely on RPATH. Tested on Fedora 39, 37, and 36. https://pagure.io/fedora-docs/package-maintainer-docs/issue/97 --- diff --git a/modules/ROOT/pages/Packaging_Tutorial_GNU_Hello.adoc b/modules/ROOT/pages/Packaging_Tutorial_GNU_Hello.adoc index c3363b0..605405a 100644 --- a/modules/ROOT/pages/Packaging_Tutorial_GNU_Hello.adoc +++ b/modules/ROOT/pages/Packaging_Tutorial_GNU_Hello.adoc @@ -288,17 +288,26 @@ so the Texinfo manual can be added as follows: %{_infodir}/hello.info.* ---- -The https://src.fedoraproject.org/rpms/texinfo[texinfo package] -has rpm triggers that automatically generate the Texinfo `+dir+` file -from all the texinfo pages in the system. -Thus, the `+dir+` generated by GNU Hello build script must not be installed. -This can be done by removing it from the _buildroot_ at the end of the `+%install+` section: +The `+dir+` file generated by GNU Hello build script indexes all texinfo pages +in your system. Because the installed pages differ among systems, the file +cannot be prebuilt and packaged. Instead it needs to be created and updated +when the package is installed. The update is automaticlly performed by rpm +triggers in `+info+` binary package of +https://src.fedoraproject.org/rpms/texinfo[texinfo source package]. + +To prevent from installing the `+dir+` file, remove it from the _buildroot_ at +the end of the `+%install+` section with `+rm+` command. + +However, GNU Hello build script only generates the `+dir+` file if `+info+` +package is installed during the build. Blindly removing the file would raise +an error if the `+hello+` package were built on a system without `+info+` +package. To deal with both cases, delete the file if it exists: [source, rpm-spec] ---- %install %make_install -rm %{buildroot}%{_infodir}/dir +test -f %{buildroot}/%{_infodir}/dir && rm %{buildroot}/%{_infodir}/dir ---- === Translations @@ -385,6 +394,100 @@ Testsuite summary for GNU Hello 2.10 ============================================================================ ---- +== Fixing automagic == + +Now the package succefully builds. But that does not mean that the `.spec` +file is correct. + +=== Listing all build-time dependencies === + +If you carefully read a build output, you can discover lines which mention +`+sed+` command: + +---- ++ /usr/bin/make -O -j4 V=1 VERBOSE=1 +rm -f lib/arg-nonnull.h-t lib/arg-nonnull.h && \ +sed -n -e '/GL_ARG_NONNULL/,$p' \ +---- + +Therefore you need to add this line close to other BuildRequires lines: + +[source, rpm-spec] +---- +BuildRequires: sed +---- + +Smilarly, studing `+configure+` script in the unpackaged sources, which is +executed by `+%configure+` macro, reveals it's a `/bin/sh` script: + +---- +$ head configure +#! /bin/sh +# Guess values for system-dependent variables and create Makefiles. +# Generated by GNU Autoconf 2.69 for GNU Hello 2.10. +---- + +Thus you also should record this dependency on `+bash+`: + +[source, rpm-spec] +---- +BuildRequires: bash +---- + +Why on `+bash+`? Because `+/bin/sh+` program is provided by `+bash+` package: + +---- +rpm --qf '%{name}\n' -qf /bin/sh +bash +---- + +Specifying all used dependencies helps to make the `.spec` file resilient +against changes in the build environment. If e.g. `+sed+` package were removed +from the environment, this GNU Hello package would fail to build. + +=== Listing all build options === + +The GNU Hello build script, `+configure+` has many build options which enables +or disables optional features. Their nondefault forms can be listed with +`+--help+` option: + +---- +$ ./configure --help +`configure' configures GNU Hello 2.10 to adapt to many kinds of systems. + +Usage: ./configure [OPTION]... [VAR=VALUE]... +⋮ +Optional Features: + --disable-option-checking ignore unrecognized --enable/--with options + --disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no) + --enable-FEATURE[=ARG] include FEATURE [ARG=yes] + --enable-silent-rules less verbose build output (undo: "make V=1") + --disable-silent-rules verbose build output (undo: "make V=0") + --enable-dependency-tracking + do not reject slow dependency extractors + --disable-dependency-tracking + speeds up one-time build + --disable-nls do not use Native Language Support + --disable-rpath do not hardcode runtime library paths +---- + +Some of them are already specified within `+%configure+` and `+%make_build+` +macros. The rest of the options, if they are important for the built package, +should be explicitly written in the `.spec` file to prevent from their +sudden and unnoticed changes. Either because a new Hello version changes the +default, or because a package which they depend on appears of disappears from +the build environment. + +Therefore modify `+%configure+` invocation in `+%build+` section like this: + + +[source, rpm-spec] +---- +%configure \ + --enable-nls \ + --disable-rpath +---- + == Checking the result with rpmlint Next you should check them for conformance with RPM design rules, @@ -408,9 +511,13 @@ Descriptions of various error codes can be queried with `+rpmlint -e +`. In this case, in order to ensure a pure utf-8 installation, the file needs to be converted in `+%prep+`. -This can be done with the `+iconv+` utility: +This can be done with the `+iconv+` utility which is provided by +`+glibc-common+` package, and `+mv+` tool from `+coreutils+`: ---- +BuildRequires: coreutils +BuildRequires: glibc-common +⋮ mv THANKS THANKS.old iconv --from-code=ISO-8859-1 --to-code=UTF-8 --output=THANKS THANKS.old ---- @@ -419,7 +526,7 @@ Run `fedpkg lint` again and observe that the warning is fixed. == A Complete hello.spec File -Here is the initial version of `hello.spec`: +Here is the final version of `hello.spec`: [source, rpm-spec] ---- @@ -432,9 +539,13 @@ License: GPL-3.0-or-later URL: http://ftp.gnu.org/gnu/%{name} Source: http://ftp.gnu.org/gnu/%{name}/%{name}-%{version}.tar.gz +BuildRequires: bash +BuildRequires: coreutils BuildRequires: gcc BuildRequires: gettext +BuildRequires: glibc-common BuildRequires: make +BuildRequires: sed %description The GNU Hello program produces a familiar, friendly greeting. Yes, this is @@ -447,12 +558,14 @@ mv THANKS THANKS.old iconv --from-code=ISO-8859-1 --to-code=UTF-8 --output=THANKS THANKS.old %build -%configure +%configure \ + --enable-nls \ + --disable-rpath %make_build %install %make_install -rm %{buildroot}/%{_infodir}/dir +test -f %{buildroot}/%{_infodir}/dir && rm %{buildroot}/%{_infodir}/dir %find_lang %{name} %check