]> git.pld-linux.org Git - packages/rpm-pld-macros.git/blame - macros.pld
- version 1.752: "noarchpackage" macro to cut down boilerplate
[packages/rpm-pld-macros.git] / macros.pld
CommitLineData
7982022e
ER
1# vim:ts=4 sw=4 noet ft=spec
2#
f51bfb2f
ER
3# PLD Linux rpm macros.
4# <http://www.pld-linux.org/>
d54662bf 5
2b05614d 6# can be used by builder script to check for version
2fb1b7ce 7%rpm_build_macros {Revision}
98c5c988 8
e05017c1 9%epoch 0
3241033b 10%x8664 x86_64 amd64 ia32e
9c404149 11
46763914 12# compiler version
eab5f7f4
ER
13%cc_version %{expand:%%global cc_version %(%{__cc} -dumpversion 2>/dev/null || echo 0.0)}%cc_version
14%cxx_version %{expand:%%global cxx_version %(%{__cxx} -dumpversion 2>/dev/null || echo 0.0)}%cxx_version
46763914 15
69bcfbf3 16%__rm /bin/rm --interactive=never
36eccf0d 17
33040789 18# Build system path macros.
69bcfbf3
ER
19%__autoconf autoconf %{?debug:-Wall}
20%__automake automake -a -c -f --foreign
21%__autopoint autopoint --force
22
23# add parallel build flags: -jN
82f23c63 24# jobs macro is available since 1.657
a5656a95 25#
11ecb0a1 26# if you want to disable parallel build do:
82f23c63 27# echo '%__jobs %{nil}' >> ~/.rpmmacros
799bf7ab 28%__jobs %{expand:%%global __jobs %(_NCPUS=$(/usr/bin/getconf _NPROCESSORS_ONLN); [ "$_NCPUS" -gt 3 ] && echo $(($_NCPUS / 2)))%%{nil}}%__jobs
82f23c63
ER
29
30# expands to -jN if %__jobs has a value
31%_smp_mflags %{expand:%%global _smp_mflags %(jobs=%{__jobs}; echo ${jobs:+-j$jobs}%%{nil})}%_smp_mflags
32
8579c486 33%__make /usr/bin/make %{?_make_opts} %{?_smp_mflags}
11ecb0a1
ER
34%__scons /usr/bin/scons %{?_smp_mflags}
35%__waf /usr/bin/waf %{?_smp_mflags}
fa16fde1 36%__cmake /usr/bin/cmake -Wno-dev
f72d45c4 37%__meson /usr/bin/meson
9cfca9d1
AM
38%__meson_wrap_mode nodownload
39%__ninja /usr/bin/ninja
40%__ninja_common_opts -v %{?_smp_mflags}
a5656a95 41
83094b62 42%__gettextize { \
b8dd0565 43 gettextize --copy --force --no-changelog; \
8a995cff 44 if [ ! -f po/Makevars ]; then \
3241033b 45 cp -f po/Makevars{.template,}; \
8a995cff 46 fi; \
8a995cff 47}
f93109a0 48
49%__glib_gettextize glib-gettextize --copy --force
50%__gnome_doc_common gnome-doc-common --copy
fb59e475 51%__gnome_doc_prepare gnome-doc-prepare --copy --force
f93109a0 52%__gtkdocize gtkdocize --copy
53%__intltoolize intltoolize --copy --force
c26f1b59 54%__libtoolize libtoolize --copy --force --install
33040789 55
751c2bdd
ER
56# topdir is where builder script lives,
57# fallback to old style if SPECS/SOURCES dirs were found.
58%_topdir %{expand:%%global _topdir %(
59 if [ -d SPECS -a -d SOURCES ]; then
60 # old style rpmdir: in topdir
df3151c2 61 pwd
751c2bdd
ER
62 elif [ -d ../SPECS -a -d ../SOURCES ]; then
63 # old style rpmdir: in subdir
df3151c2 64 cd ..; pwd
751c2bdd
ER
65 elif [ -d $HOME/rpm/SPECS -a -d $HOME/rpm/SOURCES ]; then \
66 # if old style rpm dir exist, go with it
67 echo $HOME/rpm; \
68 elif [ -x ../builder -a ! -d ../builder ]; then
69 # relative new style rpmdir: in package dir
df3151c2 70 cd ..; pwd
751c2bdd
ER
71 elif [ -x builder -a ! -d builder ]; then
72 # relative new style rpmdir: in packages
df3151c2 73 pwd
751c2bdd
ER
74 elif [ -x packages/builder -a ! -d packages/builder ]; then
75 # relative new style rpmdir: packages dir in current dir
df3151c2 76 cd packages; pwd
751c2bdd
ER
77 else
78 # fallback to new style rpmdir
79 echo $HOME/rpm/packages
80 fi; \
81)}%_topdir
1052b4b8 82
751c2bdd 83# if %{_topdir}/SPECS exists, it's old style structure
3303369c 84%_specdir %{expand:%%global _specdir %([ ! -d %{_topdir}/SPECS ] && echo %{_topdir}/%{name} || echo %{_topdir}/SPECS)}%_specdir
751c2bdd 85%_sourcedir %{expand:%%global _sourcedir %([ ! -d %{_topdir}/SOURCES ] && echo %{_specdir} || echo %{_topdir}/SOURCES)}%_sourcedir
1052b4b8 86
af9d1e61 87# BUILD/RPMS/SRPMS are on same level by default as packages dir, if these exist
1052b4b8
ER
88# if they don't exist assume we are having custom topdir (which is not named as
89# "packages", i.e ~/rpm/kde/{kdelibs,BUILD/RPMS/SRPMS})
af9d1e61 90# NOTE: readlink fails if some parent dir is not readable (/home/services/builder for example can't read /home/services), therefore the extra echo
df3151c2
ER
91%_builddir %{expand:%%global _builddir %(if [ -d %{_topdir}/BUILD ]; then echo %{_topdir}/BUILD; else readlink -m %{_topdir}/../BUILD || echo %{_topdir}/../BUILD; fi)}%_builddir
92%_rpmdir %{expand:%%global _rpmdir %(if [ -d %{_topdir}/RPMS ]; then echo %{_topdir}/RPMS; else readlink -m %{_topdir}/../RPMS || echo readlink -m %{_topdir}/../RPMS; fi)}%_rpmdir
93%_srcrpmdir %{expand:%%global _srcrpmdir %(if [ -d %{_topdir}/SRPMS ]; then echo %{_topdir}/SRPMS; else readlink -m %{_topdir}/../SRPMS || echo readlink -m %{_topdir}/../SRPMS; fi)}%_srcrpmdir
384e1b2b 94
81e450f7
ER
95# The number of cvs changelog entries kept when building package.
96%_buildchangelogtruncate 20
97
6a5eda77 98%dependencytracking %{nil}
3241033b 99
e5da9169
ER
100# Relations between package names that cause dependency loops
101# with legacy packages that cannot be fixed. Relations are
102# specified as
103# p>q
104# where package p has a Requires: on something that package q Provides:
105#
106# XXX Note: that there cannot be any whitespace within the string "p>q",
107# and that both p and q are package names (i.e. no version/release).
108%_dependency_whiteout %{nil}
109
810fa5c4 110#-----------------------------------------------------------------
111#
112# (re)definition of %{rpm*flags} with %filterout_* support
b5e977c5
ER
113# BuildRequires: awk
114# BuildRequires: rpmbuild(macros) >= 1.315
810fa5c4 115#
116# Flags specified in %filterout_* are removed from %rpm*flags, exactly:
09a90176 117# %rpmcflags = %optflags - %filterout - %filterout_c - %filterout_ld
118# %rpmcxxflags = %optflags - %filterout - %filterout_cxx - %filterout_ld
98e7f050 119# %rpmcppflags = %optcppflags - %filterout - %filterout_cpp - %filterout_ld
09a90176 120# %rpmldflags = %optldflags - %filterout_ld
810fa5c4 121#
122# Regular expressions are supported, but to avoid some character be treated
123# as regular expression it must be escaped twice.
124
048f3050
JR
125%filter_out \
126 for (i = 1; i in I; i++) { A=0; \
810fa5c4 127 for (f in F) { \
128 if (I[i] ~ "^" F[f] "$") A=1; \
129 }; \
130 if (!A) printf(I[i] FS); \
131 }
132
133%rpmcflags %(awk 'BEGIN {
134 split("%{?debug:%debugcflags}%{!?debug:%optflags}%{?debuginfocflags}",I);
09a90176 135 split("%{?filterout} %{?filterout_c} %{?filterout_ld}",F);
810fa5c4 136 %{filter_out}
137}')
138
139%rpmcxxflags %(awk 'BEGIN {
09a90176 140 split("%{?debug:%debugcflags}%{!?debug:%optflags}%{?debuginfocflags}",I);
141 split("%{?filterout} %{?filterout_cxx} %{?filterout_ld}",F);
810fa5c4 142 %{filter_out}
143}')
144
98e7f050
AM
145%rpmcppflags %(awk 'BEGIN {
146 split("%{?debug:%debugcppflags}%{!?debug:%optcppflags}%{?debuginfocppflags}",I);
147 split("%{?filterout} %{?filterout_cpp} %{?filterout_cpp}",F);
148 %{filter_out}
149}')
150
810fa5c4 151%rpmldflags %(awk 'BEGIN {
c05a0741 152 split("%{?optldflags}",I);
810fa5c4 153 split("%{?filterout_ld}",F)
154 %{filter_out}
155}')
156
25f52d1a 157# rpmldflags with stripped -Wl, -- in the form flags have to be passed to 'ld'
158# but, don't use it, better use gcc as linker
159%ld_rpmldflags %(awk 'BEGIN {
160 split("%{rpmldflags}",F);
161 for (f in F) {
162 s = F[f];
163 if (s ~ /^-Wl,/) {
164 s = substr(s,5);
165 gsub(/,/," ",s);
166 };
167 printf(s FS);
168 };
169}')
170
8ef644e5 171#-----------------------------------------------------------------
172#
173# Generate a command which cleans environment, leaving only the
174# most important variables.
175# If any spec requires any additional environment it should
176# redefine %_preserve_env in following manner:
177#
178# # ADDITIONAL_VAR is required because [a good reason here]
82d10503 179# %define _preserve_env ADDITIONAL_VAR
8ef644e5 180
57ba0f59 181%_preserve_env_base PATH HOME TMP TMPDIR SSH_AUTH_SOCK
8ef644e5 182
bb597f2b 183# "env -i" must end in first line of expaned macros because it's used as first line of shell script (#! env...)
7c0a3893
MK
184%_clean_env env -i %(awk -vq="'" -vqq="\\"'\\"" -vq2q="'\\"'" 'BEGIN {
185 split("%{?_preserve_env:%_preserve_env %_preserve_env_base}%{!?_preserve_env:%_preserve_env_base}", P);
a363d727
ER
186 for (i in P) {
187 p = P[i];
82d10503
ER
188 if (!ENVIRON[p] || d[p]) {
189 continue;
8ef644e5 190 }
82d10503
ER
191 d[p] = 1;
192 split(ENVIRON[p], V, "");
193 val = p "=";
194 for (j = 1; j in V; j++) {
195 v = V[j];
196 if (v == q)
197 v = qq;
198 else if (v == "\\"")
199 v = q2q;
200 else if (v == "\\\\")
201 v = "\\\\\\\\";
202 else
203 gsub("[^a-zA-Z0-9/:._-]", "\\"&\\"", v);
204 val = val "" v;
205 }
206 printf(val " ");
8ef644e5 207 }
208}')
209
dd64e428
JK
210# override %__spec_build_pre and %__spec_install_pre from macros.rpmbuild
211# adding %{_clean_env}
212%__spec_build_pre %{_clean_env}\
213%{___build_pre}\
214%{nil}
215%__spec_install_pre %{_clean_env}\
216%{___build_pre}\
217%{?buildroot:%{__rm} -rf '%{buildroot}'; %{__mkdir_p} '%{buildroot}'}\
218%{nil}
219
9c404149 220#-----------------------------------------------------------------
9f4ce098 221%configure2_13 { \
9c404149
AM
222 if [ -n "$LINGUAS" ]; then unset LINGUAS; fi; \
223 LDFLAGS="${LDFLAGS:-%rpmldflags}" ; export LDFLAGS ; \
224 CFLAGS="${CFLAGS:-%rpmcflags}" ; export CFLAGS ; \
f4cc8832 225 CXXFLAGS="${CXXFLAGS:-%rpmcxxflags}" ; export CXXFLAGS ; \
9c404149 226 FFLAGS="${FFLAGS:-%rpmcflags}" ; export FFLAGS ; \
e9d801f4 227 FCFLAGS="${FCFLAGS:-%rpmcflags}" ; export FCFLAGS ; \
98e7f050 228 CPPFLAGS="${CPPFLAGS:-%rpmcppflags}" ; export CPPFLAGS ; \
8983c4c4
AM
229 %{?__cc:CC="%{__cc}" ; export CC ; } \
230 %{?__cxx:CXX="%{__cxx}" ; export CXX ; } \
8f74418b 231 %{?configuredir:%{configuredir}}%{!?configuredir:.}/configure \
2a7cfd3f 232 --host=%{_target_platform} \
048f3050 233 --prefix=%{_prefix} \
9c404149
AM
234 --exec-prefix=%{_exec_prefix} \
235 --bindir=%{_bindir} \
236 --sbindir=%{_sbindir} \
237 --sysconfdir=%{_sysconfdir} \
238 --datadir=%{_datadir} \
239 --includedir=%{_includedir} \
240 --libdir=%{_libdir} \
241 --libexecdir=%{_libexecdir} \
242 --localstatedir=%{_localstatedir} \
243 --sharedstatedir=%{_sharedstatedir} \
244 --mandir=%{_mandir} \
245 --infodir=%{_infodir} \
b6c5da52 246 --x-libraries=%{?_x_libraries}%{!?_x_libraries:%{_libdir}} \
93059874 247 %{dependencytracking} \
9c404149
AM
248}
249
b6ce5bb6
JB
250# Note: pass only standard cmake macros here.
251# The only exception is SYSCONF_INSTALL_DIR, used commonly in KDE packages,
252# where the default (${CMAKE_INSTALL_PREFIX}/etc) is not FHS-compliant and
253# absolute path MUST be used to comply with FHS.
254# The other non-standard cmake macros used commonly in KDE
255# (INCLUDE_INSTALL_DIR, LIB_INSTALL_DIR, SHARE_INSTALL_PREFIX)
256# have sane default values in KDE, and some packages use these names
257# in different way (e.g. expect them to be always relative or always
258# absolute).
c4a85bd8 259%cmake \
018307da
ER
260%{?__cc:CC="${CC:-%{__cc}}"} \\\
261%{?__cxx:CXX="${CXX:-%{__cxx}}"} \\\
d41caea6 262CPPFLAGS="${CPPFLAGS:-%{rpmcppflags}}" \\\
c4a85bd8 263%{__cmake} \\\
8736ae44 264 -DCMAKE_VERBOSE_MAKEFILE=ON \\\
547ff095 265 -DCMAKE_BUILD_TYPE=%{!?debug:PLD}%{?debug:Debug} \\\
e23de4fc
AM
266 -DCMAKE_INSTALL_BINDIR:PATH=%{_bindir} \\\
267 -DCMAKE_INSTALL_SBINDIR:PATH=%{_sbindir} \\\
268 -DCMAKE_INSTALL_LIBEXECDIR:PATH=%{_libexecdir} \\\
269 -DCMAKE_INSTALL_SYSCONFDIR:PATH=%{_sysconfdir} \\\
270 -DCMAKE_INSTALL_SHAREDSTATEDIRPATH:PATH=%{_sharedstatedir} \\\
271 -DCMAKE_INSTALL_LOCALSTATEDIRPATH:PATH=%{_localstatedir} \\\
8736ae44 272 -DCMAKE_INSTALL_LIBDIR:PATH=%{_libdir} \\\
e23de4fc
AM
273 -DCMAKE_INSTALL_INCLUDEDIR:PATH=%{_includedir} \\\
274 -DCMAKE_INSTALL_OLDINCLUDEDIR:PATH=%{_includedir} \\\
275 -DCMAKE_INSTALL_DATAROOTDIR:PATH=%{_datadir} \\\
276 -DCMAKE_INSTALL_DATADIR:PATH=%{_datadir} \\\
277 -DCMAKE_INSTALL_INFODIR:PATH=%{_infodir} \\\
278 -DCMAKE_INSTALL_LOCALEDIR:PATH=%{_localedir} \\\
279 -DCMAKE_INSTALL_MANDIR:PATH=%{_mandir} \\\
280 -DCMAKE_INSTALL_DOCDIR:PATH=%{_docdir} \\\
8736ae44 281 -DCMAKE_INSTALL_PREFIX:PATH=%{_prefix} \\\
8736ae44 282 -DSYSCONF_INSTALL_DIR:PATH=%{_sysconfdir} \\\
1271c350
AM
283 -DCMAKE_CXX_FLAGS_PLD="${CXXFLAGS:-%{rpmcxxflags} -DNDEBUG -DQT_NO_DEBUG}" \\\
284 -DCMAKE_C_FLAGS_PLD="${CFLAGS:-%{rpmcflags} -DNDEBUG -DQT_NO_DEBUG}" \\\
285 -DCMAKE_Fortran_FLAGS_PLD="${CFLAGS:-%{rpmcflags} -DNDEBUG -DQT_NO_DEBUG}" \\\
547ff095
KK
286 -DCMAKE_EXE_LINKER_FLAGS_PLD="${LDFLAGS:-%{rpmldflags}}" \\\
287 -DCMAKE_SHARED_LINKER_FLAGS_PLD="${LDFLAGS:-%{rpmldflags}}" \\\
288 -DCMAKE_MODULE_LINKER_FLAGS_PLD="${LDFLAGS:-%{rpmldflags}}" \\\
c27b3ff8 289%if "%{_lib}" == "lib64" \
c4a85bd8 290 -DLIB_SUFFIX=64 \\\
a5e43006
JR
291%endif \
292%if "%{_lib}" == "libx32" \
293 -DLIB_SUFFIX=x32 \\\
9d1e0c01 294%endif \
8736ae44 295 -DBUILD_SHARED_LIBS:BOOL=ON \\\
c4a85bd8 296%{nil}
89f4ca1f 297
89f4ca1f
ER
298%scons { \
299%{__scons} \
5c76736d
ER
300 LDFLAGS="${LDFLAGS:-%rpmldflags}" \
301 CFLAGS="${CFLAGS:-%rpmcflags}" \
302 CXXFLAGS="${CXXFLAGS:-%rpmcxxflags}" \
303 FFLAGS="${FFLAGS:-%rpmcflags}" \
98e7f050 304 CPPFLAGS="${CPPFLAGS:-%rpmcppflags}" \
5c76736d
ER
305 %{?__cc:CC="%{__cc}"} \
306 %{?__cxx:CXX="%{__cxx}"} \
307 libsuffix=%{_lib} \
308 prefix=%{_prefix} \
39b9534b
ER
309}
310
6339d32d 311# waf. see waf.spec
6339d32d 312%waf { \
6339d32d
ER
313CC="%{__cc}" \
314CXX="%{__cxx}" \
9e244007 315CPP="%{__cpp}" \
6339d32d
ER
316CFLAGS="%{rpmcflags}" \
317CXXFLAGS="%{rpmcxxflags}" \
32c27cc0 318LINKFLAGS="%{rpmldflags}" \
6339d32d 319%{__waf} \
6339d32d
ER
320}
321
f72d45c4
JP
322# meson
323%meson { \
324%{?__cc:CC="${CC:-%{__cc}}"} \
325%{?__cxx:CXX="${CXX:-%{__cxx}}"} \
326CFLAGS="${CFLAGS:-%{rpmcflags}}" \
327CPPFLAGS="${CPPFLAGS:-%{rpmcppflags}}" \
328CXXFLAGS="${CXXFLAGS:-%{rpmcxxflags}}" \
329LDFLAGS="${LDFLAGS:-%{rpmldflags}}" \
e2329ed5 330LC_ALL=C.UTF-8 %{__meson} \
f72d45c4 331 --buildtype=plain \
4cb9865f 332 --bindir=%{_bindir} \
4cb9865f
JP
333 --datadir=%{_datadir} \
334 --includedir=%{_includedir} \
9cfca9d1 335 --infodir=%{_infodir} \
4cb9865f
JP
336 --libdir=%{_libdir} \
337 --libexecdir=%{_libexecdir} \
9cfca9d1 338 --localedir=%{_localedir} \
4cb9865f 339 --localstatedir=%{_localstatedir} \
4cb9865f 340 --mandir=%{_mandir} \
9cfca9d1
AM
341 --prefix=%{_prefix} \
342 --sbindir=%{_sbindir} \
343 --sharedstatedir=%{_sharedstatedir} \
344 --sysconfdir=%{_sysconfdir} \
345 --wrap-mode=%{__meson_wrap_mode} \
bc702a45 346 --default-library='both' \
f72d45c4 347}
003c1a6e
ER
348
349%___meson_deprecate() {echo >&2 "DEPRECATED: %%%1 must be replaced with %%%2"; %{expand:%%%2} }
350%meson_build %___meson_deprecate meson_build ninja_build
351%meson_install %___meson_deprecate meson_install ninja_install
352%meson_test %___meson_deprecate meson_test ninja_test
f72d45c4
JP
353
354# ninja
003c1a6e
ER
355%ninja_build LC_ALL=C.UTF-8 %{__ninja} %{__ninja_common_opts}
356%ninja_install LC_ALL=C.UTF-8 DESTDIR=%{buildroot} %{__ninja} install %{__ninja_common_opts}
357%ninja_test LC_ALL=C.UTF-8 %{__ninja} test %{__ninja_common_opts}
f72d45c4 358
4a6b0d54 359#----------------------------------------------------------------
9bacbb5b 360#%configure_cache 0
fe6c4bdd 361%configure_cache_file %{buildroot}.configure.cache
73f832b3 362
e84cd836 363%configure {./configure \
048f3050 364 LDFLAGS="${LDFLAGS:-%rpmldflags}" \
4a6b0d54 365 CFLAGS="${CFLAGS:-%rpmcflags}" \
f4cc8832 366 CXXFLAGS="${CXXFLAGS:-%rpmcxxflags}" \
4a6b0d54 367 FFLAGS="${FFLAGS:-%rpmcflags}" \
e9d801f4 368 FCFLAGS="${FCFLAGS:-%rpmcflags}" \
98e7f050 369 CPPFLAGS="${CPPFLAGS:-%rpmcppflags}" \
8983c4c4
AM
370 %{?__cc:CC="%{__cc}"} \
371 %{?__cxx:CXX="%{__cxx}"} \
8e4cb85a 372 --host=%{_target_platform} \
4a6b0d54 373 --build=%{_target_platform} \
048f3050 374 --prefix=%{_prefix} \
4a6b0d54
AF
375 --exec-prefix=%{_exec_prefix} \
376 --bindir=%{_bindir} \
377 --sbindir=%{_sbindir} \
378 --sysconfdir=%{_sysconfdir} \
379 --datadir=%{_datadir} \
380 --includedir=%{_includedir} \
381 --libdir=%{_libdir} \
382 --libexecdir=%{_libexecdir} \
383 --localstatedir=%{_localstatedir} \
384 --sharedstatedir=%{_sharedstatedir} \
385 --mandir=%{_mandir} \
386 --infodir=%{_infodir} \
b6c5da52 387 --x-libraries=%{?_x_libraries}%{!?_x_libraries:%{_libdir}} \
93059874 388 %{dependencytracking} \
9bacbb5b 389 %{?configure_cache:--cache-file=%{configure_cache_file}} \
4a6b0d54
AF
390}
391
611a25d5 392# Simple macros to simplify adding bconded options to configure scripts.
393# Each macro requires bcond name and accepts optional option name, if option
394# isn't specified bcond name is used as option name. Options returning
395# --with and --enable also allow third argument which will be added as value
396# ( --with-option=value or --enable-option=value ) in case or positive
397# condition, but won't be added otherwise ( nothing or just --disable-option ).
398
399# Requirements:
400# BuildRequires: rpmbuild(macros) >= 1.527
401
402# Usage example:
403# %{__enable bcond} - returns --enable-bcond iff build condition is set
404# %{__disable bcond option} - returns --enable-option iff bcond is not set
405# %{__enable_disable bcond option value} - returns --enable-option=value if
406# bcond is set, returns --disable-option otherwise
407
408# expand bconds to --enable-something and --disable-something
409%__enable() %{expand:%%{?with_%{1}:--enable-%{?2}%{!?2:%{1}}%{?3:=%{3}}}}
410%__disable() %{expand:%%{!?with_%{1}:--disable-%{?2}%{!?2:%{1}}}}
411%__enable_disable() %{expand:%%{?with_%{1}:--enable-%{?2}%{!?2:%{1}}%{?3:=%{3}}}%%{!?with_%{1}:--disable-%{?2}%{!?2:%{1}}}}
412
413# same as above, but condition inverted
414%__enable_unless() %{expand:%%{!?with_%{1}:--enable-%{?2}%{!?2:%{1}}%{?3:=%{3}}}}
415%__disable_if() %{expand:%%{?with_%{1}:--disable-%{?2}%{!?2:%{1}}}}
416%__enable_disable_not() %{expand:%%{!?with_%{1}:--enable-%{?2}%{!?2:%{1}}%{?3:=%{3}}}%%{?with_%{1}:--disable-%{?2}%{!?2:%{1}}}}
417
418# expand bconds to --with-something and --without-something
419%__with() %{expand:%%{?with_%{1}:--with-%{?2}%{!?2:%{1}}%{?3:=%{3}}}}
420%__without() %{expand:%%{!?with_%{1}:--without-%{?2}%{!?2:%{1}}}}
421%__with_without() %{expand:%%{?with_%{1}:--with-%{?2}%{!?2:%{1}}%{?3:=%{3}}}%%{!?with_%{1}:--without-%{?2}%{!?2:%{1}}}}
422
423# same as above, but condition inverted
424%__with_unless() %{expand:%%{!?with_%{1}:--with-%{?2}%{!?2:%{1}}%{?3:=%{3}}}}
425%__without_if() %{expand:%%{?with_%{1}:--without-%{?2}%{!?2:%{1}}}}
426%__with_without_not() %{expand:%%{!?with_%{1}:--with-%{?2}%{!?2:%{1}}%{?3:=%{3}}}%%{?with_%{1}:--without-%{?2}%{!?2:%{1}}}}
427
f51f5213 428# expands to true or false based on bcond; for use with meson or cmake
d9ea8286 429%__true_false() %{expand:%%{?with_%{1}:true}%%{!?with_%{1}:false}}
66ce621b 430%__true_false_not() %{expand:%%{?with_%{1}:false}%%{!?with_%{1}:true}}
d9ea8286 431
84b57058 432# for use with cmake:
7cafb58f 433# Usage: cmake_on_off BCOND_NAME [OPTION_NAME]
84b57058
AG
434# BuildRequires: rpmbuild(macros) >= 1.742
435%cmake_on_off() -D%{?2}%{!?2:%{1}}:BOOL=%{expand:%%{?with_%{1}:ON}%%{!?with_%{1}:OFF}}
436
611a25d5 437#-----------------------------------------------------------------
438
b3b1397b
ER
439# overload to insert debuginfo package
440%prep \
441%if 0%{?_enable_debug_packages}\
442%{debug_package}\
443%endif\
444%%prep\
445%{nil}
446
9c404149 447# Location of autoconf macros
ef7d5e14 448%_aclocaldir %{expand:%%global _aclocaldir %(aclocal --print-ac-dir 2>/dev/null || echo ERROR)}%_aclocaldir
9c404149 449
e2804f99 450# Location of omf files
7f0f4a79 451%_omf_dest_dir %{expand:%%global _omf_dest_dir %(scrollkeeper-config --omfdir || echo ERROR)}%_omf_dest_dir
e2804f99 452
e987a186 453# Location of pkgconfig files
9a4e877a 454%_pkgconfigdir /usr/%{_lib}/pkgconfig
36219c36
JB
455# noarch pkgconfig files
456%_npkgconfigdir /usr/share/pkgconfig
e987a186 457
486b0b5f 458# Location of desktop files
459%_desktopdir /usr/share/applications
86dff2d0 460%_applnkdir ERROR:_applnkdir_is_obsolete_use_desktopdir_instead
486b0b5f 461
481463e9 462# Location of pixmaps for applnk/desktop files
e1f0a822 463%_pixmapsdir /usr/share/pixmaps
9c404149 464
481463e9 465# Location of themable icons for applnk/desktop files
b36c8e2a 466%_iconsdir /usr/share/icons
467
e987a186
JB
468# Location of fonts directories
469%_fontsdir /usr/share/fonts
470
b3282f3f 471# Location of Gtk and associated libraries documentation
fe6c4bdd 472%_gtkdocdir %{_defaultdocdir}/gtk-doc/html
b3282f3f 473
fc4d7771 474# Location of KDE documentation
fe6c4bdd 475%_kdedocdir %{_defaultdocdir}/kde/HTML
fc4d7771 476
5869828c 477# unsermake script
478%__unsermake /usr/share/unsermake/unsermake
479
9c404149 480# Current date
048f3050 481%date %(LC_ALL=C date +"%a %b %d %Y")
9c404149 482
9c404149
AM
483# Example files, programs, scripts...
484%_examplesdir /usr/src/examples
485
c0fe61f0
ER
486# SysV-style initscripts dir
487%_initddir /etc/rc.d/init.d
488
9c404149 489# If non-empty "debug" macro defined, add "dbg" suffix to release number
8f74418b 490%_rpmfilename %%{NAME}-%%{VERSION}-%%{RELEASE}%{?debug:dbg}.%%{ARCH}.rpm
9c404149 491
590bc1db 492# Bootstrap release macros.
493# Usage:
494# %bcond_with bootstrap
495# Release: %{bootstrap_release 1}
496#
497# Package will have release 1 if built normally,
498# and release 0.zzz.bootstrap if built with bootstrap
499%bootstrap_release() %{!?with_bootstrap:%{1}%{?2:.%{2}}}%{?with_bootstrap:%{!?2:%(expr %{1} - 1)}%{?2:%{1}.%(expr %{2} - 1)}.zzz.bootstrap}
500
410df6e8
ER
501# Requires name = version-release
502%requires_releq() %{!?1:ERROR}%{?2:ERROR}%{?1:%{!?2:%{expand:%%requires_eq_to -r %1 %1}}}
8cf161e2 503# Requires: name = version
91d2f1eb 504%requires_eq() %{!?1:ERROR}%{?2:ERROR}%{?1:%{!?2:%{expand:%%requires_eq_to %1 %1}}}
8cf161e2 505# Requires: name = version (version based on querying package %2)
0d3e64c0 506%requires_eq_to(r) %{!?2:ERROR}%{?3:ERROR}%{?2:%{!?3:%(if ! LC_ALL=C rpm -q --qf 'Requires: %1 = %|E?{%{E}:}|%{V}%{?-r:-%{R}}\\n' %2 | grep '^Requires:'; then echo "BuildRequires: %2"; fi)}}
01a9f990 507
90c674d3
JR
508# Requires: name >= version
509%requires_ge() %{!?1:ERROR}%{?2:ERROR}%{?1:%{!?2:%{expand:%%requires_ge_to %1 %1}}}
510# Requires: name >= version (version based on querying package %2)
511%requires_ge_to(r) %{!?2:ERROR}%{?3:ERROR}%{?2:%{!?3:%(if ! LC_ALL=C rpm -q --qf 'Requires: %1 >= %|E?{%{E}:}|%{V}%{?-r:-%{R}}\\n' %2 | grep '^Requires:'; then echo "BuildRequires: %2"; fi)}}
512
048f3050 513# helper for renaming packages
807b9424
JR
514# %rename old-package
515%rename() \
516Obsoletes: %{1} < %{?epoch:%{epoch}:}%{?version:%{version}}%{?release:-%{release}} \
048f3050 517Provides: %{1} = %{?epoch:%{epoch}:}%{?version:%{version}}%{?release:-%{release}}
807b9424 518
d77fb7bd 519# for package versions comparison (incl. cc_version or _rpmversion)
a04002a8 520# BuildRequires: rpmbuild(macros) >= 1.749
8f8e1b51
JB
521%_ver_lt() %(test $(rpmvercmp "%{1}" "%{2}" >/dev/null 2>&1; echo $?) -ne 2; echo $?)
522%_ver_ge() %(test $(rpmvercmp "%{1}" "%{2}" >/dev/null 2>&1; echo $?) -eq 2; echo $?)
d77fb7bd 523
0b4ebb8c
JB
524# noarch subpackage helper
525# BuildRequires: rpmbuild(macros) >= 1.752
526%noarchpackage \
527%if %{_ver_ge '%{_rpmversion}' '4.6'} \
528BuildArch: noarch \
529%endif \
530%{nil}
531
c94807f3 532%apache_modules_api %{expand:%%global apache_modules_api %(awk '/#define MODULE_MAGIC_NUMBER_MAJOR/ {print $3}' /usr/include/apache/ap_mmn.h 2>/dev/null || echo ERROR)}%apache_modules_api
b9d5d440 533
e00dd7f6 534# sgml macros
3241033b
ER
535%xmlcat_add() /usr/bin/xmlcatalog --noout --add nextCatalog \"\" %1 /etc/xml/catalog ;
536%xmlcat_del() /usr/bin/xmlcatalog --noout --del %1 /etc/xml/catalog ;
537%xmlcat_add_rewrite /usr/bin/xmlcatalog --noout --add rewriteSystem
538%xmlcat_create() /usr/bin/xmlcatalog --noout --create %1 ;
539%sgmlcat_add() /usr/bin/install-catalog --add %1 %2 > /dev/null ;
540%sgmlcat_del() /usr/bin/install-catalog --remove %1 %2 > /dev/null ;
e00dd7f6 541%docbook_sgmlcat_fix() { for l in \
542'' \
543' -- default decl --' \
544'DTDDECL "-//OASIS//DTD DocBook XML V%2//EN" "../../xml.dcl"' \
545' -- hacks for opensp --' \
546'SYSTEM "file://%{_datadir}/sgml/docbook/xml-dtd-%2/docbookx.dtd" "%{_datadir}/sgml/docbook/xml-dtd-%2/docbookx.dtd"' \
3303369c 547'SYSTEM "http://www.oasis-open.org/docbook/xml/%2/docbookx.dtd" "%{_datadir}/sgml/docbook/xml-dtd-%2/docbookx.dtd"' \
e00dd7f6 548'' \
549; do echo $l; done >> %1 \
550}
551
eea64748
ER
552# vim - "
553
4f044018
ER
554# minimum file size needed for compressed documents.
555# just smaller files than this get larger when compressed.
a88ae20f
ER
556# some stats:
557# - 0 byte file compressed was 25 bytes .gz
558# - 39 byte file was compressed as 57
559# - with test/test.spec@man 158 byte file was compressed also 158
560%_min_compress_bytes 159
4f044018 561
9c404149
AM
562#-----------------------------------------------------------------
563# find and gzip all files in %{_mandir} and %{infodir}
564#
565# Requires: xargs, find
566#
567#%no_install_post_compress_docs 1
568%__spec_install_post_compress_docs { \
53d5af13 569%{!?no_install_post_compress_docs:__spec_install_post_compress_docs() { \
f58a5195 570 %{!?debug:set +x;} \
4e10ec06 571 for i in /usr/share/man /usr/X11R6/man; do \
9c404149 572 if [ -d "$RPM_BUILD_ROOT$i" ]; then \
4e10ec06 573 echo "Compress man pages: $i"; \
f1e00d64
AM
574 find "$RPM_BUILD_ROOT$i" -name '*.bz2' -print0 | xargs -0 -r %{__bzip2} -df; \
575 find "$RPM_BUILD_ROOT$i" -name '*.gz' -print0 | xargs -0 -r %{__gzip} -dnf; \
6375241c 576 find $RPM_BUILD_ROOT$i -type l | while read a; do \
9774b98f 577 m=$(readlink "$a"); \
7d032b46
ER
578 if [[ "$m" = */* ]]; then \
579 # handle links to different man section \
580 l=$(readlink -f "$a"); \
581 # full/relative paths that resolve symlink \
582 l=${l#$RPM_BUILD_ROOT/usr/share/man/}; \
583 l=${l#$RPM_BUILD_ROOT/usr/X11R6/man/}; \
584 # full paths that do not resolve symlink \
585 l=${l#/usr/share/man/}; \
586 l=${l#/usr/X11R6/man/}; \
587 else \
5b7659c8
JR
588 l=${a#$RPM_BUILD_ROOT$i/}; \
589 l=${l%/*}; \
590 l="$l/$m"; \
7d032b46 591 fi; \
6375241c 592 rm -f $a; \
9774b98f
ER
593 echo ".so $l" > $a; \
594 echo >&2 "Converted ${a#$RPM_BUILD_ROOT} from symlink to man link: $l"; \
6375241c 595 done; \
5ae32dbb
JB
596 # verify that .so links point to existing files (not allowed to point to "other package") \
597 # TODO: iterate over all man dirs, but in Th there is only one true man dir \
b012dc65 598 err=$(grep -rl '^\.so ' "$RPM_BUILD_ROOT$i" | while read doc; do \
e5637efc 599 l=$(grep -r '^\.so ' "$doc"); \
b012dc65 600 l=${l#.so }; \
b27f6a7a 601 d=$(dirname $doc); \
0f7dd079 602 test -e $RPM_BUILD_ROOT$i/$l || test -e $d/$(basename $l) || echo " ${doc#$RPM_BUILD_ROOT} points to inexistent manpage: $l"; \
b012dc65
ER
603 done); \
604 test "$err" != "" && { echo >&2 "Man page link errors:"; echo >&2 "$err"; exit 1; }; \
f1e00d64 605 find "$RPM_BUILD_ROOT$i" -type f -size +%{_min_compress_bytes}c -print0 | xargs -0 -r %{__gzip} -9nf; \
9c404149
AM
606 fi; \
607 done; \
728ad671
JB
608 if [ -d "$RPM_BUILD_ROOT%{_infodir}" ]; then \
609 echo "Compress info pages: %{_infodir}"; \
f1e00d64
AM
610 find "$RPM_BUILD_ROOT%{_infodir}" -name '*.bz2' -print0 | xargs -0 -r %{__bzip2} -df; \
611 find "$RPM_BUILD_ROOT%{_infodir}" -name '*.gz' -print0 | xargs -0 -r %{__gzip} -dnf; \
612 find "$RPM_BUILD_ROOT%{_infodir}" -name '*.info*' -type f -size +%{_min_compress_bytes}c -print0 | xargs -0 -r %{__gzip} -9nf; \
4e10ec06 613 fi; \
53d5af13 614}; __spec_install_post_compress_docs } }
9c404149
AM
615
616#-----------------------------------------------------------------
617# Strip executable binaries and shared object files
618#
619# Requires: find, awk, strip, cut, xargs
620#
a2ad2754
JB
621# Special macros which affect this process:
622#%no_install_post_strip 1 # disable stripping at all
623#%_noautostrip regexp # exclude files matching (anchored!) regex from stripping
624#%_autostripall regexp # strip files matching (anchored!) regex using plain strip
625#%_autostripunneeded regexp # strip files matching (anchored!) regex using strip --strip-unneeded
626#%_autostripdebug regexp # strip files matching (anchored!) regex using strip --strip-debug
627#
9c404149 628%__spec_install_post_strip {%{!?debug: \
53d5af13 629%{!?no_install_post_strip:__spec_install_post_strip() { \
f58a5195 630%{!?debug:set +x;} \
98a06bad 631if [ -d "$RPM_BUILD_ROOT" ]; then \
eea64748 632 if [ -d $RPM_BUILD_ROOT/lib/modules ]; then \
cbfd7965 633 modulelist=$(find $RPM_BUILD_ROOT/lib/modules \( -name '*.o' -o -name '*.ko' \) -type f -print); \
4d5370ac
ER
634 if [ "$modulelist" ]; then \
635 modulecount=$(echo "$modulelist" | wc -l); \
737fefdc 636 printf "Stripping %d kernel modules..." $modulecount; \
3df8db34 637 echo "$modulelist" | xargs -l512 chmod u+w; \
f0b25c9c 638 echo "$modulelist" | xargs -l512 %{__strip} -g --remove-section=.comment --remove-section=.note.GNU-stack; \
3df8db34
ER
639 echo "DONE"; \
640 fi; \
eea64748 641 fi; \
0b083a56 642 filelist=$(find $RPM_BUILD_ROOT -type f ! -regex ".*/usr/lib[x0-9]*/debug/.*\.debug" ! -regex ".*/usr/lib[x0-9]*.*/guile/.*\.go" ! -regex ".*/lib/modules/.*" ! -regex ".*%{_docdir}/.*" ! -regex ".*%{_includedir}/.*" %{?_noautostrip:! -regex "%{_noautostrip}"} %{?_autostripall:! -regex "%{_autostripall}"} %{?_autostripunneeded:! -regex "%{_autostripunneeded}"} %{?_autostripdebug:! -regex "%{_autostripdebug}"}); \
f89ccb5f
JB
643 if [ -n "$filelist" ]; then \
644 filetypes=`echo "$filelist" | xargs -r -d'\\n' file`; \
645 elfexelist=`echo "$filetypes" | awk -F: '/ELF.*executable/ {print $1}'`; \
646 elfsharedlist=`echo "$filetypes" | awk -F: '/LF.*shared object/ {print $1}'`; \
a2ad2754 647 archiveslist=`echo "$filetypes" | awk -F: '/current ar archive/ {print $1}'`; \
f89ccb5f 648 if [ -n "$elfexelist" ]; then \
4d5370ac 649 printf "Stripping %d ELF executables..." $(echo "$elfexelist" | wc -l); \
6a7faaa9
ER
650 echo "$elfexelist" | xargs -r -d'\n' chmod u+w; \
651 echo "$elfexelist" | xargs -r -d'\n' %{__strip} --remove-section=.note --remove-section=.comment; \
f89ccb5f
JB
652 echo "DONE"; \
653 fi; \
654 if [ -n "$elfsharedlist" ]; then \
4d5370ac 655 printf "Stripping %d ELF shared libraries..." $(echo "$elfsharedlist" | wc -l); \
6a7faaa9
ER
656 echo "$elfsharedlist" | xargs -r -d'\n' chmod u+w; \
657 echo "$elfsharedlist" | xargs -r -d'\n' %{__strip} --strip-unneeded --remove-section=.note --remove-section=.comment; \
f89ccb5f
JB
658 echo "DONE"; \
659 fi; \
660 if [ -n "$archiveslist" ]; then \
4d5370ac 661 printf "Stripping %d ar archives..." $(echo "$archiveslist" | wc -l); \
6a7faaa9
ER
662 echo "$archiveslist" | xargs -r -d'\n' chmod u+w; \
663 echo "$archiveslist" | xargs -r -d'\n' %{__strip} --strip-debug --remove-section=.note --remove-section=.comment; \
f89ccb5f
JB
664 echo "DONE"; \
665 fi; \
98a06bad 666 fi; \
0ac49134
ER
667 filelist_all=%{?_autostripall:$(find $RPM_BUILD_ROOT -type f -regex "%{_autostripall}")}; \
668 filelist_unneeded=%{?_autostripunneeded:$(find $RPM_BUILD_ROOT -type f -regex "%{_autostripunneeded}")}; \
669 filelist_debug=%{?_autostripdebug:$(find $RPM_BUILD_ROOT -type f -regex "%{_autostripdebug}")}; \
f89ccb5f 670 if [ -n "$filelist_all" ]; then \
4d5370ac 671 printf "Stripping everything from %d additional files..." $(echo "$filelist_all" | wc -l); \
a2ad2754 672 chmod u+w $filelist_all; \
f89ccb5f 673 %{__strip} --remove-section=.note --remove-section=.comment $filelist_all; \
322f84b9 674 echo "DONE"; \
9c404149 675 fi; \
f89ccb5f 676 if [ -n "$filelist_unneeded" ]; then \
4d5370ac 677 printf "Stripping unneeded from %d additional files..." $(echo "$filelist_unneeded" | wc -l); \
a2ad2754 678 chmod u+w $filelist_unneeded; \
f89ccb5f 679 %{__strip} --strip-unneeded --remove-section=.note --remove-section=.comment $filelist_unneeded; \
322f84b9 680 echo "DONE"; \
8f74418b 681 fi; \
f89ccb5f 682 if [ -n "$filelist_debug" ]; then \
4d5370ac 683 printf "Stripping debuginfo from %d additional files..." $(echo "$filelist_debug" | wc -l); \
a2ad2754 684 chmod u+w $filelist_debug; \
f89ccb5f 685 %{__strip} --strip-debug --remove-section=.note --remove-section=.comment $filelist_debug; \
322f84b9 686 echo "DONE"; \
9f0d4f36 687 fi; \
53d5af13 688fi; }; __spec_install_post_strip } } }
3241033b 689
fc5d7e20 690#-----------------------------------------------------------------
4d31c695 691# remove all RPATH/RUNPATH from executable binaries and shared object files
fc5d7e20 692#
693# Requires: find, awk, cut, xargs, chrpath, uname
694#
a2ad2754
JB
695# Special macros which affect this process
696#%no_install_post_chrpath 1 # disable chrpath at all
697#%_noautochrpath regex # exclude files matching (anchored!) regex from chrpath
698#
fc5d7e20 699%__spec_install_post_chrpath {%{!?debug: \
53d5af13 700%{!?no_install_post_chrpath: __spec_install_post_chrpath() { \
f58a5195 701%{!?debug:set +x;} \
9f0d4f36 702if [ -d "$RPM_BUILD_ROOT" ]; then \
0ac49134 703 files=`find $RPM_BUILD_ROOT -type f ! -regex ".*ld-[0-9.]*so.*" ! -regex ".*/usr/lib[0-9]*/debug/.*" ! -regex ".*/lib/modules/.*" ! -regex ".*%{_docdir}/.*" ! -regex ".*%{_includedir}/.*" %{?_noautochrpath:! -regex "%{_noautochrpath}"}`; \
98a06bad 704 if [ -n "$files" ]; then \
d5517264 705 objs=`echo "$files" | xargs -r -d'\\n' file | awk -F: '/ELF.*(executable.*dynamically linked|shared object)/ {print $1}'`; \
3401a2cd 706 fi; \
98a06bad 707 if [ -n "$objs" ]; then \
4d31c695 708 printf "Remove RPATH/RUNPATH from %d executable binaries and shared object files.\n" $(echo "$objs" | wc -l); \
98a06bad
ER
709 echo "$objs" | \
710 while read file; do \
711 rpath= ; \
712 chmod u+w "$file"; \
d8ba59fb 713 for dir in $(chrpath -l "$file" | awk '/(R|RUN)PATH=/ { gsub(/.*RPATH=/,""); gsub(/.*RUNPATH=/,""); gsub(/:/," "); print $0 }'); do \
eda6b510
AM
714 case $dir in \
715 '$ORIGIN' ) \
716 if [ "$rpath" = "" ] ; then rpath="$dir" ; \
717 else rpath="$rpath:$dir" ; fi ; \
718 continue ; \
719 ;; \
720 esac ; \
f9abaddb
AM
721 newdir=$(readlink -m "$dir"); \
722 [ ${#newdir} -le ${#dir} ] && dir=$newdir; \
98a06bad
ER
723 case $dir in \
724 /home/* | /tmp/* | /usr/lib | /usr/lib64 | /lib | /lib64 | /usr/local/lib | /usr/local/lib64 | /usr/X11R6/lib | /usr/X11R6/lib64 ) \
725 echo "remove-rpath: $dir in $file"; \
726 ;; \
727 * ) \
728 if [ "$rpath" = "" ] ; then rpath="$dir" ; \
729 else rpath="$rpath:$dir" ; fi ; \
730 ;; \
731 esac ; \
732 done ; \
733 if [ "$rpath" = "" ] ; then chrpath -d "$file" > /dev/null ; \
734 else chrpath -r "$rpath" "$file" > /dev/null ; fi ; \
735 done; \
736 fi; \
53d5af13 737fi; }; __spec_install_post_chrpath } } }
3241033b 738
611a25d5 739# vim: "
740
d366d7e0
AM
741#-----------------------------------------------------------------
742# Find all shared object files with unresolved symbols. Warn
743# and terminate if any found (termination can be turned off by define).
744#%no_install_post_check_so 1
ff8c88f6 745#%skip_post_check_so libwithunresolvedok.so.*
e067aec9 746#
747# NOTE: define skip_post_check_so only if such library really requires
748# unresolved symbols and always leave a comment why it is required:
749# # executable provides symbols foo, bar for those libraries:
750# %define skip_post_check_so libwithoutfoo.so.* libwithoutbar.so.*
751#
d366d7e0 752%__spec_install_post_check_so { \
229037b6 753__spec_install_post_check_so() { \
f58a5195 754%{!?debug:set +x;} \
229037b6
ER
755 fail=0; \
756 printf "Searching for shared objects with unresolved symbols..."; \
757 for f in $(find $RPM_BUILD_ROOT -type f -name '*.so.*' -print); do \
bca5d19b 758 LC_ALL=C objdump -T $f 2> /dev/null | LC_ALL=C awk -v "file=$f" 'BEGIN { found=0; skip["program_name"]=1; skip["_ZSt15__once_callable"]=1; skip["_ZSt11__once_call"]=1; symbols = "" } /^[0-9a-z]+ +D +\*UND\*/ { if ($NF in skip) { next; }; found = 1; symbols = symbols "\n\t" $NF } END { if (found) { print "\nUnresolved symbols found in: " file symbols; %{?skip_post_check_so:split("%{skip_post_check_so}", R); for (i=1; i in R; i++) { if (file ~ "(^|/)" R[i] "$") { print "Library marked with skip_post_check_so, ignoring errors.\n"; exit(0); } } } exit(1); } } ' || fail=1 ; \
229037b6
ER
759 done ; \
760 echo " DONE"; \
761 %{!?no_install_post_check_so:return $fail;} \
d366d7e0
AM
762}; __spec_install_post_check_so }}
763
56dfec19
JR
764#-----------------------------------------------------------------
765# Find all ELF files with executable stac. Warn and terminate if any found
766# (termination can be turned off by define).
73c33fdc 767# Details: https://wiki.gentoo.org/wiki/Hardened/GNU_stack_quickstart
56dfec19
JR
768#%no_install_post_check_stackexec 1
769#%skip_post_check_stackexec libwithexecstackok.so.*
770#
771# NOTE: define skip_post_check_stackexec only if such program or library
772# really requires executable stack and always leave a comment why
773# it is required:
774# # Programs full of nested functions that cannot be fixed
775# %define skip_post_check_execstack /bin/foo libwithexecstack.so.*
776#
777%__spec_install_post_check_execstack { \
778__spec_install_post_check_execstack() { \
779%{!?debug:set +x;} \
780 fail=0; \
781 printf "Searching for ELF programs with executable stack..."; \
782 for f in $(find $RPM_BUILD_ROOT -type f -print) ; do \
783 LC_ALL=C readelf -lW $f 2>/dev/null | \
784 LC_ALL=C awk -v "file=$f" 'BEGIN { found=0; } /GNU_STACK/ { if ($7 ~ "E") { found=1 } } END { if (found) { print "\nExecutable stack found in: " file; %{?skip_post_check_execstack:split("%{skip_post_check_execstack}", R); for (i=1; i in R; i++) { if (file ~ "(^|/)" R[i] "$") { print "File marked with skip_post_check_execstack, ignoring errors.\n"; exit(0); } } } exit(1); } }' || fail=1 ; \
785 done ; \
786 echo " DONE"; \
787 %{!?no_install_post_check_execstack:return $fail;} \
788}; __spec_install_post_check_execstack }}
789
918e69bf
JR
790#-----------------------------------------------------------------
791# Verify that for each directory under /var/run package contains
792# tmpfiles.d configuration. Warn and terminate build if config is
793# missing.
794#
795#%no_install_post_check_tmpfiles 1
796#
797%__spec_install_post_check_tmpfiles { \
798__spec_install_post_check_tmpfiles() { \
799%{!?debug:set +x;} \
800 fail=0; \
801 echo "Checking /var/run <-> tmpfiles.d completeness..."; \
802 for d in $RPM_BUILD_ROOT/var/run/*; do \
803 [ -d "$d" ] || continue; \
804 d=${d##$RPM_BUILD_ROOT}; \
0b39f25d 805 if ! grep -qsF "$d" $RPM_BUILD_ROOT/usr/lib/tmpfiles.d/*.conf $RPM_BUILD_ROOT/etc/tmpfiles.d/*.conf; then\
3303369c 806 echo "No tmpfiles configuration for '$d'";\
918e69bf
JR
807 fail=1 ; \
808 fi \
809 done ; \
810 echo " DONE"; \
811 %{!?no_install_post_check_tmpfiles:return $fail;} \
812}; __spec_install_post_check_tmpfiles }}
813
02bc4ed5
JK
814#-----------------------------------------------------------------
815# Verify that scripts have reasonable shebangs
968c9e06 816# Test spec: see "test/spec_install_post_check_shebangs" branch on packages/test.spec
02bc4ed5
JK
817#
818#%no_install_post_check_shebangs 1
819#
820%__spec_install_post_check_shebangs { \
821__spec_install_post_check_shebangs() { \
822%{!?debug:set +x;} \
02bc4ed5 823 echo "Checking script shebangs..."; \
2d6f7949
JB
824 fail=` \
825 find $RPM_BUILD_ROOT -type f -perm -500 -print | { fail=0; while IFS= read -r f; do \
b5868bc3
JK
826 shebang="$(sed -e'1s/#! *\(.*\)/\1/;t;d;q' "$f")" ; \
827 f="${f##$RPM_BUILD_ROOT}"; \
02bc4ed5 828 case "$shebang" in \
38dac5ff 829 "%{__python}"|"%{__python3}"|"%{__python} "*|"%{__python3} "* \
c8444a8b
JK
830 |"/usr/bin/python%{py_ver}"|"/usr/bin/python%{py_ver} "* \
831 |"/usr/bin/python%{py3_ver}"|"/usr/bin/python%{py3_ver} "*) \
02bc4ed5
JK
832 ;; \
833 "/usr/bin/env python"*|"/usr/bin/python"|"/usr/bin/python "*) \
834 echo "$f starts with '#!$shebang', should be '#!%{__python}' or '#!%{__python3}'" >&2;\
835 fail=1 ; \
836 ;; \
837 "/usr/bin/env "*) \
838 echo "$f starts with '#!$shebang', should be explicit interpreter path" >&2;\
839 fail=1 ; \
840 ;; \
841 *) ;;\
842 esac ; \
843 done ; \
2d6f7949
JB
844 echo "$fail" ; \
845 }`; \
02bc4ed5 846 echo " DONE" ; \
c53b26d7
AM
847 %{!?no_install_post_check_shebangs:return $fail;} \
848}; __spec_install_post_check_shebangs }}
02bc4ed5 849
ef64802f
ER
850# Remove common Perl files we don't package
851%__spec_install_post_perl_clean {\
852%{!?no_install_post_perl_clean: \
853%{?pdir:rm -f $RPM_BUILD_ROOT{%{perl_archlib}/perllocal.pod,%{perl_vendorarch}/auto/%{pdir}%{?pnam:/%(echo %{pnam} | tr - /)}/.packlist}} \
854} }
855
b541a244
JB
856# Helpers to specify SONAME depdendencies, e.g.:
857# Requires: %{_soname_prov libfoo.so.1}
858# Requires: %{_soname_prov libfoo.so.1(SOME_SYMVER)}
859#
860# BuildRequires: rpmbuild(macros) >= 1.721
861#
862%_soname_tag %(echo %{_lib} | sed -e 's/^lib//' -e 's/^\\(.\\+\\)$/(\\1bit)/')
863%_soname_prov() %(echo "%{1}()%{_soname_tag}" | sed -e 's/^\\([^(]*([^)]\\+)\\)()%{_soname_tag}$/\\1%{_soname_tag}/;s/()$//')
864
83094b62 865#-----------------------------------------------------------------
0e4cb4dd 866# Update GConf2 schemas
83094b62 867#
868# Requires: GConf2
869#
46885239 870%gconf_schema_install() \
307ac6c9
ER
871 umask 022; \
872 GCONF_CONFIG_SOURCE="xml:readwrite:/etc/gconf/gconf.xml.defaults" \\\
873 /usr/bin/gconftool-2 --makefile-install-rule /etc/gconf/schemas/%{?1}%{!?1:*.schemas} > /dev/null; \
f27cf2fd 874%{nil}
46885239 875
876%gconf_schema_uninstall() \
24336a54 877if [ $1 = 0 -a -x /usr/bin/gconftool-2 ]; then \
3241033b 878 umask 022; \
24336a54
ER
879 GCONF_CONFIG_SOURCE="xml:readwrite:/etc/gconf/gconf.xml.defaults" \\\
880 /usr/bin/gconftool-2 --makefile-uninstall-rule /etc/gconf/schemas/%{?1} > /dev/null \
f27cf2fd 881fi; \
f93109a0 882%{nil}
883
884#-----------------------------------------------------------------
885# Update desktop MIME database
c0a4caa0 886# requires: desktop-file-utils
c3bcd10e 887%update_desktop_database() {{ \
f93109a0 888 umask 022; \
fb59e475 889 /usr/bin/update-desktop-database -q; \
c00bf95c
MB
890};} \
891%{nil}
f93109a0 892
c3bcd10e
ER
893%update_desktop_database_post %update_desktop_database
894
895%update_desktop_database_postun() {{ \
f27cf2fd 896if [ "$1" = "0" ]; then \
c00bf95c 897 %update_desktop_database \
f27cf2fd 898fi; \
c00bf95c
MB
899};} \
900%{nil}
f93109a0 901
fb59e475 902#-----------------------------------------------------------------
903# Update shared MIME info database
904# requires: shared-mime-info
35d0c9a6
TP
905# Note: https://bugs.freedesktop.org/show_bug.cgi?id=70366#c19
906# https://bugzilla.redhat.com/show_bug.cgi?id=1052173
907# TODO: if you want this running with fdatasync(), make sure it's:
908# 1. announcing ~minute delay by echoing appropriate message,
909# 2. running only once after rpm transaction.
fb59e475 910#
c3bcd10e 911%update_mime_database() {{ \
fb59e475 912 umask 022; \
c8c0d5f5 913 PKGSYSTEM_ENABLE_FSYNC=0 \
fb59e475 914 /usr/bin/update-mime-database %{_datadir}/mime; \
c00bf95c
MB
915};} \
916%{nil}
fb59e475 917
918#-----------------------------------------------------------------
919# Update icon cache
3303369c
TP
920# BuildRequires: rpmbuild(macros) >= 1.596
921# Requires: hicolor-icon-theme
fb59e475 922#
c3bcd10e 923%update_icon_cache() {{ \
9639d726
ER
924 %{!?1:%{error:%{0}: Required theme name missing}} \
925 if [ -x /usr/bin/gtk-update-icon-cache ]; then \
926 umask 022; \
927 touch --no-create %{_iconsdir}/%1; \
928 /usr/bin/gtk-update-icon-cache -qf %{_iconsdir}/%1; \
929 fi; \
c00bf95c
MB
930};} \
931%{nil}
fb59e475 932
f93109a0 933#-----------------------------------------------------------------
934# Update scrollkeeper database
935# requires: scrollkeeper
936#
937%scrollkeeper_update_post() \
f93109a0 938 /usr/bin/scrollkeeper-update -q; \
f27cf2fd 939%{nil}
f93109a0 940
941%scrollkeeper_update_postun() \
f27cf2fd 942if [ "$1" = "0" ]; then \
f93109a0 943 /usr/bin/scrollkeeper-update -q; \
f27cf2fd 944fi; \
f93109a0 945%{nil}
946
c9704b95
MB
947#-----------------------------------------------------------------
948# Compile GSettings schemas
949# requires: glib2 >= 1:2.26.0
950#
951%glib_compile_schemas() {{ \
952 umask 022; \
953 /usr/bin/glib-compile-schemas %{_datadir}/glib-2.0/schemas; \
954};} \
955%{nil}
956
16bd8442
JB
957# BuildRequires: rpmbuild(macros) >= 1.751
958# Requires(post,postun): /usr/bin/texhash # if you want to ensure cache is updated
959%texhash() {{ \
960 umask 022; \
961 /usr/bin/texhash >&2; \
962};} \
963%{nil}
964
9c404149
AM
965#-----------------------------------------------------------------
966# post %install sequence:
967# - autodeps exceptions
968# - compress all man and info pages,
969# - strip all ELF executables and ELF shared objects if not %debug.
8f74418b 970# - compress kernel modules if any
9c404149
AM
971
972###################################################################
973# Requires/Provides automation
3e202b06 974# exceptions system by Jacek Konieczny <jajcus@pld-linux.org>
338726a6 975#
2892b5df
JB
976%__noautoreqfiles %(sed -e s'/#.*//' /etc/rpm/noautoreqfiles)%{?_noautoreqfiles: %{_noautoreqfiles}}
977%__noautoprovfiles %(sed -e s'/#.*//' /etc/rpm/noautoprovfiles)%{?_noautoprovfiles: %{_noautoprovfiles}}
2892b5df 978%__noautoreqdep %(sed -e s'/#.*//' /etc/rpm/noautoreqdep)%{?_noautoreqdep: %{_noautoreqdep}}
da8e49db
JB
979%__noautoprov %(sed -e s'/#.*//' /etc/rpm/noautoprov) \
980 %{?_noautoprov: %{_noautoprov}} \
981 %{?_noautoprov_java: %{__noauto_regexp_helper -p java %{_noautoprov_java}}} \
982 %{?_noautoprov_mono: %{__noauto_regexp_helper -p mono %{_noautoprov_mono}}} \
983 %{?_noautoprov_pear: %{__noauto_regexp_helper -p pear %{_noautoprov_pear}}} \
984 %{?_noautoprov_perl: %{__noauto_regexp_helper -p perl %{_noautoprov_perl}}} \
985 %{?_noautoprov_pyegg: %{__noauto_regexp_helper -p pythonegg %{_noautoprov_pyegg}}} \
986 %{?_noautoprov_py3egg: %{__noauto_regexp_helper -p python3egg %{_noautoprov_py3egg}}} \
987 %{nil}
0a9bb974
ER
988%__noautoreq %(sed -e s'/#.*//' /etc/rpm/noautoreq) \
989 %{?_noautoreq: %{_noautoreq}} \
4e311fe4 990 %{?_noautoreq_java: %{__noauto_regexp_helper -p java %{_noautoreq_java}}} \
4dc4b33c 991 %{?_noautoreq_mono: %{__noauto_regexp_helper -p mono %{_noautoreq_mono}}} \
0a9bb974
ER
992 %{?_noautoreq_pear: %{__noauto_regexp_helper -p pear %{_noautoreq_pear}}} \
993 %{?_noautoreq_perl: %{__noauto_regexp_helper -p perl %{_noautoreq_perl}}} \
e7053164
JR
994 %{?_noautoreq_pyegg: %{__noauto_regexp_helper -p pythonegg %{_noautoreq_pyegg}}} \
995 %{?_noautoreq_py3egg: %{__noauto_regexp_helper -p python3egg %{_noautoreq_py3egg}}} \
0a9bb974
ER
996 %{nil}
997
998# helper for wrapping _noautoreq between perl() or pear()
999# Author: Elan Ruusamäe <glen@pld-linux.org>
1000# Usage:
1001# BuildRequires: rpmbuild(macros) >= 1.654
1002# %define _noautoreq_pear Excluded.php PEAR/Something.php
1003# %define _noautoreq_perl Apache::.*
42bc86d6
ER
1004# BuildRequires: rpmbuild(macros) >= 1.672
1005# %define _noautoreq_java ClassDataVersion
90a48f11
ER
1006# BuildRequires: rpmbuild(macros) >= 1.709
1007# %define _noautoreq_pyegg argparse
1008# %define _noautoreq_py3egg backports.ssl-match-hostname ipaddress
4e311fe4
JB
1009# BuildRequires: rpmbuild(macros) >= 1.730
1010# %define _noautoreq_mono Gendarme.Framework
da8e49db
JB
1011# BuildRequires: rpmbuild(macros) >= 1.737
1012# %define _noautoprov_java Class
1013# %define _noautoprov_mono Excluded.Provide
1014# %define _noautoprov_pear Excluded.php
1015# %define _noautoprov_perl Excluded::Module
1016# %define _noautoprov_pyegg excluded
1017# %define _noautoprov_py3egg excluded3
4b369e1f
ER
1018#
1019%__noauto_regexp_helper(p:) %(echo "%*" | awk 'BEGIN{RS=" "}{printf("%{-p*}%{__qchar}(%%s%{__qchar}) ", $1)}')
1020# detect quote character runtime
1021%__qchar_4 \\\\%{nil}
1022%__qchar_5 \\\\\\%{nil}
1023%__qchar %{expand:%%global __qchar %%__qchar_%(echo %{_rpmversion} | cut -c1)}%__qchar
c94807f3 1024
338726a6
JB
1025#%_noautocompressdoc %{nil}
1026#
8f74418b
MM
1027%_missing_doc_files_terminate_build 1%{nil}
1028%_unpackaged_files_terminate_build %{nil}
54b2501c 1029
09961759
ER
1030# node.js libdir
1031# Requirements:
1032# BuildRequires: rpmbuild(macros) >= 1.634
1033%nodejs_libdir /usr/lib/node_modules
57241c0e 1034
1316894b 1035# bash-completion 2.0 completions dir
a4e1cc18 1036# Requirements:
ea132ee6 1037# BuildRequires: rpmbuild(macros) >= 1.673
bb45f0fe 1038# Requires: bash-completion >= 2.0
1316894b 1039%bash_compdir /usr/share/bash-completion/completions
a4e1cc18 1040
d46b35f5
ER
1041# fish completions dir
1042# Requirements:
1043# BuildRequires: rpmbuild(macros) >= 1.720
1044%fish_compdir /usr/share/fish/vendor_completions.d
1045
ea132ee6
ER
1046# zsh completions dir
1047# Requirements:
1048# BuildRequires: rpmbuild(macros) >= 1.719
1049%zsh_compdir /usr/share/zsh/site-functions
1050
0fc5cff8 1051# depmod macro
1052%depmod() { \
f6148427 1053umask 022; \
0fc5cff8 1054if [ -e /boot/System.map-%1 ]; then \
3241033b 1055 /sbin/depmod -a -F /boot/System.map-%1 %1; \
0fc5cff8 1056else \
3241033b
ER
1057 if [ -e /boot/System.map ]; then \
1058 /sbin/depmod -a -F /boot/System.map %1; \
1059 else \
1060 /sbin/depmod -a %1; \
1061 fi \
0fc5cff8 1062fi; \
1063}
1064
848c0d68 1065# user/group checking macros
1066#
1067# Usage:
1068# %userremove myuser
1069#
1070%userremove /usr/lib/rpm/user_group.sh user del
1071%groupremove /usr/lib/rpm/user_group.sh group del
1072#
1073# Usage:
1074# if %usertestrm myuser; then
1075# /usr/sbin/userdel -r myuser
1076# Note:
1077# use these macros only if you need to call userdel/groupdel with
1078# a non-standard option or take an extra action; otherwise use the
1079# %userremove/%groupremove macros
1080#
1081%usertestrm /usr/lib/rpm/user_group.sh user testrm
1082%grouptestrm /usr/lib/rpm/user_group.sh group testrm
08d9b1f6
JK
1083# user group membership management macros
1084#
1085# Usage:
efbc7726 1086# %addusertogroup [-q] myuser agroup
08d9b1f6 1087#
efbc7726
ER
1088# -q if user or group don't exist, don't make big noise of it (MISSINGOK behaviour)
1089#
1090# Requirements:
1091# BuildRequires: rpmbuild(macros) >= 1.515
2b29e157
ER
1092%addusertogroup(q) quiet=%{-q:1} /usr/lib/rpm/user_group.sh user addtogroup %*; \
1093%{nil}
72fcfcb3 1094
1095# banner support (useful in {pre,post}{,un} and triggers)
1096#
1097# Usage:
908f5713 1098# %banner name [-a] [-e] [-n] [-tn] [-o] <<EOF
72fcfcb3 1099# the banner text, the banner text
aa41c920
ER
1100# the banner text, and following line
1101#EOF
1102# You can use any form of here-document, <<'EOF' <<-EOT will do.
1103# NOTE: if your use "<<-EOF", then You can actually indent inside here-document.
1104#
3303369c
TP
1105# -a - append to the banner
1106# -e - send to stderr instead of stdout
1107# -n - don't show banner (overrides -t)
1108# -t - show only, if RPM_SCRIPTVERBOSITY >= n; default n=5
1109# -o - show only once, i.e when package is installed for the first time
276a7b45
ER
1110#
1111# Tests:
1112# (rpm -E '%banner -e banner <<EOF'; echo -e 'hi\nEOF') > m; sh -x m
908f5713
ER
1113# (rpm -E '%banner -o -e banner <<EOF'; echo -e 'hi\nEOF') > m; sh -x m
1114# (rpm -E '%banner -o -e banner <<EOF'; echo -e 'hi\nEOF') > m; sh -x m 1
276a7b45 1115# rpm -E 'date | %banner -e banner' > m; sh -x m
908f5713 1116# rpm -E 'date | %banner -o -e banner' > m; sh -x m
276a7b45 1117#
908f5713 1118%banner(aenot:) %{-o:([ "$1" != 1 ] ||} ( \
1b334fe4 1119RPM_SCRIPTVERBOSITY=5 \
1120[ -r /etc/sysconfig/rpm ] && . /etc/sysconfig/rpm \
1121if [ -x /usr/bin/banner.sh ]; then \
aa41c920 1122 CMD="/usr/bin/banner.sh %{-e:--stderr} %{!-n:$([ $RPM_SCRIPTVERBOSITY -ge %{-t:%{-t*}}%{!-t:5} ] && echo -s)} %{!-a:-m}%{-a:-M} %1" \
1b334fe4 1123else \
a8b9562a 1124 CMD="cat%{-e: >&2}" \
1b334fe4 1125fi \
908f5713 1126eval $CMD %{?2:%2}%{?3: %3})%{-o:)} \
276a7b45 1127%{nil}
628754cb 1128
990bd03f 1129# useradd/groupadd macros
4c73bc69 1130# Author: Elan Ruusamäe <glen@pld-linux.org>
90627280
ER
1131#
1132# Usage:
1133# %useradd [-P package] [-u uid] [-d home_dir] [-s shell] [-c comment]
1134# [-g initial_group] [-G group[,...]] login
1135#
1136# -u uid. REQUIRED
1137# -g gid/group. REQUIRED
1138# -s defaults to /bin/false
1139# -d defaults to /usr/share/empty
1140# -c No default
1141# -r is accepted but ignored (it's always set)
6bd4c218 1142# -k skeleton dir. defaults to /usr/share/empty
90627280
ER
1143# rpm specific flags
1144# -P package name. defaults to %{name}
1145#
90627280 1146%useradd(c:d:e:f:g:G:Mmk:op:s:u:rP:) \
9ba02ba9
ER
1147%{!-u:%{error:useradd: Required argument -u missing}} \
1148%{!-g:%{error:useradd: Required argument -g missing}} \
1149%{!?1:%{error:useradd: Required parameter login missing}} \
90627280
ER
1150if [ -n "`/bin/id -u %{expand:%{%{#}}} 2>/dev/null`" ]; then \
1151 if [ "`/bin/id -u %{expand:%{%{#}}}`" != "%{-u*}" ]; then \
1152 echo "Error: user %{expand:%{%{#}}} doesn't have uid=%{-u*}. Correct this before installing %{-P*}%{!?-P:%{name}}." 1>&2 \
1153 exit 1 \
1154 fi \
1155else \
1156 echo "Adding user %{expand:%{%{#}}} UID=%{-u*}." \
1157 /usr/sbin/useradd \\\
b5a7d552 1158 %{-m:-m -k %{-k*}%{!-k:/usr/share/empty}} \\\
90627280
ER
1159 -u %{-u*} \\\
1160 -r \\\
1161 -d %{-d*}%{!-d:/usr/share/empty} \\\
1162 -s %{-s*}%{!-s:/bin/false} \\\
840e7b00 1163 %{-c:-c "%(set -- %{-c*} %{*}; echo $1)"}\\\
90627280
ER
1164 -g %{-g*} \\\
1165 %{-M} \\\
1166 %{-G:-G %{-G*}} \\\
1aac682a 1167 %{expand:%{%{#}}} 1>&2 || exit $? \
bcf63b58 1168 [ ! -x /usr/sbin/nscd ] || /usr/sbin/nscd -i passwd || : \
90627280 1169fi;
611a25d5 1170# vim: "
90627280 1171
90627280
ER
1172# Usage:
1173# %groupadd [-P package] [-g gid] group
1174#
1175# -g gid. REQUIRED
1176#
1177# Sample:
1178# %groupadd -P %{name}-base -g %{gid} %{name}
1179
1180%groupadd(g:P:rfo) \
9ba02ba9
ER
1181%{!-g:%{error:groupadd: Required argument -g missing}} \
1182%{!?1:%{error:groupadd: Required parameter group missing}} \
637962e6 1183if /usr/bin/getgid %{1} > /dev/null 2>&1; then \
90627280
ER
1184 if [ "`/usr/bin/getgid %{1}`" != "%{-g*}" ]; then \
1185 echo "Error: group %{1} doesn't have gid=%{-g*}. Correct this before installing %{-P*}%{!?-P:%{name}}." 1>&2 \
1186 exit 1 \
1187 fi \
1188else \
1189 echo "Adding group %{1} GID=%{-g*}." \
1aac682a 1190 /usr/sbin/groupadd -g %{-g*} -r %{1} 1>&2 || exit $? \
bcf63b58 1191 [ ! -x /usr/sbin/nscd ] || /usr/sbin/nscd -i group || : \
90627280 1192fi;
7cb77741 1193
462b26fa 1194# service macro.
4c73bc69 1195# Author: Elan Ruusamäe <glen@pld-linux.org>
462b26fa
ER
1196#
1197# calls usual service restart on package %post, but skips the restart if
1198# administrator has disabled automatic service restarts in either global
1199# /etc/sysconfig/rpm or per service /etc/sysconfig/SERVICE file.
2aa55885
TP
1200# NOTE: systemd_booted machines do not print
1201# Run "{command}" to restart {service}.
1202# message for packages without native systemd unit (not here, no %systemd_post).
462b26fa 1203#
462b26fa 1204# Usage:
7377b5ca 1205# %service [-q] [-n] SERVICE ACTION ["SERVICE NICE DESCRIPTION"]
462b26fa 1206#
a0bbe604 1207# -q be silent when service isn't started (for scriplets restaring other package's services)
7377b5ca 1208# -n NOOP mode, do not actually restart service
462b26fa 1209#
7377b5ca
ER
1210# Requirements:
1211# BuildRequires: rpmbuild(macros) >= 1.268
1212# Requires: rc-scripts
1213# -n option:
1214# BuildRequires: rpmbuild(macros) >= 1.450
207c9ca4 1215%service(qn) {{%(export noop=%{-n:1} quiet=%{-q:1} RPM_BUILD_ROOT=%{buildroot}; /usr/lib/rpm/service_generator.sh %{*}) };}
6aedae62 1216
b0bc2936 1217%env_update [ ! -x /sbin/env-update ] || /sbin/env-update -u || :
d834e0a1 1218
fa65356c 1219# patchset macros
4b7f0e84
ER
1220# generate SourceX urls from range START STOP
1221# Format can be SINGLE format char of %e, %f, %g, see seq(1)
1222# The sources start from 10000
1223#
4c73bc69 1224# Author: Elan Ruusamäe <glen@pld-linux.org>
fa65356c
ER
1225#
1226# Usage:
1227# %patchset_source -f <seq(1) format> <start> [<end>]
1228# %patchset_patch <start> [<end>]
fa65356c
ER
1229# If <end> is omited, it is assumed to be <start>.
1230#
1231# For example in preamble:
1232# %patchset_source -f ftp://ftp.vim.org/pub/editors/vim/patches/7.0/7.0.%03g 33 44
1233# and in %prep:
1234# %patchset_patch 33 44
4b7f0e84
ER
1235#
1236# Using sources list:
edd07077 1237# BuildRequires: rpmbuild(macros) >= 1.426
4b7f0e84
ER
1238# %patchset_source -f <url> -s <filelist>
1239# %patchset_patch -s <filelist>
1240# For example (ncurses):
edd07077 1241# BuildRequires: rpmbuild(macros) >= 1.683
4b7f0e84
ER
1242# %patchset_source -f ftp://dickey.his.com/ncurses/%{basever}/ -s sources
1243# %patchset_patch -s sources -p1
1244#
1245
1246%patchset_source(f:b:s:) %(
1247 base=%{-b*}%{!-b*:10000}
1248%{-s:
1249 baseurl='%{-f*}'
1250 filelist='%{-s*}'
1251 i=$base
1252 while read checksum file; do
1253 printf "Patch%d: %s%s\\n" $i "$baseurl" "$file"
1254 i=$((i+1))
1255 done < $filelist
1256}
1257%{!-s:
962f9ecf
ER
1258 start=$(expr $base + %1);
1259 end=$(expr $base + %{?2}%{!?2:%{1}});
e91610db
ER
1260 # we need to call seq twice as it doesn't allow two formats
1261 seq -f 'Patch%g:' $start $end > %{tmpdir}/__ps1;
1262 seq -f '%{-f*}' %1 %{?2}%{!?2:%{1}} > %{tmpdir}/__ps2;
1263 paste %{tmpdir}/__ps{1,2};
1264 rm -f %{tmpdir}/__ps{1,2};
4b7f0e84 1265}
962f9ecf
ER
1266) \
1267%{nil}
fa65356c
ER
1268
1269# apply sources from %patchset_source
1270# -p specify -pX for %patch line
1271# -b base offset: defaults to 10000
4b7f0e84
ER
1272# -s filelist to read files from
1273%patchset_patch(f:p:b:s:) %(
1274 base=%{-b*}%{!-b*:10000}
1275 patchlevel=%{-p*:-p%{-p*}}
1276%{-s:
1277 filelist='%{-s*}'
1278 i=$base
1279 while read checksum file; do
1280 printf "patch%d %s\\n" $i "$patchlevel" | sed -e s,^,%%,
1281 i=$((i+1))
1282 done < $filelist
1283}
1284%{!-s:
962f9ecf
ER
1285 start=$(expr $base + %1);
1286 end=$(expr $base + %{?2}%{!?2:%{1}});
e91610db 1287 echo ": patchset_patch %1%{?2: to %2}";
4b7f0e84
ER
1288 seq -f "patch%g $patchlevel" $start $end | sed -e s,^,%%,;
1289}
962f9ecf
ER
1290) \
1291%{nil}
fa65356c 1292
c0d21ccc
ER
1293# return EXPANDED source url N from current spec
1294%sourceurl(n:) %(test "$IN_RPM" = 1 && exit 1; export IN_RPM=1; rpmbuild --nodigest --nosignature --nobuild -D "prep %%dump" %{_specdir}/%{name}.spec 2>&1 | awk '$2 ~ /^SOURCEURL%{-n*}/ {print $3}')
1295
ad17b654
ER
1296# Helper for LUA.
1297# split string separated by space into quoted list
1298#
4c73bc69 1299# Author: Elan Ruusamäe <glen@pld-linux.org>
ad17b654
ER
1300#
1301# %__lua_split /bin/sh /bin/pdksh -> "/bin/sh", "/bin/pdksh"
1302%__lua_split() %(echo "%*" | awk '{for (i=1;i<=NF;i++) printf("\\"%%s\\"%%s", $i, i == NF ? "" : ", ")}')
1303
1304# adjust /etc/shells by adding and removing shells from there
4c73bc69 1305# Author: Elan Ruusamäe <glen@pld-linux.org>
ad17b654
ER
1306#
1307# Usage:
d9b789d9
ER
1308# %post -p <lua>
1309# %lua_add_etc_shells /bin/sh /bin/pdksh
ad17b654 1310#
d9b789d9
ER
1311# %preun -p <lua>
1312# if arg[2] == 0 then
1313# %lua_remove_etc_shells /bin/bash /bin/rbash
1314# end
7377b5ca
ER
1315#
1316# Requirements:
d9b789d9
ER
1317# BuildRequires: rpmbuild(macros) >= 1.462
1318#
ad17b654 1319
d9b789d9 1320%lua_add_etc_shells() \
ad17b654
ER
1321t = {}\
1322f = io.open("/etc/shells", "r")\
1323if f then\
1324 for l in f:lines() do t[l]=l; end\
1325 f:close()\
1326end\
1327for _, s in ipairs({%{expand:%%__lua_split %*}}) do\
1328 if not t[s] then\
b8c0bc18 1329 print("Adding "..s.." to /etc/shells")\
da13045e 1330 f = io.open("/etc/shells", "a")\
b7e89f70
AM
1331 if f then\
1332 f:write(s.."\\n")\
1333 f:close()\
0ecc917f 1334 end\
ad17b654
ER
1335 end\
1336end\
1337%{nil}
1338
d9b789d9
ER
1339%lua_remove_etc_shells() \
1340t = {}\
1341f = io.open("/etc/shells", "r")\
1342if f then\
1343 for l in f:lines() do t[l]=l; end\
1344 f:close()\
1345end\
1346for _, l in pairs({%{expand:%%__lua_split %*}}) do\
1347 print("Removing "..l.." from /etc/shells")\
1348 t[l] = nil\
1349end\
1350s=""\
1351for _, l in pairs(t) do\
1352 s=s..l.."\\n"\
1353end\
d2c9cab9
AM
1354f = io.open("/etc/shells", "w")\
1355if f then\
a449721f 1356 f:write(s)\
d2c9cab9
AM
1357 f:close()\
1358end\
d9b789d9
ER
1359%{nil}
1360
1361# Backwards compat. Use of %lua_ prefixed macros is preferred as these are cleaner to read.
1362#
1363# Author: Elan Ruusamäe <glen@pld-linux.org>
1364#
1365# Usage:
1366# %post -p %add_etc_shells -p /bin/sh /bin/pdksh
1367# %preun -p %remove_etc_shells -p /bin/sh /bin/pdksh
1368#
1369# -p (optional) -- specifies that result is embeded %post script (prepends <lua> as first line)
1370#
1371# Requirements:
1372# BuildRequires: rpmbuild(macros) >= 1.429
1373#
1374%add_etc_shells(p) %{-p:<lua>}\
1375%{expand:%%lua_add_etc_shells %*}\
1376%{nil}
1377
ad17b654 1378%remove_etc_shells(p) %{-p:<lua>}\
b8c0bc18 1379%{-p:if arg[2] == 0 then}\
d9b789d9 1380%{expand:%%lua_remove_etc_shells %*}\
750e19f4 1381%{-p:end} \
ad17b654
ER
1382%{nil}
1383
f602e4a0 1384# Undos files
1385#
1386# Author: Paweł Zuzelski <pawelz@pld-linux.org>
0217c63b 1387# Author: Elan Ruusamäe <glen@pld-linux.org>
f602e4a0 1388#
1389# Usage:
1390# %undos list_of_files
0217c63b
ER
1391# %undos -f EXT[,EXT]
1392# %undos -i -f EXT[,EXT]
1393#
1394# -f EXT[,EXT] - find(1) files by extensions
1395# -i - case insensitive file search
1396#
1397# Example:
1398# Un-DOS all *.js, *.css files
1399# %undos -f js,css
1400# Un-DOS all *.js, *.JS files
1401# %undos -f js -i
1402# undos all Makefiles
1403# %{__find} -name Makefile | xargs %undos
f602e4a0 1404#
1405# Requirements:
1406# BuildRequires: sed >= 4.0
9878ac15 1407# BuildRequires: rpmbuild(macros) >= 1.674
f602e4a0 1408
0217c63b 1409# NB: make sure this macro stays on one line
81a64c94 1410# NB: make sure it includes newline escape
9878ac15 1411%undos(f:i) %{-f:%{__find} -type f -regextype posix-extended -%{-i:i}regex '^.+\\.(%(echo %{-f*} | tr ',' '|'))$' -print0 | xargs -0} %{__sed} -i -e 's,\\r$,,' %* \
81a64c94 1412%{nil}
f602e4a0 1413
6dc7026b
MB
1414#-----------------------------------------------------------------
1415# Update hardware database index
1416#
1417# Requirements:
1418# BuildRequires: rpmbuild(macros) >= 1.691
1419# Requires: udev-core >= 1:196
1420
1421%udev_hwdb_update() \
1422/sbin/udevadm hwdb --update >/dev/null 2>&1 || : \
1423%{nil}
1424
705210a4
JP
1425# Generate vim help tags file
1426#
1427# Requirements:
1428# BuildRequires: rpmbuild(macros) >= 1.718
1429# Requires(post,postun): /usr/bin/vim
1430# Requires(post,postun): vim-rt >= 4:7.4.2054-2
1431%vim_doc_helptags() \
1432umask 022; \
261c16b9 1433/usr/bin/vim -c ':helptags /usr/share/vim/doc' -c ':q' 2>/dev/null \
705210a4
JP
1434%{nil}
1435
7982022e 1436# EOF
This page took 0.680887 seconds and 4 git commands to generate.