]> git.pld-linux.org Git - packages/rpm-build-macros.git/blobdiff - rpm.macros
- v1.654: extend _noautoreq with language specific macros
[packages/rpm-build-macros.git] / rpm.macros
index 000e83fe697aaf348cbfee749b79d60150d18e17..5a9c6d2c1e507fb8460c212b79a8f2083c3f8d78 100644 (file)
@@ -1,20 +1,22 @@
-# $Revision$, $Date$
+# vim:ts=4 sw=4 noet ft=spec
+#
 # PLD Linux rpm macros.
 # <http://www.pld-linux.org/>
 
 # can be used by builder script to check for version
-%rpm_build_macros      %(R="$Revision$"; RR="${R##: }"; echo ${RR%%?})
+%rpm_build_macros      $Revision$
 
 %epoch         0
 %x8664         x86_64 amd64 ia32e
+%arm           armv3l armv4b armv4l armv5teb armv5tel
 
 # kernel compiler
 %kgcc          %{__cc}
 %kgcc_package  gcc
 
 # compiler version
-%cc_version    %{expand:%%global cc_version %(%{__cc} -dumpversion || echo ERROR)}%cc_version
-%cxx_version   %{expand:%%global cxx_version %(%{__cxx} -dumpversion || echo ERROR)}%cxx_version
+%cc_version    %{expand:%%global cc_version %(%{__cc} -dumpversion 2>/dev/null || echo 0.0)}%cc_version
+%cxx_version   %{expand:%%global cxx_version %(%{__cxx} -dumpversion 2>/dev/null || echo 0.0)}%cxx_version
 
 %__rm          /bin/rm --interactive=never
 
@@ -34,7 +36,7 @@
 %__cmake       /usr/bin/cmake
 
 %_smp_mflags %(_NCPUS=$(/usr/bin/getconf _NPROCESSORS_ONLN); \\\
-                               [ "$_NCPUS" -gt 1 ] && echo "-j$(($_NCPUS * 2))")
+                               [ "$_NCPUS" -gt 2 ] && echo "-j$(($_NCPUS / 2))")
 
 %__gettextize { \
        if grep -qs 'AM_GNU_GETTEXT.*external' configure.{ac,in} ; then \
        %{dependencytracking} \
 }
 
-%cmake { \
-CC="%{__cc}" \
-CXX="%{__cxx}" \
-CFLAGS="%{rpmcflags}" \
-CXXFLAGS="%{rpmcxxflags}" \
-LDFLAGS="%{rpmldflags}" \
-%{__cmake} \
-}
+%cmake \
+%{?__cc:CC="%{__cc}"} \\\
+%{?__cxx:CXX="%{__cxx}"} \\\
+CPPFLAGS="${CPPFLAGS:-%{rpmcppflags}}" \\\
+%{__cmake} \\\
+       -DCMAKE_VERBOSE_MAKEFILE=ON \\\
+       -DCMAKE_BUILD_TYPE=%{!?debug:PLD}%{?debug:Debug} \\\
+       -DCMAKE_INSTALL_LIBDIR:PATH=%{_libdir} \\\
+       -DCMAKE_INSTALL_PREFIX:PATH=%{_prefix} \\\
+       -DINCLUDE_INSTALL_DIR:PATH=%{_includedir} \\\
+       -DLIB_INSTALL_DIR:PATH=%{_libdir} \\\
+       -DSHARE_INSTALL_PREFIX:PATH=%{_datadir} \\\
+       -DSYSCONF_INSTALL_DIR:PATH=%{_sysconfdir} \\\
+       -DCMAKE_CXX_FLAGS_PLD="${CXXFLAGS:-%{rpmcxxflags} -DNDEBUG}" \\\
+       -DCMAKE_C_FLAGS_PLD="${CFLAGS:-%{rpmcflags} -DNDEBUG}" \\\
+       -DCMAKE_Fortran_FLAGS_PLD="${CFLAGS:-%{rpmcflags} -DNDEBUG}" \\\
+       -DCMAKE_EXE_LINKER_FLAGS_PLD="${LDFLAGS:-%{rpmldflags}}" \\\
+       -DCMAKE_SHARED_LINKER_FLAGS_PLD="${LDFLAGS:-%{rpmldflags}}" \\\
+       -DCMAKE_MODULE_LINKER_FLAGS_PLD="${LDFLAGS:-%{rpmldflags}}" \\\
+%if "%{_lib}" == "lib64" \
+       -DLIB_SUFFIX=64 \\\
+%endif \
+       -DBUILD_SHARED_LIBS:BOOL=ON \\\
+%{nil}
 
 %scons { \
 %{__scons} \
@@ -410,9 +428,9 @@ CXXFLAGS="%{rpmcxxflags}" \
 %bootstrap_release() %{!?with_bootstrap:%{1}%{?2:.%{2}}}%{?with_bootstrap:%{!?2:%(expr %{1} - 1)}%{?2:%{1}.%(expr %{2} - 1)}.zzz.bootstrap}
 
 # -n drm to generate kernel%{_alt_kernel}-drm dependency
-%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
-%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
-%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
+%releq_kernel(n:)              %{expand:%%global releq_kernel %(R=$(cd %{_kernelsrcdir} 2>/dev/null && LC_ALL=C rpm -q --qf '%{N}%{?-n:-%{-n*}} = %|E?{%{E}:}|%{V}-%{R}' -f include/linux/version.h 2>/dev/null | grep -v 'is not' | sed -e 's:-headers::;s:-config::'); echo ${R:-ERROR})}%releq_kernel
+%releq_kernel_up(n:)   %{expand:%%global releq_kernel_up %(R=$(cd %{_kernelsrcdir} 2>/dev/null && LC_ALL=C rpm -q --qf '%{N}%{?-n:-%{-n*}}-up = %|E?{%{E}:}|%{V}-%{R}' -f include/linux/version.h 2>/dev/null | grep -v 'is not' | sed -e 's:-headers::;s:-config::'); echo ${R:-ERROR})}%releq_kernel_up
+%releq_kernel_smp(n:)  %{expand:%%global releq_kernel_smp %(R=$(cd %{_kernelsrcdir} 2>/dev/null && LC_ALL=C rpm -q --qf '%{N}%{?-n:-%{-n*}}-smp = %|E?{%{E}:}|%{V}-%{R}' -f include/linux/version.h 2>/dev/null | grep -v 'is not' | sed -e 's:-headers::;s:-config::'); echo ${R:-ERROR})}%releq_kernel_smp
 
 # -s post to generate Requires(post) dependency
 %requires_releq_kernel(s:n:)           Requires%{-s:(%{-s*})}: %releq_kernel
@@ -431,6 +449,12 @@ CXXFLAGS="%{rpmcxxflags}" \
 # Requires: name >= version (version based on querying package %2)
 %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)}}
 
+# \helper for renaming packages
+# %rename old-package
+%rename() \
+Obsoletes: %{1} < %{?epoch:%{epoch}:}%{?version:%{version}}%{?release:-%{release}} \
+Provides: %{1} = %{?epoch:%{epoch}:}%{?version:%{version}}%{?release:-%{release}} 
+
 %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
 
 # kernel version-release handling
@@ -440,8 +464,8 @@ CXXFLAGS="%{rpmcxxflags}" \
        echo ${Z:-ERROR}; \\
 )}%__kernel_ver
 
-%__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
-%__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
+%__kernel_rel  %{expand:%%global __kernel_rel %(Z=$(cd %{_kernelsrcdir} 2>/dev/null && LC_ALL=C rpm -qf include/linux/fs.h 2>/dev/null --qf "%{R}" | grep -v "is not"); echo ${Z:-ERROR})}%__kernel_rel
+%__kernel_rpmvr        %{expand:%%global __kernel_rpmvr %(Z=$(cd %{_kernelsrcdir} 2>/dev/null && LC_ALL=C rpm -qf include/linux/fs.h 2>/dev/null --qf "%{V}-%{R}" | grep -v "is not"); echo ${Z:-ERROR})}%__kernel_rpmvr
 %_kernel_ver   %{expand:%%global _kernel_ver %{__kernel_ver}%{?with_dist_kernel:%(echo %{__kernel_ver} | grep -q -e - || echo -%{__kernel_rel})}}%_kernel_ver
 %_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
 
@@ -484,16 +508,31 @@ CXXFLAGS="%{rpmcxxflags}" \
 #%no_install_post_compress_docs        1
 %__spec_install_post_compress_docs { \
 %{!?no_install_post_compress_docs:__spec_install_post_compress_docs() { \
+       %{!?debug:set +x;} \
        for i in /usr/share/man /usr/X11R6/man; do \
                if [ -d "$RPM_BUILD_ROOT$i" ]; then \
                        echo "Compress man pages: $i"; \
                        find "$RPM_BUILD_ROOT$i" -name '*.bz2' -print | xargs -r %{__bzip2} -df; \
                        find "$RPM_BUILD_ROOT$i" -name '*.gz' -print | xargs -r %{__gzip} -dnf; \
                        find $RPM_BUILD_ROOT$i -type l | while read a; do \
-                               m=$(readlink $a); \
+                               m=$(readlink "$a"); \
+                               if [[ "$m" = */* ]]; then \
+                                       # handle links to different man section \
+                                       l=$(readlink -f "$a"); \
+                                       # full/relative paths that resolve symlink \
+                                       l=${l#$RPM_BUILD_ROOT/usr/share/man/}; \
+                                       l=${l#$RPM_BUILD_ROOT/usr/X11R6/man/}; \
+                                       # full paths that do not resolve symlink \
+                                       l=${l#/usr/share/man/}; \
+                                       l=${l#/usr/X11R6/man/}; \
+                               else \
+                                       l=${a#$RPM_BUILD_ROOT$i/}; \
+                                       l=${l%/*}; \
+                                       l="$l/$m"; \
+                               fi; \
                                rm -f $a; \
-                               echo .so ${m##*/} > $a; \
-                               echo >&2 "Converted ${a#$RPM_BUILD_ROOT} from symlink to man link: ${m##*/}"; \
+                               echo ".so $l" > $a; \
+                               echo >&2 "Converted ${a#$RPM_BUILD_ROOT} from symlink to man link: $l"; \
                        done; \
                        find "$RPM_BUILD_ROOT$i" -type f -size +%{_min_compress_bytes}c -print | xargs -r %{__gzip} -9nf; \
                fi; \
@@ -520,6 +559,7 @@ CXXFLAGS="%{rpmcxxflags}" \
 #
 %__spec_install_post_strip {%{!?debug: \
 %{!?no_install_post_strip:__spec_install_post_strip() { \
+%{!?debug:set +x;} \
 if [ -d "$RPM_BUILD_ROOT" ]; then \
        if [ -d $RPM_BUILD_ROOT/lib/modules ]; then \
                modulelist=$(find $RPM_BUILD_ROOT/lib/modules -name '*o' -type f -print); \
@@ -527,7 +567,7 @@ if [ -d "$RPM_BUILD_ROOT" ]; then \
                        modulecount=$(echo "$modulelist" | wc -l); \
                        printf "Stripping %d kernel modules..." $modulecount; \
                        echo "$modulelist" | xargs -l512 chmod u+w; \
-                       echo "$modulelist" | xargs -l512 %{__strip} --strip-unneeded --remove-section=.comment --remove-section=.note.GNU-stack; \
+                       echo "$modulelist" | xargs -l512 %{__strip} -g --remove-section=.comment --remove-section=.note.GNU-stack; \
                        echo "DONE"; \
                fi; \
        fi; \
@@ -539,20 +579,20 @@ if [ -d "$RPM_BUILD_ROOT" ]; then \
                archiveslist=`echo "$filetypes" | awk -F: '/current ar archive/ {print $1}'`; \
                if [ -n "$elfexelist" ]; then \
                        printf "Stripping %d ELF executables..." $(echo "$elfexelist" | wc -l); \
-                       chmod u+w $elfexelist; \
-                       %{__strip} --remove-section=.note --remove-section=.comment $elfexelist; \
+                       echo "$elfexelist" | xargs -r -d'\n' chmod u+w; \
+                       echo "$elfexelist" | xargs -r -d'\n' %{__strip} --remove-section=.note --remove-section=.comment; \
                        echo "DONE"; \
                fi; \
                if [ -n "$elfsharedlist" ]; then \
                        printf "Stripping %d ELF shared libraries..." $(echo "$elfsharedlist" | wc -l); \
-                       chmod u+w $elfsharedlist; \
-                       %{__strip} --strip-unneeded --remove-section=.note --remove-section=.comment $elfsharedlist; \
+                       echo "$elfsharedlist" | xargs -r -d'\n' chmod u+w; \
+                       echo "$elfsharedlist" | xargs -r -d'\n' %{__strip} --strip-unneeded --remove-section=.note --remove-section=.comment; \
                        echo "DONE"; \
                fi; \
                if [ -n "$archiveslist" ]; then \
                        printf "Stripping %d ar archives..." $(echo "$archiveslist" | wc -l); \
-                       chmod u+w $archiveslist; \
-                       %{__strip} --strip-debug --remove-section=.note --remove-section=.comment $archiveslist; \
+                       echo "$archiveslist" | xargs -r -d'\n' chmod u+w; \
+                       echo "$archiveslist" | xargs -r -d'\n' %{__strip} --strip-debug --remove-section=.note --remove-section=.comment; \
                        echo "DONE"; \
                fi; \
        fi; \
@@ -590,6 +630,7 @@ fi; }; __spec_install_post_strip } } }
 #
 %__spec_install_post_chrpath {%{!?debug: \
 %{!?no_install_post_chrpath: __spec_install_post_chrpath() { \
+%{!?debug:set +x;} \
 if [ -d "$RPM_BUILD_ROOT" ]; then \
        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}"}`; \
        if [ -n "$files" ]; then \
@@ -633,17 +674,49 @@ fi; }; __spec_install_post_chrpath } } }
 # Find all shared object files with unresolved symbols. Warn
 # and terminate if any found (termination can be turned off by define).
 #%no_install_post_check_so 1
+#%skip_post_check_so libwithunresolvedok.so.*
+#
+# NOTE: define skip_post_check_so only if such library really requires
+#       unresolved symbols and always leave a comment why it is required:
+#      # executable provides symbols foo, bar for those libraries:
+#      %define skip_post_check_so libwithoutfoo.so.* libwithoutbar.so.*
+#
 %__spec_install_post_check_so { \
- __spec_install_post_check_so() { \
-    fail=0; \
-    printf "Searching for shared objects with unresolved symbols..."; \
-    for f in $(find $RPM_BUILD_ROOT -type f -name '*.so.*' -print); do \
-        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 ; \
-    done ; \
-    echo " DONE"; \
-    %{!?no_install_post_check_so:[ $fail -eq 1 ] && : || :;} \
+__spec_install_post_check_so() { \
+%{!?debug:set +x;} \
+       fail=0; \
+       printf "Searching for shared objects with unresolved symbols..."; \
+       for f in $(find $RPM_BUILD_ROOT -type f -name '*.so.*' -print); do \
+               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; %{?skip_post_check_so:split("%{skip_post_check_so}", R); for (i=1; i in R; i++) { if (file ~ "(^|/)" R[i] "$") { print "Library marked with skip_post_check_so, ignoring errors.\n"; exit(0); } } } exit(1); } } ' || fail=1 ; \
+       done ; \
+       echo " DONE"; \
+       %{!?no_install_post_check_so:return $fail;} \
 }; __spec_install_post_check_so }}
 
+#-----------------------------------------------------------------
+# Verify that for each directory under /var/run package contains
+# tmpfiles.d configuration. Warn and terminate build if config is
+# missing.
+#
+#%no_install_post_check_tmpfiles 1
+#
+%__spec_install_post_check_tmpfiles { \
+__spec_install_post_check_tmpfiles() { \
+%{!?debug:set +x;} \
+       fail=0; \
+       echo "Checking /var/run <-> tmpfiles.d completeness..."; \
+       for d in $RPM_BUILD_ROOT/var/run/*; do \
+               [ -d "$d" ] || continue; \
+               d=${d##$RPM_BUILD_ROOT}; \
+               if ! grep -qsF "$d" $RPM_BUILD_ROOT/usr/lib/tmpfiles.d/*.conf $RPM_BUILD_ROOT/etc/tmpfiles.d/*.conf; then\
+                   echo "No tmpfiles configuration for '$d'";\
+                       fail=1 ; \
+               fi \
+       done ; \
+       echo " DONE"; \
+       %{!?no_install_post_check_tmpfiles:return $fail;} \
+}; __spec_install_post_check_tmpfiles }}
+
 #-----------------------------------------------------------------
 # Find and gzip all kernel modules
 #
@@ -652,6 +725,7 @@ fi; }; __spec_install_post_chrpath } } }
 #%no_install_post_compress_modules     1
 %__spec_install_post_compress_modules { \
 %{!?no_install_post_compress_modules: __spec_install_post_compress_modules() { \
+%{!?debug:set +x;} \
        if [ -d $RPM_BUILD_ROOT/lib/modules ]; then \
                q=$(find $RPM_BUILD_ROOT/lib/modules -name '*o' -type f -print); \
                if [ "$q" ]; then \
@@ -719,11 +793,16 @@ fi; \
 
 #-----------------------------------------------------------------
 # Update icon cache
-# requires: gtk+
+# BuildRequires:  rpmbuild(macros) >= 1.596
+# Requires:  hicolor-icon-theme
 #
 %update_icon_cache() {{ \
-       umask 022; \
-       /usr/bin/gtk-update-icon-cache -qf %{_datadir}/icons/%1; \
+       %{!?1:%{error:%{0}: Required theme name missing}} \
+       if [ -x /usr/bin/gtk-update-icon-cache ]; then \
+               umask 022; \
+               touch --no-create %{_iconsdir}/%1; \
+               /usr/bin/gtk-update-icon-cache -qf %{_iconsdir}/%1; \
+       fi; \
 };} \
 %{nil}
 
@@ -741,6 +820,16 @@ if [ "$1" = "0" ]; then \
 fi; \
 %{nil}
 
+#-----------------------------------------------------------------
+# Compile GSettings schemas
+# requires: glib2 >= 1:2.26.0
+#
+%glib_compile_schemas() {{ \
+       umask 022; \
+       /usr/bin/glib-compile-schemas %{_datadir}/glib-2.0/schemas; \
+};} \
+%{nil}
+
 #-----------------------------------------------------------------
 # post %install sequence:
 # - autodeps exceptions
@@ -754,9 +843,21 @@ fi; \
 #
 %__noautoreqfiles      %(sed -e s'/#.*//' /etc/rpm/noautoreqfiles)%{?_noautoreqfiles: %{_noautoreqfiles}}
 %__noautoprovfiles     %(sed -e s'/#.*//' /etc/rpm/noautoprovfiles)%{?_noautoprovfiles: %{_noautoprovfiles}}
-%__noautoreq           %(sed -e s'/#.*//' /etc/rpm/noautoreq)%{?_noautoreq: %{_noautoreq}}
 %__noautoreqdep                %(sed -e s'/#.*//' /etc/rpm/noautoreqdep)%{?_noautoreqdep: %{_noautoreqdep}}
 %__noautoprov          %(sed -e s'/#.*//' /etc/rpm/noautoprov)%{?_noautoprov: %{_noautoprov}}
+%__noautoreq           %(sed -e s'/#.*//' /etc/rpm/noautoreq) \
+       %{?_noautoreq: %{_noautoreq}} \
+       %{?_noautoreq_pear: %{__noauto_regexp_helper -p pear %{_noautoreq_pear}}} \
+       %{?_noautoreq_perl: %{__noauto_regexp_helper -p perl %{_noautoreq_perl}}} \
+       %{nil}
+
+# helper for wrapping _noautoreq between perl() or pear()
+# Author: Elan Ruusamäe <glen@pld-linux.org>
+# Usage:
+# BuildRequires:       rpmbuild(macros) >= 1.654
+# %define _noautoreq_pear Excluded.php PEAR/Something.php
+# %define _noautoreq_perl Apache::.*
+%__noauto_regexp_helper(p:) %(echo "%*" | awk 'BEGIN{RS=" "}{printf("%{-p*}\\\\\\(%%s\\\\\\) ", $1)}')
 
 #%_noautocompressdoc   %{nil}
 #
@@ -810,23 +911,30 @@ fi; \
 %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
 %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
 %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
-%zend_zts                              %{expand:%%global zend_zts %(Z=$(grep -sc '^#define ZTS 1' %{php_includedir}/main/php_config.h); echo ${Z:-ERROR})}%zend_zts
+%_zend_zts                             %{expand:%%global _zend_zts %(Z=$(grep -sc '^#define ZTS 1' %{php_includedir}/main/php_config.h); echo ${Z:-ERROR})}%_zend_zts
+# "_ts" if ZTS enabled, empty otherwise
+%zend_zts                              %{expand:%%global _zend_zts_%{?_zend_zts} 1}%{?_zend_zts_1:_ts}
+
+# name of php package
+%php_name                              php%{?php_suffix}
+# use rpmbuild -D 'php_suffix 54' to build php extension for php 5.4
+%php_suffix                            %{nil}
 
 # helper macro
-%__php_api_requires(v:) Requires: php%{-v*}(%{expand:%1}) = %{expand:%{%{!?2:%{1}}%{?2}}}
+%__php_api_requires(v:) Requires: %{php_name}(%{expand:%1}) = %{expand:%{%{!?2:%{1}}%{?2}}}
 
 # macros for public use
 # for php extensions (php-pecl)
 %requires_php_extension %{__php_api_requires modules_api php_api_version} \
 %{__php_api_requires zend_module_api} \
-%{__php_api_requires -v %php_major_version debug php_debug} \
-%{__php_api_requires -v %php_major_version thread-safety zend_zts}
+%{__php_api_requires debug php_debug} \
+%{__php_api_requires thread-safety _zend_zts}
 
 # for zend extensions
 %requires_zend_extension %{__php_api_requires zend_module_api} \
 %{__php_api_requires zend_extension_api} \
-%{__php_api_requires -v %php_major_version debug php_debug} \
-%{__php_api_requires -v %php_major_version thread-safety zend_zts}
+%{__php_api_requires debug php_debug} \
+%{__php_api_requires thread-safety _zend_zts}
 
 # for php pdo modules (php-pecl-PDO_*)
 %requires_php_pdo_module %{__php_api_requires PDO_API php_pdo_api_version}
@@ -931,11 +1039,11 @@ fi \
 
 # directories
 %py3_prefix            %{expand:%%global py3_prefix %(%{__python3} -c "import sys; print(sys.prefix)" 2>/dev/null || echo ERROR)}%py3_prefix
-%py3_libdir            %{py3_prefix}/%{_lib}/python%{py3_ver}
+%py3_libdir            %{expand:%%global py3_libdir %(%{__python3} -c "import sysconfig; print(sysconfig.get_path('platstdlib'))" 2>/dev/null || echo ERROR)}%py3_libdir
+%py3_incdir            %{expand:%%global py3_incdir %(%{__python3} -c "import sysconfig; print(sysconfig.get_path('include'))" 2>/dev/null || echo ERROR)}%py3_incdir
+%py3_sitedir           %{expand:%%global py3_sitedir %(%{__python3} -c "import sysconfig; print(sysconfig.get_path('platlib'))" 2>/dev/null || echo ERROR)}%py3_sitedir
+%py3_sitescriptdir             %{expand:%%global py3_sitescriptdir %(%{__python3} -c "import sysconfig; print(sysconfig.get_path('purelib'))" 2>/dev/null || echo ERROR)}%py3_sitescriptdir
 %py3_scriptdir %{py3_prefix}/share/python%{py3_ver}
-%py3_incdir            /usr/include/python%{py3_ver}
-%py3_sitedir           %{py3_libdir}/site-packages
-%py3_sitescriptdir %{py3_scriptdir}/site-packages
 %py3_dyndir            %{py3_libdir}/lib-dynload
 
 # pure python modules compilation
@@ -943,9 +1051,15 @@ fi \
 
 %py3_ocomp             %{__python3} -O -c "import compileall; import sys; compileall.compile_dir(sys.argv[1], ddir=sys.argv[1][len('$RPM_BUILD_ROOT'):])"
 
+# node.js libdir
+# Requirements:
+# BuildRequires: rpmbuild(macros) >= 1.634
+%nodejs_libdir         /usr/lib/node_modules
+
 # Hardlink binary identical .pyc and .pyo files
 %__spec_install_post_py_hardlink {\
 %{!?no_install_post_py_hardlink: __spec_install_post_py_hardlink() { \
+%{!?debug:set +x;} \
 local a b c=0 t=0; \
 if [ -d "$RPM_BUILD_ROOT" ]; then \
        find "$RPM_BUILD_ROOT" -name '*.pyc' > __rpm_pyc; \
@@ -969,12 +1083,6 @@ for d in %{py_sitescriptdir} %{py_sitedir} %*; do \
 done \
 %{nil}
 
-%py3_postclean() \
-for d in %{py3_sitescriptdir} %{py3_sitedir} %*; do \
- [ ! -d "$RPM_BUILD_ROOT$d" ] || find "$RPM_BUILD_ROOT$d" -name '*.py' -print0 | xargs -0r -l512 rm;\
-done \
-%{nil}
-
 # depmod macro
 %depmod() { \
 umask 022; \
@@ -1001,7 +1109,8 @@ fi; \
 %xmms_effect_plugindir         %{expand:%%global xmms_effect_plugindir %(xmms-config --effect-plugin-dir 2>/dev/null || echo ERROR)}%xmms_effect_plugindir
 %xmms_general_plugindir                %{expand:%%global xmms_general_plugindir %(xmms-config --general-plugin-dir 2>/dev/null || echo ERROR)}%xmms_general_plugindir
 
-%_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/')}%_target_base_arch
+%_host_base_arch       %{expand:%%global _host_base_arch %(echo %{_host_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/')}%_host_base_arch
+%_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
 
 # user/group checking macros
 #
@@ -1036,7 +1145,7 @@ fi; \
 # banner support (useful in {pre,post}{,un} and triggers)
 #
 # Usage:
-#      %banner name [-a] [-e] [-n] [-tn] <<EOF
+#      %banner name [-a] [-e] [-n] [-tn] [-o] <<EOF
 # the banner text, the banner text
 # the banner text, and following line
 #EOF
@@ -1047,12 +1156,16 @@ fi; \
 # -e   - send to stderr instead of stdout
 # -n   - no show banner (overrides -t)
 # -t   - show only, if RPM_SCRIPTVERBOSITY >= n; default n=5
+# -o   - show only once, i.e when package is installed for the first time
 #
 # Tests:
 # (rpm -E '%banner -e banner <<EOF'; echo -e 'hi\nEOF') > m; sh -x m
+# (rpm -E '%banner -o -e banner <<EOF'; echo -e 'hi\nEOF') > m; sh -x m
+# (rpm -E '%banner -o -e banner <<EOF'; echo -e 'hi\nEOF') > m; sh -x m 1
 # rpm -E 'date | %banner -e banner' > m; sh -x m
+# rpm -E 'date | %banner -o -e banner' > m; sh -x m
 #
-%banner(aent:) ( \
+%banner(aenot:) %{-o:([ "$1" != 1 ] ||} ( \
 RPM_SCRIPTVERBOSITY=5 \
 [ -r /etc/sysconfig/rpm ] && . /etc/sysconfig/rpm \
 if [ -x /usr/bin/banner.sh ]; then \
@@ -1060,7 +1173,7 @@ if [ -x /usr/bin/banner.sh ]; then \
 else \
        CMD="cat%{-e: >&2}" \
 fi \
-eval $CMD %{?2:%2}%{?3: %3}) \
+eval $CMD %{?2:%2}%{?3: %3})%{-o:)} \
 %{nil}
 
 # useradd/groupadd macros
@@ -1184,8 +1297,7 @@ fi \
 # Requires:    rc-scripts
 # -n option:
 # BuildRequires:       rpmbuild(macros) >= 1.450
-%service(qn) {{%(export noop=%{-n:1} quiet=%{-q:1}; /usr/lib/rpm/service_generator.sh %{*}) };}
-
+%service(qn) {{%(export noop=%{-n:1} quiet=%{-q:1} RPM_BUILD_ROOT=%{buildroot}; /usr/lib/rpm/service_generator.sh %{*}) };}
 
 # Java macros. based on jpackage macros.java
 #
@@ -1352,10 +1464,11 @@ echo -e "</dependencies>\\n" >> %{_mavendepmapdir}/maven2-depmap.xml
 #      %%pear_package_setup ...
 #
 # -a #   - also unpack SOURCE#. for PEAR bootstrapping
-# -n FMT - create builddir with FMT, instead of default %%{_pearname}-%%{version}
+# -n FMT - create builddir with FMT, instead of default %%{pearname}-%%{version}
 # -z     - unpack pear package and let pear use package.xml (not tarball) for install. for PEAR bootstrapping
 # -D     - pass -D to %setup (so the build dir is not removed)
 # -c     - register channel from local channel.xml file
+# -d     - pass -d arg to pearcmd
 #
 # unpack PEAR package to %%{_builddir}/FMT. package is extracted with already
 # destination hierarchy. you should copy the tree to buildroot after
@@ -1377,7 +1490,7 @@ echo -e "</dependencies>\\n" >> %{_mavendepmapdir}/maven2-depmap.xml
 %__pear_install_log \
 tee install.log \
 # make post message of optional packages \
-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 \
+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-,' > optional-packages.txt \
 if [ -s optional-packages.txt ]; then \
        awk -F'"' '/use package/{print $2}' optional-packages.txt | sed -e "s,_,/,g;s,php-pear-, 'pear(,;s,$,.*)'," | tr -d '\\\n' > _noautoreq \
 else \
@@ -1385,10 +1498,11 @@ else \
 fi \
 %{nil}
 
-# command invoking pear cli
-%__pear /usr/bin/pear
+# Command invoking PEAR CLI
+# Same as /usr/bin/pear, except we force GMT timezone
+%__pear        %__php -doutput_buffering=1 -dopen_basedir="" -dmemory_limit=-1 -ddate.timezone=GMT /usr/share/pear/pearcmd.php
 
-%pear_install(a:n:zD) \
+%pear_install(a:d:n:zD) \
 %__pear \\\
        -c %{builddir}/pearrc \\\
        -d doc_dir=/docs \\\
@@ -1397,6 +1511,7 @@ fi \
        -d bin_dir=%{_bindir} \\\
        -d data_dir=%{php_pear_dir}/data \\\
        -d test_dir=%{php_pear_dir}/tests \\\
+       %{-d:%(echo "%{-d*}" | awk 'BEGIN{RS=","}{printf("-d %%s \\\\\\n\\t", $1)}')} \\\
        install \\\
        --packagingroot=%{builddir} \\\
        --offline \\\
@@ -1410,27 +1525,29 @@ fi \
 # using this macro will append optional-packages.txt to the nocompressdoc list
 # as it's displayed to user after package install. and adding additional gzip
 # dep is just waste ;)
-%pear_package_setup(a:n:zDc:) \
-%define srcdir %{-n*}%{!-n:%{_pearname}-%{version}} \
+%pear_package_setup(a:d:n:zDc:) \
+%define srcdir %{-n*}%{!-n:%{?_pearname}%{!?_pearname:%{pearname}}-%{version}} \
 %define builddir %{_builddir}/%{srcdir} \
 %setup -q -c -T %{-D:-D} -n %{srcdir} \
-%{-z:tar zxf %{S:0}; %{-a:tar zxf %{S:%{-a*}}}} \
+%{-z:%{__tar} zxf %{S:0}; %{-a:%{__tar} zxf %{S:%{-a*}}}} \
 %{-z:_P=package2.xml; [ -f $_P ] || _P=package.xml; _N=%{srcdir}; mv $_P $_N; cd $_N} \
 %{-c:%{__pear} -c pearrc config-set php_dir %{builddir}/%{php_pear_dir}; %__pear -c %{builddir}/pearrc channel-add %{-c*}} \
 %pear_install \
 %{-z:cd ..} \
+%{__tar} --wildcards -zvxf %{S:0} package*.xml \
 cat %{-z:$_N/}.install.log | %__pear_install_log \
-\
-# undos sources \
-find -type f -print0 | xargs -0 sed -i -e 's,\\r$,,' \
+%undos -f php,html,js,xml \
 %{!?_noautocompressdoc:%global _noautocompressdoc %{nil}}%{expand:%%global _noautocompressdoc %{_noautocompressdoc} optional-packages.txt} \
 %{!?_noautoprov:%global _noautoprov %{nil}}%{expand:%%global _noautoprov %{_noautoprov} 'pear(tests/.*)'} \
 %{nil}
 
-# Copies exctracted PEAR package structure and PEAR registry to buildroot.
+# Copies extracted PEAR package structure and PEAR registry to buildroot.
 # Author: Elan Ruusamäe <glen@pld-linux.org>
 %pear_package_install() \
 cp -a ./%{php_pear_dir}/{.registry,*} $RPM_BUILD_ROOT%{php_pear_dir} \
+# tests should not be packaged \
+%{__rm} -rf $RPM_BUILD_ROOT%{php_pear_dir}/tests \
+# cleanup backups \
 find $RPM_BUILD_ROOT%{php_pear_dir} '(' -name '*~' -o -name '*.orig' ')' | xargs -r rm -v \
 # help the developer out a little: \
 if [ -f _noautoreq ]; then \
@@ -1439,6 +1556,21 @@ if [ -f _noautoreq ]; then \
 fi \
 %{nil}
 
+# Print optional package info for pear packages
+# Author: Elan Ruusamäe <glen@pld-linux.org>
+# Usage:
+#   %post -p <lua>
+#      %%pear_package_print_optionalpackages
+#
+# Requirements:
+# BuildRequires:       rpmbuild(macros) >= 1.571
+%pear_package_print_optionalpackages \
+f = io.open("%{_docdir}/%{name}-%{version}/optional-packages.txt", "r") \
+if f then \
+       for l in f:lines() do print(l); end \
+end \
+%{nil}
+
 
 # Register OpenLDAP schema.
 # Author: Elan Ruusamäe <glen@pld-linux.org>
@@ -1522,8 +1654,8 @@ done \
 %{!?-m:%{error:%{0}: Required module name/list missing} exit 1}                \
                                                                                                                                        \
 %define Opts                                                                                                           \\\\\\\
-%if "%{_target_base_arch}" != "%{_arch}"                                                       \\\
-       %if "%{_arch}" == "x86_64" && "%{_target_base_arch}" == "i386"  \\\
+%if "%{_target_base_arch}" != "%{_host_base_arch}"                                     \\\
+       %if "%{_host_base_arch}" == "x86_64" && "%{_target_base_arch}" == "i386" \\\
        CC="%{kgcc}" ARCH=%{_target_base_arch}                                                  \\\
        %else                                                                                                                   \\\
        ARCH=%{_target_base_arch} CROSS_COMPILE=%{_target_cpu}-pld-linux- \\\
@@ -1536,6 +1668,45 @@ done \
                                                                                                                                        \
 %{?-C:cd %{-C*}}                                                                                                       \
 compile() {                                                                                                                    \
+       local L="<" PATCH_SH;                                                                                   \
+       [[ '%{*}' != *$L$L* ]] || PATCH_SH="set -x -e;$(cat)"                   \
+       set -e -x                                                                                                               \
+                                                                                                                                       \
+       [ -r "%{_kernelsrcdir}/.config" ] || exit 1                                             \
+       rm -rf o                                                                                                                \
+       install -d o/include/linux o/include/generated o/arch/x86/include o/arch/powerpc/lib    \
+       ln -sf %{_kernelsrcdir}/.config o/.config                                               \
+       ln -sf %{_kernelsrcdir}/Module.symvers o/Module.symvers                 \
+       if [ -f %{_kernelsrcdir}/include/generated/autoconf.h ]; then   \
+               ln -sf %{_kernelsrcdir}/include/generated/autoconf.h o/include/generated/autoconf.h \
+               ln -s ../generated/autoconf.h o/include/linux/autoconf.h        \
+       else                                                                                                                    \
+               ln -sf %{_kernelsrcdir}/include/linux/autoconf.h o/include/linux/autoconf.h \
+       fi                                                                                                                              \
+       if [ -d %{_kernelsrcdir}/arch/x86/include/generated ]; then             \
+               ln -s %{_kernelsrcdir}/arch/x86/include/generated o/arch/x86/include    \
+       fi                                                                                                                              \
+                                                                                                                                       \
+       set +x                                                                                                                  \
+       [ -z "$PATCH_SH" ] || echo "$PATCH_SH" | %__spec_build_shell    \
+       set -x                                                                                                                  \
+                                                                                                                                       \
+       install -d o/include/config                                                                             \
+       touch o/include/config/MARKER                                                                   \
+       ln -sf %{_kernelsrcdir}/include/config/auto.conf o/include/config/auto.conf     \
+       ln -sf %{_kernelsrcdir}/scripts o/scripts                                               \
+                                                                                                                                       \
+       %{!?-c:%{__make} -C %{_kernelsrcdir} clean                                              \\\
+               RCS_FIND_IGNORE="-name '*.[ks]o' -o"                                            \\\
+               ${1+"$@"}                                                                                                       \\\
+               M=$PWD %{MakeOpts}}                                                                                     \
+                                                                                                                                       \
+       %{__make} -C %{_kernelsrcdir} modules                                                   \\\
+               ${1+"$@"}                                                                                                       \\\
+               M=$PWD CONSTIFY_PLUGIN="" %{MakeOpts}                                           \
+%{?-C:cd -}                                                                                                                    \
+}                                                                                                                                      \
+compile_old() {                                                                                                                \
        local L="<" PATCH_SH;                                                                                   \
        [[ '%{*}' != *$L$L* ]] || PATCH_SH="set -x -e;$(cat)"                   \
        set -e -x                                                                                                               \
@@ -1571,13 +1742,13 @@ for cfg in ${cfgs:-dist}; do                                        \
        %endif                                                                                                                  \
                                                                                                                                        \
        %{!?-c:%{__make} -C %{_kernelsrcdir} clean                                              \\\
-               RCS_FIND_IGNORE="-name '*.ko' -o"                                                       \\\
+               RCS_FIND_IGNORE="-name '*.[ks]o' -o"                                                    \\\
                ${1+"$@"}                                                                                                       \\\
                M=$PWD %{MakeOpts}}                                                                                     \
                                                                                                                                        \
        %{__make} -C %{_kernelsrcdir} modules                                                   \\\
                ${1+"$@"}                                                                                                       \\\
-               M=$PWD %{MakeOpts}                                                                                      \
+               M=$PWD CONSTIFY_PLUGIN="" %{MakeOpts}                                           \
                                                                                                                                        \
        for MODULE in {%{-m*},}; do                                                                             \
                [ -z "${MODULE}" ] || mv ${MODULE}{,-$cfg}.ko                           \
@@ -1585,7 +1756,11 @@ for cfg in ${cfgs:-dist}; do                                        \
 done                                                                                                                           \
 %{?-C:cd -}                                                                                                                    \
 }                                                                                                                                      \
-compile %{*}\
+if [ -r "%{_kernelsrcdir}/.config" ]; then     \
+       compile %{*}                                                    \
+else                                                                           \
+       compile_old %{*}                                                \
+fi                                                                                     \
 %{nil}
 
 
@@ -1614,6 +1789,18 @@ compile %{*}\
 %define ModprobeD $RPM_BUILD_ROOT%{_sysconfdir}/modprobe.d/%{_kernel_ver} \
                                                                                                                                        \
 __install_kernel_modules() {                                                                           \
+%{!?debug:set +x;} \
+                                                                                                                                       \
+for MODULE in {%{-m*},}; do                                                                                    \
+       [ -n "${MODULE}" ] || continue                                                                  \
+       MNAME=${MODULE##*/}                                                                                     \
+       install -D ${MODULE}.ko %{KernelD}/%{-d*}/${MNAME}%{-s:-%{-s*}}.ko      \
+       %{?-s:install -d %{ModprobeD}                                                   \
+               echo "alias ${MNAME} ${MNAME}-%{-s*}" >> %{ModprobeD}/%{-n*}.conf}      \
+done                                                                                                                           \
+}                                                                                                                                      \
+__install_kernel_modules_old() {                                                                       \
+%{!?debug:set +x;} \
 local cfgs='%{?with_dist_kernel:%{?with_smp: smp}%{?with_up: up}}%{!?with_dist_kernel: nondist}' \
                                                                                                                                        \
 for MODULE in {%{-m*},}; do                                                                                    \
@@ -1629,7 +1816,11 @@ for MODULE in {%{-m*},}; do                                                                                      \
        done                                                                                                                    \
 done                                                                                                                           \
 }                                                                                                                                      \
-__install_kernel_modules                                                                                       \
+if [ -r "%{_kernelsrcdir}/.config" ]; then     \
+       __install_kernel_modules                                \
+else                                                                           \
+       __install_kernel_modules_old                    \
+fi                                                                                     \
 %{nil}
 
 # patchset macros
@@ -1673,6 +1864,9 @@ __install_kernel_modules                                                                                  \
 ) \
 %{nil}
 
+# return EXPANDED source url N from current spec
+%sourceurl(n:) %(test "$IN_RPM" = 1 && exit 1; export IN_RPM=1; rpmbuild --nodigest --nosignature --nobuild -D "prep %%dump" %{_specdir}/%{name}.spec 2>&1 | awk '$2 ~ /^SOURCEURL%{-n*}/ {print $3}')
+
 # browser plugins v2
 # Author: Elan Ruusamäe <glen@pld-linux.org>
 #
@@ -1790,30 +1984,35 @@ io.open("/etc/shells", "w"):write(s)\
 #
 # Requirements:
 # BuildRequires:       python
-# BuildRequires:       rpmbuild(macros) >= 1.469
+# BuildRequires:       rpmbuild(macros) >= 1.602
 
 %py_lint() \
 __py_lint() { \
+%{!?debug:set +x;} \
 find "$@" -type f -name '*.py' | python -c ' \
 import sys \
 import compiler \
 \
-err = 0\
+found = err = 0\
 for f in sys.stdin: \
-       fd = open(f.strip()) \
+       fd = open(f.rstrip()) \
        c = fd.read() \
        fd.close() \
+       found = found + 1 \
        try: \
                compiler.parse(c) \
        except SyntaxError, e: \
-               print "py_lint: %s: %s" % (f.strip(), e) \
+               print "py_lint: %s: %s" % (f.rstrip(), e) \
                err = err + 1\
 \
-if err: \
+if not found:\
+       print >> sys.stderr, "\\npy_lint: ERROR: No files processed.\\n" \
+       sys.exit(1) \
+elif err: \
        print >> sys.stderr, "\\npy_lint: ERROR: Syntax errors in %d files.\\n" % err \
        sys.exit(1) \
 else: \
-       print >> sys.stderr,  "py_lint: Found no syntax errors." \
+       print >> sys.stderr,  "py_lint: %d files scanned, found no syntax errors." % found \
 ' \
 }; __py_lint %* \
 %{nil}
@@ -1821,16 +2020,32 @@ else: \
 # Undos files
 #
 # Author: Paweł Zuzelski <pawelz@pld-linux.org>
+# Author: Elan Ruusamäe <glen@pld-linux.org>
 #
 # Usage:
 #   %undos list_of_files
+#   %undos -f EXT[,EXT]
+#   %undos -i -f EXT[,EXT]
+#
+#  -f EXT[,EXT] - find(1) files by extensions
+#  -i - case insensitive file search
+#
+# Example:
+#   Un-DOS all *.js, *.css files
+#   %undos -f js,css
+#   Un-DOS all *.js, *.JS files
+#   %undos -f js -i
+#   undos all Makefiles
+#   %{__find} -name Makefile | xargs %undos
 #
 # Requirements:
 # BuildRequires:       sed >= 4.0
-# BuildRequires:       rpmbuild(macros) >= 1.553
+# BuildRequires:       rpmbuild(macros) >= 1.565
 
-# NB: make sure this command stays on one line
-%undos         %{__sed} -i -e 's,\\r$,,'
+# NB: make sure this macro stays on one line
+# NB: make sure it includes newline escape
+%undos(f:i)    %{-f:%{__find} -regextype posix-extended -%{-i:i}regex '^.+\\.(%(echo %{-f*} | tr ',' '|'))$' -print0 | xargs -0} %{__sed} -i -e 's,\\r$,,' %* \
+%{nil}
 
 # Hook to register nagios object based plugins in Nagios NRPE daemon config.
 #
@@ -1882,10 +2097,15 @@ else: \
 # %cacti_import_template %{resourcedir}/cacti_host_template_varnish.xml
 #
 # Requires:    cacti >= 0.8.7e-8
-# BuildRequires:       rpmbuild(macros) >= 1.554
+# BuildRequires:       rpmbuild(macros) >= 1.630
+# Note: 1.1 (cacti-0.8.7h) adds requirement for --with-template-rras or --with-user-rras option
 
 %cacti_import_template() {\
-/usr/share/cacti/cli/import_template.php --filename=%1 || :; \
+v=$(%{__sed} -rne 's/.+Add Graphs Script ([0-9\.]+).+/\1/p' /usr/share/cacti/cli/import_template.php); \
+if [ "$v" != "1.0" ]; then \
+       rra="--with-template-rras"; \
+fi; \
+/usr/share/cacti/cli/import_template.php --filename=%1 $rra || :; \
 }%{nil}
 
 # pre/post script for -upstart subpackages
@@ -1909,18 +2129,146 @@ else: \
 
 # migrate from init script to upstart job
 %upstart_post() \
-       if [ -f /var/lock/subsys/"%1" ] ; then \
-               /sbin/service --no-upstart "%1" stop \
-               /sbin/service "%1" start \
+       if [ -f /var/lock/subsys/%1 ]; then \
+               /sbin/service --no-upstart %1 stop \
+               /sbin/service %1 start \
        fi
 
 # restart the job after upgrade or migrate to init script on removal
 # cannot be stopped with 'service' as /etc/init/$name.conf may be missing
 # at this point
 %upstart_postun() \
-       if [ -x /sbin/initctl ] && /sbin/initctl status "%1" 2>/dev/null | grep -q 'running' ; then \
-               /sbin/initctl stop "%1" >/dev/null 2>&1 \
-               [ -f "/etc/rc.d/init.d/%1" -o -f "/etc/init/%1.conf" ] && { echo -n "Re-" ; /sbin/service "%1" start ; } ; \
+       if [ -x /sbin/initctl ] && /sbin/initctl status %1 2>/dev/null | grep -q 'running' ; then \
+               /sbin/initctl stop %1 >/dev/null 2>&1 \
+               [ -f /etc/rc.d/init.d/%1 -o -f /etc/init/%1.conf ] && { echo -n "Re-"; /sbin/service %1 start; }; \
        fi
 
-# vim:ts=4 sw=4 noet ft=spec
+# Haskell Macros
+# BuildRequires:  rpmbuild(macros) >= 1.608
+%ghcdir                ghc-%(/usr/bin/ghc --numeric-version 2>/dev/null || echo ERROR)
+
+# update /usr/lib*/ghc-*/package.conf.d/package.cache
+# Requires: ghc
+# BuildRequires:  rpmbuild(macros) >= 1.607
+#
+%ghc_pkg_recache() {{ \
+       umask 022; \
+       /usr/bin/ghc-pkg recache; \
+};} \
+%{nil}
+
+
+# pre/post script for packages supporting systemd units
+#
+# Author: Bartlomiej Zimon <uzi18@o2.pl>
+#                Jan Rękorajski <baggins@mimuw.edu.pl>
+#
+# Usage:
+# %systemd_reload
+# %systemd_service <unit command> service_name1.service service_name2.service
+# %systemd_service_enable service_name1.service service_name2.service
+# %systemd_service_disable service_name1.service service_name2.service
+# %systemd_service_start service_name1.service service_name2.service
+# %systemd_service_stop service_name1.service service_name2.service
+# %systemd_service_restart service_name1.service service_name2.service
+# %systemd_service_reload service_name1.service service_name2.service
+#
+# %systemd_post service_name1.service service_name2.service
+# %systemd_preun service_name1.service service_name2.service
+# %systemd_trigger service_name1.service service_name2.service
+#
+# Sample:
+# %post
+# %systemd_post %{name}.service
+#
+# %preun
+# %systemd_preun %{name}.service
+#
+# %postun
+# %systemd_reload
+#
+# %triggerpostun -- %{name} < first-version-with-systemd-units
+# %systemd_trigger %{name}.service
+#
+# Requirements:
+# BuildRequires:       rpmbuild(macros) >= 1.647
+# Requires:    systemd-units >= 38
+
+%systemd_reload /bin/systemd_booted && SYSTEMD_LOG_LEVEL=warning SYSTEMD_LOG_TARGET=syslog /bin/systemctl --quiet daemon-reload || :
+
+%systemd_service_enable() \
+       export SYSTEMD_LOG_LEVEL=warning SYSTEMD_LOG_TARGET=syslog \
+       /bin/systemctl --quiet enable %{*} || : \
+       /bin/systemd_booted && echo 'Run "/bin/systemctl start %{*}" to start %{*}.' || : \
+%{nil}
+
+%systemd_service_disable() \
+       export SYSTEMD_LOG_LEVEL=warning SYSTEMD_LOG_TARGET=syslog \
+       /bin/systemctl --quiet disable %{*} || : \
+%{nil}
+
+%systemd_service() \
+       export SYSTEMD_LOG_LEVEL=warning SYSTEMD_LOG_TARGET=syslog \
+       /bin/systemd_booted && /bin/systemctl --quiet %{*} || : \
+%{nil}
+
+%systemd_service_start() \
+       export SYSTEMD_LOG_LEVEL=warning SYSTEMD_LOG_TARGET=syslog \
+       /bin/systemd_booted && /bin/systemctl --quiet start %{*} || : \
+%{nil}
+
+%systemd_service_stop() \
+       export SYSTEMD_LOG_LEVEL=warning SYSTEMD_LOG_TARGET=syslog \
+       /bin/systemd_booted && /bin/systemctl --quiet stop %{*} || : \
+%{nil}
+
+%systemd_service_restart() \
+       export SYSTEMD_LOG_LEVEL=warning SYSTEMD_LOG_TARGET=syslog \
+       /bin/systemd_booted && /bin/systemctl --quiet try-restart %{*} || : \
+%{nil}
+
+%systemd_service_reload() \
+       export SYSTEMD_LOG_LEVEL=warning SYSTEMD_LOG_TARGET=syslog \
+       /bin/systemd_booted && /bin/systemctl --quiet reload %{*} || : \
+%{nil}
+
+%systemd_trigger() \
+want_enable_service() { \
+       [ -f /etc/sysconfig/rpm ] && . /etc/sysconfig/rpm \
+       [ ${RPM_ENABLE_SYSTEMD_SERVICE:-yes} = no ] && return 1 \
+       /sbin/chkconfig --list ${1%.service} 2>/dev/null | grep -qsv "[0-6]:on" && return 1 \
+       return 0 \
+}\
+       export SYSTEMD_LOG_LEVEL=warning SYSTEMD_LOG_TARGET=syslog \
+       for s in %{*}; do \
+               if want_enable_service $s; then \
+                       /bin/systemctl --quiet enable $s || : \
+               fi \
+       done \
+%{nil}
+
+%systemd_post() \
+       export SYSTEMD_LOG_LEVEL=warning SYSTEMD_LOG_TARGET=syslog \
+       /bin/systemd_booted && /bin/systemctl --quiet daemon-reload || : \
+       if [ $1 -eq 1 ]; then \
+               /bin/systemctl --quiet enable %{*} || : \
+               /bin/systemd_booted && echo 'Run "/bin/systemctl start %{*}" to start %{*}.' || : \
+       elif [ -z "$NORESTART" ]; then \
+               /bin/systemd_booted && /bin/systemctl --quiet try-restart %{*} || : \
+       else \
+               /bin/systemd_booted && echo 'Run "/bin/systemctl restart %{*}" to restart %{*}.' || : \
+       fi \
+%{nil}
+
+%systemd_preun() \
+       if [ $1 -eq 0 ]; then \
+               export SYSTEMD_LOG_LEVEL=warning SYSTEMD_LOG_TARGET=syslog \
+               /bin/systemd_booted && /bin/systemctl --quiet stop %{*} || : \
+               /bin/systemctl --quiet disable %{*} || : \
+       fi \
+%{nil}
+
+%systemdunitdir /lib/systemd/system
+%systemdtmpfilesdir /usr/lib/tmpfiles.d
+
+# EOF
This page took 0.07606 seconds and 4 git commands to generate.