Creating RPM Spec File#

Listing Build Requires#

To list build dependencies:

$ rpmspec -q --buildrequires specs/pki-core.spec
apache-commons-cli
apache-commons-codec
apache-commons-io
apache-commons-lang
apr-devel
apr-util-devel
cmake >= 2.8.9-1
...

To list what packages provide a build dependency:

$ dnf repoquery --whatrequires <package>

To list what packages depend on recursively:

$ dnf --enablerepo=fedora-source \
  --enablerepo=updates \
  --enablerepo=updates-testing-source \
  repoquery --recursive --whatrequires <package>

Listing Requires#

To list runtime dependencies:

$ rpm -q --requires pki-server
/bin/sh
/bin/sh
/bin/sh
/usr/bin/python
hostname
java-1.8.0-openjdk-headless
libselinux-python
net-tools
nuxwdog-client-java >= 1.0.1-11
openldap-clients
openssl
pki-base = 10.4.1-7.el7
pki-base-java = 10.4.1-7.el7
pki-tools = 10.4.1-7.el7
policycoreutils
policycoreutils-python
procps-ng
python(abi) = 2.7
python-ldap
python-lxml
rpmlib(CompressedFileNames) <= 3.0.4-1
rpmlib(FileDigests) <= 4.6.0-1
rpmlib(PartialHardlinkSets) <= 4.0.4-1
rpmlib(PayloadFilesHavePrefix) <= 4.0-1
selinux-policy-targeted >= 3.13.1-152
shadow-utils
systemd-units
systemd-units
systemd-units
tomcat >= 7.0.69
tomcatjss >= 7.2.1-3
velocity
rpmlib(PayloadIsXz) <= 5.2-1

To list package usages:

$ rpm -q --whatrequires pki-server
dogtag-pki-10.6.1-3.fc27.noarch
pki-ca-10.6.1-3.fc27.noarch
pki-kra-10.6.1-3.fc27.noarch
pki-ocsp-10.6.1-3.fc27.noarch
pki-tks-10.6.1-3.fc27.noarch
pki-tps-10.6.1-3.fc27.x86_64

To list packages recommending another package:

$ dnf repoquery --whatrecommends <package>

Listing Provides#

To list capabilities provided by a package:

$ rpm -q --provides pki-server
pki-deploy = 10.4.1-7.el7
pki-server = 10.4.1-7.el7
pki-setup = 10.4.1-7.el7
pki-silent = 10.4.1-7.el7

To list what packages provide a dependency:

$ rpm -q --whatprovides <dependency>

Building RPM#

To download the sources:

$ spectool -g -S <spec file>

To build the RPM package:

$ rpmbuild -bb [--define "<name> <value>"] [--with <cond>] [--without <cond>] <spec file>

To rebuild a source RPM package:

$ rpmbuild --rebuild <source RPM>

Macro#

To use the macro value defined in the command line:

%{?name}

To use a different value if the macro is defined:

%{?name:}

To use a default value if the macro is not defined:

%{!?name:

}

Conditionals#

To add –with condition:

%bcond_with <name>

To add –without condition:

%bcond_without <name>

To test the condition:

%if %{with <name>}
...
%endif

From /usr/lib/rpm/macros:

# Shorthand for %{defined with_...}
%with()         %{expand:%%{?with_%{1}:1}%%{!?with_%{1}:0}}
%without()      %{expand:%%{?with_%{1}:0}%%{!?with_%{1}:1}}

# Handle conditional builds. %bcond_with is for case when feature is
# default off and needs to be activated with --with ... command line
# switch. %bcond_without is for the dual case.
#
# %bcond_with foo defines symbol with_foo if --with foo was specified on
# command line.
# %bcond_without foo defines symbol with_foo if --without foo was *not*
# specified on command line.

# The bottom line: never use without_foo, _with_foo nor _without_foo, only
# with_foo. This way changing default set of bconds for given spec is just
# a matter of changing single line in it and syntax is more readable.
%bcond_with()           %{expand:%%{?_with_%{1}:%%global with_%{1} 1}}
%bcond_without()        %{expand:%%{!?_without_%{1}:%%global with_%{1} 1}}

See also:

Displaying Expanded Macros#

To display available macros:

$ rpm --showrc

To display the value of a macro:

$ rpm --eval '%{dist}'
.fc28

To display the spec file with expanded macros:

``$ rpmspec -P ``

RPM Spec Validation#

To validate a spec file:

``$ rpmlint ``

See also:

Extracting RPM File#

$ rpm2cpio ``\ `` | cpio -idmv

Creating RPM Repository#

$ dnf install createrepo
$ createrepo <path>
$ cat /etc/yum.repos.d/local.repo << EOF
[local]
name=Local Repository
baseurl=file://<path>
enabled=1
gpgcheck=0
EOF

References#