Macros de RPM
RPM proporciona un amplio conjunto de macros para simplificar y homogeneizar el mantenimiento de los paquetes. Por ejemplo, incluye una lista de definiciones de rutas predeterminadas que utilizan las macros del sistema de compilación, así como definiciones para los directorios específicos de compilación de paquetes RPM. Generalmente, se recomienda usar estas definiciones en lugar de directorios codificados. También proporciona el conjunto predeterminado de opciones de compilación como macros, que deben usarse al compilar manualmente y no depender de un sistema de compilación.
Obtener y configurar Macros en la línea de instrucción
Es posible dejar la evaluación de RPM de cadenas arbitrarias conteniendo macros en la línea de comando ejecutando rpm --eval en la línea de comando:
$ rpm --eval "some text printed on %{_arch}"
some text printed on x86_64
Additionally, values for macros can be temporarily provided (and overridden) by providing command line options to rpm and rpmbuild:
$ rpm --define "test Hello, World!" --eval "%{test}"
Hello, World!
Macros for paths set and used by build systems
The macros for build system invocations (for example, %configure, %cmake, or %meson) use the values defined by RPM to set installation paths for packages. So, it’s usually preferable to not hard-code these paths in spec files either, but use the same macros for consistency.
The values for these macros can be inspected by looking at /usr/lib/rpm/platform/*/macros for the respective platform.
The following table lists macros which are widely used in fedora .spec files.
| macro | definition | comment |
|---|---|---|
|
|
|
|
|
can be defined to |
|
|
default: |
|
|
default: |
|
|
default: |
|
|
default: |
|
|
default: |
|
|
default: |
|
|
default: |
|
|
default: |
|
|
default: |
|
|
|
|
|
|
|
|
|
|
|
|
Some seldomly used macros are listed below for completeness. Old .spec files might still use them, and there might be cases where they are still needed.
| macro | definition | comment |
|---|---|---|
|
|
default: |
|
|
|
|
|
historically |
|
|
default: |
|
|
|
|
|
default: |
|
|
default: |
|
|
old misspelling, provided for compatiblity |
Macros set for the RPM (and SRPM) build process
RPM also exposes the locations of several directories that are relevant to the package build process via macros.
The only macro that’s widely used in .spec files is %{buildroot}, which points to the root of the installation target directory. It is used for setting DESTDIR in the package’s %install step.
The other macros are usually only used outside .spec files. For example, they are set by fedpkg to override the default directories.
| macro | definition | comment |
|---|---|---|
|
|
same as |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Macros proporcionen indicadores de compilador y enlazados
The default build flags for binaries on fedora are available via macros. They are used by the build system macros to setup the build environment, so it is usually not necessary to use them directly — except, for example, when doing bare bones compilation with gcc directly.
The set of flags listed below reflects the current state of fedora 42 on a x86_64 machine, as defined in the file /usr/lib/rpm/redhat/macros.
The %{optflags} macro contains flags that determine CFLAGS, CXXFLAGS, FFLAGS, etc.
Las definiciones actual de estos valores pueden ser encontrados dentro del paquete redhat-rpm-config, en el build flags documentation.
$ rpm --eval "%{optflags}"
-O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Wno-complain-wrong-lang -Werror=format-security -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -march=x86-64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -mtls-dialect=gnu2 -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer
El valor de la variable del entorno LDFLAGS fijado por sistemas de compilación está determinado por la macro %{build_ldflags}:
$ rpm -E "%{build_ldflags}"
-Wl,-z,relro -Wl,--as-needed -Wl,-z,pack-relative-relocs -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -Wl,--build-id=sha1
Want to help? Learn how to contribute to Fedora Docs ›