]> git.pld-linux.org Git - packages/rpm-build-macros.git/blob - rpm.macros
- merged from AC-branch
[packages/rpm-build-macros.git] / rpm.macros
1 # PLD rpm macros
2
3 # other macros
4 %epoch          0
5 %_enable_debug_packages 1
6
7 %_topdir         %(echo $HOME)/rpm
8 #-----------------------------------------------------------------
9 # CFLAGS and LDFLAGS used to build
10
11 %debuginfocflags        %{expand:%%define __dic_%{?_enable_debug_packages} 1}%{?__dic_1: -ggdb}%{expand:%%undefine __dic_%{?_enable_debug_packages}}
12
13 %debugcflags    -O0 -g -Wall
14 %rpmcflags      %{?debug:%debugcflags}%{!?debug:%optflags}%{?debuginfocflags}
15 %rpmcxxflags    %{rpmcflags}
16 %rpmldflags     %{nil}
17 # %rpmldflags   -Wl,--as-needed
18
19 # kernel compiler
20 %kgcc           gcc
21 %kgcc_package   gcc
22
23 # Build system path macros.
24 #
25 %__autoconf             autoconf %{?debug:-Wall}
26 %__automake             automake -a -c -f --foreign
27 %__autopoint            autopoint --force
28
29 %__gettextize { \
30     if ! gettextize --version | grep -q '0\.10\.' ; then \
31         if grep -qs 'AM_GNU_GETTEXT.*external' configure.{ac,in} ; then \
32             gettextize --copy --force --no-changelog; \
33         else \
34             gettextize --copy --force --no-changelog --intl; \
35         fi; \
36         if [ ! -f po/Makevars ]; then \
37             cp -f po/Makevars{.template,}; \
38         fi; \
39     else \
40         gettextize --copy --force; \
41     fi; \
42 }
43
44 %__glib_gettextize      glib-gettextize --copy --force
45 %__gnome_doc_common     gnome-doc-common --copy
46 %__gtkdocize            gtkdocize --copy
47 %__intltoolize          intltoolize --copy --force
48 %__libtoolize           libtoolize --copy --force
49
50 %dependencytracking     %{nil}
51 #-----------------------------------------------------------------
52 %configure2_13 { \
53  if [ -n "$LINGUAS" ]; then unset LINGUAS; fi; \
54  LDFLAGS="${LDFLAGS:-%rpmldflags}" ; export LDFLAGS ; \
55  CFLAGS="${CFLAGS:-%rpmcflags}" ; export CFLAGS ; \
56  CXXFLAGS="${CXXFLAGS:-%rpmcxxflags}" ; export CXXFLAGS ; \
57  FFLAGS="${FFLAGS:-%rpmcflags}" ; export FFLAGS ; \
58  CPPFLAGS="${CPPFLAGS:-}" ; export CPPFLAGS ; \
59  %{?__cc:CC="%{__cc}" ; export CC ; } \
60  %{?__cxx:CXX="%{__cxx}" ; export CXX ; } \
61  %{?configuredir:%{configuredir}}%{!?configuredir:.}/configure \
62         --host=%{_target_platform} \
63         --prefix=%{_prefix} \
64         --exec-prefix=%{_exec_prefix} \
65         --bindir=%{_bindir} \
66         --sbindir=%{_sbindir} \
67         --sysconfdir=%{_sysconfdir} \
68         --datadir=%{_datadir} \
69         --includedir=%{_includedir} \
70         --libdir=%{_libdir} \
71         --libexecdir=%{_libexecdir} \
72         --localstatedir=%{_localstatedir} \
73         --sharedstatedir=%{_sharedstatedir} \
74         --mandir=%{_mandir} \
75         --infodir=%{_infodir} \
76         --x-libraries=/usr/X11R6/%{_lib} \
77         %{dependencytracking} \
78 }
79
80 #----------------------------------------------------------------
81 %global configure_cache 0
82 %configure_cache_file   %{buildroot}.configure.cache
83
84 %configure {./configure \
85         LDFLAGS="${LDFLAGS:-%rpmldflags}" \
86         CFLAGS="${CFLAGS:-%rpmcflags}" \
87         CXXFLAGS="${CXXFLAGS:-%rpmcxxflags}" \
88         FFLAGS="${FFLAGS:-%rpmcflags}" \
89         CPPFLAGS="${CPPFLAGS:-}" \
90         %{?__cc:CC="%{__cc}"} \
91         %{?__cxx:CXX="%{__cxx}"} \
92         --host=%{_target_platform} \
93         --build=%{_target_platform} \
94         --prefix=%{_prefix} \
95         --exec-prefix=%{_exec_prefix} \
96         --bindir=%{_bindir} \
97         --sbindir=%{_sbindir} \
98         --sysconfdir=%{_sysconfdir} \
99         --datadir=%{_datadir} \
100         --includedir=%{_includedir} \
101         --libdir=%{_libdir} \
102         --libexecdir=%{_libexecdir} \
103         --localstatedir=%{_localstatedir} \
104         --sharedstatedir=%{_sharedstatedir} \
105         --mandir=%{_mandir} \
106         --infodir=%{_infodir} \
107         --x-libraries=/usr/X11R6/%{_lib} \
108         %{dependencytracking} \
109         %{?configure_cache:--cache-file=%{configure_cache_file:-%{buildroot}.configure.cache}} \
110 }
111
112 # ------------------------------------------------------------------------
113 # Overloading of some basic macros
114 %prep \
115 %%prep\
116 LANG=C\
117 export LANG\
118 unset DISPLAY ||:\
119 unset LINGUAS ||:\
120 %{nil}
121
122 %build %%build\
123 LANG=C\
124 export LANG\
125 unset DISPLAY ||:\
126 unset LINGUAS ||:\
127 %{nil}
128
129 %install \
130 %if 0%{?_enable_debug_packages}\
131 %{?buildsubdir:%{debug_package}}\
132 %endif\
133 %%install\
134 LANG=C\
135 export LANG\
136 unset DISPLAY ||:\
137 unset LINGUAS ||:\
138 %{nil}
139
140 # ------------------------------------------------------------------------
141 # Conditional build stuff.
142
143 # Check if symbol is defined.
144 # Example usage: %if %{defined with_foo} && %{undefined with_bar} ...
145 %defined()      %{expand:%%{?%{1}:1}%%{!?%{1}:0}}
146 %undefined()    %{expand:%%{?%{1}:0}%%{!?%{1}:1}}
147
148 # Shorthand for %{defined with_...}
149 %with()         %{expand:%%{?with_%{1}:1}%%{!?with_%{1}:0}}
150 %without()      %{expand:%%{?with_%{1}:0}%%{!?with_%{1}:1}}
151
152 # Handle conditional builds. %bcond_with is for case when feature is
153 # default off and needs to be activated with --with ... command line 
154 # switch. %bcond_without is for the dual case.
155 #
156 # %bcond_with foo defines symbol with_foo if --with foo was specified on
157 # command line.
158 # %bcond_without foo defines symbol with_foo if --without foo was *not* 
159 # specified on command line.
160 #
161 # For example:
162 #
163 # %bcond_with extra_fonts
164 # %bcond_without static
165 # %if %{with extra_fonts}
166 # ...
167 # %endif
168 # %ifdef %{with static}
169 # ...
170 # %endif
171 # %{?with_static: ... }
172 # %{!?with_static: ... }
173 # %{?with_extra_fonts: ... }
174 # %{!?with_extra_fonts: ... }
175
176 # The bottom line: never use without_foo, _with_foo nor _without_foo, only
177 # with_foo. This way changing default set of bconds for given spec is just
178 # a matter of changing single line in it and syntax is more readable.
179 %bcond_with()           %{expand:%%{?_with_%{1}:%%global with_%{1} 1}}
180 %bcond_without()        %{expand:%%{!?_without_%{1}:%%global with_%{1} 1}}
181 # ------------------------------------------------------------------------
182
183 # Location of autoconf macros
184 %_aclocaldir    %(aclocal --print-ac-dir)
185
186 # Location of omf files
187 %_omf_dest_dir  %(scrollkeeper-config --omfdir)
188
189 # Location of pkgconfig files
190 %_pkgconfigdir  /usr/%{_lib}/pkgconfig
191
192 # Location of desktop files
193 %_desktopdir    /usr/share/applications
194 %_applnkdir     ERROR:_applnkdir_is_obsolete_use_desktopdir_instead
195
196 # Location of pixmaps for applnk/desktop files
197 %_pixmapsdir    /usr/share/pixmaps
198
199 # Location of themable icons for applnk/desktop files
200 %_iconsdir      /usr/share/icons
201
202 # Location of fonts directories
203 %_fontsdir      /usr/share/fonts
204
205 # Location of Gtk and associated libraries documentation
206 %_gtkdocdir  %{_defaultdocdir}/gtk-doc/html
207
208 # Location of KDE documentation
209 %_kdedocdir  %{_defaultdocdir}/kde/HTML
210
211 # unsermake script
212 %__unsermake /usr/share/unsermake/unsermake
213
214 # Current date
215 %date           %(LC_ALL="C" date +"%a %b %d %Y")
216
217 # tmp directory
218 %tmpdir         %(echo "${TMPDIR:-/tmp}")
219
220 # Example files, programs, scripts...
221 %_examplesdir   /usr/src/examples
222
223 # The directory holding Linux kernel sources
224 %_kernelsrcdir  /usr/src/linux
225
226 # If non-empty "debug" macro defined, add "dbg" suffix to release number
227 %_rpmfilename           %%{NAME}-%%{VERSION}-%%{RELEASE}%{?debug:dbg}.%%{ARCH}.rpm
228
229 # Requires name = version-release
230 %requires_releq()               %(echo '%*' | LC_ALL="C" xargs -r rpm -q --qf 'Requires: %%{name} = %%{epoch}:%%{version}-%%{release}\\n' | sed -e 's/ (none):/ /' | grep -v "is not")
231
232 %releq_kernel_up()              %(LC_ALL="C" rpm -qf --qf '%%{name}-up = %%{epoch}:%%{version}-%%{release}\\n' %{_kernelsrcdir}/include/linux/version.h | sed -e 's/ (none):/ /' | sed -e 's:-headers::' | grep -vE "(is not|no such)")
233 %releq_kernel_smp()             %(LC_ALL="C" rpm -qf --qf '%%{name}-smp = %%{epoch}:%%{version}-%%{release}\\n' %{_kernelsrcdir}/include/linux/version.h | sed -e 's/ (none):/ /' | sed -e 's:-headers::' | grep -vE "(is not|no such)")
234 %requires_releq_kernel_up()     %(LC_ALL="C" rpm -qf --qf 'PreReq: %%{name}-up = %%{epoch}:%%{version}-%%{release}\\n' %{_kernelsrcdir}/include/linux/version.h | sed -e 's/ (none):/ /' | sed -e 's:-headers::' | grep -vE "(is not|no such)")
235 %requires_releq_kernel_smp()    %(LC_ALL="C" rpm -qf --qf 'PreReq: %%{name}-smp = %%{epoch}:%%{version}-%%{release}\\n' %{_kernelsrcdir}/include/linux/version.h | sed -e 's/ (none):/ /' | sed -e 's:-headers::' | grep -vE "(is not|no such)")
236
237 %requires_eq_to() %(LC_ALL="C" rpm -q --qf 'Requires: %1 = %%{epoch}:%%{version}\\n' %2 | sed -e 's/ (none):/ /' | grep -v "is not")
238
239 %apache_modules_api %(awk '/#define MODULE_MAGIC_NUMBER_MAJOR/ {print $3}' /usr/include/apache/ap_mmn.h 2>/dev/null || echo ERROR)
240
241 # kernel version-release handling
242 %__kernel_ver    %([ -f %{_kernelsrcdir}/include/linux/version.h ] && (grep UTS_RELEASE %{_kernelsrcdir}/include/linux/version.h 2>/dev/null | head -n 1 | cut -d'"' -f2) || (awk '/^VERSION/ { ver = $0; gsub(/VERSION.*=/, NIL, ver); } /^PATCHLEVEL/ { plev = $0; gsub(/PATCHLEVEL.*=/, NIL, plev); } /^SUBLEVEL/ { slev = $0; gsub(/SUBLEVEL.*=/, NIL, slev); } /^EXTRAVERSION/ { ever = $0; gsub(/EXTRAVERSION.*=/, NIL, ever); gsub(/ /, NIL, ever); } END { printf("%d.%d.%d%s", ver, plev, slev, ever); }' %{_kernelsrcdir}/Makefile 2> /dev/null))
243 %__kernel_rel    %(LC_ALL="C" rpm -qf %{_kernelsrcdir}/include/linux/fs.h 2>/dev/null --qf "%{RELEASE}" | grep -v "is not")
244 %__kernel_rpmvr  %(LC_ALL="C" rpm -qf %{_kernelsrcdir}/include/linux/fs.h 2>/dev/null --qf "%{VERSION}-%{RELEASE}" | grep -v "is not")
245 %_kernel_ver     %{__kernel_ver}%{?with_dist_kernel:%(echo %{__kernel_ver} | grep -q -e - || echo -%{__kernel_rel})}
246 %_kernel_ver_str %(echo %{!?_without_dist_kernel:%{__kernel_rpmvr}}%{?_without_dist_kernel:%{__kernel_ver}} | sed -e 's/-/_/g')
247
248 # sgml macros
249 %xmlcat_add()            /usr/bin/xmlcatalog --noout --add nextCatalog \"\" %1 /etc/xml/catalog ;
250 %xmlcat_del()            /usr/bin/xmlcatalog --noout --del %1 /etc/xml/catalog ;
251 %xmlcat_add_rewrite      /usr/bin/xmlcatalog --noout --add rewriteSystem
252 %xmlcat_create()          /usr/bin/xmlcatalog --noout --create %1 ;
253 %sgmlcat_add()           /usr/bin/install-catalog --add %1 %2 > /dev/null ;
254 %sgmlcat_del()           /usr/bin/install-catalog --remove %1 %2 > /dev/null ;
255 %docbook_sgmlcat_fix() { for l in \
256 '' \
257 '  -- default decl --' \
258 'DTDDECL "-//OASIS//DTD DocBook XML V%2//EN" "../../xml.dcl"' \
259 '  -- hacks for opensp --' \
260 'SYSTEM "file://%{_datadir}/sgml/docbook/xml-dtd-%2/docbookx.dtd" "%{_datadir}/sgml/docbook/xml-dtd-%2/docbookx.dtd"' \
261 'SYSTEM "http://www.oasis-open.org/docbook/xml/%2/docbookx.dtd"                  "%{_datadir}/sgml/docbook/xml-dtd-%2/docbookx.dtd"' \
262 '' \
263 ; do echo $l; done >> %1 \
264 }
265
266 #-----------------------------------------------------------------
267 # find and gzip all files in %{_mandir} and %{infodir}
268 #
269 # Requires: xargs, find
270 #
271 #%no_install_post_compress_docs 1
272 %__spec_install_post_compress_docs { \
273 %{!?no_install_post_compress_docs: \
274         echo "Compress man and info pages."; \
275         %{?verbose:set -x;} \
276         for i in /usr/share/man /usr/X11R6/man /usr/share/info; do \
277                 if [ -d "$RPM_BUILD_ROOT$i" ]; then \
278                         find "$RPM_BUILD_ROOT$i" -name \*.bz2 -print | xargs -r %{__bzip2} -df; \
279                         find "$RPM_BUILD_ROOT$i" -name \*.gz -print | xargs -r %{__gzip} -dnf; \
280                         find "$RPM_BUILD_ROOT$i" -type f -print | xargs -r %{__gzip} -9nf; \
281                 fi; \
282         done; \
283 } }
284
285 #-----------------------------------------------------------------
286 # Strip executable binaries and shared object files
287 #
288 # Requires: find, awk, strip, cut, xargs
289 #
290 #%no_install_post_strip 1
291 %__spec_install_post_strip {%{!?debug: \
292 %{!?no_install_post_strip: \
293     %{?verbose:set -x;} \
294     if [ -d "$RPM_BUILD_ROOT" ]; then \
295         echo "Strip executable binaries, archives and shared object files."; \
296         filelist=`find $RPM_BUILD_ROOT -type f ! -regex ".*ld-[0-9.]*so.*" ! -regex ".*/usr/lib[0-9]*/debug/.*\.debug" %{?_noautostrip:! -regex "%{_noautostrip}"}`; \
297         elfexelist=`echo $filelist | xargs -r file | \
298                 awk '/ELF.*executable/ {print $1}' | cut -d: -f1`; \
299         elfsharedlist=`echo $filelist | xargs -r file | \
300                 awk '/LF.*shared object/ {print $1}' | cut -d: -f1`; \
301         elfarchiveslist=`echo $filelist | xargs -r file | \
302                 awk '/current ar archive/ {print $1}' | cut -d: -f1`; \
303         if [ -n "$elfexelist" ]; then \
304                 %{__strip} --remove-section=.note  --remove-section=.comment $elfexelist; \
305         fi; \
306         if [ -n "$elfsharedlist" ]; then \
307                 %{__strip} --strip-unneeded --remove-section=.note  --remove-section=.comment $elfsharedlist; \
308         fi; \
309         if [ -n "$elfarchiveslist" ]; then \
310                 %{__strip} --strip-debug --remove-section=.note  --remove-section=.comment $elfarchiveslist; \
311         fi; \
312     fi; } \
313 } }
314 #-----------------------------------------------------------------
315 # remove all RPATH from executable binaries and shared object files
316 #
317 # Requires: find, awk, cut, xargs, chrpath, uname
318 #
319 #%no_install_post_chrpath       1
320 %__spec_install_post_chrpath {%{!?debug: \
321 %{!?no_install_post_chrpath: \
322         %{?verbose:set -x;} \
323 if [ -d "$RPM_BUILD_ROOT" ]; then \
324 echo "Remove RPATH from executable binaries and shared object files."; \
325 find $RPM_BUILD_ROOT -type f ! -regex ".*ld-[0-9.]*so.*" ! -regex ".*/usr/lib[0-9]*/debug/.*" %{?_noautochrpath:! -regex "%{_noautochrpath}"} | xargs -r file | \
326         awk '/ELF.*(executable.*dynamically linked|shared object)/ {print $1}' | cut -d: -f1 | \
327 while read file ; do \
328         rpath= ; \
329         chmod u+w "$file"; \
330         for dir in `chrpath -l "$file" | \
331                     awk '/RPATH=/ { gsub(/.*RPATH=/,""); gsub(/:/," "); print $0 }'` ; do \
332                         case $dir in \
333                         /home/* | /tmp/* | /usr/lib | /usr/lib64 | /lib | /lib64 | /usr/local/lib | /usr/local/lib64 | /usr/X11R6/lib | /usr/X11R6/lib64 ) \
334                                 echo "remove-rpath: $dir in $file"; \
335                                 ;; \
336                         * ) \
337                                 if [ "$rpath" = "" ] ; then rpath="$dir" ; \
338                                 else rpath="$rpath:$dir" ; fi ; \
339                                 ;; \
340                         esac ; \
341         done ; \
342         if [ "$rpath" = "" ] ; then chrpath -d "$file" > /dev/null ; \
343         else chrpath -r "$rpath" "$file" > /dev/null ; fi ; \
344 done; \
345 fi; } \
346 } }
347 #-----------------------------------------------------------------
348 # Find and gzip all kernel modules
349 #
350 # Requires: find
351 #
352 #%no_install_post_compress_modules  1
353 %__spec_install_post_compress_modules { \
354 %{!?no_install_post_compress_modules: \
355     %{?verbose:set -x;} \
356     if [ -d "$RPM_BUILD_ROOT" ]; then \
357 echo "Compress kernel modules if any."; \
358     if test -d $RPM_BUILD_ROOT/lib/modules ; then \
359         find $RPM_BUILD_ROOT/lib/modules -name \*o -type f -print | \
360         xargs -r %{__gzip} -9nf; \
361            find $RPM_BUILD_ROOT/lib/modules -name \*o -type l -printf "%p %l\n" | \
362            while read a b; do ln -sf $b.gz $a.gz; rm -f $a; done; \
363     fi; \
364     fi; \
365 } }
366
367 %_source_payload        w9.gzdio
368 %_binary_payload        w9.bzdio
369
370 #-----------------------------------------------------------------
371 # Update GConf2 schemas
372 #
373 # Requires: GConf2
374 #
375 %gconf_schema_install() \
376     umask 022; \
377     GCONF_CONFIG_SOURCE="xml:readwrite:/etc/gconf/gconf.xml.defaults" /usr/bin/gconftool-2 --makefile-install-rule /etc/gconf/schemas/%{?1}%{!?1:*.schemas} > /dev/null \
378     %{nil}
379
380 %gconf_schema_uninstall() \
381 if [ $1 = 0 ]; then \
382     umask 022; \
383     GCONF_CONFIG_SOURCE="xml:readwrite:/etc/gconf/gconf.xml.defaults" /usr/bin/gconftool-2 --makefile-uninstall-rule /etc/gconf/schemas/%{?1} > /dev/null \
384 fi \
385 %{nil}
386
387 #-----------------------------------------------------------------
388 # Update desktop MIME database
389 # requires: desktop-file-utils
390 #
391 %update_desktop_database_post() {{ \
392         umask 022; \
393         /usr/bin/update-desktop-database; \
394 }}
395
396 %update_desktop_database_postun() {{ \
397 if [ $1 = 0 ]; then \
398         umask 022; \
399         /usr/bin/update-desktop-database; \
400 fi \
401 }}
402
403 #-----------------------------------------------------------------
404 # Update scrollkeeper database
405 # requires: scrollkeeper
406 #
407 %scrollkeeper_update_post() \
408         /usr/bin/scrollkeeper-update -q; \
409         %{nil}
410
411 %scrollkeeper_update_postun() \
412 if [ $1 = 0 ]; then \
413         /usr/bin/scrollkeeper-update -q; \
414 fi \
415 %{nil}
416
417 #-----------------------------------------------------------------
418 # Run ldconfig after installing/deinstalling libraries
419 #
420 %ldconfig_post() \
421         /sbin/ldconfig; \
422         %{nil}
423
424 %ldconfig_postun() \
425         /sbin/ldconfig; \
426         %{nil}
427
428 #-----------------------------------------------------------------
429 # post %install sequence:
430 # - autodeps exceptions
431 # - compress all man and info pages,
432 # - strip all ELF executables and ELF shared objects if not %debug.
433 # - compress kernel modules if any
434
435 ###################################################################
436 # Requires/Provides automation
437 # exceptions system by Jacek Konieczny <jajcus@pld.org.pl>
438 #
439 %__noautoreqfiles       %(sed -e s'/#.*//' /etc/rpm/noautoreqfiles)%{?_noautoreqfiles: %{_noautoreqfiles}}
440 %__noautoprovfiles      %(sed -e s'/#.*//' /etc/rpm/noautoprovfiles)%{?_noautoprovfiles: %{_noautoprovfiles}}
441 %__noautoreq            %(sed -e s'/#.*//' /etc/rpm/noautoreq)%{?_noautoreq: %{_noautoreq}}
442 %__noautoreqdep         %(sed -e s'/#.*//' /etc/rpm/noautoreqdep)%{?_noautoreqdep: %{_noautoreqdep}}
443 %__noautoprov           %(sed -e s'/#.*//' /etc/rpm/noautoprov)%{?_noautoprov: %{_noautoprov}}
444 #%_noautocompressdoc    %{nil}
445 #
446 %_missing_doc_files_terminate_build     1%{nil}
447 %_unpackaged_files_terminate_build      %{nil}
448 # (X)emacs support
449 %___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;}'
450 %_emacs_lispdir %(emacs %___emacs_lispdir_helper)
451 %_xemacs_lispdir %(xemacs %___emacs_lispdir_helper)
452
453 %__php_provides %{nil}
454 %__php_requires %{nil}
455 %__perl_provides %{nil}
456 %__perl_requires %{nil}
457 %__mono_provides %{nil}
458 %__mono_requires %{nil}
459
460 # Perl specific macro definitions.
461 %perl_privlib   %(eval "`%{__perl} -V:installprivlib`"; echo $installprivlib)
462 %perl_archlib   %(eval "`%{__perl} -V:installarchlib`"; echo $installarchlib)
463 %perl_vendorlib %(eval "`%{__perl} -V:installvendorlib`"; echo $installvendorlib)
464 %perl_vendorarch        %(eval "`%{__perl} -V:installvendorarch`"; echo $installvendorarch)
465 %perl_sitelib   %(eval "`%{__perl} -V:installsitelib`"; echo $installsitelib)
466 %perl_sitearch  %(eval "`%{__perl} -V:installsitearch`"; echo $installsitearch)
467
468 %php_pear_dir   %{_datadir}/pear
469
470 # extract php/zend api versions
471 %php_api_version %(awk '/#define PHP_API_VERSION/{print $3}' /usr/include/php/main/php.h)
472 %zend_module_api %(awk '/#define ZEND_MODULE_API_NO/{print $3}' /usr/include/php/Zend/zend_modules.h)
473 %zend_extension_api %(awk '/#define ZEND_EXTENSION_API_NO/{print $3}' /usr/include/php/Zend/zend_extensions.h)
474
475 # directory where php includes are installed on system.
476 %__php_includedir               /usr/include/php
477 %php_major_version              %(awk '/#define PHP_MAJOR_VERSION/{print $3}' %{__php_includedir}/main/php_version.h 2>/dev/null || echo ERROR)
478 %php_api_version                %(awk '/#define PHP_API_VERSION/{print $3}' %{__php_includedir}/main/php.h 2>/dev/null || echo ERROR)
479 %php_debug                              %(awk '/#define ZEND_DEBUG/{print $3}' %{__php_includedir}/main/php_config.h 2>/dev/null || echo ERROR)
480 %zend_module_api                %(awk '/#define ZEND_MODULE_API_NO/{print $3}' %{__php_includedir}/Zend/zend_modules.h 2>/dev/null || echo ERROR)
481 %zend_extension_api             %(awk '/#define ZEND_EXTENSION_API_NO/{print $3}' %{__php_includedir}/Zend/zend_extensions.h 2>/dev/null || echo ERROR)
482 %zend_zts                               %(Z=$(grep -sc '^#define ZTS 1' %{__php_includedir}/main/php_config.h); echo ${Z:-ERROR})
483
484 # helper macro
485 %__php_api_requires(v:) Requires: php%{-v*}(%{expand:%1}) = %{expand:%{%{!?2:%{1}}%{?2}}}
486
487 # macros for public use
488 # for php extensions (php-pecl)
489 %requires_php_extension %{__php_api_requires modules_api php_api_version} \
490 %{__php_api_requires -v %php_major_version debug php_debug} \
491 %{__php_api_requires -v %php_major_version thread-safety zend_zts}
492
493 # for zend extensions
494 %requires_zend_extension %{__php_api_requires zend_module_api} \
495 %{__php_api_requires zend_extension_api} \
496 %{__php_api_requires -v %php_major_version debug php_debug} \
497 %{__php_api_requires -v %php_major_version thread-safety zend_zts}
498
499 # Python specific macro definitions.
500 # python main version
501 %py_ver         %(echo `python -c "import sys; print sys.version[:3]"`)
502
503 # directories
504 %py_prefix      %(echo `python -c "import sys; print sys.prefix"`)
505 %py_libdir      %{py_prefix}/%{_lib}/python%{py_ver}
506 %py_scriptdir   %{py_prefix}/share/python%{py_ver}
507 %py_incdir      /usr/include/python%{py_ver}
508 %py_sitedir     %{py_libdir}/site-packages
509 %py_sitescriptdir %{py_scriptdir}/site-packages
510 %py_dyndir      %{py_libdir}/lib-dynload
511
512 # pure python modules compilation
513 %py_comp        python -c "import compileall; import sys; compileall.compile_dir(sys.argv[1], ddir=sys.argv[1][len('$RPM_BUILD_ROOT'):])"
514
515 %py_ocomp       python -O -c "import compileall; import sys; compileall.compile_dir(sys.argv[1], ddir=sys.argv[1][len('$RPM_BUILD_ROOT'):])"
516
517 # Software written in Python language require Python with main version
518 %pyrequires_eq() Requires:      %1
519
520
521 # Hardlink binary identical .pyc and .pyo files
522 # (idea by glen <at> pld-linux <dot> org)
523 %__spec_install_post_py_hardlink {\
524 %{!?no_install_post_py_hardlink: \
525 [ ! -d "$RPM_BUILD_ROOT" ] || find "$RPM_BUILD_ROOT" -name '*.pyc' | while read a; do \
526         b="$(echo $a|sed -e 's/.pyc$/.pyo/')"; \
527         if cmp -s "$a" "$b"; then \
528                 ln -f "$a" "$b"; \
529         fi; \
530 done \
531 } }
532
533 # remove python sources, so that check-files won't complain
534 # (idea by glen <at> pld-linux <dot> org)
535 %py_postclean() \
536 for d in %{py_sitescriptdir} %{py_sitedir} %*; do \
537  [ ! -d "$RPM_BUILD_ROOT$d" ] || find "$RPM_BUILD_ROOT$d" -name '*.py' -print0 | xargs -0r -l512 rm;\
538 done \
539 %{nil}
540
541 # depmod macro
542 %depmod() { \
543 umask 022; \
544 if [ -e /boot/System.map-%1 ]; then \
545         /sbin/depmod -a -F /boot/System.map-%1 %1; \
546 else \
547         if [ -e /boot/System.map ]; then \
548                 /sbin/depmod -a -F /boot/System.map %1; \
549         else \
550                 /sbin/depmod -a %1; \
551         fi \
552 fi; \
553 }
554
555 # XMMS specific macros
556 %xmms_prefix                  %(xmms-config --prefix 2>/dev/null)
557 %xmms_exec_prefix             %(xmms-config --exec-prefix 2>/dev/null)
558 %xmms_version                 %(xmms-config --version 2>/dev/null)
559 %xmms_datadir                 %(xmms-config --data-dir 2>/dev/null)
560 %xmms_plugindir               %(xmms-config --plugin-dir 2>/dev/null)
561 %xmms_visualization_plugindir %(xmms-config --visualization-plugin-dir 2>/dev/null)
562 %xmms_input_plugindir         %(xmms-config --input-plugin-dir 2>/dev/null)
563 %xmms_output_plugindir        %(xmms-config --output-plugin-dir 2>/dev/null)
564 %xmms_effect_plugindir        %(xmms-config --effect-plugin-dir 2>/dev/null)
565 %xmms_general_plugindir       %(xmms-config --general-plugin-dir 2>/dev/null)
566
567 %_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/')
568
569 %x8664                  x86_64 amd64 ia32e
570
571 # user/group checking macros
572 #
573 # Usage:
574 #       %userremove myuser
575 #
576 %userremove     /usr/lib/rpm/user_group.sh user del
577 %groupremove    /usr/lib/rpm/user_group.sh group del
578 #
579 # Usage:
580 #       if %usertestrm myuser; then
581 #               /usr/sbin/userdel -r myuser
582 # Note:
583 #       use these macros only if you need to call userdel/groupdel with
584 #       a non-standard option or take an extra action; otherwise use the
585 #       %userremove/%groupremove macros
586 #
587 %usertestrm     /usr/lib/rpm/user_group.sh user testrm
588 %grouptestrm    /usr/lib/rpm/user_group.sh group testrm
589 # user group membership management macros
590 #
591 # Usage:
592 #       %addusertogroup myuser agroup
593 #
594 %addusertogroup /usr/lib/rpm/user_group.sh user addtogroup
595
596 # banner support (useful in {pre,post}{,un} and triggers)
597 #
598 # Usage:
599 #       %banner name [-a] [-e] [-n] [-tn] <<EOF
600 # the banner text, the banner text
601 # the banner text, and following line
602 #EOF
603 # You can use any form of here-document, <<'EOF' <<-EOT will do.
604 # NOTE: if your use "<<-EOF", then You can actually indent inside here-document.
605 #
606 # -a   - append to the banner
607 # -e   - send to stderr instead of stdout
608 # -n   - no show banner (overrides -t)
609 # -t   - show only, if RPM_SCRIPTVERBOSITY >= n; default n=5
610 %banner(aent:)  \
611 RPM_SCRIPTVERBOSITY=5 \
612 [ -r /etc/sysconfig/rpm ] && . /etc/sysconfig/rpm \
613 if [ -x /usr/bin/banner.sh ]; then \
614         CMD="/usr/bin/banner.sh %{-e:--stderr} %{!-n:$([ $RPM_SCRIPTVERBOSITY -ge %{-t:%{-t*}}%{!-t:5} ] && echo -s)} %{!-a:-m}%{-a:-M} %1" \
615 else \
616         CMD="cat%{-e: >&2}" \
617 fi \
618 eval $CMD %2%{?3: %3} \
619 %nil
620
621 # useradd/groupadd macros written by glen@pld-linux.org.
622 # All rights reserved. Permission to copy is hereby granted.. yada, yada, yada
623 #
624 # Usage:
625 #   %useradd [-P package] [-u uid] [-d home_dir] [-s shell] [-c comment]
626 #   [-g initial_group] [-G group[,...]] login
627 #
628 #  -u uid. REQUIRED
629 #  -g gid/group. REQUIRED
630 #  -s defaults to /bin/false
631 #  -d defaults to /usr/share/empty
632 #  -c No default
633 #  -r is accepted but ignored (it's always set)
634 #  -k skeleton dir. defaults to /usr/share/empty
635 # rpm specific flags
636 #  -P package name. defaults to %{name}
637 #
638 %useradd(c:d:e:f:g:G:Mmk:op:s:u:rP:) \
639 %{!-u:%{error:useradd: Required argument -u missing}} \
640 %{!-g:%{error:useradd: Required argument -g missing}} \
641 %{!?1:%{error:useradd: Required parameter login missing}} \
642 if [ -n "`/bin/id -u %{expand:%{%{#}}} 2>/dev/null`" ]; then \
643         if [ "`/bin/id -u %{expand:%{%{#}}}`" != "%{-u*}" ]; then \
644                 echo "Error: user %{expand:%{%{#}}} doesn't have uid=%{-u*}. Correct this before installing %{-P*}%{!?-P:%{name}}." 1>&2 \
645                 exit 1 \
646         fi \
647 else \
648         echo "Adding user %{expand:%{%{#}}} UID=%{-u*}." \
649         /usr/sbin/useradd \\\
650                 %{-m:-m -k %{-k*}%{!-k:/usr/share/empty}} \\\
651                 -u %{-u*} \\\
652                 -r \\\
653                 -d %{-d*}%{!-d:/usr/share/empty} \\\
654                 -s %{-s*}%{!-s:/bin/false} \\\
655                 %{-c:-c "%(set -- %{-c*} %{*}; echo $1)"}\\\
656                 -g %{-g*} \\\
657                 %{-M} \\\
658                 %{-G:-G %{-G*}} \\\
659                 %{expand:%{%{#}}} 1>&2 \
660 fi;
661
662 # Usage:
663 #   %groupadd [-P package] [-g gid] group
664 #
665 # -g gid. REQUIRED
666 #
667 # Sample:
668 #   %groupadd -P %{name}-base -g %{gid} %{name}
669
670 %groupadd(g:P:rfo)      \
671 %{!-g:%{error:groupadd: Required argument -g missing}} \
672 %{!?1:%{error:groupadd: Required parameter group missing}} \
673 if [ -n "`/usr/bin/getgid %{1}`" ]; then \
674         if [ "`/usr/bin/getgid %{1}`" != "%{-g*}" ]; then \
675                 echo "Error: group %{1} doesn't have gid=%{-g*}. Correct this before installing %{-P*}%{!?-P:%{name}}." 1>&2 \
676                 exit 1 \
677         fi \
678 else \
679         echo "Adding group %{1} GID=%{-g*}." \
680         /usr/sbin/groupadd -g %{-g*} -r %{1} 1>&2 \
681 fi;
682
683 # apache_config_{install/uninstall} macros written by glen@pld-linux.org.
684 # All rights reserved. Permission to copy is hereby granted.. yada, yada, yada
685 #
686 # The config is installed/removed inside trigger, this means that you can any
687 # time install apache1 or apache package and the configuration file is updated.
688 # if you don't need the config for various reason for specific apache, just
689 # remove the symlink from apache config directory. the trigger will not put the
690 # config again to that version of apache. In other words the config is linked
691 # to apache config directory on first install of PACKAGE or apache.
692 #
693 # should be called in trigger body:
694 #  %triggerin -- apache1 >= 1.3.33-2
695 #  %apache_config_install -v 1
696 #
697 # Add package's apache config to apache config.
698 #
699 # Usage:
700 #   %apache_config_install -v {1|2} -c %{_sysconfdir}/apache-%{name}.conf -n 99
701 #
702 #  -v REQUIRED: specify apache version. can be 1 or 2.
703 #  -c OPTIONAL: specify full path to PACKAGE's config. Defaults to %{_sysconfdir}/apache-%{name}.conf.
704 #  -n OPTIONAL: specify config "slot". defaults to 99
705 #
706 # Internal macros. don't use ;).
707 # expands apache config dir by apache version at build time.
708 %__apache_confdir() %(if [ %{1} = 1 ]; then echo /etc/apache/conf.d; elif [ %{1} = 2 ]; then echo /etc/httpd/httpd.conf; else echo >&2 Unknown apache version specified; fi)
709 # expands apache service name by apache version at build time.
710 %__apache_svcname() %(if [ %{1} = 1 ]; then echo apache; elif [ %{1} = 2 ]; then echo httpd; else echo >&2 Unknown apache version specified; fi)
711
712 %apache_config_install(v:c:n:) \
713 %{!-v:%{error:apache_config_install: Required argument -v missing}} \
714 %{?debug:set -x; echo "apache_config_install:%{-v*} %{name}-%{version}-%{release} 1:[$1]; 2:[$2]"} \
715 if [ "$1" = "1" ] && [ "$2" = "1" ] && [ -d %{__apache_confdir %{-v*}} ]; then\
716         ln -sf %{-c*}%{!-c:%{_sysconfdir}/apache-%{name}.conf} %{__apache_confdir %{-v*}}/%{-n*}%{!-n:99}_%{name}.conf\
717 fi\
718 # reload apache if the config symlink is there\
719 if [ -L %{__apache_confdir %{-v*}}/%{-n*}%{!-n:99}_%{name}.conf ]; then\
720         # additionally don't reload if target package (the webserver) is upgraded, as webserver is restarted anyway in %post \
721         if [ "$2" != "2" ] && [ -f /var/lock/subsys/%{__apache_svcname %{-v*}} ]; then\
722                 /etc/rc.d/init.d/%{__apache_svcname %{-v*}} reload 1>&2\
723         fi\
724 fi\
725 %{nil}
726
727 # Remove package's apache config from apache config.
728 #
729 # Usage:
730 #   %apache_config_uninstall -v {1|2} -n 99
731 #
732 #  -v REQUIRED: specify apache version. can be 1 or 2.
733 #  -n OPTIONAL: specify config "slot". defaults to 99
734 %apache_config_uninstall(v:n:) \
735 %{!-v:%{error:apache_config_uninstall: Required argument -v missing}} \
736 %{?debug:set -x; echo "apache_config_uninstall:%{-v*} %{name}-%{version}-%{release}: 1:[$1]; 2:[$2]"} \
737 # remove link if either of the packages are gone \
738 if [ "$1" = "0" ] || [ "$2" = "0" ]; then \
739         if [ -L %{__apache_confdir %{-v*}}/%{-n*}%{!-n:99}_%{name}.conf ]; then \
740                 rm -f %{__apache_confdir %{-v*}}/%{-n*}%{!-n:99}_%{name}.conf \
741                 if [ -f /var/lock/subsys/%{__apache_svcname %{-v*}} ]; then \
742                         /etc/rc.d/init.d/%{__apache_svcname %{-v*}} reload 1>&2 \
743                 fi \
744         fi \
745 fi \
746 %{nil}
747
748 # see browser-plugins.spec / template-browser-plugin.spec
749 # written by glen@pld-linux.org.
750 %nsplugin_install(d:f) { \
751 # create link if it's first install of either of the packages \
752 if [ -n "%{-f:1}" ] || ([ "$1" = "1" ] && [ "$2" = "1" ] && [ -d %{-d*} ]); then \
753 ( \
754 %( \
755         for file in %{*}; do \
756                 echo echo Installing $file to %{-d*}; \
757                 echo "ln -sf %{_libdir}/browser-plugins/$file %{-d*};"; \
758         done ) \
759 ) | ( %banner -t 5 -e %{name}-in ); fi; \
760 }
761
762 %nsplugin_uninstall(d:) { \
763 # remove link if either of the packages are gone \
764 if [ "$1" = "0" ] || [ "$2" = "0" ]; then \
765 ( \
766 %( \
767         for file in %{*}; do \
768                 echo echo Removing $file from %{-d*}; \
769                 echo "rm -f %{-d*}/$file;"; \
770         done ) \
771 ) | ( %banner -t 5 -e %{name}-un ); fi; \
772 }
773
774 # service macro.
775 #
776 # calls usual service restart on package %post, but skips the restart if
777 # administrator has disabled automatic service restarts in either global
778 # /etc/sysconfig/rpm or per service /etc/sysconfig/SERVICE file.
779 #
780 # written by glen@pld-linux.org.
781 # All rights reserved. Permission to copy is hereby granted.. yada, yada, yada
782 #
783 # Usage:
784 #   %service [-q] SERVICE ACTION ["SERVICE NICE DESCRIPTION"]
785 #
786 #  -q be silent when service isn't started (for postun scriplets)
787 #
788 %service(q) {{ \
789 # we use function, not to globber namespace with useless variables \
790 skip_auto_restart() { \
791         . /etc/sysconfig/rpm; # global setting \
792         [ -f /etc/sysconfig/%1 ] && . /etc/sysconfig/%1; # per service setting \
793         echo ${RPM_SKIP_AUTO_RESTART:-no}; \
794 }; \
795 if [ -f /var/lock/subsys/%1 ]; then \
796         if [ $(skip_auto_restart) = no ]; then \
797                 /etc/rc.d/init.d/%1 %2 1>&2; \
798         else \
799                 echo 'Run "/etc/rc.d/init.d/%1 %2" to %2 %{!?3:%1 service}%{?3:%(set -- %{*}; echo "$3")}.'; \
800         fi \
801 %{!-q:else} \
802         %{!-q:echo 'Run "/etc/rc.d/init.d/%1 start" to start %{!?3:%1 service}%{?3:%(set -- %{*}; echo "$3")}.';} \
803 fi }; }
804
This page took 0.1154 seconds and 4 git commands to generate.