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