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