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