Packaging:RPMMacros

From FedoraProject

(Difference between revisions)
Jump to: navigation, search
m (1 revision(s))
m (fix _buildroot thinko)
 
(7 intermediate revisions by 3 users not shown)
Line 1: Line 1:
<!-- page was renamed from Extras/RPMMacros
+
== Valid RPM Macros ==
-->
+
= Valid RPM Macros =
+
  
Here are the definitions for some common specfile macros as they are defined on Fedora Core 3 (rpm-4.3.2-21). For definitions of more macros, examine the output of "<code>rpm --showrc</code>". To see the expanded definition of a macro use the command "<code>rpm --eval '</code>'''%{macro}'''<code>'</code>".  Note that neither command will take into account macros defined inside specfiles, but both will take into account macros defined in your <code>~/.rpmmacros</code> file and macros defined on the command line.
+
Here are the definitions for some common specfile macros as they are defined on Fedora 13 (rpm-4.8.0-14.fc13). For definitions of more macros, examine the output of "<code>rpm --showrc</code>". To see the expanded definition of a macro use the command <code>rpm --eval "%{macro}"</code>.  Note that neither command will take into account macros defined inside specfiles, but both will take into account macros defined in your <code>~/.rpmmacros</code> file and macros defined on the command line.
  
 +
Keep in mind that some of these macros may evaluate differently on older Fedora or EPEL releases.
  
 
=== Macros mimicking autoconf variables ===
 
=== Macros mimicking autoconf variables ===
 
<pre>
 
<pre>
 
%{_sysconfdir}        /etc
 
%{_sysconfdir}        /etc
%{_initrddir}        %{_sysconfdir}/rc.d/init.d
 
 
%{_prefix}            /usr
 
%{_prefix}            /usr
 
%{_exec_prefix}      %{_prefix}
 
%{_exec_prefix}      %{_prefix}
 
%{_bindir}            %{_exec_prefix}/bin
 
%{_bindir}            %{_exec_prefix}/bin
%{_lib}              lib (lib64 on 64bit systems)
 
 
%{_libdir}            %{_exec_prefix}/%{_lib}
 
%{_libdir}            %{_exec_prefix}/%{_lib}
 
%{_libexecdir}        %{_exec_prefix}/libexec
 
%{_libexecdir}        %{_exec_prefix}/libexec
 
%{_sbindir}          %{_exec_prefix}/sbin
 
%{_sbindir}          %{_exec_prefix}/sbin
%{_sharedstatedir}    %{_prefix}/com
+
%{_sharedstatedir}    /var/lib
%{_datadir}          %{_prefix}/share
+
%{_datarootdir}      %{_prefix}/share
 +
%{_datadir}          %{_datarootdir}
 
%{_includedir}        %{_prefix}/include
 
%{_includedir}        %{_prefix}/include
%{_oldincludedir}    /usr/include
 
 
%{_infodir}          /usr/share/info
 
%{_infodir}          /usr/share/info
 
%{_mandir}            /usr/share/man
 
%{_mandir}            /usr/share/man
 
%{_localstatedir}    /var
 
%{_localstatedir}    /var
 +
%{_initddir}          %{_sysconfdir}/rc.d/init.d
 
</pre>
 
</pre>
 +
{{admon/important|Differences in EPEL 4 & 5|
 +
* <code>%{_initddir}</code> does not exist in EPEL 4 & 5, use the deprecated <code>%{_initrddir}</code> macro instead
 +
* <code>%{_sharedstatedir}</code> expands to <code>%{_prefix}/com</code> in EPEL 4 & 5
 +
}}
  
=== RPM directory macros ===
+
=== Other macros and variables for paths ===
<pre>
+
These macros should be used for paths that are not covered by the macros mimicking autoconf variables. The <code>%{buildroot}</code> macro or the <code>$RPM_BUILD_ROOT</code> variable is the directory that should be assumed to be the root file system when installing files. Is is used as the value for the <code>DESTDIR</code> variable.
%{_topdir}           %{_usrsrc}/redhat
+
%{_builddir}          %{_topdir}/BUILD
+
%{_rpmdir}            %{_topdir}/RPMS
+
%{_sourcedir}        %{_topdir}/SOURCES
+
%{_specdir}          %{_topdir}/SPECS
+
%{_srcrpmdir}        %{_topdir}/SRPMS
+
</pre>
+
 
+
=== Build flags macros ===
+
<pre>
+
%{_global_cflags}    -O2 -g -pipe
+
%{_optflags}          %{__global_cflags} -m32 -march=i386 -mtune=pentium4 # if redhat-rpm-config is installed
+
</pre>
+
 
+
=== Other macros ===
+
 
<pre>
 
<pre>
 
%{_var}              /var
 
%{_var}              /var
Line 48: Line 35:
 
%{_usr}              /usr
 
%{_usr}              /usr
 
%{_usrsrc}            %{_usr}/src
 
%{_usrsrc}            %{_usr}/src
 +
%{_lib}              lib (lib64 on 64bit multilib systems)
 
%{_docdir}            %{_datadir}/doc
 
%{_docdir}            %{_datadir}/doc
 +
%{buildroot}          %{_buildrootdir}/%{name}-%{version}-%{release}.%{_arch}
 +
$RPM_BUILD_ROOT      %{buildroot}
 
</pre>
 
</pre>
  
== Reference ==
+
=== Build flags macros and variables ===
Here are macros from other distributions to aid you in package conversion:
+
These macros should be used as flags for the compiler or linker. Note that the values for the macros below reflect the settings on Fedora 13 (i686) with redhat-rpm-config installed.
 +
 
 +
<pre>
 +
%{__global_cflags}  -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4
 +
%{optflags}          %{__global_cflags} -m32 -march=i686 -mtune=atom -fasynchronous-unwind-tables
 +
$RPM_OPT_FLAGS      %{optflags}
 +
</pre>
 +
 
 +
 
 +
=== RPM directory macros ===
 +
The macros are usually used with <code>rpmbuild --define</code> to specify which directories rpmbuild should use, it is unusual to use them within SPEC files.
 +
<pre>
 +
%{_topdir}            %{getenv:HOME}/rpmbuild
 +
%{_builddir}          %{_topdir}/BUILD
 +
%{_rpmdir}            %{_topdir}/RPMS
 +
%{_sourcedir}        %{_topdir}/SOURCES
 +
%{_specdir}          %{_topdir}/SPECS
 +
%{_srcrpmdir}        %{_topdir}/SRPMS
 +
%{_buildrootdir}      %{_topdir}/BUILDROOT
 +
</pre>
 +
{{admon/important|Differences in EPEL 4 & 5|
 +
* <code>%{_buildrootdir}</code> does not exist in EPEL 4 & 5
 +
}}
  
* [[Extras/ReferencePLDRPMMacros| PLD RPM Macros]]
+
[[Category:Packaging guidelines]]
* [[Extras/ReferenceMandrakeRPMMacros| Mandrake RPM Macros]]
+
----
+
[[Category:Extras]]
+

Latest revision as of 18:55, 19 December 2011

Contents

[edit] Valid RPM Macros

Here are the definitions for some common specfile macros as they are defined on Fedora 13 (rpm-4.8.0-14.fc13). For definitions of more macros, examine the output of "rpm --showrc". To see the expanded definition of a macro use the command rpm --eval "%{macro}". Note that neither command will take into account macros defined inside specfiles, but both will take into account macros defined in your ~/.rpmmacros file and macros defined on the command line.

Keep in mind that some of these macros may evaluate differently on older Fedora or EPEL releases.

[edit] Macros mimicking autoconf variables

%{_sysconfdir}        /etc
%{_prefix}            /usr
%{_exec_prefix}       %{_prefix}
%{_bindir}            %{_exec_prefix}/bin
%{_libdir}            %{_exec_prefix}/%{_lib}
%{_libexecdir}        %{_exec_prefix}/libexec
%{_sbindir}           %{_exec_prefix}/sbin
%{_sharedstatedir}    /var/lib
%{_datarootdir}       %{_prefix}/share
%{_datadir}           %{_datarootdir}
%{_includedir}        %{_prefix}/include
%{_infodir}           /usr/share/info
%{_mandir}            /usr/share/man
%{_localstatedir}     /var
%{_initddir}          %{_sysconfdir}/rc.d/init.d
Important.png
Differences in EPEL 4 & 5
  • %{_initddir} does not exist in EPEL 4 & 5, use the deprecated %{_initrddir} macro instead
  • %{_sharedstatedir} expands to %{_prefix}/com in EPEL 4 & 5

[edit] Other macros and variables for paths

These macros should be used for paths that are not covered by the macros mimicking autoconf variables. The %{buildroot} macro or the $RPM_BUILD_ROOT variable is the directory that should be assumed to be the root file system when installing files. Is is used as the value for the DESTDIR variable.

%{_var}               /var
%{_tmppath}           %{_var}/tmp
%{_usr}               /usr
%{_usrsrc}            %{_usr}/src
%{_lib}               lib (lib64 on 64bit multilib systems)
%{_docdir}            %{_datadir}/doc
%{buildroot}          %{_buildrootdir}/%{name}-%{version}-%{release}.%{_arch}
$RPM_BUILD_ROOT       %{buildroot}

[edit] Build flags macros and variables

These macros should be used as flags for the compiler or linker. Note that the values for the macros below reflect the settings on Fedora 13 (i686) with redhat-rpm-config installed.

%{__global_cflags}   -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4
%{optflags}          %{__global_cflags} -m32 -march=i686 -mtune=atom -fasynchronous-unwind-tables
$RPM_OPT_FLAGS       %{optflags}


[edit] RPM directory macros

The macros are usually used with rpmbuild --define to specify which directories rpmbuild should use, it is unusual to use them within SPEC files.

%{_topdir}            %{getenv:HOME}/rpmbuild
%{_builddir}          %{_topdir}/BUILD
%{_rpmdir}            %{_topdir}/RPMS
%{_sourcedir}         %{_topdir}/SOURCES
%{_specdir}           %{_topdir}/SPECS
%{_srcrpmdir}         %{_topdir}/SRPMS
%{_buildrootdir}      %{_topdir}/BUILDROOT
Important.png
Differences in EPEL 4 & 5
  • %{_buildrootdir} does not exist in EPEL 4 & 5