Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

RPMMacros.txt 6.3 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
  1. :last-reviewed: 2019-02-14
  2. :build-flags: link:https://src.fedoraproject.org/rpms/redhat-rpm-config/blob/master/f/buildflags.md[build flags documentation]
  3. = RPM Macros
  4. RPM provides a rich set of macros
  5. to make package maintenance simpler and consistent across packages.
  6. For example, it includes a list of default path definitions
  7. which are used by the build system macros,
  8. and definitions for RPM package build specific directories.
  9. They usually should be used instead of hard-coded directories.
  10. It also provides the default set of compiler flags as macros,
  11. which should be used when compiling manually and not relying on a build system.
  12. == Getting and setting Macros on the command line
  13. It's possible to let RPM evaluate arbitrary strings containing macros
  14. on the command line by running `rpm --eval` on the command line:
  15. ....
  16. $ rpm --eval "some text printed on %{_arch}"
  17. some text printed on x86_64
  18. ....
  19. Additionally, values for macros can be temporarily provided (and overridden)
  20. by providing command line options to `rpm` and `rpmbuild`:
  21. ....
  22. $ rpm --define "test Hello, World!" --eval "%{test}"
  23. Hello, World!
  24. ....
  25. [#macros_installation]
  26. == Macros for paths set and used by build systems
  27. The macros for build system invocations
  28. (for example, `%configure`, `%cmake`, or `%meson`)
  29. use the values defined by RPM to set installation paths for packages.
  30. So, it's usually preferable to not hard-code these paths in spec files either,
  31. but use the same macros for consistency.
  32. The values for these macros can be inspected
  33. by looking at `/usr/lib/rpm/platform/*/macros` for the respective platform.
  34. The following table lists macros which are widely used in fedora `.spec` files.
  35. [cols="20%m,30%m,50%",options="header"]
  36. |=================================
  37. | macro | definition | comment
  38. | +%{_sysconfdir}+ | /etc |
  39. | +%{_prefix}+ | /usr | can be defined to `/app` for flatpak builds
  40. | +%{_exec_prefix}+ | +%{_prefix}+ | default: `/usr`
  41. | +%{_includedir}+ | +%{_prefix}+/include | default: `/usr/include`
  42. | +%{_bindir}+ | +%{_exec_prefix}+/bin | default: `/usr/bin`
  43. | +%{_libdir}+ | +%{_exec_prefix}/%{_lib}+ | default: `+/usr/%{_lib}+`
  44. | +%{_libexecdir}+ | +%{_exec_prefix}+/libexec | default: `/usr/libexec`
  45. | +%{_datadir}+ | +%{_datarootdir}+ | default: `/usr/share`
  46. | +%{_infodir}+ | +%{_datarootdir}+/info | default: `/usr/share/info`
  47. | +%{_mandir}+ | +%{_datarootdir}+/man | default: `/usr/share/man`
  48. | +%{_docdir}+ | +%{_datadir}+/doc | default: `/usr/share/doc`
  49. | +%{_rundir}+ | /run |
  50. | +%{_localstatedir}+ | /var |
  51. | +%{_sharedstatedir}+ | /var/lib |
  52. | +%{_lib}+ | lib64 | `lib` on 32bit platforms
  53. |=================================
  54. Some seldomly used macros are listed below for completeness.
  55. Old `.spec` files might still use them,
  56. and there might be cases where they are still needed.
  57. [cols="20%m,30%m,50%",options="header"]
  58. |=================================
  59. | macro | definition | comment
  60. | +%{_datarootdir}+ | +%{_prefix}/share+ | default: `/usr/share`
  61. | +%{_var}+ | /var |
  62. | +%{_sbindir}+ | same as +%{_bindir}+ | historically `/usr/sbin`, now `/usr/bin`, provided for compatibility
  63. | +%{_tmppath}+ | +%{_var}/tmp+ | default: `/var/tmp`
  64. | +%{_usr}+ | /usr |
  65. | +%{_usrsrc}+ | +%{_usr}/src+ | default: `/usr/src`
  66. | +%{_initddir}+ | +%{_sysconfdir}/rc.d/init.d+ | default: `/etc/rc.d/init.d`
  67. | +%{_initrddir}+ | +%{_initddir}+ | old misspelling, provided for compatiblity
  68. |=================================
  69. == Macros set for the RPM (and SRPM) build process
  70. RPM also exposes the locations of several directories
  71. that are relevant to the package build process via macros.
  72. The only macro that's widely used in `.spec` files is `+%{buildroot}+`,
  73. which points to the root of the installation target directory.
  74. It is used for setting `DESTDIR` in the package's `%install` step.
  75. The other macros are usually only used outside `.spec` files.
  76. For example, they are set by `fedpkg` to override the default directories.
  77. [cols="20%m,60%m,20%",options="header"]
  78. |=================================
  79. | macro | definition | comment
  80. | +%{buildroot}+ | +%{_buildrootdir}/%{name}-%{version}-%{release}.%{_arch}+ | same as `$BUILDROOT`
  81. | +%{_topdir}+ | +%{getenv:HOME}/rpmbuild+ |
  82. | +%{_builddir}+ | +%{_topdir}/BUILD+ |
  83. | +%{_rpmdir}+ | +%{_topdir}/RPMS+ |
  84. | +%{_sourcedir}+ | +%{_topdir}/SOURCES+ |
  85. | +%{_specdir}+ | +%{_topdir}/SPECS+ |
  86. | +%{_srcrpmdir}+ | +%{_topdir}/SRPMS+ |
  87. | +%{_buildrootdir}+ | +%{_topdir}/BUILDROOT+ |
  88. |=================================
  89. == Macros providing compiler and linker flags
  90. The default build flags for binaries on fedora are also available via macros.
  91. They are used by the build system macros to setup the build environment,
  92. so it is usually not necessary to use them directly --
  93. except, for example, when doing bare bones compilation with `gcc` directly.
  94. The set of flags listed below reflects the current state of fedora 28
  95. on a `x86_64` machine, as defined in the file `/usr/lib/rpm/redhat/macros`.
  96. The `+%{optflags}+` macro contains flags that determine `CFLAGS`, `CXXFLAGS`,
  97. `FFLAGS`, etc. -- the `+%{__global_cflags}+` macro evaluates to the same string.
  98. The current definitions of these values
  99. can be found in the `redhat-rpm-config` package, in the {build-flags}.
  100. ....
  101. $ rpm --eval "%{optflags}"
  102. -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection
  103. ....
  104. The value of the `LDFLAGS` environment variable set by build systems
  105. is determined by the `+%{build_ldflags}+` macro:
  106. ....
  107. $ rpm -E "%{build_ldflags}"
  108. -Wl,-z,relro -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld
  109. ....
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...