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