Work with spec files
To package new software with RPM, you must create a spec file.
You can create the spec file in one of the following ways:
- Write the new
specfile manually from scratch. - Use the
rpmdev-newspecutility. This utility creates an unpopulatedspecfile, where you fill the necessary directives and fields.
spec file with their own spec template. The rpmdev-newspec utility provides an editor-agnostic method.Create a new spec file for sample Bash, Python, and C programs Copy linkLink copied!
Create a spec file for each of the three sample implementations of the Hello World! program by using the rpmdev-newspec utility.
Before you begin Copy linkLink copied!
- The following
Hello World!program implementations were placed into the~/rpmbuild/SOURCESdirectory:
Procedure Copy linkLink copied!
Modify an original spec file Copy linkLink copied!
Provide necessary instructions for the rpmbuild utility by modifying the original output spec file generated by the rpmdev-newspec utility. rpmbuild then uses these instructions to build an RPM package.
Before you begin Copy linkLink copied!
- The unpopulated
~/rpmbuild/SPECS/<name>.specspecfile was created by using therpmdev-newspecutility. For more information, see Creating a new spec file for sample Bash, Python, and C programs.
Procedure Copy linkLink copied!
An example spec file for a sample Bash program Copy linkLink copied!
Review the following annotated example spec file for a sample program written in the Bash programming language (bello).
To install bello, you must create the destination directory and install the executable bash script file there. Therefore, you can use the install command in the %install section. You can use RPM macros to do this without hardcoding paths.
An example spec file for the bello program Copy linkLink copied!
Name: bello
Version: 0.1
Release: 1%{?dist}
Summary: Hello World example implemented in bash script
License: GPLv3+
URL: https://www.example.com/%{name}
Source0: https://www.example.com/%{name}/releases/%{name}-%{version}.tar.gz
Requires: bash
BuildArch: noarch
%description
The long-tail description for our Hello World Example implemented in
bash script.
%prep
%setup -q
%build
%install
mkdir -p %{buildroot}/%{_bindir}
install -m 0755 %{name} %{buildroot}/%{_bindir}/%{name}
%files
%license LICENSE
%{_bindir}/%{name}
%changelog
* Tue May 31 2016 Adam Miller <maxamillion@fedoraproject.org> - 0.1-1
- First bello package
- Example second item in the changelog for version-release 0.1-1
- The
BuildRequiresdirective, which specifies build-time dependencies for the package, was deleted because there is no building step forbello. Bash is a raw interpreted programming language, and the files are just installed to their location on the system. - The
Requiresdirective, which specifies run-time dependencies for the package, includes onlybash, because thebelloscript requires only thebashshell environment to run. - The
%buildsection, which specifies how to build the software, is blank, because thebashscript does not need to be built.
An example spec file for a sample Python program Copy linkLink copied!
Review the following annotated example spec file for a sample program written in the Python programming language (pello).
This example of creating a wrapper script in-line in the spec file shows that the spec file itself is scriptable. This wrapper script executes the Python byte-compiled code by using the here document.
An example spec file for the pello program Copy linkLink copied!
Name: pello
Version: 0.1.1
Release: 1%{?dist}
Summary: Hello World example implemented in Python
License: GPLv3+
URL: https://www.example.com/%{name}
Source0: https://www.example.com/%{name}/releases/%{name}-%{version}.tar.gz
BuildRequires: python
Requires: python
Requires: bash
BuildArch: noarch
%description
The long-tail description for our Hello World Example implemented in Python.
%prep
%setup -q
%build
python -m compileall %{name}.py
%install
mkdir -p %{buildroot}/%{_bindir}
mkdir -p %{buildroot}/usr/lib/%{name}
cat > %{buildroot}/%{_bindir}/%{name} <<EOF
#!/bin/bash
/usr/bin/python /usr/lib/%{name}/%{name}.pyc
EOF
chmod 0755 %{buildroot}/%{_bindir}/%{name}
install -m 0644 %{name}.py* %{buildroot}/usr/lib/%{name}/
%files
%license LICENSE
%dir /usr/lib/%{name}/
%{_bindir}/%{name}
/usr/lib/%{name}/%{name}.py*
%changelog
* Tue May 31 2016 Adam Miller <maxamillion@fedoraproject.org> - 0.1.1-1
- First pello package
- The
Requiresdirective, which specifies run-time dependencies for the package, includes two packages:- The
pythonpackage required to execute the byte-compiled code at runtime. - The
bashpackage required to execute the small entry-point script.
- The
- The
BuildRequiresdirective, which specifies build-time dependencies for the package, includes only thepythonpackage. Thepelloprogram requirespythonto perform the byte-compile build process. - The
%buildsection, which specifies how to build the software, creates a byte-compiled version of the script. Note that in real-world packaging, it is usually done automatically, depending on the distribution used. - The
%installsection corresponds to the fact that you must install the byte-compiled file into a library directory on the system so that it can be accessed.
An example spec file for a sample C program Copy linkLink copied!
Review the following annotated example spec file for a sample program written in the C programming language (cello).
You can install the cello program by using the %make_install macro. This is possible because the Makefile file for the cello program is available.
An example spec file for the cello program Copy linkLink copied!
Name: cello
Version: 1.0
Release: 1%{?dist}
Summary: Hello World example implemented in C
License: GPLv3+
URL: https://www.example.com/%{name}
Source0: https://www.example.com/%{name}/releases/%{name}-%{version}.tar.gz
Patch0: cello-output-first-patch.patch
BuildRequires: gcc
BuildRequires: make
%description
The long-tail description for our Hello World Example implemented in
C.
%prep
%setup -q
%patch0
%build
make %{?_smp_mflags}
%install
%make_install
%files
%license LICENSE
%{_bindir}/%{name}
%changelog
* Tue May 31 2016 Adam Miller <maxamillion@fedoraproject.org> - 1.0-1
- First cello package
- The
BuildRequiresdirective, which specifies build-time dependencies for the package, includes the following packages required to perform the compilation build process:gccmake
- The
Requiresdirective, which specifies run-time dependencies for the package, is omitted in this example. All runtime requirements are handled byrpmbuild, and thecelloprogram does not require anything outside of the core C standard libraries. - The
%buildsection reflects the fact that in this example theMakefilefile for the cello program was written. Therefore, you can use the GNU make command. However, you must remove the call to%configurebecause you did not provide a configure script.