1,885
edits
Changes
Created page with 'RPM packages are built from the source files plus a spec file, using the ''rpmbuild'' program. {{Admon/caution|Do Not Build as Root|Always build RPM packages as a regular, non-r…'
RPM packages are built from the source files plus a spec file, using the ''rpmbuild'' program.
{{Admon/caution|Do Not Build as Root|Always build RPM packages as a regular, non-root user. Building as a root user is unnecessary and may cause unintended side effects, including damaging your system.}}
= Setting up the Packaging Environment =
== Needed Packages ==
Install with ''yum'':
* rpm-build
* rpmdevtools
* rpmlint
* yum-utils
{{Admon/tip|"Fedora Packager" group|Many of these tools can be installed at once by installing the "Fedora Packager" group: <code>yum groupinstall "Fedora Packager"</code>}}
== Setting up the RPM tree ==
The directories used by the rpm build tools can be defined as RPM macros. A script is provided in the ''rpmdevtools'' package to create a set of personal build directories and create the appropriate entries in the <code>~/.rpmmacros</code> file:
rpmdev-setuptree
The directories created are:
* ~/rpmbuild/SOURCES - for source code (tarballs/zip archives and patches)
* ~/rpmbuild/SPECS - for the spec file
* ~/rpmbuild/SRPMS - for the resulting source RPMs
* ~/rpmbuild/RPMS - for the resulting binary RPMs
* ~/rpmbuild/BUILD - directory used to perform the build
* ~/rpmbuild/BUILDROOT - contains a fake root directory into which the built files are "installed" prior to being packaged
= Examining Existing SRPMs =
A great place to start when learning to build RPMs is to examine some existing SRPMs.
# Download the source code for an existing RPM: <code>yumdownloader --source ''nameofpackage''</code>
# Install that package
* Taking a look at existing source RPMS (useful as examples)
** Installing
*** <code>yumdownloader --source <i>nameofpackage</i></code>
*** <code>rpm -i <i>nameofpackage</i>.src.rpm</code>
*** Source will be in ~/rpmbuild/SOURCES and specfile will be in ~/rpmbuild/SPECS
** Examine the specfile
** Rebuild on the local machine -- takes a source RPM (SRPM) as input, produces binary and source RPMs as output
*** <code>rpmbuild --rebuild <i>nameofpackage</i>.src.rpm</code>
** Building from the spec file -- takes a specfile and source code as input, produces binary and source RPMs as output
*** <code>cd ~/rpmbuild/SPECS; rpmbuild -ba <i>nameofpackage</i>.spec</code>
{{Admon/caution|Do Not Build as Root|Always build RPM packages as a regular, non-root user. Building as a root user is unnecessary and may cause unintended side effects, including damaging your system.}}
= Setting up the Packaging Environment =
== Needed Packages ==
Install with ''yum'':
* rpm-build
* rpmdevtools
* rpmlint
* yum-utils
{{Admon/tip|"Fedora Packager" group|Many of these tools can be installed at once by installing the "Fedora Packager" group: <code>yum groupinstall "Fedora Packager"</code>}}
== Setting up the RPM tree ==
The directories used by the rpm build tools can be defined as RPM macros. A script is provided in the ''rpmdevtools'' package to create a set of personal build directories and create the appropriate entries in the <code>~/.rpmmacros</code> file:
rpmdev-setuptree
The directories created are:
* ~/rpmbuild/SOURCES - for source code (tarballs/zip archives and patches)
* ~/rpmbuild/SPECS - for the spec file
* ~/rpmbuild/SRPMS - for the resulting source RPMs
* ~/rpmbuild/RPMS - for the resulting binary RPMs
* ~/rpmbuild/BUILD - directory used to perform the build
* ~/rpmbuild/BUILDROOT - contains a fake root directory into which the built files are "installed" prior to being packaged
= Examining Existing SRPMs =
A great place to start when learning to build RPMs is to examine some existing SRPMs.
# Download the source code for an existing RPM: <code>yumdownloader --source ''nameofpackage''</code>
# Install that package
* Taking a look at existing source RPMS (useful as examples)
** Installing
*** <code>yumdownloader --source <i>nameofpackage</i></code>
*** <code>rpm -i <i>nameofpackage</i>.src.rpm</code>
*** Source will be in ~/rpmbuild/SOURCES and specfile will be in ~/rpmbuild/SPECS
** Examine the specfile
** Rebuild on the local machine -- takes a source RPM (SRPM) as input, produces binary and source RPMs as output
*** <code>rpmbuild --rebuild <i>nameofpackage</i>.src.rpm</code>
** Building from the spec file -- takes a specfile and source code as input, produces binary and source RPMs as output
*** <code>cd ~/rpmbuild/SPECS; rpmbuild -ba <i>nameofpackage</i>.spec</code>