Changes

Jump to: navigation, search

RPM spec File Contents

6,952 bytes added, 09:08, 13 January 2011
no edit summary
[[Category:SBR600]][[Category:RPM]]
These are the basic sections of a spec file:
* A spec file is the file that contains metadata and scripting necessary to build an RPM. In essence, it defines the RPM. = Basic Sections=# preamble - basic metadata, including:#* Name - name of the software package (e.g., "bash")#* Epoch - the ''era'' of the software (optional, and rarely used). See [[ENVR]]#* Version - version of the software, as identified by the software source (1.5)#* Release - release of the package, as identified by the packager (1, 2, 3, ...; or 1.fc16; or 1.ct)#* Summary - a one-line description of the software (avoid trailing periods)#* Group - software group (general classification of the package) - see <code>/usr/share/doc/rpm-*/GROUPS</code> for a list of valid group names#* License - the license under which the package is provided (GPLv2, GPLv2+, GPLv3, GPLv3+, BSD, ASL, MSL, ...)#* URL - the web location of the package's main site#* Source (Source0, Source1, ...) - the URL (preferred) of the source package. The filename portion of the Source must match the filename present in the <code>~/rpmbuild/SOURCES</code> directory#* BuildRoot - Location where the software will be installed. Note that this is automatically set up by <code>rpmdev-newspec</code> and should not be changed. Depracated and ignored in new versions of RPM#* BuildRequires - packages and capabilities required to build the software. For example, software written in fortran might require the gfortran package in order to be built successfully, but may not require gfortran to be installed for use. A very basic set of build capabilities is always assumed (including bash, make, gcc, and ld)#* Requires - packages and capabilities required to install and use the software. For example, software written in Python will require the Python interpreter, and web applications will require a web server#* %description - a detailed, multi-line description of the package# %prep - commands to prepare the package for building. This might include operations such as untarring or unzipping the archive and applying any patch files# %build - commands to build the package, such as compiling, linking, building game data, processing sound/video/font files, and so forth# %install - commands to install the built files. These files will be installed into the buildroot rather than into the actual destination location. For example, files that will ultimately be installed into /usr/bin are installed into $RPM_BUILD_ROOT/usr/bin during the install process (usually written using macros as <code>%{buildroot}/%{_bindir}</code>). The installation is typically done by a <code>make install DESTDIR=$RPM_BUILD_ROOT</code> command, but if the software has no ''make install'' capability, this section may consist of a series of commands to create directories and copy files to the correct location. Everything installed in the buildroot must ultimately be included in the binary RPM, so any files that are not desired are deleted during the install phase of the build# %check - commands to check/test the built files (optional, often not included). If the upstream software includes automated tests, they should be executed in this section# %clean - commands to clean up the disk space- this section is deprecated and will not be used in new versions of RPM. The commands created by ''rpmdev-newspec'' are sufficient and should not be changed# %files - list of files to be included in the pacakgepackage. Every file in the buildroot must be specified here so that it is included in the binary RPM. In addition, any documentation files in the original source archive that should be included, such as a README file or license text, must be identified with the ''%doc'' macro. Configuration files must be identified with the ''%config(replace)'' or ''%config(noreplace)'' macros# %changelog - record of the package's change-history. Each new* = Scriptlets= Short script segments which are executed when the RPM is installed or removed. Each script is placed in its own section, with an identifying macro:** %pre -- run before installation** %post -- run after installation** %preun -- run before uninstallation** %postun -- run after uninstallation*** Note that during upgrade, the installation of the new package is considered to happen before the removal of the old package.* = Triggers = Triggers are scripts that are executed when another, related RPM is installed or removed. The use of triggers should be avoided. = Macros = Macros are a type of text variable that get substituted into the spec file in place of the variable name. For example, if the macro ''foo'' is defined:  %foo 3 The this line:  Release: %{foo} Is evaluated as:  Release: 3 Macros can be as short as null (nothing) or as long as several pages of text. Confusingly, they are used both as variables and as procedures or functions. == Common Procedure Macros==** %setup - a macro used in the %configure section which performs the customary steps of unpacking the tarball (or zip file) for Source0 and then changing into the directory identified by %{name}-%{_tmppathversion}. For example, if the name of the package is ''foo'' and the version is ''1.2'', then the %setup macro will unpack that tarball and change to the directory <code>foo-1.2</code>. However, if the source archive is was not originally designed to unpack in this way, then the behaviour of %setup can be modified using options -- see the [[:fedora:PackageMaintainers/CreatingPackageHowTo#.25prep_section:_.25setup_command|details on the Fedora wiki]]* %configure - a macro which executes a ./configure script.* %makeinstall - a macro which runs ''make install'' with appropriate arguments. This is deprecated and should not be used == Common Variable Macros == * Macros used to hold paths:** %{buildroot}- equivalent to the RPM_BUILD_ROOT environment variable - contains the name of the directory into which files will be installed before packaging** %{_bindir}- /usr/bin** %{_datadir}- /usr/share** %{_mandir}- /usr/share/man* Macros containing flags passed to ''make'' and ''cc'' or ''gcc'':** %{_smp_flags} - passed to ''make'' to execute jobs in parallel. Usually defined in <code>~/.rpmmacros</code>** %{optflags} - options for the ''gcc'' compiler. Usually passed to ''make'' as CCOPTIONS: <code>make CCOPTIONS="%{optflags} -c" ${_smp_flags}* Macros containing information from the metadata section of the spec file:** %{name}** %{version}** %{release}** ...etc...* Macros used in the %files section:** %setupdefattr() - sets default file attributes for files in the binary RPM. Four attributes are placed in the parenthesis: permissions for files (or - to use the permissions already present on the files), owner of files and directories, group of files and directories, permissions for directories (or - to use the permissions already present on the files). Example: <code>%defattr(-,root,root,-)</code> will keep file and directory permissions, and will make ''root'' the owner and group for all packaged files** %attr() - like %defattr but affects only files listed on the same line** %configuredoc - all files listed on this line will be treated as documentation. These files are not typically located in the buildroot, but are found in the source archive (for example: README.txt, INSTALL, COPYING)** %makeinstallconfig(replace) and %config(noreplace) - marks files as config files. Config files marked as ''replace'' are installed in place of the previous config file when the software is upgraded, after renaming the previous config file <code>''name''.rpmold</code>; those marked as ''noreplace'' are saved as <code>''name''.rpmnew</code> - therefore, config files which are compatible with the previous version of the software should be marked as ''noreplace'', while config files which are incompatible with the previous version of the software should be marked as ''replace''

Navigation menu