From Fedora Project Wiki

(→‎RPM directory macros: add use case of the rpm directory macros)
(add several other issues: $buildroot, ordering, variables, unhandled issues, introductions, use case for rpm directory macros, %optflags)
Line 1: Line 1:
I propose the following changes:
I propose the following changes:
* Use an admon/important template to highlight the differences in EPEL 4 & 5
* Use an admon/important template to highlight the differences in EPEL 4 & 5
* change %{_optflag} to %{optflag}, which seems to be right according to <code>rpm --eval</code>and was mentioned in the discussion page of the original site
* change %{_optflag} to %{optflag}, which seems to be right according to <code>rpm --eval</code> and was mentioned in the discussion page of the original site
* Do not mention Fedora 10 or older, since it is EOL
* Do not mention Fedora 10 or older, since it is EOL
* Do not call Fedora 11 "Fedora Core 11", Core and Extras merged
* Do not call Fedora 11 "Fedora Core 11", Core and Extras merged
* Explain use case for rpm directory macros
* reorder macros: first macros to be used in specs, then the macros to be used in rpmbuild
* Add introductions to some sections
* add %buildroot
* add $RPM_OPT_FLAGS, $RPM_BUILD_ROOT - they are variables and not macros, but serve the same use case
* fix alignment in build flag macros
Uncovered issues:
* %{opflags} are out of sync for F12 (and probably F11, because there -march is set to i586 afaik):
** x86_64: <code>-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic</code>
** i386: <code>-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m32 -march=i686 -mtune=atom -fasynchronous-unwind-tables</code>
* having two macros for the same path is imho bad: <code>%{_var}</code> vs <code>%{_localstatedir}</code> and <code>%{_usr}</code> vs <code>%{_prefix}</code>




Line 35: Line 47:
* <code>%{_sharedstatedir}</code> expands to <code>%{_prefix}/com</code> in EPEL 4 & 5
* <code>%{_sharedstatedir}</code> expands to <code>%{_prefix}/com</code> in EPEL 4 & 5
}}
}}
=== Other macros and variables for paths ===
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.
<pre>
%{_var}              /var
%{_tmppath}          %{_var}/tmp
%{_usr}              /usr
%{_usrsrc}            %{_usr}/src
%{_docdir}            %{_datadir}/doc
%{_buildroot}        %{_buildrootdir}/%{name}-%{version}-%{release}
$RPM_BUILD_ROOT      %{_buildroot}
</pre>
=== Build flags macros and variables ===
These macros should be used as flags for the compiler or linker.
<pre>
%{_global_cflags}    -O2 -g -pipe
%{optflags}          %{__global_cflags} -m32 -march=i386 -mtune=pentium4 # if redhat-rpm-config is installed
$RPM_OPT_FLAGS      %{optflags}
</pre>


=== RPM directory macros ===
=== RPM directory macros ===
Line 51: Line 84:
}}
}}


=== 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>
%{_var}              /var
%{_tmppath}          %{_var}/tmp
%{_usr}              /usr
%{_usrsrc}            %{_usr}/src
%{_docdir}            %{_datadir}/doc
</pre>


== Reference ==
== Reference ==

Revision as of 13:41, 14 February 2010

I propose the following changes:

  • Use an admon/important template to highlight the differences in EPEL 4 & 5
  • change %{_optflag} to %{optflag}, which seems to be right according to rpm --eval and was mentioned in the discussion page of the original site
  • Do not mention Fedora 10 or older, since it is EOL
  • Do not call Fedora 11 "Fedora Core 11", Core and Extras merged
  • Explain use case for rpm directory macros
  • reorder macros: first macros to be used in specs, then the macros to be used in rpmbuild
  • Add introductions to some sections
  • add %buildroot
  • add $RPM_OPT_FLAGS, $RPM_BUILD_ROOT - they are variables and not macros, but serve the same use case
  • fix alignment in build flag macros

Uncovered issues:

  • %{opflags} are out of sync for F12 (and probably F11, because there -march is set to i586 afaik):
    • x86_64: -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic
    • i386: -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m32 -march=i686 -mtune=atom -fasynchronous-unwind-tables
  • having two macros for the same path is imho bad: %{_var} vs %{_localstatedir} and %{_usr} vs %{_prefix}


Valid RPM Macros

Here are the definitions for some common specfile macros as they are defined on Fedora 11 (rpm-4.7.0-1.fc11). 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.

Macros mimicking autoconf variables

%{_sysconfdir}        /etc
%{_prefix}            /usr
%{_exec_prefix}       %{_prefix}
%{_bindir}            %{_exec_prefix}/bin
%{_lib}               lib (lib64 on 64bit systems)
%{_libdir}            %{_exec_prefix}/%{_lib}
%{_libexecdir}        %{_exec_prefix}/libexec
%{_sbindir}           %{_exec_prefix}/sbin
%{_sharedstatedir}    /var/lib
%{_datadir}           %{_prefix}/share
%{_includedir}        %{_prefix}/include
%{_oldincludedir}     /usr/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

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
%{_docdir}            %{_datadir}/doc
%{_buildroot}         %{_buildrootdir}/%{name}-%{version}-%{release}
$RPM_BUILD_ROOT       %{_buildroot}

Build flags macros and variables

These macros should be used as flags for the compiler or linker.

%{_global_cflags}    -O2 -g -pipe
%{optflags}          %{__global_cflags} -m32 -march=i386 -mtune=pentium4 # if redhat-rpm-config is installed
$RPM_OPT_FLAGS       %{optflags}


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


Reference

Here are macros from other distributions to aid you in package conversion: