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