]> git.pld-linux.org Git - packages/rpm-build-macros.git/blobdiff - rpm.macros
v1.717: %py_install_opts, %py3_install_opts
[packages/rpm-build-macros.git] / rpm.macros
index 3b02732f27b78fcbf0bb9633b69bcbe2b9a18bd3..aeb242c2e0f8bb96568419ba49168e01f4ef84d6 100644 (file)
@@ -1,20 +1,15 @@
-# $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 2>/dev/null || echo 0.0)}%cc_version
 %cxx_version   %{expand:%%global cxx_version %(%{__cxx} -dumpversion 2>/dev/null || echo 0.0)}%cxx_version
 %__autopoint   autopoint --force
 
 # add parallel build flags: -jN
+# jobs macro is available since 1.657
 #
 # if you want to disable parallel build do:
-# echo '%_smp_mflags %{nil}' >> ~/.rpmmacros
-#
-%__make                /usr/bin/make %{?_smp_mflags}
+# echo '%__jobs %{nil}' >> ~/.rpmmacros
+%__jobs                %{expand:%%global __jobs %(_NCPUS=$(/usr/bin/getconf _NPROCESSORS_ONLN); [ "$_NCPUS" -gt 3 ] && echo $(($_NCPUS / 2)))%%{nil}}%__jobs
+
+# expands to -jN if %__jobs has a value
+%_smp_mflags   %{expand:%%global _smp_mflags %(jobs=%{__jobs}; echo ${jobs:+-j$jobs}%%{nil})}%_smp_mflags
+
+%__make                /usr/bin/make %{?_make_opts} %{?_smp_mflags}
 %__scons       /usr/bin/scons %{?_smp_mflags}
 %__waf         /usr/bin/waf %{?_smp_mflags}
 %__cmake       /usr/bin/cmake
 
-%_smp_mflags %(_NCPUS=$(/usr/bin/getconf _NPROCESSORS_ONLN); \\\
-                               [ "$_NCPUS" -gt 1 ] && echo "-j$(($_NCPUS * 2))")
-
 %__gettextize { \
        if grep -qs 'AM_GNU_GETTEXT.*external' configure.{ac,in} ; then \
                gettextize --copy --force --no-changelog; \
 %_specdir       %{expand:%%global _specdir %([ ! -d %{_topdir}/SPECS ] && echo %{_topdir}/%{name} || echo %{_topdir}/SPECS)}%_specdir
 %_sourcedir            %{expand:%%global _sourcedir %([ ! -d %{_topdir}/SOURCES ] && echo %{_specdir} || echo %{_topdir}/SOURCES)}%_sourcedir
 
-# BUILD/RPMS/SRPMS are one same level by default as packages dir, if these exist
+# BUILD/RPMS/SRPMS are on same level by default as packages dir, if these exist
 # if they don't exist assume we are having custom topdir (which is not named as
 # "packages", i.e ~/rpm/kde/{kdelibs,BUILD/RPMS/SRPMS})
-# NOTE: readlink fails if some parent dir is not readable (/home/services/builder for example can't read /home/services), therfore the extra echo
+# NOTE: readlink fails if some parent dir is not readable (/home/services/builder for example can't read /home/services), therefore the extra echo
 %_builddir             %{expand:%%global _builddir %(if [ -d %{_topdir}/BUILD ]; then echo %{_topdir}/BUILD; else readlink -m %{_topdir}/../BUILD || echo %{_topdir}/../BUILD; fi)}%_builddir
 %_rpmdir               %{expand:%%global _rpmdir %(if [ -d %{_topdir}/RPMS ]; then echo %{_topdir}/RPMS; else readlink -m %{_topdir}/../RPMS || echo readlink -m %{_topdir}/../RPMS; fi)}%_rpmdir
 %_srcrpmdir            %{expand:%%global _srcrpmdir %(if [ -d %{_topdir}/SRPMS ]; then echo %{_topdir}/SRPMS; else readlink -m %{_topdir}/../SRPMS || echo readlink -m %{_topdir}/../SRPMS; fi)}%_srcrpmdir
 # Regular expressions are supported, but to avoid some character be treated
 # as regular expression it must be escaped twice.
 
-%filter_out                                            \
-       for (i = 1; i in I; i++) {      A=0;    \
+%filter_out                                                    \
+       for (i = 1; i in I; i++) { A=0; \
                for (f in F) {                          \
                        if (I[i] ~ "^" F[f] "$") A=1;   \
                };                                                      \
 %_preserve_env_base    PATH HOME TMP TMPDIR SSH_AUTH_SOCK
 
 # "env -i" must end in first line of expaned macros because it's used as first line of shell script (#! env...)
-%_clean_env            %{!?_preserve_env:%global _preserve_env %{nil}}%{expand:%%global _preserve_env %{_preserve_env} %_preserve_env_base} env -i %(awk -vq="'" -vqq="\\"'\\"" -vq2q="'\\"'" 'BEGIN {
-       split("%{?_preserve_env}", P);
+%_clean_env env -i %(awk -vq="'" -vqq="\\"'\\"" -vq2q="'\\"'" 'BEGIN {
+       split("%{?_preserve_env:%_preserve_env %_preserve_env_base}%{!?_preserve_env:%_preserve_env_base}", P);
        for (i in P) {
                p = P[i];
                if (!ENVIRON[p] || d[p]) {
        }
 }')
 
+# override %__spec_build_pre and %__spec_install_pre from macros.rpmbuild
+# adding %{_clean_env}
+%__spec_build_pre      %{_clean_env}\
+%{___build_pre}\
+%{nil}
+%__spec_install_pre    %{_clean_env}\
+%{___build_pre}\
+%{?buildroot:%{__rm} -rf '%{buildroot}'; %{__mkdir_p} '%{buildroot}'}\
+%{nil}
+
 #-----------------------------------------------------------------
 %configure2_13 { \
  if [ -n "$LINGUAS" ]; then unset LINGUAS; fi; \
  %{?__cxx:CXX="%{__cxx}" ; export CXX ; } \
  %{?configuredir:%{configuredir}}%{!?configuredir:.}/configure \
        --host=%{_target_platform} \
-       --prefix=%{_prefix} \
+       --prefix=%{_prefix} \
        --exec-prefix=%{_exec_prefix} \
        --bindir=%{_bindir} \
        --sbindir=%{_sbindir} \
        %{dependencytracking} \
 }
 
+# Note: pass only standard cmake macros here.
+# The only exception is SYSCONF_INSTALL_DIR, used commonly in KDE packages,
+# where the default (${CMAKE_INSTALL_PREFIX}/etc) is not FHS-compliant and
+# absolute path MUST be used to comply with FHS.
+# The other non-standard cmake macros used commonly in KDE
+# (INCLUDE_INSTALL_DIR, LIB_INSTALL_DIR, SHARE_INSTALL_PREFIX)
+# have sane default values in KDE, and some packages use these names
+# in different way (e.g. expect them to be always relative or always
+# absolute).
 %cmake \
-%{?__cc:CC="%{__cc}"} \\\
-%{?__cxx:CXX="%{__cxx}"} \\\
+%{?__cc:CC="${CC:-%{__cc}}"} \\\
+%{?__cxx:CXX="${CXX:-%{__cxx}}"} \\\
 CPPFLAGS="${CPPFLAGS:-%{rpmcppflags}}" \\\
 %{__cmake} \\\
        -DCMAKE_VERBOSE_MAKEFILE=ON \\\
        -DCMAKE_BUILD_TYPE=%{!?debug:PLD}%{?debug:Debug} \\\
+       -DCMAKE_INSTALL_BINDIR:PATH=%{_bindir} \\\
+       -DCMAKE_INSTALL_SBINDIR:PATH=%{_sbindir} \\\
+       -DCMAKE_INSTALL_LIBEXECDIR:PATH=%{_libexecdir} \\\
+       -DCMAKE_INSTALL_SYSCONFDIR:PATH=%{_sysconfdir} \\\
+       -DCMAKE_INSTALL_SHAREDSTATEDIRPATH:PATH=%{_sharedstatedir} \\\
+       -DCMAKE_INSTALL_LOCALSTATEDIRPATH:PATH=%{_localstatedir} \\\
        -DCMAKE_INSTALL_LIBDIR:PATH=%{_libdir} \\\
+       -DCMAKE_INSTALL_INCLUDEDIR:PATH=%{_includedir} \\\
+       -DCMAKE_INSTALL_OLDINCLUDEDIR:PATH=%{_includedir} \\\
+       -DCMAKE_INSTALL_DATAROOTDIR:PATH=%{_datadir} \\\
+       -DCMAKE_INSTALL_DATADIR:PATH=%{_datadir} \\\
+       -DCMAKE_INSTALL_INFODIR:PATH=%{_infodir} \\\
+       -DCMAKE_INSTALL_LOCALEDIR:PATH=%{_localedir} \\\
+       -DCMAKE_INSTALL_MANDIR:PATH=%{_mandir} \\\
+       -DCMAKE_INSTALL_DOCDIR:PATH=%{_docdir} \\\
        -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_CXX_FLAGS_PLD="${CXXFLAGS:-%{rpmcxxflags} -DNDEBUG -DQT_NO_DEBUG}" \\\
+       -DCMAKE_C_FLAGS_PLD="${CFLAGS:-%{rpmcflags} -DNDEBUG -DQT_NO_DEBUG}" \\\
+       -DCMAKE_Fortran_FLAGS_PLD="${CFLAGS:-%{rpmcflags} -DNDEBUG -DQT_NO_DEBUG}" \\\
        -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 \
+%if "%{_lib}" == "libx32" \
+       -DLIB_SUFFIX=x32 \\\
 %endif \
        -DBUILD_SHARED_LIBS:BOOL=ON \\\
 %{nil}
@@ -286,6 +316,7 @@ CXX="%{__cxx}" \
 CPP="%{__cpp}" \
 CFLAGS="%{rpmcflags}" \
 CXXFLAGS="%{rpmcxxflags}" \
+LINKFLAGS="%{rpmldflags}" \
 %{__waf} \
 }
 
@@ -294,7 +325,7 @@ CXXFLAGS="%{rpmcxxflags}" \
 %configure_cache_file  %{buildroot}.configure.cache
 
 %configure {./configure \
-       LDFLAGS="${LDFLAGS:-%rpmldflags}" \
+       LDFLAGS="${LDFLAGS:-%rpmldflags}" \
        CFLAGS="${CFLAGS:-%rpmcflags}" \
        CXXFLAGS="${CXXFLAGS:-%rpmcxxflags}" \
        FFLAGS="${FFLAGS:-%rpmcflags}" \
@@ -304,7 +335,7 @@ CXXFLAGS="%{rpmcxxflags}" \
        %{?__cxx:CXX="%{__cxx}"} \
        --host=%{_target_platform} \
        --build=%{_target_platform} \
-       --prefix=%{_prefix} \
+       --prefix=%{_prefix} \
        --exec-prefix=%{_exec_prefix} \
        --bindir=%{_bindir} \
        --sbindir=%{_sbindir} \
@@ -402,17 +433,11 @@ CXXFLAGS="%{rpmcxxflags}" \
 %__unsermake /usr/share/unsermake/unsermake
 
 # Current date
-%date          %(LC_ALL=C date +"%a %b %d %Y")
+%date          %(LC_ALL=C date +"%a %b %d %Y")
 
 # Example files, programs, scripts...
 %_examplesdir  /usr/src/examples
 
-# Alternative kernel type/version
-%_alt_kernel   %{nil}%{?alt_kernel:-%{?alt_kernel}}
-
-# The directory holding Linux kernel sources
-%_kernelsrcdir /usr/src/linux%{_alt_kernel}
-
 # SysV-style initscripts dir
 %_initddir             /etc/rc.d/init.d
 
@@ -428,16 +453,6 @@ CXXFLAGS="%{rpmcxxflags}" \
 # and release 0.zzz.bootstrap if built with bootstrap
 %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
-
-# -s post to generate Requires(post) dependency
-%requires_releq_kernel(s:n:)           Requires%{-s:(%{-s*})}: %releq_kernel
-%requires_releq_kernel_up(s:n:)                Requires%{-s:(%{-s*})}: %releq_kernel_up
-%requires_releq_kernel_smp(s:n:)       Requires%{-s:(%{-s*})}: %releq_kernel_smp
-
 # Requires name = version-release
 %requires_releq()      %{!?1:ERROR}%{?2:ERROR}%{?1:%{!?2:%{expand:%%requires_eq_to -r %1 %1}}}
 # Requires: name = version
@@ -450,22 +465,13 @@ 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)}}
 
-%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
+# helper for renaming packages
+# %rename old-package
+%rename() \
+Obsoletes: %{1} < %{?epoch:%{epoch}:}%{?version:%{version}}%{?release:-%{release}} \
+Provides: %{1} = %{?epoch:%{epoch}:}%{?version:%{version}}%{?release:-%{release}}
 
-# kernel version-release handling
-%__kernel_ver   %{expand:%%global __kernel_ver %( \\
-       Z=$([ -f '%{_kernelsrcdir}/include/generated/utsrelease.h' ] && awk -F'"' '/UTS_RELEASE/{print $2}' %{_kernelsrcdir}/include/{linux/version,generated/utsrelease}.h 2>/dev/null || awk -F'"' '/UTS_RELEASE/{print $2}' %{_kernelsrcdir}/include/linux/{version,utsrelease}.h 2>/dev/null); \\
-       Z=${Z:-$(awk -F' = ' '/^VERSION/{v=$2} /^PATCHLEVEL/{p=$2} /^SUBLEVEL/{s=$2} /^EXTRAVERSION/{e=$2} END {printf("%d.%d.%d%s", v, p, s, e)}' %{_kernelsrcdir}/Makefile 2>/dev/null)}; \\
-       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_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
-
-# `uname -r` to be used in @release field
-%_kernel_vermagic      %{expand:%%global _kernel_vermagic %(echo %{_kernel_ver} | sed -e 's/-/_/g')}%_kernel_vermagic
+%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
 
 # sgml macros
 %xmlcat_add()          /usr/bin/xmlcatalog --noout --add nextCatalog \"\" %1 /etc/xml/catalog ;
@@ -503,17 +509,41 @@ 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; \
+                       # verify that .so links point to existing files (not allowed to point to "other package") \
+                       # TODO: iterate over all man dirs, but in Th there is only one true man dir \
+                       err=$(grep -rl '^\.so ' "$RPM_BUILD_ROOT$i" | while read doc; do \
+                               l=$(grep -r '^\.so ' "$doc"); \
+                               l=${l#.so }; \
+                               d=$(dirname $doc); \
+                               test -e $RPM_BUILD_ROOT$i/$l || test -e $d/$(basename $l) || echo "  ${doc#$RPM_BUILD_ROOT} points to inexistent manpage: $l"; \
+                       done); \
+                       test "$err" != "" && { echo >&2 "Man page link errors:"; echo >&2 "$err"; exit 1; }; \
                        find "$RPM_BUILD_ROOT$i" -type f -size +%{_min_compress_bytes}c -print | xargs -r %{__gzip} -9nf; \
                fi; \
        done; \
@@ -539,6 +569,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); \
@@ -546,7 +577,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; \
@@ -558,20 +589,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; \
@@ -599,7 +630,7 @@ if [ -d "$RPM_BUILD_ROOT" ]; then \
 fi; }; __spec_install_post_strip } } }
 
 #-----------------------------------------------------------------
-# remove all RPATH from executable binaries and shared object files
+# remove all RPATH/RUNPATH from executable binaries and shared object files
 #
 # Requires: find, awk, cut, xargs, chrpath, uname
 #
@@ -609,18 +640,19 @@ 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 \
                objs=`echo "$files" | xargs -r -d'\\n' file | awk -F: '/ELF.*(executable.*dynamically linked|shared object)/ {print $1}'`; \
        fi; \
        if [ -n "$objs" ]; then \
-               printf "Remove RPATH from %d executable binaries and shared object files.\n" $(echo "$objs" | wc -l); \
+               printf "Remove RPATH/RUNPATH from %d executable binaries and shared object files.\n" $(echo "$objs" | wc -l); \
                echo "$objs" | \
                while read file; do \
                        rpath= ; \
                        chmod u+w "$file"; \
-                       for dir in $(chrpath -l "$file" | awk '/RPATH=/ { gsub(/.*RPATH=/,""); gsub(/:/," "); print $0 }'); do \
+                       for dir in $(chrpath -l "$file" | awk '/(R|RUN)PATH=/ { gsub(/.*RPATH=/,""); gsub(/.*RUNPATH=/,""); gsub(/:/," "); print $0 }'); do \
                                        case $dir in \
                                        '$ORIGIN' ) \
                                                if [ "$rpath" = "" ] ; then rpath="$dir" ; \
@@ -661,6 +693,7 @@ fi; }; __spec_install_post_chrpath } } }
 #
 %__spec_install_post_check_so { \
 __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 \
@@ -671,24 +704,62 @@ __spec_install_post_check_so() { \
 }; __spec_install_post_check_so }}
 
 #-----------------------------------------------------------------
-# Find and gzip all kernel modules
+# Verify that for each directory under /var/run package contains
+# tmpfiles.d configuration. Warn and terminate build if config is
+# missing.
 #
-# Requires: find
+#%no_install_post_check_tmpfiles 1
 #
-#%no_install_post_compress_modules     1
-%__spec_install_post_compress_modules { \
-%{!?no_install_post_compress_modules: __spec_install_post_compress_modules() { \
-       if [ -d $RPM_BUILD_ROOT/lib/modules ]; then \
-               q=$(find $RPM_BUILD_ROOT/lib/modules -name '*o' -type f -print); \
-               if [ "$q" ]; then \
-                       printf "Compress %d kernel modules..." $(echo "$q" | wc -l); \
-                       echo "$q" | xargs -r %{__gzip} -9nf; \
-                       echo "DONE"; \
-                       find $RPM_BUILD_ROOT/lib/modules -name '*o' -type l -printf "%p %l\n" | \
-                       while read a b; do ln -sf $b.gz $a.gz; rm -f $a; done; \
-               fi; \
-       fi; \
-}; __spec_install_post_compress_modules } }
+%__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 }}
+
+#-----------------------------------------------------------------
+# Verify that scripts have reasonable shebangs
+# Test spec: see "test/spec_install_post_check_shebangs" branch on packages/test.spec
+#
+#%no_install_post_check_shebangs 1
+#
+%__spec_install_post_check_shebangs { \
+__spec_install_post_check_shebangs() { \
+%{!?debug:set +x;} \
+       fail=0; \
+       echo "Checking script shebangs..."; \
+       find $RPM_BUILD_ROOT -type f -perm -500 -print | \
+       while read f ; do \
+               shebang="$(sed -e'1s/#! *\(.*\)/\1/;t;d;q' "$f")" ; \
+               f="${f##$RPM_BUILD_ROOT}"; \
+               case "$shebang" in \
+                       "%{__python}"|"%{__python3}"|"%{__python} "*|"%{__python3} "* \
+                       |"/usr/bin/python%{py_ver}"|"/usr/bin/python%{py_ver} "* \
+                       |"/usr/bin/python%{py3_ver}"|"/usr/bin/python%{py3_ver} "*) \
+                               ;; \
+                       "/usr/bin/env python"*|"/usr/bin/python"|"/usr/bin/python "*) \
+                               echo "$f starts with '#!$shebang', should be '#!%{__python}' or '#!%{__python3}'" >&2;\
+                               fail=1 ; \
+                               ;; \
+                       "/usr/bin/env "*) \
+                               echo "$f starts with '#!$shebang', should be explicit interpreter path" >&2;\
+                               fail=1 ; \
+                               ;; \
+                       *) ;;\
+               esac ; \
+       done ; \
+       echo " DONE" ; \
+}; %{!?no_install_post_check_shebangs:__spec_install_post_check_shebangs} }
 
 # Remove common Perl files we don't package
 %__spec_install_post_perl_clean {\
@@ -795,9 +866,31 @@ 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}}} \
+       %{?_noautoreq_java: %{__noauto_regexp_helper -p java %{_noautoreq_java}}} \
+       %{?_noautoreq_pyegg: %{__noauto_regexp_helper -p pythonegg %{_noautoreq_pyegg}}} \
+       %{?_noautoreq_py3egg: %{__noauto_regexp_helper -p python3egg %{_noautoreq_py3egg}}} \
+       %{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::.*
+# BuildRequires:       rpmbuild(macros) >= 1.672
+# %define _noautoreq_java ClassDataVersion
+#
+%__noauto_regexp_helper(p:) %(echo "%*" | awk 'BEGIN{RS=" "}{printf("%{-p*}%{__qchar}(%%s%{__qchar}) ", $1)}')
+# detect quote character runtime
+%__qchar_4 \\\\%{nil}
+%__qchar_5 \\\\\\%{nil}
+%__qchar %{expand:%%global __qchar %%__qchar_%(echo %{_rpmversion} | cut -c1)}%__qchar
 
 #%_noautocompressdoc   %{nil}
 #
@@ -825,17 +918,34 @@ fi; \
 
 # Ruby
 %__ruby                                /usr/bin/ruby
-%ruby_archdir          %{expand:%%global ruby_archdir %(%{__ruby} -r rbconfig -e 'print Config::CONFIG["archdir"]' 2>/dev/null || echo ERROR)}%ruby_archdir
-%ruby_ridir                    %{expand:%%global ruby_ridir %(%{__ruby} -r rbconfig -e 'include Config; print File.join(CONFIG["datadir"], "ri", CONFIG["ruby_version"], "system")' 2>/dev/null || echo ERROR)}%ruby_ridir
-%ruby_rubylibdir       %{expand:%%global ruby_rubylibdir %(%{__ruby} -r rbconfig -e 'print Config::CONFIG["rubylibdir"]' 2>/dev/null || echo ERROR)}%ruby_rubylibdir
-%ruby_vendorarchdir    %{expand:%%global ruby_vendorarchdir %(%{__ruby} -r rbconfig -e 'print Config::CONFIG["vendorarchdir"]' 2>/dev/null || echo ERROR)}%ruby_vendorarchdir
-%ruby_vendorlibdir     %{expand:%%global ruby_vendorlibdir %(%{__ruby} -r rbconfig -e 'print Config::CONFIG["vendorlibdir"]' 2>/dev/null || echo ERROR)}%ruby_vendorlibdir
-%ruby_sitearchdir      %{expand:%%global ruby_sitearchdir %(%{__ruby} -r rbconfig -e 'print Config::CONFIG["sitearchdir"]' 2>/dev/null || echo ERROR)}%ruby_sitearchdir
-%ruby_sitelibdir       %{expand:%%global ruby_sitelibdir %(%{__ruby} -r rbconfig -e 'print Config::CONFIG["sitelibdir"]' 2>/dev/null || echo ERROR)}%ruby_sitelibdir
+
+# Ruby ABI version
+# NOTE: %ruby_version may be empty, depending how Ruby was built
+%ruby_abi                      %{expand:%%global ruby_abi %(%{__ruby} -r rbconfig -e 'print [RbConfig::CONFIG["MAJOR"], RbConfig::CONFIG["MINOR"]].join(".")' 2>/dev/null || echo ERROR)}%ruby_abi
+
+# get rbconfig parameter
+%__ruby_rbconfig()     %(%{__ruby} -r rbconfig -e 'print RbConfig::CONFIG["%1"]' 2>/dev/null || echo ERROR)
+%__ruby_rbconfig_path()        %(%{__ruby} -r rbconfig -r pathname -e 'print Pathname(RbConfig::CONFIG["%1"]).cleanpath' 2>/dev/null || echo ERROR)
+
+%ruby_archdir          %{expand:%%global ruby_archdir %{__ruby_rbconfig_path archdir}}%ruby_archdir
+%ruby_libdir           %{expand:%%global ruby_libdir %{__ruby_rbconfig rubylibdir}}%ruby_libdir
+%ruby_ridir                    %{expand:%%global ruby_ridir %(%{__ruby} -r rbconfig -e 'print File.join(RbConfig::CONFIG["datadir"], "ri", RbConfig::CONFIG["ruby_version"], "system")' 2>/dev/null || echo ERROR)}%ruby_ridir
+%ruby_rubylibdir       %{expand:%%global ruby_rubylibdir %{__ruby_rbconfig_path rubylibdir}}%ruby_rubylibdir
+%ruby_vendorarchdir    %{expand:%%global ruby_vendorarchdir %{__ruby_rbconfig vendorarchdir}}%ruby_vendorarchdir
+%ruby_vendorlibdir     %{expand:%%global ruby_vendorlibdir %{__ruby_rbconfig_path vendorlibdir}}%ruby_vendorlibdir
+%ruby_sitearchdir      %{expand:%%global ruby_sitearchdir %{__ruby_rbconfig sitearchdir}}%ruby_sitearchdir
+%ruby_sitedir          %{expand:%%global ruby_sitedir %{__ruby_rbconfig sitedir}}%ruby_sitedir
+%ruby_sitelibdir       %{expand:%%global ruby_sitelibdir %{__ruby_rbconfig_path sitelibdir}}%ruby_sitelibdir
 %ruby_rdocdir          /usr/share/rdoc
-%ruby_version          %{expand:%%global ruby_version %(%{__ruby} -r rbconfig -e 'print Config::CONFIG["ruby_version"]' 2>/dev/null || echo ERROR)}%ruby_version
-%ruby_ver_requires_eq  Requires:       ruby(ver) = %ruby_version
-%ruby_mod_ver_requires_eq      Requires:       ruby-modules(ver) = %ruby_version
+%ruby_vendordir                %{expand:%%global ruby_vendordir %{__ruby_rbconfig vendordir}}%ruby_vendordir
+%ruby_version          %{expand:%%global ruby_version %(r=%{__ruby_rbconfig ruby_version}; echo ${r:-%%nil})}%ruby_version
+
+%ruby_gemdir           %{expand:%%global ruby_gemdir %(%{__ruby} -r rubygems -e 'puts Gem.respond_to?(:default_dirs) ? Gem.default_dirs[:system][:gem_dir] : Gem.path.first' 2>/dev/null || echo ERROR)}%{ruby_gemdir}
+%ruby_specdir          %{ruby_gemdir}/specifications
+
+# deprecated, ruby 2.0 noarch packages are versionless and extension dependency is generated by rpm5
+%ruby_ver_requires_eq  %{nil}
+%ruby_mod_ver_requires_eq      %{nil}
 
 %php_pear_dir          /usr/share/pear
 %php_data_dir          /usr/share/php
@@ -855,21 +965,33 @@ fi; \
 # "_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
+# NOTE: error output must be empty. otherwise can't build pecl packages if no php*-devel is installed
+%php_suffix                            %{expand:%%global php_suffix %(c=$(php-config --sysconfdir 2>/dev/null) || echo '' && echo ${c#/etc/php})%%{nil}}%php_suffix
+
+# phpXY, version always present for using current php version (in regards of php*-devel package)
+%php_versuffix                 %{expand:%%global php_versuffix %((IFS=.; set -- $(php-config --version); echo $1$2))%%{nil}}%php_versuffix
+
+# php cli. version that php headers are installed for
+%__php                                 /usr/bin/php%{php_versuffix}
+
 # helper macro
-%__php_api_requires(v:) Requires: php%{-v*}(%{expand:%1}) = %{expand:%{%{!?2:%{1}}%{?2}}}
+%__php_api_requires() 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}
@@ -884,8 +1006,8 @@ if [ -x /etc/rc.d/init.d/php-fcgi ]; then \
                %service -q php-fcgi restart \
        fi \
 fi \
-if [ -x /etc/rc.d/init.d/php-fpm ]; then \
-       %service -q php-fpm restart \
+if [ -x /etc/rc.d/init.d/%{php_name}-fpm ]; then \
+       %service -q %{php_name}-fpm restart \
 fi \
 %{nil}
 
@@ -969,16 +1091,15 @@ fi \
 
 # Python 3.x
 # python main version
-%__python3                     python3
+%__python3                     /usr/bin/python3
 %py3_ver                       %{expand:%%global py3_ver %(%{__python3} -c "import sys; print(sys.version[:3])" 2>/dev/null || echo ERROR)}%py3_ver
 
 # directories
 %py3_prefix            %{expand:%%global py3_prefix %(%{__python3} -c "import sys; print(sys.prefix)" 2>/dev/null || echo ERROR)}%py3_prefix
+%py3_incdir            %{expand:%%global py3_incdir %(%{__python3} -c "import sysconfig; print(sysconfig.get_path('include'))" 2>/dev/null || echo ERROR)}%py3_incdir
 %py3_libdir            %{py3_prefix}/%{_lib}/python%{py3_ver}
-%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_sitedir   %{py3_libdir}/site-packages
+%py3_sitescriptdir %{py3_prefix}/share/python%{py3_ver}/site-packages
 %py3_dyndir            %{py3_libdir}/lib-dynload
 
 # pure python modules compilation
@@ -986,13 +1107,87 @@ fi \
 
 %py3_ocomp             %{__python3} -O -c "import compileall; import sys; compileall.compile_dir(sys.argv[1], ddir=sys.argv[1][len('$RPM_BUILD_ROOT'):])"
 
+%py_build { \
+       LDFLAGS="${LDFLAGS:-%rpmldflags}"; export LDFLAGS; \
+       CFLAGS="${CFLAGS:-%rpmcppflags %rpmcflags}"; export CFLAGS; \
+       CXXFLAGS="${CXXFLAGS:-%rpmcppflags %rpmcxxflags}"; export CXXFLAGS; \
+       %{?__cc:CC="%{__cc}"; export CC;} \
+       %{?__cxx:CXX="%{__cxx}"; export CXX;} \
+       %{__python} setup.py \
+                               build --build-base=build-2 \
+}
+
+# "shrink" filter to keep this macro without newlines,
+# so it could be used as make arguments
+%py_install_opts() %{shrink: \
+       --prefix=%{_prefix} \
+       --install-purelib=%{py_sitescriptdir} \
+       --install-platlib=%{py_sitedir} \
+       --optimize=2 \
+}
+
+%py_install { \
+       LDFLAGS="${LDFLAGS:-%rpmldflags}"; export LDFLAGS; \
+       CFLAGS="${CFLAGS:-%rpmcppflags %rpmcflags}"; export CFLAGS; \
+       CXXFLAGS="${CXXFLAGS:-%rpmcppflags %rpmcxxflags}"; export CXXFLAGS; \
+       %{?__cc:CC="%{__cc}"; export CC;} \
+       %{?__cxx:CXX="%{__cxx}"; export CXX;} \
+       %{__python} setup.py \
+                               build --build-base=build-2 \
+                               install --skip-build \
+                               %{py_install_opts} \
+                               --root=$RPM_BUILD_ROOT \
+}
+
+%py3_build { \
+       LDFLAGS="${LDFLAGS:-%rpmldflags}"; export LDFLAGS; \
+       CFLAGS="${CFLAGS:-%rpmcppflags %rpmcflags}"; export CFLAGS; \
+       CXXFLAGS="${CXXFLAGS:-%rpmcppflags %rpmcxxflags}"; export CXXFLAGS; \
+       %{?__cc:CC="%{__cc}"; export CC;} \
+       %{?__cxx:CXX="%{__cxx}"; export CXX;} \
+       %{__python3} setup.py build --build-base=build-3 \
+}
+
+# "shrink" filter to keep this macro without newlines,
+# so it could be used as make arguments
+%py3_install_opts() %{shrink: \
+       --prefix=%{_prefix} \
+       --install-purelib=%{py3_sitescriptdir} \
+       --install-platlib=%{py3_sitedir} \
+       --optimize=2 \
+}
+
+%py3_install { \
+       LDFLAGS="${LDFLAGS:-%rpmldflags}"; export LDFLAGS; \
+       CFLAGS="${CFLAGS:-%rpmcppflags %rpmcflags}"; export CFLAGS; \
+       CXXFLAGS="${CXXFLAGS:-%rpmcppflags %rpmcxxflags}"; export CXXFLAGS; \
+       %{?__cc:CC="%{__cc}"; export CC;} \
+       %{?__cxx:CXX="%{__cxx}"; export CXX;} \
+       %{__python3} setup.py \
+                               build --build-base=build-3 \
+                               install --skip-build \
+                               %{py3_install_opts} \
+                               --root=$RPM_BUILD_ROOT \
+}
+
+# node.js libdir
+# Requirements:
+# BuildRequires: rpmbuild(macros) >= 1.634
+%nodejs_libdir         /usr/lib/node_modules
+
+# bash-completion 2.0 completions dir
+# Requirements:
+# BuildRequires: rpmbuild(macros) >= 1.673
+# Requires:    bash-completion >= 2.0
+%bash_compdir          /usr/share/bash-completion/completions
 
 # Hardlink binary identical .pyc and .pyo files
 %__spec_install_post_py_hardlink {\
 %{!?no_install_post_py_hardlink: __spec_install_post_py_hardlink() { \
-local a b c=0 t=0; \
+%{!?debug:set +x;} \
+local a b c=0 t=0 pyc=%{tmpdir}/%{name}-%{version}-%{release}__rpm_pyc; \
 if [ -d "$RPM_BUILD_ROOT" ]; then \
-       find "$RPM_BUILD_ROOT" -name '*.pyc' > __rpm_pyc; \
+       find "$RPM_BUILD_ROOT" -name '*.pyc' > $pyc; \
        while read a; do \
                b="${a%.pyc}.pyo"; \
                if cmp -s "$a" "$b"; then \
@@ -1000,22 +1195,27 @@ if [ -d "$RPM_BUILD_ROOT" ]; then \
                        c=$((c + 1)); \
                fi; \
                t=$((t + 1)); \
-       done < __rpm_pyc; \
+       done < $pyc; \
        [ $t -gt 0 ] && printf "Hardlink Python files: %d/%d files hardlinked\n" $c $t; \
-       rm -f __rpm_pyc; \
+       rm -f $pyc; \
 fi; \
 }; __spec_install_post_py_hardlink } }
 
-# remove python sources, so that check-files won't complain
-%py_postclean() \
+# Remove Python 2.x sources,
+# PLD Linux policy is to package only compiled .py[co] for Python 2.x libraries.
+# Author: Elan Ruusamäe <glen@pld-linux.org>
+#
+# Usage:
+# %py_postclean /usr/share/extra -x keepme.py,keeptoo.py
+# Options:
+# -x - comma separated of file basenames to preserve (rpmbuild(macros) >= 1.658)
+# ARGS - extra directories to clean for .py sources
+#
+# BuildRequires:       rpmbuild(macros) >= 1.189
+#
+%py_postclean(x:) \
 for d in %{py_sitescriptdir} %{py_sitedir} %*; do \
- [ ! -d "$RPM_BUILD_ROOT$d" ] || find "$RPM_BUILD_ROOT$d" -name '*.py' -print0 | xargs -0r -l512 rm;\
-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;\
+       [ ! -d "$RPM_BUILD_ROOT$d" ] || find "$RPM_BUILD_ROOT$d" -name '*.py' -print0 %{-x:| grep -ZzvE '/(%(echo '%{-x*}' | tr ',' '|'))$'} | xargs -0r -l512 rm;\
 done \
 %{nil}
 
@@ -1045,8 +1245,6 @@ 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/;s/arm.*/arm/')}%_target_base_arch
-
 # user/group checking macros
 #
 # Usage:
@@ -1232,8 +1430,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
 #
@@ -1377,7 +1574,7 @@ echo -e "</dependencies>\\n" >> %{_mavendepmapdir}/maven2-depmap.xml
 # JAVA macros specific for PLD
 
 # Directory for tomcat context configuration files
-%_tomcatconfdir        %{_sharedstatedir}/tomcat/conf/Catalina/localhost
+%_tomcatconfdir        /etc/tomcat/Catalina/localhost
 
 # Tomcat cache path
 %_tomcatcachedir %{_sharedstatedir}/tomcat/work/Catalina/localhost
@@ -1436,7 +1633,7 @@ fi \
 
 # 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 %{php_pear_dir}/pearcmd.php
+%__pear        %__php -doutput_buffering=1 -dopen_basedir="" -dmemory_limit=-1 -ddate.timezone=GMT /usr/share/pear/pearcmd.php
 
 %pear_install(a:d:n:zD) \
 %__pear \\\
@@ -1504,6 +1701,7 @@ fi \
 f = io.open("%{_docdir}/%{name}-%{version}/optional-packages.txt", "r") \
 if f then \
        for l in f:lines() do print(l); end \
+       f:close() \
 end \
 %{nil}
 
@@ -1555,170 +1753,45 @@ done \
 
 %env_update [ ! -x /sbin/env-update ] || /sbin/env-update -u || :
 
-
-# Build modules for kernels 2.6
-# Author: Przemyslaw Iskra <sparky@pld-linux.org>
-#
-# Usage:
-#      %build_kernel_modules -m <modules> -C <directory>
-#
-#  remember that proper Makefile is still required
-# Options:
-#  -m <modules> (required) -- comma-separated list of modules to save,
-#              without .ko extension, may be placed in subdirectory
-#  -C <directory> -- change to <directory> before doing anything
-#  -p <arg>, -P <arg> -- arguments passeed to make scripts
-#  -c -- do not execute make clean
-#  <additional arguments> -- all additional arguments will be passed to
-#              make modules
-#
-# Additional patching supported via here document. Try:
-#      %build_kernel_modules -m module <<'EOF'
-#      your patch script here
-#      EOF
-# Don't use it unless patching depends on config options.
-
-# Developer note: don't touch it unless you know how to handle '\'.
-# - \ in script expands to nothing
-# - \\\ in script expands to \
-# - \\\ inside definition expands to nothing
-# - \\\\\\\ inside definition expands to \
-# - in last line \ has to touch arguments so arguments passing
-#   in new lines (using \) will be supported
-
-%build_kernel_modules(p:P:m:C:c)                                                                       \
-%{!?-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"  \\\
-       CC="%{kgcc}" ARCH=%{_target_base_arch}                                                  \\\
-       %else                                                                                                                   \\\
-       ARCH=%{_target_base_arch} CROSS_COMPILE=%{_target_cpu}-pld-linux- \\\
-       %endif                                                                                                                  \\\
-%else                                                                                                                          \\\
-       CC="%{kgcc}"                                                                                                    \\\
-%endif                                                                                                                         \
-%define        MakeOpts HOSTCC="%{kgcc}" SYSSRC=%{_kernelsrcdir} SYSOUT=$PWD/o \\\\\\\
-               O=$PWD/o %{?with_verbose:V=1} %{Opts}                                           \
-                                                                                                                                       \
-%{?-C:cd %{-C*}}                                                                                                       \
-compile() {                                                                                                                    \
-       local L="<" PATCH_SH;                                                                                   \
-       [[ '%{*}' != *$L$L* ]] || PATCH_SH="set -x -e;$(cat)"                   \
-       set -e -x                                                                                                               \
-       local cfgs='%{?with_dist_kernel:%{?with_smp: smp}%{?with_up: up}}%{!?with_dist_kernel: nondist}' \
-                                                                                                                                       \
-for cfg in ${cfgs:-dist}; do                                        \
-       [ -r "%{_kernelsrcdir}/config-$cfg" ] || exit 1                                 \
-                                                                                                                                       \
-       rm -rf o                                                                                                                \
-       install -d o/include/linux o/include/generated o/arch/powerpc/lib       \
-       ln -sf %{_kernelsrcdir}/config-$cfg o/.config                                   \
-       ln -sf %{_kernelsrcdir}/Module.symvers-$cfg o/Module.symvers    \
-       if [ -f %{_kernelsrcdir}/include/generated/autoconf-$cfg.h ]; then      \
-               ln -sf %{_kernelsrcdir}/include/generated/autoconf-$cfg.h o/include/generated/autoconf.h \
-               ln -s ../generated/autoconf.h o/include/linux/autoconf.h \
-       else                                                                                                                    \
-               ln -sf %{_kernelsrcdir}/include/linux/autoconf-$cfg.h o/include/linux/autoconf.h \
-       fi                                                                                                                              \
-                                                                                                                                       \
-       set +x                                                                                                                  \
-       [ -z "$PATCH_SH" ] || echo "$PATCH_SH" | %__spec_build_shell    \
-       set -x                                                                                                                  \
-                                                                                                                                       \
-       %if %{with dist_kernel} || %(test -f %{_kernelsrcdir}/scripts/bin2c ; echo $?)  \
-               %{__make} -j1 -C %{_kernelsrcdir} prepare scripts                       \\\
-                       %{-p*} %{-P*}                                                                                   \\\
-                       %{MakeOpts}                                                                                             \
-       %else                                                                                                                   \
-               install -d o/include/config                                                                     \
-               touch o/include/config/MARKER                                                           \
-               ln -sf %{_kernelsrcdir}/include/config/auto-$cfg.conf o/include/config/auto.conf        \
-               ln -sf %{_kernelsrcdir}/scripts o/scripts                                       \
-       %endif                                                                                                                  \
-                                                                                                                                       \
-       %{!?-c:%{__make} -C %{_kernelsrcdir} clean                                              \\\
-               RCS_FIND_IGNORE="-name '*.ko' -o"                                                       \\\
-               ${1+"$@"}                                                                                                       \\\
-               M=$PWD %{MakeOpts}}                                                                                     \
-                                                                                                                                       \
-       %{__make} -C %{_kernelsrcdir} modules                                                   \\\
-               ${1+"$@"}                                                                                                       \\\
-               M=$PWD %{MakeOpts}                                                                                      \
-                                                                                                                                       \
-       for MODULE in {%{-m*},}; do                                                                             \
-               [ -z "${MODULE}" ] || mv ${MODULE}{,-$cfg}.ko                           \
-       done                                                                                                                    \
-done                                                                                                                           \
-%{?-C:cd -}                                                                                                                    \
-}                                                                                                                                      \
-compile %{*}\
-%{nil}
-
-
-# Install kernel modules built by %build_kernel_modules
-# Author: Przemyslaw Iskra <sparky@pld-linux.org>
-#
-# Usage:
-#      %install_kernel_modules -m <modules> -d <directory>
-#
-# Options:
-#  -m <modules> (required) -- comma-separated list of modules to install,
-#              without .ko extension, may be placed in subdirectory
-#  -d <directory> (required) -- in what subdirectory modules should be
-#              installed (eg. misc, kernel/drivers/net)
-#  -s <suffix> -- suffix to use when installing modules, useful when module
-#              with same name exists in kernel already
-#  -n <file> -- name of modprobe config file to use (without .conf extension)
-#              for defining aliases, only useful with -s
-
-%install_kernel_modules(m:d:s:n:)                                                                      \
-%{!?-m:%{error:%{0}: Required module name (-m) missing}exit 1}         \
-%{!?-d:%{error:%{0}: Required module directory missing}exit 1}         \
-%{?-n:%{!?-s:%{error:%{0}: Modprobe .conf file requires module suffix}exit 1}} \
-                                                                                                                                       \
-%define KernelD $RPM_BUILD_ROOT/lib/modules/%{_kernel_ver}                     \
-%define ModprobeD $RPM_BUILD_ROOT%{_sysconfdir}/modprobe.d/%{_kernel_ver} \
-                                                                                                                                       \
-__install_kernel_modules() {                                                                           \
-local cfgs='%{?with_dist_kernel:%{?with_smp: smp}%{?with_up: up}}%{!?with_dist_kernel: nondist}' \
-                                                                                                                                       \
-for MODULE in {%{-m*},}; do                                                                                    \
-       [ -n "${MODULE}" ] || continue                                                                  \
-       for cfg in ${cfgs:-dist}; do                                    \
-               [ "$cfg" = smp ] && suf=smp || suf=                                                     \
-               MNAME=${MODULE##*/}                                                                                     \
-               install -D ${MODULE}-$cfg.ko                                                            \\\
-                       %{KernelD}$suf/%{-d*}/${MNAME}%{-s:-%{-s*}}.ko                  \
-               %{?-s:install -d %{ModprobeD}$suf                                                       \
-                       echo "alias ${MNAME} ${MNAME}-%{-s*}"                                   \\\
-                       >> %{ModprobeD}$suf/%{-n*}.conf}                                                \
-       done                                                                                                                    \
-done                                                                                                                           \
-}                                                                                                                                      \
-__install_kernel_modules                                                                                       \
-%{nil}
-
 # patchset macros
+# generate SourceX urls from range START STOP
+# Format can be SINGLE format char of %e, %f, %g, see seq(1)
+# The sources start from 10000
+#
 # Author: Elan Ruusamäe <glen@pld-linux.org>
 #
 # Usage:
 #   %patchset_source -f <seq(1) format> <start> [<end>]
 #   %patchset_patch <start> [<end>]
-#
 # If <end> is omited, it is assumed to be <start>.
 #
 # For example in preamble:
 #  %patchset_source -f ftp://ftp.vim.org/pub/editors/vim/patches/7.0/7.0.%03g 33 44
 # and in %prep:
 #  %patchset_patch 33 44
-
-# generate SourceX urls from range START STOP
-# Format can be SINGLE format char of %e, %f, %g, see seq(1)
-# The sources start from 10000
-%patchset_source(f:b:) %(
-       base=%{-b*}%{!-b*:10000};
+#
+# Using sources list:
+#   BuildRequires:     rpmbuild(macros) >= 1.426
+#   %patchset_source -f <url> -s <filelist>
+#   %patchset_patch -s <filelist>
+# For example (ncurses):
+#   BuildRequires:     rpmbuild(macros) >= 1.683
+#   %patchset_source -f ftp://dickey.his.com/ncurses/%{basever}/ -s sources
+#   %patchset_patch -s sources -p1
+#
+
+%patchset_source(f:b:s:) %(
+       base=%{-b*}%{!-b*:10000}
+%{-s:
+       baseurl='%{-f*}'
+       filelist='%{-s*}'
+       i=$base
+       while read checksum file; do
+               printf "Patch%d: %s%s\\n" $i "$baseurl" "$file"
+               i=$((i+1))
+       done < $filelist
+}
+%{!-s:
        start=$(expr $base + %1);
        end=$(expr $base + %{?2}%{!?2:%{1}});
        # we need to call seq twice as it doesn't allow two formats
@@ -1726,21 +1799,37 @@ __install_kernel_modules                                                                                        \
        seq -f '%{-f*}' %1 %{?2}%{!?2:%{1}} > %{tmpdir}/__ps2;
        paste %{tmpdir}/__ps{1,2};
        rm -f %{tmpdir}/__ps{1,2};
+}
 ) \
 %{nil}
 
 # apply sources from %patchset_source
 # -p specify -pX for %patch line
 # -b base offset: defaults to 10000
-%patchset_patch(f:p:b:) %(
-       base=%{-b*}%{!-b*:10000};
+# -s filelist to read files from
+%patchset_patch(f:p:b:s:) %(
+       base=%{-b*}%{!-b*:10000}
+       patchlevel=%{-p*:-p%{-p*}}
+%{-s:
+       filelist='%{-s*}'
+       i=$base
+       while read checksum file; do
+               printf "patch%d %s\\n" $i "$patchlevel" | sed -e s,^,%%,
+               i=$((i+1))
+       done < $filelist
+}
+%{!-s:
        start=$(expr $base + %1);
        end=$(expr $base + %{?2}%{!?2:%{1}});
        echo ": patchset_patch %1%{?2: to %2}";
-       seq -f 'patch%g %{-p*:-p%{-p*}}' $start $end | sed -e s,^,%%,;
+       seq -f "patch%g $patchlevel" $start $end | sed -e s,^,%%,;
+}
 ) \
 %{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>
 #
@@ -1802,7 +1891,11 @@ end\
 for _, s in ipairs({%{expand:%%__lua_split %*}}) do\
        if not t[s] then\
                print("Adding "..s.." to /etc/shells")\
-               f = io.open("/etc/shells", "a"); f:write(s.."\\n"); f:close()\
+               f = io.open("/etc/shells", "a")\
+               if f then\
+                       f:write(s.."\\n")\
+                       f:close()\
+               end\
        end\
 end\
 %{nil}
@@ -1822,7 +1915,11 @@ s=""\
 for _, l in pairs(t) do\
        s=s..l.."\\n"\
 end\
-io.open("/etc/shells", "w"):write(s)\
+f = io.open("/etc/shells", "w")\
+if f then\
+       f:write(s)\
+       f:close()\
+end\
 %{nil}
 
 # Backwards compat. Use of %lua_ prefixed macros is preferred as these are cleaner to read.
@@ -1862,6 +1959,7 @@ io.open("/etc/shells", "w"):write(s)\
 
 %py_lint() \
 __py_lint() { \
+%{!?debug:set +x;} \
 find "$@" -type f -name '*.py' | python -c ' \
 import sys \
 import compiler \
@@ -1913,11 +2011,11 @@ else: \
 #
 # Requirements:
 # BuildRequires:       sed >= 4.0
-# BuildRequires:       rpmbuild(macros) >= 1.565
+# BuildRequires:       rpmbuild(macros) >= 1.674
 
 # 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$,,' %* \
+%undos(f:i)    %{-f:%{__find} -type f -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.
@@ -1939,20 +2037,25 @@ else: \
 # Requirements:
 # Requires:                    grep
 # Requires:                    sed >= 4.0
-# BuildRequires:       rpmbuild(macros) >= 1.552
+# BuildRequires:       rpmbuild(macros) >= 1.685
 %nagios_nrpe(a:d:c:f:) {\
-       m=$(md5sum < /etc/nagios/nrpe.cfg); \
+       if %{__grep} -q '^include_dir=/etc/nagios/nrpe.d' /etc/nagios/nrpe.cfg && [ -d /etc/nagios/nrpe.d ]; then \
+               file=/etc/nagios/nrpe.d/%{-a*}%{-d*}.cfg; \
+       else \
+               file=/etc/nagios/nrpe.cfg; \
+       fi; \
+       m=$(test -f $file && md5sum < $file); \
        %{-a:# on -a and config exists \
        if [ -f /etc/nagios/nrpe.cfg ]; then \
-               if ! %{__grep} -q '^command\[%{-a*}\]' /etc/nagios/nrpe.cfg; then \
-                               %{__sed} -ne 's/^[ \t]*command_line[ \t]\+\(.\+\)/command[%{-a*}]=\1/p' %{-f*} >> /etc/nagios/nrpe.cfg; \
+               if [ ! -f $file ] || ! %{__grep} -q '^command\[%{-a*}\]' $file; then \
+                       %{__sed} -ne 's/^[ \t]*command_line[ \t]\+\(.\+\)/command[%{-a*}]=\1/p' %{-f*} >> $file; \
                fi; \
        fi;} \
        %{-d:# on package remove, -d and config exists \
-       if [ "$1" = "0" -a -f /etc/nagios/nrpe.cfg ]; then \
-               %{__sed} -i -e '/^[ \t]*command\[%{-d*}\]/d' /etc/nagios/nrpe.cfg; \
+       if [ "$1" = "0" -a -f $file ]; then \
+               %{__sed} -i -e '/^[ \t]*command\[%{-d*}\]/d' $file; \
        fi;} \
-       if [ "$m" != "$(md5sum < /etc/nagios/nrpe.cfg)" ]; then \
+       if [ "$m" != "$(md5sum < $file)" ]; then \
                %service -q nrpe restart; \
        fi; \
 }%{nil}
@@ -1970,15 +2073,21 @@ 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
 #
 # Author: Jacek Konieczny <jajcus@jajcus.net>
+# Author: Elan Ruusamäe <glen@pld-linux.org>
 #
 # Usage:
 #      %upstart_post service_name
@@ -1992,15 +2101,16 @@ else: \
 # %upstart_postun %{name}
 #
 # Requirements:
-# BuildRequires:       rpmbuild(macros) >= 1.560
+# BuildRequires:       rpmbuild(macros) >= 1.690
 # Requires:                    rc-scripts >= 0.4.3
 
 # migrate from init script to upstart job
 %upstart_post() \
-       if [ -f /var/lock/subsys/%1 ]; then \
+       if [ -x /sbin/initctl ] && [ -f /var/lock/subsys/%1 ]; then \
                /sbin/service --no-upstart %1 stop \
                /sbin/service %1 start \
-       fi
+       fi \
+%{nil}
 
 # 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
@@ -2009,7 +2119,8 @@ else: \
        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
+       fi \
+%{nil}
 
 # Haskell Macros
 # BuildRequires:  rpmbuild(macros) >= 1.608
@@ -2021,8 +2132,134 @@ else: \
 #
 %ghc_pkg_recache() {{ \
        umask 022; \
-       /usr/bin/ghc-pkg recache; \
+       [ ! -x /usr/bin/ghc-pkg ] || /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.671
+# 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 \
+       [ "$(echo /etc/rc.d/rc[0-6].d/S[0-9][0-9]${1%.service})" = "/etc/rc.d/rc[0-6].d/S[0-9][0-9]${1%.service}" ] && 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
+%systemduserunitdir /usr/lib/systemd/user
+%systemdtmpfilesdir /usr/lib/tmpfiles.d
+
+#-----------------------------------------------------------------
+# Update hardware database index
+#
+# Requirements:
+# BuildRequires:       rpmbuild(macros) >= 1.691
+# Requires:            udev-core >= 1:196
+
+%udev_hwdb_update() \
+/sbin/udevadm hwdb --update >/dev/null 2>&1 || : \
+%{nil}
+
 # EOF
This page took 0.110824 seconds and 4 git commands to generate.