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