]> git.pld-linux.org Git - packages/rpm-build-macros.git/blob - rpm.macros
- feed awk one regexp at atime
[packages/rpm-build-macros.git] / rpm.macros
1 # $Revision$, $Date$
2 # PLD Linux rpm macros.
3 # <http://www.pld-linux.org/>
4
5 # can be used by builder script to check for version
6 %rpm_build_macros       %(R="$Revision$"; RR="${R##: }"; echo ${RR%%?})
7
8 %epoch          0
9 %x8664          x86_64 amd64 ia32e
10 %arm            armv3l armv4b armv4l armv5teb armv5tel
11
12 # kernel compiler
13 %kgcc           %{__cc}
14 %kgcc_package   gcc
15
16 # compiler version
17 %cc_version     %{expand:%%global cc_version %(%{__cc} -dumpversion || echo ERROR)}%cc_version
18 %cxx_version    %{expand:%%global cxx_version %(%{__cxx} -dumpversion || echo ERROR)}%cxx_version
19
20 %__rm           /bin/rm --interactive=never
21
22 # Build system path macros.
23 %__autoconf     autoconf %{?debug:-Wall}
24 %__automake     automake -a -c -f --foreign
25 %__autopoint    autopoint --force
26
27 # add parallel build flags: -jN
28 #
29 # if you want to disable parallel build do:
30 # echo '%_smp_mflags %{nil}' >> ~/.rpmmacros
31 #
32 %__make         /usr/bin/make %{?_smp_mflags}
33 %__scons        /usr/bin/scons %{?_smp_mflags}
34 %__waf          /usr/bin/waf %{?_smp_mflags}
35 %__cmake        /usr/bin/cmake
36
37 %_smp_mflags %(_NCPUS=$(/usr/bin/getconf _NPROCESSORS_ONLN); \\\
38                                 [ "$_NCPUS" -gt 1 ] && echo "-j$(($_NCPUS * 2))")
39
40 %__gettextize { \
41         if grep -qs 'AM_GNU_GETTEXT.*external' configure.{ac,in} ; then \
42                 gettextize --copy --force --no-changelog; \
43         else \
44                 gettextize --copy --force --no-changelog --intl; \
45         fi; \
46         if [ ! -f po/Makevars ]; then \
47                 cp -f po/Makevars{.template,}; \
48         fi; \
49 }
50
51 %__glib_gettextize      glib-gettextize --copy --force
52 %__gnome_doc_common     gnome-doc-common --copy
53 %__gnome_doc_prepare    gnome-doc-prepare --copy --force
54 %__gtkdocize            gtkdocize --copy
55 %__intltoolize          intltoolize --copy --force
56 %__libtoolize           libtoolize --copy --force --install
57
58 # topdir is where builder script lives,
59 # fallback to old style if SPECS/SOURCES dirs were found.
60 %_topdir    %{expand:%%global _topdir %(
61         if [ -d SPECS -a -d SOURCES ]; then
62                 # old style rpmdir: in topdir
63                 pwd
64         elif [ -d ../SPECS -a -d ../SOURCES ]; then
65                 # old style rpmdir: in subdir
66                 cd ..; pwd
67         elif [ -d $HOME/rpm/SPECS -a -d $HOME/rpm/SOURCES ]; then \
68                 # if old style rpm dir exist, go with it
69                 echo $HOME/rpm; \
70         elif [ -x ../builder -a ! -d ../builder ]; then
71                 # relative new style rpmdir: in package dir
72                 cd ..; pwd
73         elif [ -x builder -a ! -d builder ]; then
74                 # relative new style rpmdir: in packages
75                 pwd
76         elif [ -x packages/builder -a ! -d packages/builder ]; then
77                 # relative new style rpmdir: packages dir in current dir
78                 cd packages; pwd
79         else
80                 # fallback to new style rpmdir
81                 echo $HOME/rpm/packages
82         fi; \
83 )}%_topdir
84
85 # if %{_topdir}/SPECS exists, it's old style structure
86 %_specdir       %{expand:%%global _specdir %([ ! -d %{_topdir}/SPECS ] && echo %{_topdir}/%{name} || echo %{_topdir}/SPECS)}%_specdir
87 %_sourcedir             %{expand:%%global _sourcedir %([ ! -d %{_topdir}/SOURCES ] && echo %{_specdir} || echo %{_topdir}/SOURCES)}%_sourcedir
88
89 # BUILD/RPMS/SRPMS are one same level by default as packages dir, if these exist
90 # if they don't exist assume we are having custom topdir (which is not named as
91 # "packages", i.e ~/rpm/kde/{kdelibs,BUILD/RPMS/SRPMS})
92 # NOTE: readlink fails if some parent dir is not readable (/home/services/builder for example can't read /home/services), therfore the extra echo
93 %_builddir              %{expand:%%global _builddir %(if [ -d %{_topdir}/BUILD ]; then echo %{_topdir}/BUILD; else readlink -m %{_topdir}/../BUILD || echo %{_topdir}/../BUILD; fi)}%_builddir
94 %_rpmdir                %{expand:%%global _rpmdir %(if [ -d %{_topdir}/RPMS ]; then echo %{_topdir}/RPMS; else readlink -m %{_topdir}/../RPMS || echo readlink -m %{_topdir}/../RPMS; fi)}%_rpmdir
95 %_srcrpmdir             %{expand:%%global _srcrpmdir %(if [ -d %{_topdir}/SRPMS ]; then echo %{_topdir}/SRPMS; else readlink -m %{_topdir}/../SRPMS || echo readlink -m %{_topdir}/../SRPMS; fi)}%_srcrpmdir
96
97 #       The number of cvs changelog entries kept when building package.
98 %_buildchangelogtruncate 20
99
100 %dependencytracking     %{nil}
101
102 #       Relations between package names that cause dependency loops
103 #       with legacy packages that cannot be fixed. Relations are
104 #       specified as
105 #               p>q
106 #       where package p has a Requires: on something that package q Provides:
107 #
108 # XXX   Note: that there cannot be any whitespace within the string "p>q",
109 #       and that both p and q are package names (i.e. no version/release).
110 %_dependency_whiteout   %{nil}
111
112 #-----------------------------------------------------------------
113 #
114 # (re)definition of %{rpm*flags} with %filterout_* support
115 # BuildRequires:        awk
116 # BuildRequires:        rpmbuild(macros) >= 1.315
117 #
118 # Flags specified in %filterout_* are removed from %rpm*flags, exactly:
119 # %rpmcflags    = %optflags - %filterout - %filterout_c   - %filterout_ld
120 # %rpmcxxflags  = %optflags - %filterout - %filterout_cxx - %filterout_ld
121 # %rpmcppflags  = %optcppflags - %filterout - %filterout_cpp - %filterout_ld
122 # %rpmldflags   = %optldflags - %filterout_ld
123 #
124 # Regular expressions are supported, but to avoid some character be treated
125 # as regular expression it must be escaped twice.
126
127 %filter_out                                             \
128         for (i = 1; i in I; i++) {      A=0;    \
129                 for (f in F) {                          \
130                         if (I[i] ~ "^" F[f] "$") A=1;   \
131                 };                                                      \
132                 if (!A) printf(I[i] FS);        \
133         }
134
135 %rpmcflags %(awk 'BEGIN {
136         split("%{?debug:%debugcflags}%{!?debug:%optflags}%{?debuginfocflags}",I);
137         split("%{?filterout} %{?filterout_c} %{?filterout_ld}",F);
138         %{filter_out}
139 }')
140
141 %rpmcxxflags %(awk 'BEGIN {
142         split("%{?debug:%debugcflags}%{!?debug:%optflags}%{?debuginfocflags}",I);
143         split("%{?filterout} %{?filterout_cxx} %{?filterout_ld}",F);
144         %{filter_out}
145 }')
146
147 %rpmcppflags %(awk 'BEGIN {
148         split("%{?debug:%debugcppflags}%{!?debug:%optcppflags}%{?debuginfocppflags}",I);
149         split("%{?filterout} %{?filterout_cpp} %{?filterout_cpp}",F);
150         %{filter_out}
151 }')
152
153 %rpmldflags %(awk 'BEGIN {
154         split("%{?optldflags}",I);
155         split("%{?filterout_ld}",F)
156         %{filter_out}
157 }')
158
159 # rpmldflags with stripped -Wl, -- in the form flags have to be passed to 'ld'
160 # but, don't use it, better use gcc as linker
161 %ld_rpmldflags %(awk 'BEGIN {
162         split("%{rpmldflags}",F);
163         for (f in F) {
164                 s = F[f];
165                 if (s ~ /^-Wl,/) {
166                         s = substr(s,5);
167                         gsub(/,/," ",s);
168                 };
169                 printf(s FS);
170         };
171 }')
172
173 #-----------------------------------------------------------------
174 #
175 #  Generate a command which cleans environment, leaving only the
176 # most important variables.
177 #  If any spec requires any additional environment it should
178 # redefine %_preserve_env in following manner:
179 #
180 #       # ADDITIONAL_VAR is required because [a good reason here]
181 #       %define _preserve_env ADDITIONAL_VAR
182
183 %_preserve_env_base     PATH HOME TMP TMPDIR SSH_AUTH_SOCK
184
185 # "env -i" must end in first line of expaned macros because it's used as first line of shell script (#! env...)
186 %_clean_env             %{!?_preserve_env:%global _preserve_env %{nil}}%{expand:%%global _preserve_env %{_preserve_env} %_preserve_env_base} env -i %(awk -vq="'" -vqq="\\"'\\"" -vq2q="'\\"'" 'BEGIN {
187         split("%{?_preserve_env}", P);
188         for (i in P) {
189                 p = P[i];
190                 if (!ENVIRON[p] || d[p]) {
191                         continue;
192                 }
193                 d[p] = 1;
194                 split(ENVIRON[p], V, "");
195                 val = p "=";
196                 for (j = 1; j in V; j++) {
197                         v = V[j];
198                         if (v == q)
199                                 v = qq;
200                         else if (v == "\\"")
201                                 v = q2q;
202                         else if (v == "\\\\")
203                                 v = "\\\\\\\\";
204                         else
205                                 gsub("[^a-zA-Z0-9/:._-]", "\\"&\\"", v);
206                         val = val "" v;
207                 }
208                 printf(val " ");
209         }
210 }')
211
212 #-----------------------------------------------------------------
213 %configure2_13 { \
214  if [ -n "$LINGUAS" ]; then unset LINGUAS; fi; \
215  LDFLAGS="${LDFLAGS:-%rpmldflags}" ; export LDFLAGS ; \
216  CFLAGS="${CFLAGS:-%rpmcflags}" ; export CFLAGS ; \
217  CXXFLAGS="${CXXFLAGS:-%rpmcxxflags}" ; export CXXFLAGS ; \
218  FFLAGS="${FFLAGS:-%rpmcflags}" ; export FFLAGS ; \
219  FCFLAGS="${FCFLAGS:-%rpmcflags}" ; export FCFLAGS ; \
220  CPPFLAGS="${CPPFLAGS:-%rpmcppflags}" ; export CPPFLAGS ; \
221  %{?__cc:CC="%{__cc}" ; export CC ; } \
222  %{?__cxx:CXX="%{__cxx}" ; export CXX ; } \
223  %{?configuredir:%{configuredir}}%{!?configuredir:.}/configure \
224         --host=%{_target_platform} \
225         --prefix=%{_prefix} \
226         --exec-prefix=%{_exec_prefix} \
227         --bindir=%{_bindir} \
228         --sbindir=%{_sbindir} \
229         --sysconfdir=%{_sysconfdir} \
230         --datadir=%{_datadir} \
231         --includedir=%{_includedir} \
232         --libdir=%{_libdir} \
233         --libexecdir=%{_libexecdir} \
234         --localstatedir=%{_localstatedir} \
235         --sharedstatedir=%{_sharedstatedir} \
236         --mandir=%{_mandir} \
237         --infodir=%{_infodir} \
238         --x-libraries=%{?_x_libraries}%{!?_x_libraries:%{_libdir}} \
239         %{dependencytracking} \
240 }
241
242 %cmake \
243 CC="%{__cc}" \\\
244 CXX="%{__cxx}" \\\
245 CFLAGS="%{rpmcflags}" \\\
246 CXXFLAGS="%{rpmcxxflags}" \\\
247 LDFLAGS="%{rpmldflags}" \\\
248 %{__cmake} \\\
249         -DCMAKE_INSTALL_PREFIX=%{_prefix} \\\
250         -DCMAKE_BUILD_TYPE=%{!?debug:Release}%{?debug:Debug} \\\
251 %if "%{_lib}" == "lib64" \
252         -DLIB_SUFFIX=64 \\\
253 %endif \
254 %{nil}
255
256 %scons { \
257 %{__scons} \
258         LDFLAGS="${LDFLAGS:-%rpmldflags}" \
259         CFLAGS="${CFLAGS:-%rpmcflags}" \
260         CXXFLAGS="${CXXFLAGS:-%rpmcxxflags}" \
261         FFLAGS="${FFLAGS:-%rpmcflags}" \
262         CPPFLAGS="${CPPFLAGS:-%rpmcppflags}" \
263         %{?__cc:CC="%{__cc}"} \
264         %{?__cxx:CXX="%{__cxx}"} \
265         libsuffix=%{_lib} \
266         prefix=%{_prefix} \
267 }
268
269 # waf. see waf.spec
270 %waf { \
271 CC="%{__cc}" \
272 CXX="%{__cxx}" \
273 CPP="%{__cpp}" \
274 CFLAGS="%{rpmcflags}" \
275 CXXFLAGS="%{rpmcxxflags}" \
276 %{__waf} \
277 }
278
279 #----------------------------------------------------------------
280 #%configure_cache 0
281 %configure_cache_file   %{buildroot}.configure.cache
282
283 %configure {./configure \
284         LDFLAGS="${LDFLAGS:-%rpmldflags}" \
285         CFLAGS="${CFLAGS:-%rpmcflags}" \
286         CXXFLAGS="${CXXFLAGS:-%rpmcxxflags}" \
287         FFLAGS="${FFLAGS:-%rpmcflags}" \
288         FCFLAGS="${FCFLAGS:-%rpmcflags}" \
289         CPPFLAGS="${CPPFLAGS:-%rpmcppflags}" \
290         %{?__cc:CC="%{__cc}"} \
291         %{?__cxx:CXX="%{__cxx}"} \
292         --host=%{_target_platform} \
293         --build=%{_target_platform} \
294         --prefix=%{_prefix} \
295         --exec-prefix=%{_exec_prefix} \
296         --bindir=%{_bindir} \
297         --sbindir=%{_sbindir} \
298         --sysconfdir=%{_sysconfdir} \
299         --datadir=%{_datadir} \
300         --includedir=%{_includedir} \
301         --libdir=%{_libdir} \
302         --libexecdir=%{_libexecdir} \
303         --localstatedir=%{_localstatedir} \
304         --sharedstatedir=%{_sharedstatedir} \
305         --mandir=%{_mandir} \
306         --infodir=%{_infodir} \
307         --x-libraries=%{?_x_libraries}%{!?_x_libraries:%{_libdir}} \
308         %{dependencytracking} \
309         %{?configure_cache:--cache-file=%{configure_cache_file}} \
310 }
311
312 # Simple macros to simplify adding bconded options to configure scripts.
313 #   Each macro requires bcond name and accepts optional option name, if option
314 # isn't specified bcond name is used as option name. Options returning
315 # --with and --enable also allow third argument which will be added as value
316 # ( --with-option=value or --enable-option=value ) in case or positive
317 # condition, but won't be added otherwise ( nothing or just --disable-option ).
318
319 # Requirements:
320 # BuildRequires: rpmbuild(macros) >= 1.527
321
322 # Usage example:
323 # %{__enable bcond} - returns --enable-bcond iff build condition is set
324 # %{__disable bcond option} - returns --enable-option iff bcond is not set
325 # %{__enable_disable bcond option value} - returns --enable-option=value if
326 #    bcond is set, returns --disable-option otherwise
327
328 # expand bconds to --enable-something and --disable-something
329 %__enable() %{expand:%%{?with_%{1}:--enable-%{?2}%{!?2:%{1}}%{?3:=%{3}}}}
330 %__disable() %{expand:%%{!?with_%{1}:--disable-%{?2}%{!?2:%{1}}}}
331 %__enable_disable() %{expand:%%{?with_%{1}:--enable-%{?2}%{!?2:%{1}}%{?3:=%{3}}}%%{!?with_%{1}:--disable-%{?2}%{!?2:%{1}}}}
332
333 # same as above, but condition inverted
334 %__enable_unless() %{expand:%%{!?with_%{1}:--enable-%{?2}%{!?2:%{1}}%{?3:=%{3}}}}
335 %__disable_if() %{expand:%%{?with_%{1}:--disable-%{?2}%{!?2:%{1}}}}
336 %__enable_disable_not() %{expand:%%{!?with_%{1}:--enable-%{?2}%{!?2:%{1}}%{?3:=%{3}}}%%{?with_%{1}:--disable-%{?2}%{!?2:%{1}}}}
337
338 # expand bconds to --with-something and --without-something
339 %__with() %{expand:%%{?with_%{1}:--with-%{?2}%{!?2:%{1}}%{?3:=%{3}}}}
340 %__without() %{expand:%%{!?with_%{1}:--without-%{?2}%{!?2:%{1}}}}
341 %__with_without() %{expand:%%{?with_%{1}:--with-%{?2}%{!?2:%{1}}%{?3:=%{3}}}%%{!?with_%{1}:--without-%{?2}%{!?2:%{1}}}}
342
343 # same as above, but condition inverted
344 %__with_unless() %{expand:%%{!?with_%{1}:--with-%{?2}%{!?2:%{1}}%{?3:=%{3}}}}
345 %__without_if() %{expand:%%{?with_%{1}:--without-%{?2}%{!?2:%{1}}}}
346 %__with_without_not() %{expand:%%{!?with_%{1}:--with-%{?2}%{!?2:%{1}}%{?3:=%{3}}}%%{?with_%{1}:--without-%{?2}%{!?2:%{1}}}}
347
348 #-----------------------------------------------------------------
349
350 # overload to insert debuginfo package
351 %prep \
352 %if 0%{?_enable_debug_packages}\
353 %{debug_package}\
354 %endif\
355 %%prep\
356 %{nil}
357
358 # Location of autoconf macros
359 %_aclocaldir    %{expand:%%global _aclocaldir %(aclocal --print-ac-dir 2>/dev/null || echo ERROR)}%_aclocaldir
360
361 # Location of omf files
362 %_omf_dest_dir  %{expand:%%global _omf_dest_dir %(scrollkeeper-config --omfdir || echo ERROR)}%_omf_dest_dir
363
364 # Location of pkgconfig files
365 %_pkgconfigdir  /usr/%{_lib}/pkgconfig
366 # noarch pkgconfig files
367 %_npkgconfigdir /usr/share/pkgconfig
368
369 # Location of desktop files
370 %_desktopdir    /usr/share/applications
371 %_applnkdir     ERROR:_applnkdir_is_obsolete_use_desktopdir_instead
372
373 # Location of pixmaps for applnk/desktop files
374 %_pixmapsdir    /usr/share/pixmaps
375
376 # Location of themable icons for applnk/desktop files
377 %_iconsdir      /usr/share/icons
378
379 # Location of fonts directories
380 %_fontsdir      /usr/share/fonts
381
382 # Location of Gtk and associated libraries documentation
383 %_gtkdocdir     %{_defaultdocdir}/gtk-doc/html
384
385 # Location of KDE documentation
386 %_kdedocdir     %{_defaultdocdir}/kde/HTML
387
388 # unsermake script
389 %__unsermake /usr/share/unsermake/unsermake
390
391 # Current date
392 %date           %(LC_ALL=C date +"%a %b %d %Y")
393
394 # Example files, programs, scripts...
395 %_examplesdir   /usr/src/examples
396
397 # Alternative kernel type/version
398 %_alt_kernel    %{nil}%{?alt_kernel:-%{?alt_kernel}}
399
400 # The directory holding Linux kernel sources
401 %_kernelsrcdir  /usr/src/linux%{_alt_kernel}
402
403 # SysV-style initscripts dir
404 %_initddir              /etc/rc.d/init.d
405
406 # If non-empty "debug" macro defined, add "dbg" suffix to release number
407 %_rpmfilename           %%{NAME}-%%{VERSION}-%%{RELEASE}%{?debug:dbg}.%%{ARCH}.rpm
408
409 # Bootstrap release macros.
410 # Usage:
411 #       %bcond_with     bootstrap
412 #       Release:        %{bootstrap_release 1}
413 #
414 # Package will have release 1 if built normally,
415 # and release 0.zzz.bootstrap if built with bootstrap
416 %bootstrap_release() %{!?with_bootstrap:%{1}%{?2:.%{2}}}%{?with_bootstrap:%{!?2:%(expr %{1} - 1)}%{?2:%{1}.%(expr %{2} - 1)}.zzz.bootstrap}
417
418 # -n drm to generate kernel%{_alt_kernel}-drm dependency
419 %releq_kernel(n:)               %{expand:%%global releq_kernel %(R=$(LC_ALL=C rpm -q --qf '%{N}%{?-n:-%{-n*}} = %|E?{%{E}:}|%{V}-%{R}' -f %{_kernelsrcdir}/include/linux/version.h 2>/dev/null | grep -v 'is not' | sed -e 's:-headers::;s:-config::'); echo ${R:-ERROR})}%releq_kernel
420 %releq_kernel_up(n:)    %{expand:%%global releq_kernel_up %(R=$(LC_ALL=C rpm -q --qf '%{N}%{?-n:-%{-n*}}-up = %|E?{%{E}:}|%{V}-%{R}' -f %{_kernelsrcdir}/include/linux/version.h 2>/dev/null | grep -v 'is not' | sed -e 's:-headers::;s:-config::'); echo ${R:-ERROR})}%releq_kernel_up
421 %releq_kernel_smp(n:)   %{expand:%%global releq_kernel_smp %(R=$(LC_ALL=C rpm -q --qf '%{N}%{?-n:-%{-n*}}-smp = %|E?{%{E}:}|%{V}-%{R}' -f %{_kernelsrcdir}/include/linux/version.h 2>/dev/null | grep -v 'is not' | sed -e 's:-headers::;s:-config::'); echo ${R:-ERROR})}%releq_kernel_smp
422
423 # -s post to generate Requires(post) dependency
424 %requires_releq_kernel(s:n:)            Requires%{-s:(%{-s*})}: %releq_kernel
425 %requires_releq_kernel_up(s:n:)         Requires%{-s:(%{-s*})}: %releq_kernel_up
426 %requires_releq_kernel_smp(s:n:)        Requires%{-s:(%{-s*})}: %releq_kernel_smp
427
428 # Requires name = version-release
429 %requires_releq()       %{!?1:ERROR}%{?2:ERROR}%{?1:%{!?2:%{expand:%%requires_eq_to -r %1 %1}}}
430 # Requires: name = version
431 %requires_eq()          %{!?1:ERROR}%{?2:ERROR}%{?1:%{!?2:%{expand:%%requires_eq_to %1 %1}}}
432 # Requires: name = version (version based on querying package %2)
433 %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)}}
434
435 # Requires: name >= version
436 %requires_ge()          %{!?1:ERROR}%{?2:ERROR}%{?1:%{!?2:%{expand:%%requires_ge_to %1 %1}}}
437 # Requires: name >= version (version based on querying package %2)
438 %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)}}
439
440 %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
441
442 # kernel version-release handling
443 %__kernel_ver    %{expand:%%global __kernel_ver %( \\
444         Z=$([ -f '%{_kernelsrcdir}/include/generated/utsrelease.h' ] && awk -F'"' '/UTS_RELEASE/{print $2}' %{_kernelsrcdir}/include/{linux/version,generated/utsrelease}.h 2>/dev/null || awk -F'"' '/UTS_RELEASE/{print $2}' %{_kernelsrcdir}/include/linux/{version,utsrelease}.h 2>/dev/null); \\
445         Z=${Z:-$(awk -F' = ' '/^VERSION/{v=$2} /^PATCHLEVEL/{p=$2} /^SUBLEVEL/{s=$2} /^EXTRAVERSION/{e=$2} END {printf("%d.%d.%d%s", v, p, s, e)}' %{_kernelsrcdir}/Makefile 2>/dev/null)}; \\
446         echo ${Z:-ERROR}; \\
447 )}%__kernel_ver
448
449 %__kernel_rel   %{expand:%%global __kernel_rel %(Z=$(LC_ALL=C rpm -qf %{_kernelsrcdir}/include/linux/fs.h 2>/dev/null --qf "%{R}" | grep -v "is not"); echo ${Z:-ERROR})}%__kernel_rel
450 %__kernel_rpmvr %{expand:%%global __kernel_rpmvr %(Z=$(LC_ALL=C rpm -qf %{_kernelsrcdir}/include/linux/fs.h 2>/dev/null --qf "%{V}-%{R}" | grep -v "is not"); echo ${Z:-ERROR})}%__kernel_rpmvr
451 %_kernel_ver    %{expand:%%global _kernel_ver %{__kernel_ver}%{?with_dist_kernel:%(echo %{__kernel_ver} | grep -q -e - || echo -%{__kernel_rel})}}%_kernel_ver
452 %_kernel_ver_str %{expand:%%global _kernel_ver_str %(echo %{!?_without_dist_kernel:%{__kernel_rpmvr}}%{?_without_dist_kernel:%{__kernel_ver}} | sed -e 's/-/_/g')}%_kernel_ver_str
453
454 # `uname -r` to be used in @release field
455 %_kernel_vermagic       %{expand:%%global _kernel_vermagic %(echo %{_kernel_ver} | sed -e 's/-/_/g')}%_kernel_vermagic
456
457 # sgml macros
458 %xmlcat_add()           /usr/bin/xmlcatalog --noout --add nextCatalog \"\" %1 /etc/xml/catalog ;
459 %xmlcat_del()           /usr/bin/xmlcatalog --noout --del %1 /etc/xml/catalog ;
460 %xmlcat_add_rewrite     /usr/bin/xmlcatalog --noout --add rewriteSystem
461 %xmlcat_create()        /usr/bin/xmlcatalog --noout --create %1 ;
462 %sgmlcat_add()          /usr/bin/install-catalog --add %1 %2 > /dev/null ;
463 %sgmlcat_del()          /usr/bin/install-catalog --remove %1 %2 > /dev/null ;
464 %docbook_sgmlcat_fix() { for l in \
465 '' \
466 '  -- default decl --' \
467 'DTDDECL "-//OASIS//DTD DocBook XML V%2//EN" "../../xml.dcl"' \
468 '  -- hacks for opensp --' \
469 'SYSTEM "file://%{_datadir}/sgml/docbook/xml-dtd-%2/docbookx.dtd" "%{_datadir}/sgml/docbook/xml-dtd-%2/docbookx.dtd"' \
470 'SYSTEM "http://www.oasis-open.org/docbook/xml/%2/docbookx.dtd"                  "%{_datadir}/sgml/docbook/xml-dtd-%2/docbookx.dtd"' \
471 '' \
472 ; do echo $l; done >> %1 \
473 }
474
475 # vim - "
476
477 # minimum file size needed for compressed documents.
478 # just smaller files than this get larger when compressed.
479 # some stats:
480 # - 0 byte file compressed was 25 bytes .gz
481 # - 39 byte file was compressed as 57
482 # - with test/test.spec@man 158 byte file was compressed also 158
483 %_min_compress_bytes    159
484
485 #-----------------------------------------------------------------
486 # find and gzip all files in %{_mandir} and %{infodir}
487 #
488 # Requires: xargs, find
489 #
490 #%no_install_post_compress_docs 1
491 %__spec_install_post_compress_docs { \
492 %{!?no_install_post_compress_docs:__spec_install_post_compress_docs() { \
493         for i in /usr/share/man /usr/X11R6/man; do \
494                 if [ -d "$RPM_BUILD_ROOT$i" ]; then \
495                         echo "Compress man pages: $i"; \
496                         find "$RPM_BUILD_ROOT$i" -name '*.bz2' -print | xargs -r %{__bzip2} -df; \
497                         find "$RPM_BUILD_ROOT$i" -name '*.gz' -print | xargs -r %{__gzip} -dnf; \
498                         find $RPM_BUILD_ROOT$i -type l | while read a; do \
499                                 m=$(readlink $a); \
500                                 rm -f $a; \
501                                 echo .so ${m##*/} > $a; \
502                                 echo >&2 "Converted ${a#$RPM_BUILD_ROOT} from symlink to man link: ${m##*/}"; \
503                         done; \
504                         find "$RPM_BUILD_ROOT$i" -type f -size +%{_min_compress_bytes}c -print | xargs -r %{__gzip} -9nf; \
505                 fi; \
506         done; \
507         if [ -d "$RPM_BUILD_ROOT%{_infodir}" ]; then \
508                 echo "Compress info pages: %{_infodir}"; \
509                 find "$RPM_BUILD_ROOT%{_infodir}" -name '*.bz2' -print | xargs -r %{__bzip2} -df; \
510                 find "$RPM_BUILD_ROOT%{_infodir}" -name '*.gz' -print | xargs -r %{__gzip} -dnf; \
511                 find "$RPM_BUILD_ROOT%{_infodir}" -name '*.info*' -type f -size +%{_min_compress_bytes}c -print | xargs -r %{__gzip} -9nf; \
512         fi; \
513 }; __spec_install_post_compress_docs } }
514
515 #-----------------------------------------------------------------
516 # Strip executable binaries and shared object files
517 #
518 # Requires: find, awk, strip, cut, xargs
519 #
520 # Special macros which affect this process:
521 #%no_install_post_strip 1               # disable stripping at all
522 #%_noautostrip                  regexp  # exclude files matching (anchored!) regex from stripping
523 #%_autostripall                 regexp  # strip files matching (anchored!) regex using plain strip
524 #%_autostripunneeded    regexp  # strip files matching (anchored!) regex using strip --strip-unneeded
525 #%_autostripdebug               regexp  # strip files matching (anchored!) regex using strip --strip-debug
526 #
527 %__spec_install_post_strip {%{!?debug: \
528 %{!?no_install_post_strip:__spec_install_post_strip() { \
529 if [ -d "$RPM_BUILD_ROOT" ]; then \
530         if [ -d $RPM_BUILD_ROOT/lib/modules ]; then \
531                 modulelist=$(find $RPM_BUILD_ROOT/lib/modules -name '*o' -type f -print); \
532                 if [ "$modulelist" ]; then \
533                         modulecount=$(echo "$modulelist" | wc -l); \
534                         printf "Stripping %d kernel modules..." $modulecount; \
535                         echo "$modulelist" | xargs -l512 chmod u+w; \
536                         echo "$modulelist" | xargs -l512 %{__strip} --strip-unneeded --remove-section=.comment --remove-section=.note.GNU-stack; \
537                         echo "DONE"; \
538                 fi; \
539         fi; \
540         filelist=$(find $RPM_BUILD_ROOT -type f ! -regex ".*/usr/lib[0-9]*/debug/.*\.debug" ! -regex ".*/lib/modules/.*" ! -regex ".*%{_docdir}/.*" ! -regex ".*%{_includedir}/.*" %{?_noautostrip:! -regex "%{_noautostrip}"} %{?_autostripall:! -regex "%{_autostripall}"} %{?_autostripunneeded:! -regex "%{_autostripunneeded}"} %{?_autostripdebug:! -regex "%{_autostripdebug}"}); \
541         if [ -n "$filelist" ]; then \
542                 filetypes=`echo "$filelist" | xargs -r -d'\\n' file`; \
543                 elfexelist=`echo "$filetypes" | awk -F: '/ELF.*executable/ {print $1}'`; \
544                 elfsharedlist=`echo "$filetypes" | awk -F: '/LF.*shared object/ {print $1}'`; \
545                 archiveslist=`echo "$filetypes" | awk -F: '/current ar archive/ {print $1}'`; \
546                 if [ -n "$elfexelist" ]; then \
547                         printf "Stripping %d ELF executables..." $(echo "$elfexelist" | wc -l); \
548                         chmod u+w $elfexelist; \
549                         %{__strip} --remove-section=.note --remove-section=.comment $elfexelist; \
550                         echo "DONE"; \
551                 fi; \
552                 if [ -n "$elfsharedlist" ]; then \
553                         printf "Stripping %d ELF shared libraries..." $(echo "$elfsharedlist" | wc -l); \
554                         chmod u+w $elfsharedlist; \
555                         %{__strip} --strip-unneeded --remove-section=.note --remove-section=.comment $elfsharedlist; \
556                         echo "DONE"; \
557                 fi; \
558                 if [ -n "$archiveslist" ]; then \
559                         printf "Stripping %d ar archives..." $(echo "$archiveslist" | wc -l); \
560                         chmod u+w $archiveslist; \
561                         %{__strip} --strip-debug --remove-section=.note --remove-section=.comment $archiveslist; \
562                         echo "DONE"; \
563                 fi; \
564         fi; \
565     filelist_all=%{?_autostripall:$(find $RPM_BUILD_ROOT -type f -regex "%{_autostripall}")}; \
566     filelist_unneeded=%{?_autostripunneeded:$(find $RPM_BUILD_ROOT -type f -regex "%{_autostripunneeded}")}; \
567     filelist_debug=%{?_autostripdebug:$(find $RPM_BUILD_ROOT -type f -regex "%{_autostripdebug}")}; \
568         if [ -n "$filelist_all" ]; then \
569                 printf "Stripping everything from %d additional files..." $(echo "$filelist_all" | wc -l); \
570                 chmod u+w $filelist_all; \
571                 %{__strip} --remove-section=.note --remove-section=.comment $filelist_all; \
572                 echo "DONE"; \
573         fi; \
574         if [ -n "$filelist_unneeded" ]; then \
575                 printf "Stripping unneeded from %d additional files..." $(echo "$filelist_unneeded" | wc -l); \
576                 chmod u+w $filelist_unneeded; \
577                 %{__strip} --strip-unneeded --remove-section=.note --remove-section=.comment $filelist_unneeded; \
578                 echo "DONE"; \
579         fi; \
580         if [ -n "$filelist_debug" ]; then \
581                 printf "Stripping debuginfo from %d additional files..." $(echo "$filelist_debug" | wc -l); \
582                 chmod u+w $filelist_debug; \
583                 %{__strip} --strip-debug --remove-section=.note --remove-section=.comment $filelist_debug; \
584                 echo "DONE"; \
585         fi; \
586 fi; }; __spec_install_post_strip } } }
587
588 #-----------------------------------------------------------------
589 # remove all RPATH from executable binaries and shared object files
590 #
591 # Requires: find, awk, cut, xargs, chrpath, uname
592 #
593 # Special macros which affect this process
594 #%no_install_post_chrpath       1       # disable chrpath at all
595 #%_noautochrpath        regex           # exclude files matching (anchored!) regex from chrpath
596 #
597 %__spec_install_post_chrpath {%{!?debug: \
598 %{!?no_install_post_chrpath: __spec_install_post_chrpath() { \
599 if [ -d "$RPM_BUILD_ROOT" ]; then \
600         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}"}`; \
601         if [ -n "$files" ]; then \
602                 objs=`echo "$files" | xargs -r -d'\\n' file | awk -F: '/ELF.*(executable.*dynamically linked|shared object)/ {print $1}'`; \
603         fi; \
604         if [ -n "$objs" ]; then \
605                 printf "Remove RPATH from %d executable binaries and shared object files.\n" $(echo "$objs" | wc -l); \
606                 echo "$objs" | \
607                 while read file; do \
608                         rpath= ; \
609                         chmod u+w "$file"; \
610                         for dir in $(chrpath -l "$file" | awk '/RPATH=/ { gsub(/.*RPATH=/,""); gsub(/:/," "); print $0 }'); do \
611                                         case $dir in \
612                                         '$ORIGIN' ) \
613                                                 if [ "$rpath" = "" ] ; then rpath="$dir" ; \
614                                                 else rpath="$rpath:$dir" ; fi ; \
615                                                 continue ; \
616                                                 ;; \
617                                         esac ; \
618                                         newdir=$(readlink -m "$dir"); \
619                                         [ ${#newdir} -le ${#dir} ] && dir=$newdir; \
620                                         case $dir in \
621                                         /home/* | /tmp/* | /usr/lib | /usr/lib64 | /lib | /lib64 | /usr/local/lib | /usr/local/lib64 | /usr/X11R6/lib | /usr/X11R6/lib64 ) \
622                                                 echo "remove-rpath: $dir in $file"; \
623                                                 ;; \
624                                         * ) \
625                                                 if [ "$rpath" = "" ] ; then rpath="$dir" ; \
626                                                 else rpath="$rpath:$dir" ; fi ; \
627                                                 ;; \
628                                         esac ; \
629                         done ; \
630                         if [ "$rpath" = "" ] ; then chrpath -d "$file" > /dev/null ; \
631                         else chrpath -r "$rpath" "$file" > /dev/null ; fi ; \
632                 done; \
633         fi; \
634 fi; }; __spec_install_post_chrpath } } }
635
636 # vim: "
637
638 #-----------------------------------------------------------------
639 # Find all shared object files with unresolved symbols. Warn
640 # and terminate if any found (termination can be turned off by define).
641 #%no_install_post_check_so 1
642 #%skip_post_check_so libwithunresolvedok.so.*
643 %__spec_install_post_check_so { \
644  __spec_install_post_check_so() { \
645     fail=0; \
646     printf "Searching for shared objects with unresolved symbols..."; \
647     for f in $(find $RPM_BUILD_ROOT -type f -name '*.so.*' -print); do \
648             %{?skip_post_check_so:echo %{skip_post_check_so} | LC_ALL=C awk '{ gsub(/[ \t]+/,"\n"); print }' | LC_ALL=C awk -v "file=$f" 'file ~ "(^|/)" $0 "$" { exit(1) }' || continue ;} \
649         LC_ALL=C objdump -T $f 2> /dev/null | LC_ALL=C awk -v "file=$f" 'BEGIN { found=0; skip["program_name"]=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; exit(1); } } ' || fail=1 ; \
650     done ; \
651     echo " DONE"; \
652     %{!?no_install_post_check_so:return $fail;} \
653 }; __spec_install_post_check_so }}
654
655 #-----------------------------------------------------------------
656 # Find and gzip all kernel modules
657 #
658 # Requires: find
659 #
660 #%no_install_post_compress_modules      1
661 %__spec_install_post_compress_modules { \
662 %{!?no_install_post_compress_modules: __spec_install_post_compress_modules() { \
663         if [ -d $RPM_BUILD_ROOT/lib/modules ]; then \
664                 q=$(find $RPM_BUILD_ROOT/lib/modules -name '*o' -type f -print); \
665                 if [ "$q" ]; then \
666                         printf "Compress %d kernel modules..." $(echo "$q" | wc -l); \
667                         echo "$q" | xargs -r %{__gzip} -9nf; \
668                         echo "DONE"; \
669                         find $RPM_BUILD_ROOT/lib/modules -name '*o' -type l -printf "%p %l\n" | \
670                         while read a b; do ln -sf $b.gz $a.gz; rm -f $a; done; \
671                 fi; \
672         fi; \
673 }; __spec_install_post_compress_modules } }
674
675 # Remove common Perl files we don't package
676 %__spec_install_post_perl_clean {\
677 %{!?no_install_post_perl_clean: \
678 %{?pdir:rm -f $RPM_BUILD_ROOT{%{perl_archlib}/perllocal.pod,%{perl_vendorarch}/auto/%{pdir}%{?pnam:/%(echo %{pnam} | tr - /)}/.packlist}} \
679 } }
680
681 #-----------------------------------------------------------------
682 # Update GConf2 schemas
683 #
684 # Requires: GConf2
685 #
686 %gconf_schema_install() \
687         umask 022; \
688         GCONF_CONFIG_SOURCE="xml:readwrite:/etc/gconf/gconf.xml.defaults" \\\
689         /usr/bin/gconftool-2 --makefile-install-rule /etc/gconf/schemas/%{?1}%{!?1:*.schemas} > /dev/null; \
690 %{nil}
691
692 %gconf_schema_uninstall() \
693 if [ $1 = 0 -a -x /usr/bin/gconftool-2 ]; then \
694         umask 022; \
695         GCONF_CONFIG_SOURCE="xml:readwrite:/etc/gconf/gconf.xml.defaults" \\\
696         /usr/bin/gconftool-2 --makefile-uninstall-rule /etc/gconf/schemas/%{?1} > /dev/null \
697 fi; \
698 %{nil}
699
700 #-----------------------------------------------------------------
701 # Update desktop MIME database
702 # requires: desktop-file-utils
703 %update_desktop_database() {{ \
704         umask 022; \
705         /usr/bin/update-desktop-database -q; \
706 };} \
707 %{nil}
708
709 %update_desktop_database_post %update_desktop_database
710
711 %update_desktop_database_postun() {{ \
712 if [ "$1" = "0" ]; then \
713         %update_desktop_database \
714 fi; \
715 };} \
716 %{nil}
717
718 #-----------------------------------------------------------------
719 # Update shared MIME info database
720 # requires: shared-mime-info
721 #
722 %update_mime_database() {{ \
723         umask 022; \
724         /usr/bin/update-mime-database %{_datadir}/mime; \
725 };} \
726 %{nil}
727
728 #-----------------------------------------------------------------
729 # Update icon cache
730 # requires: gtk+
731 #
732 %update_icon_cache() {{ \
733         umask 022; \
734         /usr/bin/gtk-update-icon-cache -qf %{_datadir}/icons/%1; \
735 };} \
736 %{nil}
737
738 #-----------------------------------------------------------------
739 # Update scrollkeeper database
740 # requires: scrollkeeper
741 #
742 %scrollkeeper_update_post() \
743         /usr/bin/scrollkeeper-update -q; \
744 %{nil}
745
746 %scrollkeeper_update_postun() \
747 if [ "$1" = "0" ]; then \
748         /usr/bin/scrollkeeper-update -q; \
749 fi; \
750 %{nil}
751
752 #-----------------------------------------------------------------
753 # post %install sequence:
754 # - autodeps exceptions
755 # - compress all man and info pages,
756 # - strip all ELF executables and ELF shared objects if not %debug.
757 # - compress kernel modules if any
758
759 ###################################################################
760 # Requires/Provides automation
761 # exceptions system by Jacek Konieczny <jajcus@pld-linux.org>
762 #
763 %__noautoreqfiles       %(sed -e s'/#.*//' /etc/rpm/noautoreqfiles)%{?_noautoreqfiles: %{_noautoreqfiles}}
764 %__noautoprovfiles      %(sed -e s'/#.*//' /etc/rpm/noautoprovfiles)%{?_noautoprovfiles: %{_noautoprovfiles}}
765 %__noautoreq            %(sed -e s'/#.*//' /etc/rpm/noautoreq)%{?_noautoreq: %{_noautoreq}}
766 %__noautoreqdep         %(sed -e s'/#.*//' /etc/rpm/noautoreqdep)%{?_noautoreqdep: %{_noautoreqdep}}
767 %__noautoprov           %(sed -e s'/#.*//' /etc/rpm/noautoprov)%{?_noautoprov: %{_noautoprov}}
768
769 #%_noautocompressdoc    %{nil}
770 #
771 %_missing_doc_files_terminate_build     1%{nil}
772 %_unpackaged_files_terminate_build      %{nil}
773 # (X)emacs support
774 %___emacs_lispdir_helper  -batch -q -eval '(while load-path (princ (concat (car load-path) "\\n")) (setq load-path (cdr load-path)))' 2> /dev/null|sed -n '/\\(.*\\/x\\?emacs\\/site-lisp\\)\\/\\?$/{s,,\\1,p;q;}'
775 %_emacs_lispdir %{expand:%%global _emacs_lispdir %(Z=$(emacs %___emacs_lispdir_helper); echo ${Z:-ERROR})}%_emacs_lispdir
776 %_xemacs_lispdir %{expand:%%global _xemacs_lispdir %(Z=$(xemacs %___emacs_lispdir_helper); echo ${Z:-ERROR})}%_xemacs_lispdir
777
778 %__php_provides %{nil}
779 %__php_requires %{nil}
780 %__perl_provides %{nil}
781 %__perl_requires %{nil}
782 %__mono_provides %{nil}
783 %__mono_requires %{nil}
784
785 # Perl specific macro definitions.
786 %perl_privlib           %{expand:%%global perl_privlib %(eval $(%{__perl} -V:installprivlib 2>/dev/null); echo ${installprivlib:-ERROR})}%perl_privlib
787 %perl_archlib           %{expand:%%global perl_archlib %(eval $(%{__perl} -V:installarchlib 2>/dev/null); echo ${installarchlib:-ERROR})}%perl_archlib
788 %perl_vendorlib         %{expand:%%global perl_vendorlib %(eval $(%{__perl} -V:installvendorlib 2>/dev/null); echo ${installvendorlib:-ERROR})}%perl_vendorlib
789 %perl_vendorarch        %{expand:%%global perl_vendorarch %(eval $(%{__perl} -V:installvendorarch 2>/dev/null); echo ${installvendorarch:-ERROR})}%perl_vendorarch
790 %perl_sitelib           %{expand:%%global perl_sitelib %(eval $(%{__perl} -V:installsitelib 2>/dev/null); echo ${installsitelib:-ERROR})}%perl_sitelib
791 %perl_sitearch          %{expand:%%global perl_sitearch %(eval $(%{__perl} -V:installsitearch 2>/dev/null); echo ${installsitearch:-ERROR})}%perl_sitearch
792
793 # Ruby
794 %__ruby                         /usr/bin/ruby
795 %ruby_archdir           %{expand:%%global ruby_archdir %(%{__ruby} -r rbconfig -e 'print Config::CONFIG["archdir"]' 2>/dev/null || echo ERROR)}%ruby_archdir
796 %ruby_ridir                     %{expand:%%global ruby_ridir %(%{__ruby} -r rbconfig -e 'include Config; print File.join(CONFIG["datadir"], "ri", CONFIG["ruby_version"], "system")' 2>/dev/null || echo ERROR)}%ruby_ridir
797 %ruby_rubylibdir        %{expand:%%global ruby_rubylibdir %(%{__ruby} -r rbconfig -e 'print Config::CONFIG["rubylibdir"]' 2>/dev/null || echo ERROR)}%ruby_rubylibdir
798 %ruby_vendorarchdir     %{expand:%%global ruby_vendorarchdir %(%{__ruby} -r rbconfig -e 'print Config::CONFIG["vendorarchdir"]' 2>/dev/null || echo ERROR)}%ruby_vendorarchdir
799 %ruby_vendorlibdir      %{expand:%%global ruby_vendorlibdir %(%{__ruby} -r rbconfig -e 'print Config::CONFIG["vendorlibdir"]' 2>/dev/null || echo ERROR)}%ruby_vendorlibdir
800 %ruby_sitearchdir       %{expand:%%global ruby_sitearchdir %(%{__ruby} -r rbconfig -e 'print Config::CONFIG["sitearchdir"]' 2>/dev/null || echo ERROR)}%ruby_sitearchdir
801 %ruby_sitelibdir        %{expand:%%global ruby_sitelibdir %(%{__ruby} -r rbconfig -e 'print Config::CONFIG["sitelibdir"]' 2>/dev/null || echo ERROR)}%ruby_sitelibdir
802 %ruby_rdocdir           /usr/share/rdoc
803 %ruby_version           %{expand:%%global ruby_version %(%{__ruby} -r rbconfig -e 'print Config::CONFIG["ruby_version"]' 2>/dev/null || echo ERROR)}%ruby_version
804 %ruby_ver_requires_eq   Requires:       ruby(ver) = %ruby_version
805 %ruby_mod_ver_requires_eq       Requires:       ruby-modules(ver) = %ruby_version
806
807 %php_pear_dir           /usr/share/pear
808 %php_data_dir           /usr/share/php
809 %php_extensiondir       %{expand:%%global php_extensiondir %(php-config --extension-dir 2>/dev/null || echo ERROR)}%php_extensiondir
810 %php_sysconfdir         %{expand:%%global php_sysconfdir %(php-config --sysconfdir 2>/dev/null || echo ERROR)}%php_sysconfdir
811 %php_includedir         %{expand:%%global php_includedir %(php-config --include-dir 2>/dev/null || echo ERROR)}%php_includedir
812
813 # extract php/zend api versions
814 %php_major_version              %{expand:%%global php_major_version %(awk '/#define PHP_MAJOR_VERSION/{print $3}' %{php_includedir}/main/php_version.h 2>/dev/null || echo ERROR)}%php_major_version
815 %php_minor_version              %{expand:%%global php_minor_version %(awk '/#define PHP_MINOR_VERSION/{print $3}' %{php_includedir}/main/php_version.h 2>/dev/null || echo ERROR)}%php_minor_version
816 %php_api_version                %{expand:%%global php_api_version %(awk '/#define PHP_API_VERSION/{print $3}' %{php_includedir}/main/php.h 2>/dev/null || echo ERROR)}%php_api_version
817 %php_pdo_api_version    %{expand:%%global php_pdo_api_version %(awk '/#define PDO_DRIVER_API/{print $3}' %{php_includedir}/ext/pdo/php_pdo_driver.h 2>/dev/null || echo ERROR)}%php_pdo_api_version
818 %php_debug                              %{expand:%%global php_debug %(awk '/#define ZEND_DEBUG/{print $3}' %{php_includedir}/main/php_config.h 2>/dev/null || echo ERROR)}%php_debug
819 %zend_module_api                %{expand:%%global zend_module_api %(awk '/#define ZEND_MODULE_API_NO/{print $3}' %{php_includedir}/Zend/zend_modules.h 2>/dev/null || echo ERROR)}%zend_module_api
820 %zend_extension_api             %{expand:%%global zend_extension_api %(awk '/#define ZEND_EXTENSION_API_NO/{print $3}' %{php_includedir}/Zend/zend_extensions.h 2>/dev/null || echo ERROR)}%zend_extension_api
821 %_zend_zts                              %{expand:%%global _zend_zts %(Z=$(grep -sc '^#define ZTS 1' %{php_includedir}/main/php_config.h); echo ${Z:-ERROR})}%_zend_zts
822 # "_ts" if ZTS enabled, empty otherwise
823 %zend_zts                               %{expand:%%global _zend_zts_%{?_zend_zts} 1}%{?_zend_zts_1:_ts}
824
825 # helper macro
826 %__php_api_requires(v:) Requires: php%{-v*}(%{expand:%1}) = %{expand:%{%{!?2:%{1}}%{?2}}}
827
828 # macros for public use
829 # for php extensions (php-pecl)
830 %requires_php_extension %{__php_api_requires modules_api php_api_version} \
831 %{__php_api_requires zend_module_api} \
832 %{__php_api_requires -v %php_major_version debug php_debug} \
833 %{__php_api_requires -v %php_major_version thread-safety _zend_zts}
834
835 # for zend extensions
836 %requires_zend_extension %{__php_api_requires zend_module_api} \
837 %{__php_api_requires zend_extension_api} \
838 %{__php_api_requires -v %php_major_version debug php_debug} \
839 %{__php_api_requires -v %php_major_version thread-safety _zend_zts}
840
841 # for php pdo modules (php-pecl-PDO_*)
842 %requires_php_pdo_module %{__php_api_requires PDO_API php_pdo_api_version}
843
844 # for using PHP post scripts. for PHP >= 5.0
845 %php_webserver_restart \
846 [ ! -f /etc/apache/conf.d/??_mod_php.conf ] || %service -q apache restart \
847 [ ! -f /etc/httpd/conf.d/??_mod_php.conf ] || %service -q httpd restart \
848 if [ -x /etc/rc.d/init.d/php-fcgi ]; then \
849         PHP_FCGI_BINARY=; . /etc/sysconfig/php-fcgi 2>/dev/null \
850         if [[ ${PHP_FCGI_BINARY:-php.fcgi} = *php.fcgi* ]]; then \
851                 %service -q php-fcgi restart \
852         fi \
853 fi \
854 if [ -x /etc/rc.d/init.d/php-fpm ]; then \
855         %service -q php-fpm restart \
856 fi \
857 %{nil}
858
859 # for using php post scripts. for PHP >= 4.0 && PHP < 5.0
860 %php4_webserver_restart \
861 [ ! -f /etc/apache/conf.d/??_mod_php4.conf ] || %service -q apache restart \
862 [ ! -f /etc/httpd/conf.d/??_mod_php4.conf ] || %service -q httpd restart \
863 if [ -x /etc/rc.d/init.d/php-fcgi ]; then \
864         PHP_FCGI_BINARY=; . /etc/sysconfig/php-fcgi 2>/dev/null \
865         if [[ ${PHP_FCGI_BINARY:-php.fcgi} = *php4.fcgi* ]]; then \
866                 %service -q php-fcgi restart \
867         fi \
868 fi \
869 %{nil}
870
871 # X.org helper macros
872 %__xorg_abi_requires_ge() Requires: xorg-xserver-server(%{expand:%1}-abi) >= %{expand:%{%2}}
873 %__xorg_abi_requires_lt() Requires: xorg-xserver-server(%{expand:%1}-abi) < %(awk -vv=%{expand:%{%2}} 'BEGIN{split(v, a, "."); printf("%s.0", a[1] + 1); exit}')
874
875 %xorg_xserver_ansic_abi         %{expand:%%global xorg_xserver_ansic_abi %(awk '/#define ABI_ANSIC_VERSION/ { split($0,A,/[(,)]/); printf("%d.%d",A[2], A[3]); }' /usr/include/xorg/xf86Module.h 2> /dev/null || echo ERROR)}%xorg_xserver_ansic_abi
876 %xorg_xserver_extension_abi     %{expand:%%global xorg_xserver_extension_abi %(awk '/#define ABI_EXTENSION_VERSION/ { split($0,A,/[(,)]/); printf("%d.%d",A[2], A[3]); }' /usr/include/xorg/xf86Module.h 2> /dev/null || echo ERROR)}%xorg_xserver_extension_abi
877 %xorg_xserver_font_abi          %{expand:%%global xorg_xserver_font_abi %(awk '/#define ABI_FONT_VERSION/ { split($0,A,/[(,)]/); printf("%d.%d",A[2], A[3]); }' /usr/include/xorg/xf86Module.h 2> /dev/null | echo ERROR)}%xorg_xserver_font_abi
878 %xorg_xserver_videodrv_abi      %{expand:%%global xorg_xserver_videodrv_abi %(awk '/#define ABI_VIDEODRV_VERSION/ { split($0,A,/[(,)]/); printf("%d.%d",A[2], A[3]); }' /usr/include/xorg/xf86Module.h 2> /dev/null || echo ERROR)}%xorg_xserver_videodrv_abi
879 %xorg_xserver_xinput_abi        %{expand:%%global xorg_xserver_xinput_abi %(awk '/#define ABI_XINPUT_VERSION/ { split($0,A,/[(,)]/); printf("%d.%d",A[2], A[3]); }' /usr/include/xorg/xf86Module.h 2> /dev/null || echo ERROR)}%xorg_xserver_xinput_abi
880 # vim: '
881
882 %requires_xorg_xserver_extension \
883 %{__xorg_abi_requires_ge ansic xorg_xserver_ansic_abi} \
884 %{__xorg_abi_requires_lt ansic xorg_xserver_ansic_abi} \
885 %{__xorg_abi_requires_ge extension xorg_xserver_extension_abi} \
886 %{__xorg_abi_requires_lt extension xorg_xserver_extension_abi} \
887 %{nil}
888
889 %requires_xorg_xserver_xinput \
890 %{__xorg_abi_requires_ge ansic xorg_xserver_ansic_abi} \
891 %{__xorg_abi_requires_lt ansic xorg_xserver_ansic_abi} \
892 %{__xorg_abi_requires_ge xinput xorg_xserver_xinput_abi} \
893 %{__xorg_abi_requires_lt xinput xorg_xserver_xinput_abi} \
894 %{nil}
895
896 %requires_xorg_xserver_font \
897 %{__xorg_abi_requires_ge ansic xorg_xserver_ansic_abi} \
898 %{__xorg_abi_requires_lt ansic xorg_xserver_ansic_abi} \
899 %{__xorg_abi_requires_ge font xorg_xserver_font_abi} \
900 %{__xorg_abi_requires_lt font xorg_xserver_font_abi} \
901 %{nil}
902
903 %requires_xorg_xserver_videodrv \
904 %{__xorg_abi_requires_ge ansic xorg_xserver_ansic_abi} \
905 %{__xorg_abi_requires_lt ansic xorg_xserver_ansic_abi} \
906 %{__xorg_abi_requires_ge videodrv xorg_xserver_videodrv_abi} \
907 %{__xorg_abi_requires_lt videodrv xorg_xserver_videodrv_abi} \
908 %{nil}
909
910 # TCL specific macro definitions.
911 # TODO: when th tcl is fixed use tclsh to get version: %(echo 'puts $tcl_version' | tclsh)
912 %tcl_version    %{expand:%%global tcl_version %(v=$(rpm -q --qf %{V} tcl | cut -d. -f1,2); echo ${v:-ERROR})}%tcl_version
913 %tcl_sitearch   %{_libdir}/tcl%{tcl_version}
914 %tcl_sitelib    %{_datadir}/tcl%{tcl_version}
915
916 # Python specific macro definitions.
917 # python main version
918 %py_ver                 %{expand:%%global py_ver %(%{__python} -c "import sys; print sys.version[:3]" 2>/dev/null || echo ERROR)}%py_ver
919
920 # directories
921 %py_prefix              %{expand:%%global py_prefix %(%{__python} -c "import sys; print sys.prefix" 2>/dev/null || echo ERROR)}%py_prefix
922 %py_libdir              %{py_prefix}/%{_lib}/python%{py_ver}
923 %py_scriptdir   %{py_prefix}/share/python%{py_ver}
924 %py_incdir              /usr/include/python%{py_ver}
925 %py_sitedir             %{py_libdir}/site-packages
926 %py_sitescriptdir %{py_scriptdir}/site-packages
927 %py_dyndir              %{py_libdir}/lib-dynload
928
929 # pure python modules compilation
930 %py_comp                python -c "import compileall; import sys; compileall.compile_dir(sys.argv[1], ddir=sys.argv[1][len('$RPM_BUILD_ROOT'):])"
931
932 %py_ocomp               python -O -c "import compileall; import sys; compileall.compile_dir(sys.argv[1], ddir=sys.argv[1][len('$RPM_BUILD_ROOT'):])"
933
934 # Software written in Python language require Python with main version
935 %pyrequires_eq() Requires:      %1
936
937 # Python 3.x
938 # python main version
939 %__python3                      python3
940 %py3_ver                        %{expand:%%global py3_ver %(%{__python3} -c "import sys; print(sys.version[:3])" 2>/dev/null || echo ERROR)}%py3_ver
941
942 # directories
943 %py3_prefix             %{expand:%%global py3_prefix %(%{__python3} -c "import sys; print(sys.prefix)" 2>/dev/null || echo ERROR)}%py3_prefix
944 %py3_libdir             %{py3_prefix}/%{_lib}/python%{py3_ver}
945 %py3_scriptdir  %{py3_prefix}/share/python%{py3_ver}
946 %py3_incdir             /usr/include/python%{py3_ver}
947 %py3_sitedir            %{py3_libdir}/site-packages
948 %py3_sitescriptdir %{py3_scriptdir}/site-packages
949 %py3_dyndir             %{py3_libdir}/lib-dynload
950
951 # pure python modules compilation
952 %py3_comp               %{__python3} -c "import compileall; import sys; compileall.compile_dir(sys.argv[1], ddir=sys.argv[1][len('$RPM_BUILD_ROOT'):])"
953
954 %py3_ocomp              %{__python3} -O -c "import compileall; import sys; compileall.compile_dir(sys.argv[1], ddir=sys.argv[1][len('$RPM_BUILD_ROOT'):])"
955
956 # Hardlink binary identical .pyc and .pyo files
957 %__spec_install_post_py_hardlink {\
958 %{!?no_install_post_py_hardlink: __spec_install_post_py_hardlink() { \
959 local a b c=0 t=0; \
960 if [ -d "$RPM_BUILD_ROOT" ]; then \
961         find "$RPM_BUILD_ROOT" -name '*.pyc' > __rpm_pyc; \
962         while read a; do \
963                 b="${a%.pyc}.pyo"; \
964                 if cmp -s "$a" "$b"; then \
965                         ln -f "$a" "$b"; \
966                         c=$((c + 1)); \
967                 fi; \
968                 t=$((t + 1)); \
969         done < __rpm_pyc; \
970         [ $t -gt 0 ] && printf "Hardlink Python files: %d/%d files hardlinked\n" $c $t; \
971         rm -f __rpm_pyc; \
972 fi; \
973 }; __spec_install_post_py_hardlink } }
974
975 # remove python sources, so that check-files won't complain
976 %py_postclean() \
977 for d in %{py_sitescriptdir} %{py_sitedir} %*; do \
978  [ ! -d "$RPM_BUILD_ROOT$d" ] || find "$RPM_BUILD_ROOT$d" -name '*.py' -print0 | xargs -0r -l512 rm;\
979 done \
980 %{nil}
981
982 %py3_postclean() \
983 for d in %{py3_sitescriptdir} %{py3_sitedir} %*; do \
984  [ ! -d "$RPM_BUILD_ROOT$d" ] || find "$RPM_BUILD_ROOT$d" -name '*.py' -print0 | xargs -0r -l512 rm;\
985 done \
986 %{nil}
987
988 # depmod macro
989 %depmod() { \
990 umask 022; \
991 if [ -e /boot/System.map-%1 ]; then \
992         /sbin/depmod -a -F /boot/System.map-%1 %1; \
993 else \
994         if [ -e /boot/System.map ]; then \
995                 /sbin/depmod -a -F /boot/System.map %1; \
996         else \
997                 /sbin/depmod -a %1; \
998         fi \
999 fi; \
1000 }
1001
1002 # XMMS specific macros
1003 %xmms_prefix                    %{expand:%%global xmms_prefix %(xmms-config --prefix 2>/dev/null || echo ERROR)}%xmms_prefix
1004 %xmms_exec_prefix               %{expand:%%global xmms_exec_prefix %(xmms-config --exec-prefix 2>/dev/null || echo ERROR)}%xmms_exec_prefix
1005 %xmms_version                   %{expand:%%global xmms_version %(xmms-config --version 2>/dev/null || echo ERROR)}%xmms_version
1006 %xmms_datadir                   %{expand:%%global xmms_datadir %(xmms-config --data-dir 2>/dev/null || echo ERROR)}%xmms_datadir
1007 %xmms_plugindir                 %{expand:%%global xmms_plugindir %(xmms-config --plugin-dir 2>/dev/null || echo ERROR)}%xmms_plugindir
1008 %xmms_visualization_plugindir   %{expand:%%global xmms_visualization_plugindir %(xmms-config --visualization-plugin-dir 2>/dev/null || echo ERROR)}%xmms_visualization_plugindir
1009 %xmms_input_plugindir           %{expand:%%global xmms_input_plugindir %(xmms-config --input-plugin-dir 2>/dev/null || echo ERROR)}%xmms_input_plugindir
1010 %xmms_output_plugindir          %{expand:%%global xmms_output_plugindir %(xmms-config --output-plugin-dir 2>/dev/null || echo ERROR)}%xmms_output_plugindir
1011 %xmms_effect_plugindir          %{expand:%%global xmms_effect_plugindir %(xmms-config --effect-plugin-dir 2>/dev/null || echo ERROR)}%xmms_effect_plugindir
1012 %xmms_general_plugindir         %{expand:%%global xmms_general_plugindir %(xmms-config --general-plugin-dir 2>/dev/null || echo ERROR)}%xmms_general_plugindir
1013
1014 %_target_base_arch      %{expand:%%global _target_base_arch %(echo %{_target_cpu} | sed 's/i.86/i386/;s/athlon/i386/;s/pentium./i386/;s/amd64/x86_64/;s/ia32e/x86_64/;s/sparcv./sparc/;s/arm.*/arm/')}%_target_base_arch
1015
1016 # user/group checking macros
1017 #
1018 # Usage:
1019 #       %userremove myuser
1020 #
1021 %userremove     /usr/lib/rpm/user_group.sh user del
1022 %groupremove    /usr/lib/rpm/user_group.sh group del
1023 #
1024 # Usage:
1025 #       if %usertestrm myuser; then
1026 #               /usr/sbin/userdel -r myuser
1027 # Note:
1028 #       use these macros only if you need to call userdel/groupdel with
1029 #       a non-standard option or take an extra action; otherwise use the
1030 #       %userremove/%groupremove macros
1031 #
1032 %usertestrm     /usr/lib/rpm/user_group.sh user testrm
1033 %grouptestrm    /usr/lib/rpm/user_group.sh group testrm
1034 # user group membership management macros
1035 #
1036 # Usage:
1037 #       %addusertogroup [-q] myuser agroup
1038 #
1039 #  -q if user or group don't exist, don't make big noise of it (MISSINGOK behaviour)
1040 #
1041 # Requirements:
1042 # BuildRequires:        rpmbuild(macros) >= 1.515
1043 %addusertogroup(q)      quiet=%{-q:1} /usr/lib/rpm/user_group.sh user addtogroup %*; \
1044 %{nil}
1045
1046 # banner support (useful in {pre,post}{,un} and triggers)
1047 #
1048 # Usage:
1049 #       %banner name [-a] [-e] [-n] [-tn] <<EOF
1050 # the banner text, the banner text
1051 # the banner text, and following line
1052 #EOF
1053 # You can use any form of here-document, <<'EOF' <<-EOT will do.
1054 # NOTE: if your use "<<-EOF", then You can actually indent inside here-document.
1055 #
1056 # -a   - append to the banner
1057 # -e   - send to stderr instead of stdout
1058 # -n   - no show banner (overrides -t)
1059 # -t   - show only, if RPM_SCRIPTVERBOSITY >= n; default n=5
1060 #
1061 # Tests:
1062 # (rpm -E '%banner -e banner <<EOF'; echo -e 'hi\nEOF') > m; sh -x m
1063 # rpm -E 'date | %banner -e banner' > m; sh -x m
1064 #
1065 %banner(aent:) ( \
1066 RPM_SCRIPTVERBOSITY=5 \
1067 [ -r /etc/sysconfig/rpm ] && . /etc/sysconfig/rpm \
1068 if [ -x /usr/bin/banner.sh ]; then \
1069         CMD="/usr/bin/banner.sh %{-e:--stderr} %{!-n:$([ $RPM_SCRIPTVERBOSITY -ge %{-t:%{-t*}}%{!-t:5} ] && echo -s)} %{!-a:-m}%{-a:-M} %1" \
1070 else \
1071         CMD="cat%{-e: >&2}" \
1072 fi \
1073 eval $CMD %{?2:%2}%{?3: %3}) \
1074 %{nil}
1075
1076 # useradd/groupadd macros
1077 # Author: Elan Ruusamäe <glen@pld-linux.org>
1078 #
1079 # Usage:
1080 #   %useradd [-P package] [-u uid] [-d home_dir] [-s shell] [-c comment]
1081 #   [-g initial_group] [-G group[,...]] login
1082 #
1083 #  -u uid. REQUIRED
1084 #  -g gid/group. REQUIRED
1085 #  -s defaults to /bin/false
1086 #  -d defaults to /usr/share/empty
1087 #  -c No default
1088 #  -r is accepted but ignored (it's always set)
1089 #  -k skeleton dir. defaults to /usr/share/empty
1090 # rpm specific flags
1091 #  -P package name. defaults to %{name}
1092 #
1093 %useradd(c:d:e:f:g:G:Mmk:op:s:u:rP:) \
1094 %{!-u:%{error:useradd: Required argument -u missing}} \
1095 %{!-g:%{error:useradd: Required argument -g missing}} \
1096 %{!?1:%{error:useradd: Required parameter login missing}} \
1097 if [ -n "`/bin/id -u %{expand:%{%{#}}} 2>/dev/null`" ]; then \
1098         if [ "`/bin/id -u %{expand:%{%{#}}}`" != "%{-u*}" ]; then \
1099                 echo "Error: user %{expand:%{%{#}}} doesn't have uid=%{-u*}. Correct this before installing %{-P*}%{!?-P:%{name}}." 1>&2 \
1100                 exit 1 \
1101         fi \
1102 else \
1103         echo "Adding user %{expand:%{%{#}}} UID=%{-u*}." \
1104         /usr/sbin/useradd \\\
1105                 %{-m:-m -k %{-k*}%{!-k:/usr/share/empty}} \\\
1106                 -u %{-u*} \\\
1107                 -r \\\
1108                 -d %{-d*}%{!-d:/usr/share/empty} \\\
1109                 -s %{-s*}%{!-s:/bin/false} \\\
1110                 %{-c:-c "%(set -- %{-c*} %{*}; echo $1)"}\\\
1111                 -g %{-g*} \\\
1112                 %{-M} \\\
1113                 %{-G:-G %{-G*}} \\\
1114                 %{expand:%{%{#}}} 1>&2 || exit $? \
1115         [ ! -x /usr/sbin/nscd ] || /usr/sbin/nscd -i passwd || : \
1116 fi;
1117 # vim: "
1118
1119 # Usage:
1120 #   %groupadd [-P package] [-g gid] group
1121 #
1122 # -g gid. REQUIRED
1123 #
1124 # Sample:
1125 #   %groupadd -P %{name}-base -g %{gid} %{name}
1126
1127 %groupadd(g:P:rfo)      \
1128 %{!-g:%{error:groupadd: Required argument -g missing}} \
1129 %{!?1:%{error:groupadd: Required parameter group missing}} \
1130 if /usr/bin/getgid %{1} > /dev/null 2>&1; then \
1131         if [ "`/usr/bin/getgid %{1}`" != "%{-g*}" ]; then \
1132                 echo "Error: group %{1} doesn't have gid=%{-g*}. Correct this before installing %{-P*}%{!?-P:%{name}}." 1>&2 \
1133                 exit 1 \
1134         fi \
1135 else \
1136         echo "Adding group %{1} GID=%{-g*}." \
1137         /usr/sbin/groupadd -g %{-g*} -r %{1} 1>&2 || exit $? \
1138         [ ! -x /usr/sbin/nscd ] || /usr/sbin/nscd -i group || : \
1139 fi;
1140
1141 # webapp macros
1142 # Author: Elan Ruusamäe <glen@pld-linux.org>
1143 #
1144 # The config is installed/removed inside trigger, this means that you can any
1145 # time install apache1/apache/lighttpd package and the configuration file is
1146 # updated. if you don't need the config for various reason for specific
1147 # webserver, just remove the symlink from config directory using webapp
1148 # program. the trigger will not recreate the symlink on upgrades. In other
1149 # words the config is linked to webserver config directory on first install of
1150 # PACKAGE or WEBSERVER.
1151 #
1152 # Add package's webserver config to webserver webapps dir.
1153 # Usage:
1154 #   %webapp_register [-f] WEBSERVER WEBAPP
1155 #
1156 %webapp_register(f) \
1157 %{?debug:set -x; echo "webapp_register: %{name}-%{version}-%{release} 1:[$1]; 2:[$2]"} \
1158 if [ -n "%{-f:1}" ] || [ "$1" = "1" ] && [ "$2" = "1" ]; then\
1159         /usr/sbin/webapp register %1 %2\
1160 fi\
1161 # reload webserver if the config symlink is there and skip reload if webserver is upgraded\
1162 if [ -L /etc/%1/webapps.d/%(echo "%2" | tr '/' '-').conf ] && [ "$2" -lt "2" ]; then\
1163         %{expand:%service -q %%1 reload}\
1164 fi\
1165 %{nil}
1166
1167 # Remove package's config from webserver webapps dir.
1168 # Usage:
1169 #   %webapp_register [-f] WEBSERVER WEBAPP
1170 %webapp_unregister(f) \
1171 %{?debug:set -x; echo "webapp_unregister: %{name}-%{version}-%{release}: 1:[$1]; 2:[$2]"} \
1172 # remove link if either of the packages are gone \
1173 if [ -n "%{-f:1}" ] || [ "$1" = "0" ] || [ "$2" = "0" ] && [ -L /etc/%1/webapps.d/%(echo "%2" | tr '/' '-').conf ]; then \
1174         /usr/sbin/webapp unregister %1 %2\
1175         %{expand:%service -q %%1 reload}\
1176 fi \
1177 %{nil}
1178
1179 # service macro.
1180 # Author: Elan Ruusamäe <glen@pld-linux.org>
1181 #
1182 # calls usual service restart on package %post, but skips the restart if
1183 # administrator has disabled automatic service restarts in either global
1184 # /etc/sysconfig/rpm or per service /etc/sysconfig/SERVICE file.
1185 #
1186 # Usage:
1187 #   %service [-q] [-n] SERVICE ACTION ["SERVICE NICE DESCRIPTION"]
1188 #
1189 #  -q be silent when service isn't started (for scriplets restaring other package's services)
1190 #  -n NOOP mode, do not actually restart service
1191 #
1192 # Requirements:
1193 # BuildRequires:        rpmbuild(macros) >= 1.268
1194 # Requires:     rc-scripts
1195 # -n option:
1196 # BuildRequires:        rpmbuild(macros) >= 1.450
1197 %service(qn) {{%(export noop=%{-n:1} quiet=%{-q:1}; /usr/lib/rpm/service_generator.sh %{*}) };}
1198
1199
1200 # Java macros. based on jpackage macros.java
1201 #
1202 # Root directory where all Java VMs/SDK/JREs are installed.
1203 %_jvmdir                %{_libdir}/jvm
1204
1205 # Root directory where all Java VMs/SDK/JREs expose their jars
1206 %_jvmjardir             %{_libdir}/jvm-exports
1207
1208 # Root directory for all Java VM/SDK/JRE's private things.
1209 %_jvmprivdir    %{_libdir}/jvm-private
1210
1211 # Root directory for all architecture dependent parts of Java VM/SDK/JRE's
1212 %_jvmlibdir             %{_libdir}/jvm
1213
1214 # Root directory for all architecture independent parts of Java VM/SDK/JRE's
1215 %_jvmdatadir    %{_datadir}/jvm
1216
1217 # Root directory for all configurations parts of Java VM/SDK/JRE's
1218 %_jvmsysconfdir %{_sysconfdir}/jvm
1219
1220 # Root directory for all common architecture dependent parts of Java VM/SDK/JRE's
1221 %_jvmcommonlibdir       %{_libdir}/jvm-common
1222
1223 # Root directory for all common architecture independent parts of Java VM/SDK/JRE's
1224 %_jvmcommondatadir      %{_datadir}/jvm-common
1225
1226 # Root directory for all common configurations parts of Java VM/SDK/JRE's
1227 %_jvmcommonsysconfdir   %{_sysconfdir}/jvm-common
1228
1229 # Directory where arch-specific (JNI) version-independent jars are installed.
1230 %_jnidir                %{_libdir}/java
1231
1232
1233 # JDK selection. Set this to name of the JDK implementation to use
1234 # insead of the system default
1235 #%use_jdk               icedtea6
1236
1237 # expands to the value with right jdk for BuildRequires header
1238 # 'jdk' if %%use_jdk is not defined,  jdk(%%use_jdk) otherwise
1239 # The requirement will not replace current 'default' JDK
1240 %required_jdk   jdk%{?use_jdk:(%{use_jdk})}
1241
1242 %buildrequires_jdk BuildRequires: %required_jdk
1243
1244 %java_home              %{expand:%%global java_home %([ -f %{_javadir}-utils/java-functions ] || { echo ERROR; exit 0; }; %{!?use_jdk:unset JAVA_HOME; . %{_javadir}-utils/java-functions; set_jvm}%{?use_jdk:JAVA_HOME=%{_jvmdir}/%{use_jdk}}; echo ${JAVA_HOME:-ERROR})}%java_home
1245
1246 %_javasrcdir    %{_usrsrc}/java
1247
1248 %ant                    JAVA_HOME=%{java_home} CLASSPATH=$CLASSPATH ant
1249 %jar                    %{java_home}/bin/jar
1250 %java                   %{expand:%%global java %([ -f %{_javadir}-utils/java-functions ] || { echo ERROR; exit 0; }; %{!?use_jdk:unset JAVACMD; . %{_javadir}-utils/java-functions; set_javacmd}%{?use_jdk:JAVACMD=%{java_home}/bin/java}; echo $JAVACMD)}%java
1251 %javac                  %{java_home}/bin/javac
1252 %javadoc                %{java_home}/bin/javadoc
1253
1254 %add_jvm_extension      JAVA_LIBDIR=%{buildroot}/%{_javadir}    %{_bindir}/jvmjar -l
1255
1256 %jpackage_script() \
1257 install -d $RPM_BUILD_ROOT%{_bindir}\
1258 cat > $RPM_BUILD_ROOT%{_bindir}/%5 << 'EOF' \
1259 #!/bin/sh\
1260 #\
1261 # %{name} script\
1262 # JPackage Project <http://www.jpackage.org/>\
1263 \
1264 # Source functions library\
1265 . %{_javadir}-utils/java-functions\
1266 \
1267 # Source system prefs\
1268 if [ -f %{_sysconfdir}/java/%{name}.conf ]; then\
1269     . %{_sysconfdir}/java/%{name}.conf\
1270 fi\
1271 \
1272 # Source user prefs\
1273 if [ -f $HOME/.%{name}rc ]; then\
1274     . $HOME/.%{name}rc\
1275 fi\
1276 \
1277 # Configuration\
1278 MAIN_CLASS=%1\
1279 BASE_FLAGS=%2\
1280 BASE_OPTIONS=%3\
1281 BASE_JARS="%(echo %4 | tr ':' ' ')"\
1282 \
1283 # Set parameters\
1284 set_jvm\
1285 set_classpath $BASE_JARS\
1286 set_flags $BASE_FLAGS\
1287 set_options $BASE_OPTIONS\
1288 \
1289 # Let's start\
1290 run "$@"\
1291 EOF
1292
1293 # jpackage 1.7
1294 # Directory for maven depmaps
1295 #
1296 %_mavendepmapdir /etc/maven
1297 %_mavendepmapfragdir /etc/maven/fragments
1298
1299 #
1300 # add_to_depmap adds an entry to the depmap. The arguments are:
1301 #
1302 # %1 the original groupid
1303 # %2 the original artifact id
1304 # %3 the version
1305 # %4 the new groupid
1306 # %5 the new artifactid
1307 #
1308
1309 %add_to_maven_depmap() \
1310 install -dm 755 $RPM_BUILD_ROOT/%{_mavendepmapfragdir}\
1311 cat >>$RPM_BUILD_ROOT/%{_mavendepmapfragdir}/%{name}<< EOF\
1312 <dependency>\
1313     <maven>\
1314         <groupId>%1</groupId>\
1315         <artifactId>%2</artifactId>\
1316         <version>%3</version>\
1317     </maven>\
1318     <jpp>\
1319         <groupId>%4</groupId>\
1320         <artifactId>%5</artifactId>\
1321         <version>%3</version>\
1322     </jpp>\
1323 </dependency>\
1324 \
1325 EOF\
1326 %{nil}
1327
1328 #==============================================================================
1329 #
1330 # update_maven_depmap updates the main maven depmap
1331 #
1332 %update_maven_depmap() \
1333 echo -e "<dependencies>\\n" > %{_mavendepmapdir}/maven2-depmap.xml\
1334 if [ -d %{_mavendepmapfragdir} ] && [ -n "`find %{_mavendepmapfragdir} -type f`" ]; then\
1335 cat %{_mavendepmapfragdir}/* >> %{_mavendepmapdir}/maven2-depmap.xml\
1336 fi\
1337 echo -e "</dependencies>\\n" >> %{_mavendepmapdir}/maven2-depmap.xml
1338
1339 # JAVA macros specific for PLD
1340
1341 # Directory for tomcat context configuration files
1342 %_tomcatconfdir %{_sharedstatedir}/tomcat/conf/Catalina/localhost
1343
1344 # Tomcat cache path
1345 %_tomcatcachedir %{_sharedstatedir}/tomcat/work/Catalina/localhost
1346
1347 # Clear tomcat cache
1348 # Author: Paweł Zuzelski <pawelz@pld-linux.org>
1349 #
1350 # Usage:
1351 # %%tomcat_clear_cache appname
1352 #
1353 # Call this script in %postun scriptlet. It will remove compiled jsps related to
1354 # given app.
1355 #
1356 %tomcat_clear_cache() %{!?1:ERROR}%{?2:ERROR} %{__rm} -rf %{_tomcatcachedir}/%1
1357
1358 # PEAR install macros
1359 # Author: Elan Ruusamäe <glen@pld-linux.org>
1360 #
1361 # Usage:
1362 #       %%pear_package_setup ...
1363 #
1364 # -a #   - also unpack SOURCE#. for PEAR bootstrapping
1365 # -n FMT - create builddir with FMT, instead of default %%{pearname}-%%{version}
1366 # -z     - unpack pear package and let pear use package.xml (not tarball) for install. for PEAR bootstrapping
1367 # -D     - pass -D to %setup (so the build dir is not removed)
1368 # -c     - register channel from local channel.xml file
1369 # -d     - pass -d arg to pearcmd
1370 #
1371 # unpack PEAR package to %%{_builddir}/FMT. package is extracted with already
1372 # destination hierarchy. you should copy the tree to buildroot after
1373 # patching/reorganizing with %%pear_package_install.
1374 #
1375 # additionally BUILDROOT is stripped from files and files are converted to UNIX
1376 # line endings.
1377 #
1378 # the pear install process output is recorded to install.log, you should put it
1379 # to %%doc for later debug or just for information.
1380 #
1381 # additionally additional-packages.txt is produced if it was detected that the
1382 # package has optional dependencies. the file format is suitable of displaying
1383 # in %%post of a package. you should put this file to %%doc. noautocompressdoc is
1384 # automatically added for this file.
1385
1386
1387 # records install.log and transforms PEAR names to PLD Linux rpm package names.
1388 %__pear_install_log \
1389 tee install.log \
1390 # make post message of optional packages \
1391 grep -E 'can optionally use|Optional feature' install.log | sed -e 's,package "pear/,package "php-pear-,g;s,^pear/,php-pear-,;s,^pear/,php-pear-,;s,^channel://.*/,,' > optional-packages.txt \
1392 if [ -s optional-packages.txt ]; then \
1393         awk -F'"' '/use package/{print $2}' optional-packages.txt | sed -e "s,_,/,g;s,php-pear-, 'pear(,;s,$,.*)'," | tr -d '\\\n' > _noautoreq \
1394 else \
1395         rm -f optional-packages.txt \
1396 fi \
1397 %{nil}
1398
1399 # Command invoking PEAR CLI
1400 # Same as /usr/bin/pear, except we force GMT timezone
1401 %__pear %__php -doutput_buffering=1 -dopen_basedir="" -dmemory_limit=-1 -ddate.timezone=GMT %{php_pear_dir}/pearcmd.php
1402
1403 %pear_install(a:d:n:zD) \
1404 %__pear \\\
1405         -c %{builddir}/pearrc \\\
1406         -d doc_dir=/docs \\\
1407         -d temp_dir=/tmp \\\
1408         -d php_dir=%{-c:%{builddir}/}%{php_pear_dir} \\\
1409         -d bin_dir=%{_bindir} \\\
1410         -d data_dir=%{php_pear_dir}/data \\\
1411         -d test_dir=%{php_pear_dir}/tests \\\
1412         %{-d:%(echo "%{-d*}" | awk 'BEGIN{RS=","}{printf("-d %%s \\\\\\n\\t", $1)}')} \\\
1413         install \\\
1414         --packagingroot=%{builddir} \\\
1415         --offline \\\
1416         --nodeps \\\
1417         %{-f:--force} \\\
1418         %{!-z:%{S:%{-a*}%{!-a:0}}}%{-z:$_P} > .install.log || { c=$?; cat .install.log; exit $c; }; \
1419         %{-c:cp -a %{builddir}/%{builddir}/%{php_pear_dir} %{builddir}/%(dirname %{php_pear_dir}); rm -rf %{builddir}/%{builddir}; } \
1420 %{nil}
1421
1422 # The main macro.
1423 # using this macro will append optional-packages.txt to the nocompressdoc list
1424 # as it's displayed to user after package install. and adding additional gzip
1425 # dep is just waste ;)
1426 %pear_package_setup(a:d:n:zDc:) \
1427 %define srcdir %{-n*}%{!-n:%{?_pearname}%{!?_pearname:%{pearname}}-%{version}} \
1428 %define builddir %{_builddir}/%{srcdir} \
1429 %setup -q -c -T %{-D:-D} -n %{srcdir} \
1430 %{-z:%{__tar} zxf %{S:0}; %{-a:%{__tar} zxf %{S:%{-a*}}}} \
1431 %{-z:_P=package2.xml; [ -f $_P ] || _P=package.xml; _N=%{srcdir}; mv $_P $_N; cd $_N} \
1432 %{-c:%{__pear} -c pearrc config-set php_dir %{builddir}/%{php_pear_dir}; %__pear -c %{builddir}/pearrc channel-add %{-c*}} \
1433 %pear_install \
1434 %{-z:cd ..} \
1435 %{__tar} --wildcards -zvxf %{S:0} package*.xml \
1436 cat %{-z:$_N/}.install.log | %__pear_install_log \
1437 %undos -f php,html,js,xml \
1438 %{!?_noautocompressdoc:%global _noautocompressdoc %{nil}}%{expand:%%global _noautocompressdoc %{_noautocompressdoc} optional-packages.txt} \
1439 %{!?_noautoprov:%global _noautoprov %{nil}}%{expand:%%global _noautoprov %{_noautoprov} 'pear(tests/.*)'} \
1440 %{nil}
1441
1442 # Copies exctracted PEAR package structure and PEAR registry to buildroot.
1443 # Author: Elan Ruusamäe <glen@pld-linux.org>
1444 %pear_package_install() \
1445 cp -a ./%{php_pear_dir}/{.registry,*} $RPM_BUILD_ROOT%{php_pear_dir} \
1446 find $RPM_BUILD_ROOT%{php_pear_dir} '(' -name '*~' -o -name '*.orig' ')' | xargs -r rm -v \
1447 # help the developer out a little: \
1448 if [ -f _noautoreq ]; then \
1449         echo "AutoReqdep detected:" \
1450         echo "_noautoreq $(cat _noautoreq)" \
1451 fi \
1452 %{nil}
1453
1454 # Print optional package info for pear packages
1455 # Author: Elan Ruusamäe <glen@pld-linux.org>
1456 # Usage:
1457 #   %post -p <lua>
1458 #       %%pear_package_print_optionalpackages
1459 #
1460 # Requirements:
1461 # BuildRequires:        rpmbuild(macros) >= 1.571
1462 %pear_package_print_optionalpackages \
1463 f = io.open("%{_docdir}/%{name}-%{version}/optional-packages.txt", "r") \
1464 if f then \
1465         for l in f:lines() do print(l); end \
1466 end \
1467 %{nil}
1468
1469
1470 # Register OpenLDAP schema.
1471 # Author: Elan Ruusamäe <glen@pld-linux.org>
1472 #
1473 # Usage:
1474 #   %%openldap_schema_register [-d core,nis] %{schemadir}/horde.schema
1475 #
1476 #  -d specify dependant schemas, separated by comma
1477 #
1478 %openldap_schema_register(d:) \
1479 for schema in %*; do \
1480         if ! grep -q "$schema" /etc/openldap/slapd.conf; then \
1481                 %{__sed} -i -e " \
1482                         /^include.*local.schema/{ \
1483                                 iinclude\\t     $schema\
1484                         } \
1485                 " /etc/openldap/slapd.conf \
1486         fi \
1487 done \
1488 # enable dependant schemas \
1489 if [ "%{-d*}" ]; then \
1490         %{__sed} -i -e ' \
1491         /^#include.*\\(%(echo '%{-d*}' | %{__sed} -e 's/,/\\\\|/g')\\)\\.schema/{ \
1492                 s/^#// \
1493         }' /etc/openldap/slapd.conf \
1494 fi \
1495 %{nil}
1496
1497 # Unregister OpenLDAP schema.
1498 # Author: Elan Ruusamäe <glen@pld-linux.org>
1499 #
1500 # Usage:
1501 #   %%openldap_schema_unregister %{schemadir}/horde.schema
1502 #
1503 %openldap_schema_unregister() \
1504 for schema in %*; do \
1505         if grep -q "$schema" /etc/openldap/slapd.conf; then \
1506                 %{__sed} -i -e " \
1507                 /^include.*$(echo "$schema" | %{__sed} -e 's,/,\\\\/,g')/d \
1508                 # for symmetry it would be nice if we disable enabled schemas in post, \
1509                 # but we really can not do that, it would break something else. \
1510                 " /etc/openldap/slapd.conf \
1511         fi \
1512 done \
1513 %{nil}
1514
1515 %env_update [ ! -x /sbin/env-update ] || /sbin/env-update -u || :
1516
1517
1518 # Build modules for kernels 2.6
1519 # Author: Przemyslaw Iskra <sparky@pld-linux.org>
1520 #
1521 # Usage:
1522 #       %build_kernel_modules -m <modules> -C <directory>
1523 #
1524 #  remember that proper Makefile is still required
1525 # Options:
1526 #  -m <modules> (required) -- comma-separated list of modules to save,
1527 #               without .ko extension, may be placed in subdirectory
1528 #  -C <directory> -- change to <directory> before doing anything
1529 #  -p <arg>, -P <arg> -- arguments passeed to make scripts
1530 #  -c -- do not execute make clean
1531 #  <additional arguments> -- all additional arguments will be passed to
1532 #               make modules
1533 #
1534 # Additional patching supported via here document. Try:
1535 #       %build_kernel_modules -m module <<'EOF'
1536 #       your patch script here
1537 #       EOF
1538 # Don't use it unless patching depends on config options.
1539
1540 # Developer note: don't touch it unless you know how to handle '\'.
1541 # - \ in script expands to nothing
1542 # - \\\ in script expands to \
1543 # - \\\ inside definition expands to nothing
1544 # - \\\\\\\ inside definition expands to \
1545 # - in last line \ has to touch arguments so arguments passing
1546 #   in new lines (using \) will be supported
1547
1548 %build_kernel_modules(p:P:m:C:c)                                                                        \
1549 %{!?-m:%{error:%{0}: Required module name/list missing} exit 1}         \
1550                                                                                                                                         \
1551 %define Opts                                                                                                            \\\\\\\
1552 %if "%{_target_base_arch}" != "%{_arch}"                                                        \\\
1553         %if "%{_arch}" == "x86_64" && "%{_target_base_arch}" == "i386"  \\\
1554         CC="%{kgcc}" ARCH=%{_target_base_arch}                                                  \\\
1555         %else                                                                                                                   \\\
1556         ARCH=%{_target_base_arch} CROSS_COMPILE=%{_target_cpu}-pld-linux- \\\
1557         %endif                                                                                                                  \\\
1558 %else                                                                                                                           \\\
1559         CC="%{kgcc}"                                                                                                    \\\
1560 %endif                                                                                                                          \
1561 %define MakeOpts HOSTCC="%{kgcc}" SYSSRC=%{_kernelsrcdir} SYSOUT=$PWD/o \\\\\\\
1562                 O=$PWD/o %{?with_verbose:V=1} %{Opts}                                           \
1563                                                                                                                                         \
1564 %{?-C:cd %{-C*}}                                                                                                        \
1565 compile() {                                                                                                                     \
1566         local L="<" PATCH_SH;                                                                                   \
1567         [[ '%{*}' != *$L$L* ]] || PATCH_SH="set -x -e;$(cat)"                   \
1568         set -e -x                                                                                                               \
1569         local cfgs='%{?with_dist_kernel:%{?with_smp: smp}%{?with_up: up}}%{!?with_dist_kernel: nondist}' \
1570                                                                                                                                         \
1571 for cfg in ${cfgs:-dist}; do                                        \
1572         [ -r "%{_kernelsrcdir}/config-$cfg" ] || exit 1                                 \
1573                                                                                                                                         \
1574         rm -rf o                                                                                                                \
1575         install -d o/include/linux o/include/generated o/arch/powerpc/lib       \
1576         ln -sf %{_kernelsrcdir}/config-$cfg o/.config                                   \
1577         ln -sf %{_kernelsrcdir}/Module.symvers-$cfg o/Module.symvers    \
1578         if [ -f %{_kernelsrcdir}/include/generated/autoconf-$cfg.h ]; then      \
1579                 ln -sf %{_kernelsrcdir}/include/generated/autoconf-$cfg.h o/include/generated/autoconf.h \
1580                 ln -s ../generated/autoconf.h o/include/linux/autoconf.h \
1581         else                                                                                                                    \
1582                 ln -sf %{_kernelsrcdir}/include/linux/autoconf-$cfg.h o/include/linux/autoconf.h \
1583         fi                                                                                                                              \
1584                                                                                                                                         \
1585         set +x                                                                                                                  \
1586         [ -z "$PATCH_SH" ] || echo "$PATCH_SH" | %__spec_build_shell    \
1587         set -x                                                                                                                  \
1588                                                                                                                                         \
1589         %if %{with dist_kernel} || %(test -f %{_kernelsrcdir}/scripts/bin2c ; echo $?)  \
1590                 %{__make} -j1 -C %{_kernelsrcdir} prepare scripts                       \\\
1591                         %{-p*} %{-P*}                                                                                   \\\
1592                         %{MakeOpts}                                                                                             \
1593         %else                                                                                                                   \
1594                 install -d o/include/config                                                                     \
1595                 touch o/include/config/MARKER                                                           \
1596                 ln -sf %{_kernelsrcdir}/include/config/auto-$cfg.conf o/include/config/auto.conf        \
1597                 ln -sf %{_kernelsrcdir}/scripts o/scripts                                       \
1598         %endif                                                                                                                  \
1599                                                                                                                                         \
1600         %{!?-c:%{__make} -C %{_kernelsrcdir} clean                                              \\\
1601                 RCS_FIND_IGNORE="-name '*.ko' -o"                                                       \\\
1602                 ${1+"$@"}                                                                                                       \\\
1603                 M=$PWD %{MakeOpts}}                                                                                     \
1604                                                                                                                                         \
1605         %{__make} -C %{_kernelsrcdir} modules                                                   \\\
1606                 ${1+"$@"}                                                                                                       \\\
1607                 M=$PWD %{MakeOpts}                                                                                      \
1608                                                                                                                                         \
1609         for MODULE in {%{-m*},}; do                                                                             \
1610                 [ -z "${MODULE}" ] || mv ${MODULE}{,-$cfg}.ko                           \
1611         done                                                                                                                    \
1612 done                                                                                                                            \
1613 %{?-C:cd -}                                                                                                                     \
1614 }                                                                                                                                       \
1615 compile %{*}\
1616 %{nil}
1617
1618
1619 # Install kernel modules built by %build_kernel_modules
1620 # Author: Przemyslaw Iskra <sparky@pld-linux.org>
1621 #
1622 # Usage:
1623 #       %install_kernel_modules -m <modules> -d <directory>
1624 #
1625 # Options:
1626 #  -m <modules> (required) -- comma-separated list of modules to install,
1627 #               without .ko extension, may be placed in subdirectory
1628 #  -d <directory> (required) -- in what subdirectory modules should be
1629 #               installed (eg. misc, kernel/drivers/net)
1630 #  -s <suffix> -- suffix to use when installing modules, useful when module
1631 #               with same name exists in kernel already
1632 #  -n <file> -- name of modprobe config file to use (without .conf extension)
1633 #               for defining aliases, only useful with -s
1634
1635 %install_kernel_modules(m:d:s:n:)                                                                       \
1636 %{!?-m:%{error:%{0}: Required module name (-m) missing}exit 1}          \
1637 %{!?-d:%{error:%{0}: Required module directory missing}exit 1}          \
1638 %{?-n:%{!?-s:%{error:%{0}: Modprobe .conf file requires module suffix}exit 1}} \
1639                                                                                                                                         \
1640 %define KernelD $RPM_BUILD_ROOT/lib/modules/%{_kernel_ver}                      \
1641 %define ModprobeD $RPM_BUILD_ROOT%{_sysconfdir}/modprobe.d/%{_kernel_ver} \
1642                                                                                                                                         \
1643 __install_kernel_modules() {                                                                            \
1644 local cfgs='%{?with_dist_kernel:%{?with_smp: smp}%{?with_up: up}}%{!?with_dist_kernel: nondist}' \
1645                                                                                                                                         \
1646 for MODULE in {%{-m*},}; do                                                                                     \
1647         [ -n "${MODULE}" ] || continue                                                                  \
1648         for cfg in ${cfgs:-dist}; do                                    \
1649                 [ "$cfg" = smp ] && suf=smp || suf=                                                     \
1650                 MNAME=${MODULE##*/}                                                                                     \
1651                 install -D ${MODULE}-$cfg.ko                                                            \\\
1652                         %{KernelD}$suf/%{-d*}/${MNAME}%{-s:-%{-s*}}.ko                  \
1653                 %{?-s:install -d %{ModprobeD}$suf                                                       \
1654                         echo "alias ${MNAME} ${MNAME}-%{-s*}"                                   \\\
1655                         >> %{ModprobeD}$suf/%{-n*}.conf}                                                \
1656         done                                                                                                                    \
1657 done                                                                                                                            \
1658 }                                                                                                                                       \
1659 __install_kernel_modules                                                                                        \
1660 %{nil}
1661
1662 # patchset macros
1663 # Author: Elan Ruusamäe <glen@pld-linux.org>
1664 #
1665 # Usage:
1666 #   %patchset_source -f <seq(1) format> <start> [<end>]
1667 #   %patchset_patch <start> [<end>]
1668 #
1669 # If <end> is omited, it is assumed to be <start>.
1670 #
1671 # For example in preamble:
1672 #  %patchset_source -f ftp://ftp.vim.org/pub/editors/vim/patches/7.0/7.0.%03g 33 44
1673 # and in %prep:
1674 #  %patchset_patch 33 44
1675
1676 # generate SourceX urls from range START STOP
1677 # Format can be SINGLE format char of %e, %f, %g, see seq(1)
1678 # The sources start from 10000
1679 %patchset_source(f:b:) %(
1680         base=%{-b*}%{!-b*:10000};
1681         start=$(expr $base + %1);
1682         end=$(expr $base + %{?2}%{!?2:%{1}});
1683         # we need to call seq twice as it doesn't allow two formats
1684         seq -f 'Patch%g:' $start $end > %{tmpdir}/__ps1;
1685         seq -f '%{-f*}' %1 %{?2}%{!?2:%{1}} > %{tmpdir}/__ps2;
1686         paste %{tmpdir}/__ps{1,2};
1687         rm -f %{tmpdir}/__ps{1,2};
1688 ) \
1689 %{nil}
1690
1691 # apply sources from %patchset_source
1692 # -p specify -pX for %patch line
1693 # -b base offset: defaults to 10000
1694 %patchset_patch(f:p:b:) %(
1695         base=%{-b*}%{!-b*:10000};
1696         start=$(expr $base + %1);
1697         end=$(expr $base + %{?2}%{!?2:%{1}});
1698         echo ": patchset_patch %1%{?2: to %2}";
1699         seq -f 'patch%g %{-p*:-p%{-p*}}' $start $end | sed -e s,^,%%,;
1700 ) \
1701 %{nil}
1702
1703 # browser plugins v2
1704 # Author: Elan Ruusamäe <glen@pld-linux.org>
1705 #
1706 # Usage:
1707 #       %browser_plugins_add_browser <name> -p <plugindir>
1708 #
1709 #  <name> (required) -- name of the browser. usually %{name}.
1710 #  -p <plugindir> (required) -- in what directory browser searches for its plugins.
1711 #  -b -- default blacklists
1712 #  -a <arch> override arch
1713 #
1714 # Example:
1715 #   %browser_plugins_add_browser %{name} -p %{_firefoxdir}/plugins
1716
1717 %_browserpluginsconfdir         /etc/browser-plugins
1718 %_browserpluginsdir                     %{_libdir}/browser-plugins
1719 %update_browser_plugins         /usr/sbin/update-browser-plugins || :
1720
1721 %browser_plugins_add_browser(p:b:a:) \
1722         browser=%1.%{!-a:%{_target_base_arch}}%{-a*} \
1723         install -d $RPM_BUILD_ROOT%{_browserpluginsconfdir}/{blacklist,browsers}.d \
1724         ln -s %{-p*} $RPM_BUILD_ROOT%{_browserpluginsconfdir}/browsers.d/$browser \
1725         blacklist_file=$RPM_BUILD_ROOT%{_browserpluginsconfdir}/blacklist.d/$browser.blacklist \
1726         echo '# This file format is shell globs at base dir of plugindir' > $blacklist_file \
1727         %{-b:cat >> $blacklist_file %{-b*}} \
1728 %{nil}
1729
1730 # Helper for LUA.
1731 # split string separated by space into quoted list
1732 #
1733 # Author: Elan Ruusamäe <glen@pld-linux.org>
1734 #
1735 # %__lua_split /bin/sh /bin/pdksh -> "/bin/sh", "/bin/pdksh"
1736 %__lua_split() %(echo "%*" | awk '{for (i=1;i<=NF;i++) printf("\\"%%s\\"%%s", $i, i == NF ? "" : ", ")}')
1737
1738 # adjust /etc/shells by adding and removing shells from there
1739 # Author: Elan Ruusamäe <glen@pld-linux.org>
1740 #
1741 # Usage:
1742 #   %post       -p <lua>
1743 #   %lua_add_etc_shells /bin/sh /bin/pdksh
1744 #
1745 #   %preun      -p <lua>
1746 #   if arg[2] == 0 then
1747 #       %lua_remove_etc_shells /bin/bash /bin/rbash
1748 #   end
1749 #
1750 # Requirements:
1751 # BuildRequires:        rpmbuild(macros) >= 1.462
1752 #
1753
1754 %lua_add_etc_shells() \
1755 t = {}\
1756 f = io.open("/etc/shells", "r")\
1757 if f then\
1758         for l in f:lines() do t[l]=l; end\
1759         f:close()\
1760 end\
1761 for _, s in ipairs({%{expand:%%__lua_split %*}}) do\
1762         if not t[s] then\
1763                 print("Adding "..s.." to /etc/shells")\
1764                 f = io.open("/etc/shells", "a"); f:write(s.."\\n"); f:close()\
1765         end\
1766 end\
1767 %{nil}
1768
1769 %lua_remove_etc_shells() \
1770 t = {}\
1771 f = io.open("/etc/shells", "r")\
1772 if f then\
1773         for l in f:lines() do t[l]=l; end\
1774         f:close()\
1775 end\
1776 for _, l in pairs({%{expand:%%__lua_split %*}}) do\
1777         print("Removing "..l.." from /etc/shells")\
1778         t[l] = nil\
1779 end\
1780 s=""\
1781 for _, l in pairs(t) do\
1782         s=s..l.."\\n"\
1783 end\
1784 io.open("/etc/shells", "w"):write(s)\
1785 %{nil}
1786
1787 # Backwards compat. Use of %lua_ prefixed macros is preferred as these are cleaner to read.
1788 #
1789 # Author: Elan Ruusamäe <glen@pld-linux.org>
1790 #
1791 # Usage:
1792 #   %post       -p %add_etc_shells -p /bin/sh /bin/pdksh
1793 #   %preun      -p %remove_etc_shells -p /bin/sh /bin/pdksh
1794 #
1795 #  -p (optional) -- specifies that result is embeded %post script (prepends <lua> as first line)
1796 #
1797 # Requirements:
1798 # BuildRequires:        rpmbuild(macros) >= 1.429
1799 #
1800 %add_etc_shells(p) %{-p:<lua>}\
1801 %{expand:%%lua_add_etc_shells %*}\
1802 %{nil}
1803
1804 %remove_etc_shells(p) %{-p:<lua>}\
1805 %{-p:if arg[2] == 0 then}\
1806 %{expand:%%lua_remove_etc_shells %*}\
1807 %{-p:end} \
1808 %{nil}
1809
1810 # Check syntax for Python files
1811 #
1812 # Author: Elan Ruusamäe <glen@pld-linux.org>
1813 # Author: Arkadiusz Miśkiewicz <arekm@pld-linux.org>
1814 #
1815 # Usage:
1816 #   %py_lint src
1817 #
1818 # Requirements:
1819 # BuildRequires:        python
1820 # BuildRequires:        rpmbuild(macros) >= 1.469
1821
1822 %py_lint() \
1823 __py_lint() { \
1824 find "$@" -type f -name '*.py' | python -c ' \
1825 import sys \
1826 import compiler \
1827 \
1828 err = 0\
1829 for f in sys.stdin: \
1830         fd = open(f.strip()) \
1831         c = fd.read() \
1832         fd.close() \
1833         try: \
1834                 compiler.parse(c) \
1835         except SyntaxError, e: \
1836                 print "py_lint: %s: %s" % (f.strip(), e) \
1837                 err = err + 1\
1838 \
1839 if err: \
1840         print >> sys.stderr, "\\npy_lint: ERROR: Syntax errors in %d files.\\n" % err \
1841         sys.exit(1) \
1842 else: \
1843         print >> sys.stderr,  "py_lint: Found no syntax errors." \
1844 ' \
1845 }; __py_lint %* \
1846 %{nil}
1847
1848 # Undos files
1849 #
1850 # Author: Paweł Zuzelski <pawelz@pld-linux.org>
1851 # Author: Elan Ruusamäe <glen@pld-linux.org>
1852 #
1853 # Usage:
1854 #   %undos list_of_files
1855 #   %undos -f EXT[,EXT]
1856 #   %undos -i -f EXT[,EXT]
1857 #
1858 #  -f EXT[,EXT] - find(1) files by extensions
1859 #  -i - case insensitive file search
1860 #
1861 # Example:
1862 #   Un-DOS all *.js, *.css files
1863 #   %undos -f js,css
1864 #   Un-DOS all *.js, *.JS files
1865 #   %undos -f js -i
1866 #   undos all Makefiles
1867 #   %{__find} -name Makefile | xargs %undos
1868 #
1869 # Requirements:
1870 # BuildRequires:        sed >= 4.0
1871 # BuildRequires:        rpmbuild(macros) >= 1.565
1872
1873 # NB: make sure this macro stays on one line
1874 # NB: make sure it includes newline escape
1875 %undos(f:i)     %{-f:%{__find} -regextype posix-extended -%{-i:i}regex '^.+\\.(%(echo %{-f*} | tr ',' '|'))$' -print0 | xargs -0} %{__sed} -i -e 's,\\r$,,' %* \
1876 %{nil}
1877
1878 # Hook to register nagios object based plugins in Nagios NRPE daemon config.
1879 #
1880 # Author: Elan Ruusamäe <glen@pld-linux.org>
1881 #
1882 # Usage:
1883 #  -a NAME  -- add command named NAME
1884 #  -d NAME  -- remove command named NAME
1885 #  -f FILE  -- specify plugin configuration FILE to extract command definition from
1886 #
1887 # Sample:
1888 # %triggerin -- nagios-nrpe
1889 # %nagios_nrpe -a %{plugin} -f %{_sysconfdir}/%{plugin}.cfg
1890 #
1891 # %triggerun -- nagios-nrpe
1892 # %nagios_nrpe -d %{plugin} -f %{_sysconfdir}/%{plugin}.cfg
1893 #
1894 # Requirements:
1895 # Requires:                     grep
1896 # Requires:                     sed >= 4.0
1897 # BuildRequires:        rpmbuild(macros) >= 1.552
1898 %nagios_nrpe(a:d:c:f:) {\
1899         m=$(md5sum < /etc/nagios/nrpe.cfg); \
1900         %{-a:# on -a and config exists \
1901         if [ -f /etc/nagios/nrpe.cfg ]; then \
1902                 if ! %{__grep} -q '^command\[%{-a*}\]' /etc/nagios/nrpe.cfg; then \
1903                                 %{__sed} -ne 's/^[ \t]*command_line[ \t]\+\(.\+\)/command[%{-a*}]=\1/p' %{-f*} >> /etc/nagios/nrpe.cfg; \
1904                 fi; \
1905         fi;} \
1906         %{-d:# on package remove, -d and config exists \
1907         if [ "$1" = "0" -a -f /etc/nagios/nrpe.cfg ]; then \
1908                 %{__sed} -i -e '/^[ \t]*command\[%{-d*}\]/d' /etc/nagios/nrpe.cfg; \
1909         fi;} \
1910         if [ "$m" != "$(md5sum < /etc/nagios/nrpe.cfg)" ]; then \
1911                 %service -q nrpe restart; \
1912         fi; \
1913 }%{nil}
1914
1915 # Import or update Cacti template.
1916 #
1917 # Author: Elan Ruusamäe <glen@pld-linux.org>
1918 #
1919 # Usage:
1920 # %cacti_import_template XMLFILE
1921 #  XMLFILE -- XML template to import
1922 #
1923 # Sample:
1924 # %post
1925 # %cacti_import_template %{resourcedir}/cacti_host_template_varnish.xml
1926 #
1927 # Requires:     cacti >= 0.8.7e-8
1928 # BuildRequires:        rpmbuild(macros) >= 1.554
1929
1930 %cacti_import_template() {\
1931 /usr/share/cacti/cli/import_template.php --filename=%1 || :; \
1932 }%{nil}
1933
1934 # pre/post script for -upstart subpackages
1935 #
1936 # Author: Jacek Konieczny <jajcus@jajcus.net>
1937 #
1938 # Usage:
1939 #       %upstart_post service_name
1940 #   %upstart_postun service_name
1941 #
1942 # Sample:
1943 # %post upstart
1944 # %upstart_post %{name}
1945 #
1946 # %postun upstart
1947 # %upstart_postun %{name}
1948 #
1949 # Requirements:
1950 # BuildRequires:        rpmbuild(macros) >= 1.560
1951 # Requires:                     rc-scripts >= 0.4.3
1952
1953 # migrate from init script to upstart job
1954 %upstart_post() \
1955         if [ -f /var/lock/subsys/"%1" ] ; then \
1956                 /sbin/service --no-upstart "%1" stop \
1957                 /sbin/service "%1" start \
1958         fi
1959
1960 # restart the job after upgrade or migrate to init script on removal
1961 # cannot be stopped with 'service' as /etc/init/$name.conf may be missing
1962 # at this point
1963 %upstart_postun() \
1964         if [ -x /sbin/initctl ] && /sbin/initctl status "%1" 2>/dev/null | grep -q 'running' ; then \
1965                 /sbin/initctl stop "%1" >/dev/null 2>&1 \
1966                 [ -f "/etc/rc.d/init.d/%1" -o -f "/etc/init/%1.conf" ] && { echo -n "Re-" ; /sbin/service "%1" start ; } ; \
1967         fi
1968
1969 # vim:ts=4 sw=4 noet ft=spec
This page took 0.249562 seconds and 4 git commands to generate.