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