Changes

Jump to: navigation, search

RPM Packaging Process

4,641 bytes added, 13:18, 17 July 2017
Setting up the Packaging Environment
[[Category:SBR600]][[Category:DPI908]][[Category:RPM]][[Category:SPO600]]
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.}}
 
= Resources =
 
* [[:fedora:PackageMaintainers|Fedora Package Maintainers page]]
** [[:fedora:PackageMaintainers/CreatingPackageHowTo|Packaging How-To]]
* ''Fedora Linux'' chapter 5 (see Seneca Library website > eBooks > View All > Safari > Fedora Linux).
* rpmlint
** [[:fedora:Common Rpmlint issues|Fedora Common Rpmlint issues]]
= Setting up the Packaging Environment =
== Needed Packages ==
Install with ''dnf'' (or ''yum''on older versions of Fedora):* rpm"Fedora Packager" (this is a group of packages -builduse "dnf groupinstall" or put an @ sign in front of the group name)
* 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 ==
* ~/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
 
== Wiping out the RPM tree ==
 
{{Admon/important|Wiping the Tree Deletes Data|Be sure to save any files you need from your previous build activity before wiping the tree.}}
 
When switching to a new package, it is customary to wipe out the ''rpmbuild'' tree to avoid clutter: <code>rpmdev-wipetree</code>
= Examining 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 downloaded SRPM (useful as examplesthis does not require root access): <code>rpm -i ''nameofpackage''*.src.rpm</code>#*Source will be in <code>~/rpmbuild/SOURCES</code>#* Installing Spec file will be in <code>~/rpmbuild/SPECS</code> After installing the SRPM you can: *Examine the specfile: <code>cd ~/rpmbuild/SPECS; less ''nameofpackage''.spec</code>** Prep the sources (unpack tarballs, apply patches) to see the source code as it will be built: <code>yumdownloader rpmbuild --source bp ''nameofpackage''.spec</code> # Results will be in <icode>nameofpackage~/rpmbuild/BUILD/</icode> (usually in a subdirectory named <code>''nameofpackage''-''version''</code>).*Build from source using the specfile:** # Build all (binary RPMS plus SRPMS): <code>rpm rpmbuild -i ba ''nameofpackage''.spec</code>*# Build just the spec file: <icode>rpmbuild -bs ''nameofpackage''.spec</icode== Rebuild from SRPMS == Instead of installing an SRPM and building from the spec file, it is possible to build the binary RPMs and SRPM directly from an SRPM:  rpmbuild --rebuild ''nameofpackage''*.src.rpm This is useful when a no binary package is available for a particular platform or distribution version, but an SRPM is available. = Creating a New Package = == Writing a specfile == # Run <code>rpmdev-newspec ''packagename''</code>in ~/rpmbuild/SPECS# Edit the skeleton specfile. Refer to the [[:fedora:PackageMaintainers/CreatingPackageHowTo|Packaging How-To]] for guidance. == Building the RPM == # <code>rpmbuild -ba ''packagename''.spec</code>#*** Source If successful, output will be binary RPM(s) in <code>~/rpmbuild/SOURCES RPMS</code> and specfile will be source RPM in <code>~/rpmbuild/SPECSSRPMS</code>#** Examine You can install binary RPM as root using this command: <code>rpm -i ''rpmfile''</code> or <code>yum localinstall ''rpmfile''</code>#* If unsuccessful, read the specfileerror messages carefully. ** Rebuild on Note that a successful build of a compiled binary will usually produce both a binary RPM and a ''debuginfo'' RPM. The debuginfo package contains additional information which is useful for debugging a problem, but which just takes up space when the local machine program is being used normally. Some spec files may produce multiple packages -- takes for example, they may produce separate packages for a game, game data, and documentation; or for a base package and additional plugins for use with that package; or for a source RPM base package and multiple user interfaces (SRPM) such as inputseparate command-line, graphical, produces binary and source RPMs as outputweb interfaces). This is done at the discretion of the spec file author where she decides that the user may want to install a subset of the package's features. *** {{Admon/note|Building to Different Points|The <code>rpmbuild -ba</code> argument means "build all". You can substitute different values to build to different points in the process: <code>-rebuild bp<i/code>nameofpackageto build to the prep stage, </icode>.src.rpm-bs</code>to build only a SRPM, and so forth. See the manpage for <rpmbuild" for details.}}** Building from == Testing the RPM == The ''rpmlint'' tool tests spec file -- takes a specfile and files, source code as inputRPMs, produces and binary and source RPMs as outputto verify that they were created in compliance with the Fedora packaging guidelines.*Test the spec file: <code>rpmlint ~/rpmbuild/SPECS/''packagename''*</code>* Test the source RPM: <code>cd rpmlint ~/rpmbuild/SPECS; rpmbuild -ba SRPMS/''packagename''*.src.rpm<i/code>nameofpackage* Test the binary RPMs: <code>rpmlint ~/rpmbuild/RPMS/*/i>''packagename''*.specrpm</code> Notice that the checks performed vary based on the input file. For example, some errors in the spec file (such as the summary ending in a period ".") could be determined from the spec file, but only show up when the SRPM/RPM is checked. Each run will report the number of errors and warnings; errors are serious problems which should not be ignored, while warnings may be ignored depending on the context. If you discover any errors, edit the specfile to correct them. If you need additional information on the error:* add the -i (information) option to the ''rpmlint'' command* see the [[:fedora:Common Rpmlint issues|Fedora Common Rpmlint issues]] page on the Fedora wiki = Common Challenges = Refer to these documents on the Fedora wiki for help on specific packaging challenges:* [[:fedora:Packaging:Guidelines|Packaging Guidelines]] - General packaging guidelines for Fedora, including instructions for specific languages and packaging cases* [[:fedora:Packaging:ScriptletSnippets|Scriptlet Snippets]] - Script(lets) that can be used in RPM packages to solve specific problems In particular, these sections are useful for GNU software:* [[:fedora:Packaging:ScriptletSnippets#Texinfo|Packaging .info (texinfo) documentation files]]* [[:fedora:Packaging:Guidelines#Handling_Locale_Files|Handling locale files (message translations)]]

Navigation menu