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