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