]> git.pld-linux.org Git - packages/rpm.git/blob - rpm.macros
f84d8f06c87259611cf8d5025e24d3f109c8ef3d
[packages/rpm.git] / rpm.macros
1 # PLD rpm macros
2
3 %__id           @__ID@
4 %__id_u         %{__id} -u 
5 %__chown_Rhf           @__CHOWN_RHF@
6 %__chgrp_Rhf           @__CHGRP_RHF@
7
8 %_fixowner       [ `%{__id_u}` = '0' ] && %{__chown_Rhf} root.@ROOT_GROUP@
9 %_fixgroup       true
10 %_fixperms             %{__chmod} -Rf @FIXPERMS@
11 %_topdir         %(echo $HOME)/rpm
12 #-----------------------------------------------------------------
13 # CFLAGS and LDFLAGS used to build
14
15 %debugcflags    -O0 -g -Wall
16 %rpmcflags      %{?debug:%debugcflags}%{!?debug:%optflags}
17 %rpmldflags     %{!?debug:-s}
18
19 # kernel compiler
20 %kgcc           gcc
21 %kgcc_package   gcc
22
23 # Build system path macros.
24 #
25 %__libtoolize           libtoolize --copy --force
26 %__gettextize { \
27     if ! gettextize --version | grep -q '0\.10\.' ; then \
28         if grep -qs 'AM_GNU_GETTEXT.*external' configure.{ac,in} ; then \
29             gettextize --copy --force --no-changelog; \
30         else \
31             gettextize --copy --force --no-changelog --intl; \
32         fi; \
33         if [ ! -f po/Makevars ]; then \
34             cp -f po/Makevars{.template,}; \
35         fi; \
36     else \
37         gettextize --copy --force; \
38     fi; \
39 }
40 %__autopoint            autopoint --force
41 %__automake             automake -a -c -f --foreign
42 %__autoconf             autoconf %{?debug:-Wall}
43
44 #-----------------------------------------------------------------
45 %configure2_13 { \
46  if [ -n "$LINGUAS" ]; then unset LINGUAS; fi; \
47  LDFLAGS="${LDFLAGS:-%rpmldflags}" ; export LDFLAGS ; \
48  CFLAGS="${CFLAGS:-%rpmcflags}" ; export CFLAGS ; \
49  CXXFLAGS="${CXXFLAGS:-%rpmcflags}" ; export CXXFLAGS ; \
50  FFLAGS="${FFLAGS:-%rpmcflags}" ; export FFLAGS ; \
51  CPPFLAGS="${CPPFLAGS:-}" ; export CPPFLAGS ; \
52  %{?__cc:CC=%{__cc} ; export CC ; } \
53  %{?__cxx:CXX=%{__cxx} ; export CXX ; } \
54  %{?configuredir:%{configuredir}}%{!?configuredir:.}/configure \
55         --host=%{_target_platform} \
56         --prefix=%{_prefix} \
57         --exec-prefix=%{_exec_prefix} \
58         --bindir=%{_bindir} \
59         --sbindir=%{_sbindir} \
60         --sysconfdir=%{_sysconfdir} \
61         --datadir=%{_datadir} \
62         --includedir=%{_includedir} \
63         --libdir=%{_libdir} \
64         --libexecdir=%{_libexecdir} \
65         --localstatedir=%{_localstatedir} \
66         --sharedstatedir=%{_sharedstatedir} \
67         --mandir=%{_mandir} \
68         --infodir=%{_infodir} \
69 }
70
71 #----------------------------------------------------------------
72 %configure {./configure \
73         LDFLAGS="${LDFLAGS:-%rpmldflags}" \
74         CFLAGS="${CFLAGS:-%rpmcflags}" \
75         CXXFLAGS="${CXXFLAGS:-%rpmcflags}" \
76         FFLAGS="${FFLAGS:-%rpmcflags}" \
77         CPPFLAGS="${CPPFLAGS:-}" \
78         %{?__cc:CC=%{__cc}} \
79         %{?__cxx:CXX=%{__cxx}} \
80         --build=%{_target_platform} \
81         --prefix=%{_prefix} \
82         --exec-prefix=%{_exec_prefix} \
83         --bindir=%{_bindir} \
84         --sbindir=%{_sbindir} \
85         --sysconfdir=%{_sysconfdir} \
86         --datadir=%{_datadir} \
87         --includedir=%{_includedir} \
88         --libdir=%{_libdir} \
89         --libexecdir=%{_libexecdir} \
90         --localstatedir=%{_localstatedir} \
91         --sharedstatedir=%{_sharedstatedir} \
92         --mandir=%{_mandir} \
93         --infodir=%{_infodir} \
94 }
95
96 # ------------------------------------------------------------------------
97 # Conditional build stuff.
98
99 # Check if symbol is defined.
100 # Example usage: %if %{defined with_foo} && %{undefined with_bar} ...
101 %defined()      %{expand:%%{?%{1}:1}%%{!?%{1}:0}}
102 %undefined()    %{expand:%%{?%{1}:0}%%{!?%{1}:1}}
103
104 # Shorthand for %{defined with_...}
105 %with()         %{expand:%%{?with_%{1}:1}%%{!?with_%{1}:0}}
106 %without()      %{expand:%%{?with_%{1}:0}%%{!?with_%{1}:1}}
107
108 # Handle conditional builds. %bcond_with is for case when feature is
109 # default off and needs to be activated with --with ... command line 
110 # switch. %bcond_without is for the dual case.
111 #
112 # %bcond_with foo defines symbol with_foo if --with foo was specified on
113 # command line.
114 # %bcond_without foo defines symbol with_foo if --without foo was *not* 
115 # specified on command line.
116 #
117 # For example:
118 #
119 # %bcond_with extra_fonts
120 # %bcond_without static
121 # %if %{with extra_fonts}
122 # ...
123 # %endif
124 # %ifdef %{with static}
125 # ...
126 # %endif
127 # %{?with_static: ... }
128 # %{!?with_static: ... }
129 # %{?with_extra_fonts: ... }
130 # %{!?with_extra_fonts: ... }
131
132 # The bottom line: never use without_foo, _with_foo nor _without_foo, only
133 # with_foo. This way changing default set of bconds for given spec is just
134 # a matter of changing single line in it and syntax is more readable.
135 %bcond_with()           %{expand:%%{?_with_%{1}:%%global with_%{1} 1}}
136 %bcond_without()        %{expand:%%{!?_without_%{1}:%%global with_%{1} 1}}
137 # ------------------------------------------------------------------------
138
139 # Location of autoconf macros
140 %_aclocaldir    %(aclocal --print-ac-dir)
141
142 # Location of omf files
143 %_omf_dest_dir  %(scrollkeeper-config --omfdir)
144
145 # Location of pkgconfig files
146 %_pkgconfigdir  /usr/lib/pkgconfig
147
148 # Location of top applink dir
149 %_applnkdir     /usr/X11R6/share/applnk
150
151 # Location of desktop files
152 %_desktopdir    /usr/share/applications
153
154 # Location pixmaps for applnk/desktop files
155 %_pixmapsdir    /usr/share/pixmaps
156
157 # Location of fonts directories
158 %_fontsdir      /usr/share/fonts
159
160 # Location of Gtk and associated libraries documentation
161 %_gtkdocdir  %{_defaultdocdir}/gtk-doc/html
162
163 # Current date
164 %date           %(LC_ALL="C" date +"%a %b %d %Y")
165
166 # tmp directory
167 %tmpdir         %(echo "${TMPDIR:-/tmp}")
168
169 # Example files, programs, scripts...
170 %_examplesdir   /usr/src/examples
171
172 # The directory holding Linux kernel sources
173 %_kernelsrcdir  /usr/src/linux
174
175 # If non-empty "debug" macro defined, add "dbg" suffix to release number
176 %_rpmfilename           %%{NAME}-%%{VERSION}-%%{RELEASE}%{?debug:dbg}.%%{ARCH}.rpm
177
178 # Requires name = version-release
179 %requires_releq()               %(LC_ALL="C" echo '%*' | xargs -r rpm -q --qf 'Requires: %%{name} = %%{epoch}:%%{version}-%%{release}\\n' | sed -e 's/ (none):/ /' -e 's/ 0:/ /' | grep -v "is not")
180 %requires_releq_kernel_up()     %(LC_ALL="C" rpm -qf --qf 'Prereq: kernel-up = %%{epoch}:%%{version}-%%{release}\\n' %{_kernelsrcdir}/include/linux/version.h | sed -e 's/ (none):/ /' -e 's/ 0:/ /' | grep -vE "(is not|no such)")
181 %requires_releq_kernel_smp()    %(LC_ALL="C" rpm -qf --qf 'Prereq: kernel-smp = %%{epoch}:%%{version}-%%{release}\\n' %{_kernelsrcdir}/include/linux/version.h | sed -e 's/ (none):/ /' -e 's/ 0:/ /' | grep -vE "(is not|no such)")
182
183 # kernel version-release handling
184 %__kernel_ver    %(grep UTS_RELEASE %{_kernelsrcdir}/include/linux/version.h 2>/dev/null | cut -d'"' -f2)
185 %__kernel_rel    %(LC_ALL="C" rpm -qf %{_kernelsrcdir}/include/linux/version.h --queryformat "%{RELEASE}" | grep -v "is not")
186 %_kernel_ver     %(echo %{__kernel_ver}%{!?_without_dist_kernel:-%{__kernel_rel}})
187 %_kernel_ver_str %(echo %{_kernel_ver} | sed s/-/_/g)
188
189 # sgml macros
190 %xmlcat_add()            /usr/bin/xmlcatalog --noout --add nextCatalog \"\" %1 /etc/xml/catalog
191 %xmlcat_del()            /usr/bin/xmlcatalog --noout --del %1 /etc/xml/catalog
192 %xmlcat_add_rewrite      /usr/bin/xmlcatalog --noout --add rewriteSystem
193 %xmlcat_create()          /usr/bin/xmlcatalog --noout --create %1
194 %sgmlcat_add()           /usr/bin/install-catalog --add %1 %2 > /dev/null
195 %sgmlcat_del()           /usr/bin/install-catalog --remove %1 %2 > /dev/null
196 %docbook_sgmlcat_fix() { for l in \
197 '' \
198 '  -- default decl --' \
199 'DTDDECL "-//OASIS//DTD DocBook XML V%2//EN" "../../xml.dcl"' \
200 '  -- hacks for opensp --' \
201 'SYSTEM "file://%{_datadir}/sgml/docbook/xml-dtd-%2/docbookx.dtd" "%{_datadir}/sgml/docbook/xml-dtd-%2/docbookx.dtd"' \
202 'SYSTEM "http://www.oasis-open.org/docbook/xml/%2/docbookx.dtd"                  "%{_datadir}/sgml/docbook/xml-dtd-%2/docbookx.dtd"' \
203 '' \
204 ; do echo $l; done >> %1 \
205 }
206
207 #-----------------------------------------------------------------
208 # find and gzip all files in %{_mandir} and %{infodir}
209 #
210 # Requires: xargs, find
211 #
212 #%no_install_post_compress_docs 1
213 %__spec_install_post_compress_docs { \
214 echo "Compress man and info pages."; \
215 %{!?no_install_post_compress_docs: \
216         %{?verbose:set -x;} \
217         for i in /usr/share/man /usr/X11R6/man /usr/share/info; do \
218                 if [ -d "$RPM_BUILD_ROOT$i" ]; then \
219                         find "$RPM_BUILD_ROOT$i" -name \*.bz2 -print | xargs -r %{__bzip2} -df; \
220                         find "$RPM_BUILD_ROOT$i" -name \*.gz -print | xargs -r %{__gzip} -dnf; \
221                         find "$RPM_BUILD_ROOT$i" -type f -print | xargs -r %{__gzip} -9nf; \
222                 fi; \
223         done; \
224 } }
225
226 #-----------------------------------------------------------------
227 # Strip executable binaries and shared object files
228 #
229 # Requires: find, awk, strip, cut, xargs
230 #
231 #%no_install_post_strip 1
232 %__spec_install_post_strip {%{!?debug: \
233 %{!?no_install_post_strip: \
234         %{?verbose:set -x;} \
235         echo "Strip executable binaries, archives and shared object files."; \
236         filelist=`find $RPM_BUILD_ROOT -type f ! -regex ".*ld-[0-9.]*so.*"`; \
237         elfexelist=`echo $filelist | xargs -r file | \
238                 awk '/ELF.*executable/ {print $1}' | cut -d: -f1`; \
239         elfsharedlist=`echo $filelist | xargs -r file | \
240                 awk '/LF.*shared object/ {print $1}' | cut -d: -f1`; \
241         elfarchiveslist=`echo $filelist | xargs -r file | \
242                 awk '/current ar archive/ {print $1}' | cut -d: -f1`; \
243         if [ -n "$elfexelist" ]; then \
244                 strip --remove-section=.note  --remove-section=.comment $elfexelist; \
245         fi; \
246         if [ -n "$elfsharedlist" ]; then \
247                 strip --strip-unneeded --remove-section=.note  --remove-section=.comment $elfsharedlist; \
248         fi; \
249         if [ -n "$elfarchiveslist" ]; then \
250                 strip --strip-debug --remove-section=.note  --remove-section=.comment $elfarchiveslist; \
251         fi; } \
252 } }
253 #-----------------------------------------------------------------
254 # remove all RPATH from executable binaries and shared object files
255 #
256 # Requires: find, awk, cut, xargs, chrpath, uname
257 #
258 #%no_install_post_chrpath       1
259 %__spec_install_post_chrpath {%{!?debug: \
260 %{!?no_install_post_chrpath: \
261         %{?verbose:set -x;} \
262 echo "Remove RPATH from executable binaries and shared object files."; \
263 if [ "$(uname -m)" != alpha ] ; then \
264 find $RPM_BUILD_ROOT -type f ! -regex ".*ld-[0-9.]*so.*" | xargs -r file | \
265         awk '/ELF.*(executable|shared object)/ {print $1}' | cut -d: -f1 | \
266 while read file ; do \
267         rpath= ; \
268         chmod u+w "$file"; \
269         for dir in `chrpath -l "$file" | \
270                     awk '/RPATH=/ { gsub(/.*RPATH=/,""); gsub(/:/," "); print $0 }'` ; do \
271                         case $dir in \
272                         /home/* | /tmp/* | /usr/lib | /lib | /usr/local/lib | /usr/X11R6/lib ) \
273                                 echo "remove-rpath: $dir in $file"; \
274                                 ;; \
275                         * ) \
276                                 if [ "$rpath" = "" ] ; then rpath="$dir" ; \
277                                 else rpath="$rpath:$dir" ; fi ; \
278                                 ;; \
279                         esac ; \
280         done ; \
281         if [ "$rpath" = "" ] ; then chrpath -d "$file" > /dev/null ; \
282         else chrpath -r "$rpath" "$file" > /dev/null ; fi ; \
283 done; fi; } \
284 } }
285 #-----------------------------------------------------------------
286 # Find and gzip all kernel modules
287 #
288 # Requires: find
289 #
290 #%no_install_post_compress_modules  1
291 %__spec_install_post_compress_modules { \
292 %{!?no_install_post_compress_modules: \
293 echo "Compress kernel modules if any."; \
294     %{?verbose:set -x;} \
295     if test -d $RPM_BUILD_ROOT/lib/modules ; then \
296        find $RPM_BUILD_ROOT/lib/modules -name \*.o -type f -print | \
297        xargs -r %{__gzip} -9nf; \
298            find $RPM_BUILD_ROOT/lib/modules -name \*.o -type l -printf "%p %l\n" | \
299            while read a b; do ln -sf $b.gz $a.gz; rm -f $a; done; \
300     fi; \
301 } }
302
303 %_source_payload        w9.gzdio
304 %_binary_payload        w9.bzdio
305
306 #-----------------------------------------------------------------
307 # Update all GConf2 schemas
308 #
309 # Requires: GConf2
310 #
311 %gconf_schema_install { umask 022; \
312     GCONF_CONFIG_SOURCE="xml:readwrite:/etc/gconf/gconf.xml.defaults" \
313     /usr/bin/gconftool-2 --makefile-install-rule \
314     /etc/gconf/schemas/*.schemas > /dev/null \
315 }
316
317 #-----------------------------------------------------------------
318 # post %install sequence:
319 # - autodeps exceptions
320 # - compress all man and info pages,
321 # - strip all ELF executables and ELF shared objects if not %debug.
322 # - compress kernel modules if any
323
324 ###################################################################
325 # Requires/Provides automation
326 # exceptions system by Jacek Konieczny <jajcus@pld.org.pl>
327 %__spec_prep_pre \
328 _autoreqprov=n \
329 %{?_noautoreqfiles:_autoreqprov=y}\
330 %{?_noautoreq:_autoreqprov=y}\
331 %{?_noautoreqdep:_autoreqprov=y}\
332 %{?_noautoprovfiles:_autoreqprov=y}\
333 %{?_noautoprov:_autoreqprov=y}\
334 %{?_noautocompressdoc:_autoreqprov=y}\
335 if [ "$_autoreqprov" = "y" ] ; then \
336     if [ -f %{_builddir}/__rpm_lock ] ; then \
337         echo "Some package using \%_noauto*  macros is already being built" >&2 \
338         echo "If it is not true delete %{_builddir}/__rpm_lock" >&2 \
339         exit 1 \
340     else \
341         rm -f %{_builddir}/__rpm_*\
342         touch %{_builddir}/__rpm_lock \
343     fi \
344 fi \
345 %{?_noautocompressdoc:echo '%{_noautocompressdoc}' > %{_builddir}/__rpm_noautocompressdoc}\
346 %{nil}
347
348
349 %__spec_clean_pre       %{___build_pre}\
350 _autoreqprov=n \
351 %{?_noautoreqfiles:_autoreqprov=y}\
352 %{?_noautoreq:_autoreqprov=y}\
353 %{?_noautoreqdep:_autoreqprov=y}\
354 %{?_noautoprovfiles:_autoreqprov=y}\
355 %{?_noautoprov:_autoreqprov=y}\
356 %{?_noautoreqfiles:_autoreqprov=y}\
357 %{?_noautocompressdoc:_autoreqprov=y}\
358 if [ "$_autoreqprov" = "y" ] ; then \
359         rm -f %{_builddir}/__rpm_* \
360 fi \
361 %{nil}
362
363
364 #%_noautoreqfiles       "%{_defaultdocdir}.*" "%{_examplesdir}.*"
365 #%_noautoreq            %{nil}
366 #%_noautoreqdep         %{nil}
367 #%_noautoprovfiles      %{nil}
368 #%_noautoprov           %{nil}
369 %_missing_doc_files_terminate_build     1%{nil}
370 %_unpackaged_files_terminate_build      %{nil}
371 # (X)emacs support
372 %___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;}'
373 %_emacs_lispdir %(emacs %___emacs_lispdir_helper)
374 %_xemacs_lispdir %(xemacs %___emacs_lispdir_helper)
375
376 %__php_provides @RPMCONFIGDIR@/php.prov
377 %__php_requires @RPMCONFIGDIR@/php.req
378
379 # Perl specific macro definitions.
380 %perl_privlib   %(eval "`%{__perl} -V:installprivlib`"; echo $installprivlib)
381 %perl_archlib   %(eval "`%{__perl} -V:installarchlib`"; echo $installarchlib)
382 %perl_vendorlib %(eval "`%{__perl} -V:installvendorlib`"; echo $installvendorlib)
383 %perl_vendorarch        %(eval "`%{__perl} -V:installvendorarch`"; echo $installvendorarch)
384 %perl_sitelib   %(eval "`%{__perl} -V:installsitelib`"; echo $installsitelib)
385 %perl_sitearch  %(eval "`%{__perl} -V:installsitearch`"; echo $installsitearch)
386
387 %php_pear_dir   %{_datadir}/pear
388
389 # Python specific macro definitions.
390 # python main version
391 %py_ver         %(echo `python -c "import sys; print sys.version[:3]"`)
392
393 # directories
394 %py_prefix      %(echo `python -c "import sys; print sys.prefix"`)
395 %py_libdir      %{py_prefix}/lib/python%{py_ver}
396 %py_incdir      /usr/include/python%{py_ver}
397 %py_sitedir     %{py_libdir}/site-packages
398 %py_dyndir      %{py_libdir}/lib-dynload
399
400 # pure python modules compilation
401 %py_comp        python -c "import compileall; import sys; compileall.compile_dir(sys.argv[1], ddir=sys.argv[1][len('$RPM_BUILD_ROOT'):])"
402
403 %py_ocomp       python -O -c "import compileall; import sys; compileall.compile_dir(sys.argv[1], ddir=sys.argv[1][len('$RPM_BUILD_ROOT'):])"
404
405 # Software written in Python language require Python with main version
406 # unchanged
407 %pyrequires_eq() Requires:       %1 >= %py_ver %1 < %(echo `python -c "import sys; import string; ver=sys.version[:3].split('.'); ver[1]=str(int(ver[1])+1); print string.join(ver, '.')"`)
408
409 # depmod macro
410 %depmod() { \
411 if [ -e /boot/System.map-%1 ]; then \
412         /sbin/depmod -a -F /boot/System.map-%1 %1; \
413 else \
414         if [ -e /boot/System.map ]; then \
415                 /sbin/depmod -a -F /boot/System.map %1; \
416         else \
417                 /sbin/depmod -a %1; \
418         fi \
419 fi; \
420 }
421
This page took 0.107844 seconds and 3 git commands to generate.