]> git.pld-linux.org Git - packages/rpm-build-macros.git/blobdiff - rpm.macros
- you want to quote the args with spaces, also support shell env of xxxFLAGS
[packages/rpm-build-macros.git] / rpm.macros
index 8eb7214b4362e683f8151bf2c233487e39f604b7..ad18aadaf456749232390ac8623b48fc835ed9d8 100644 (file)
@@ -1,4 +1,6 @@
 # $Revision$, $Date$
+# vim:ts=4 sw=4 noet ft=spec
+#
 # PLD Linux rpm macros.
 # <http://www.pld-linux.org/>
 
@@ -7,14 +9,15 @@
 
 %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
 
        %{dependencytracking} \
 }
 
-%cmake { \
-CC="%{__cc}" \
-CXX="%{__cxx}" \
-CFLAGS="%{rpmcflags}" \
-CXXFLAGS="%{rpmcxxflags}" \
-LDFLAGS="%{rpmldflags}" \
-%{__cmake} \
-}
+%cmake \
+%{?__cc:CC="%{__cc}"} \\\
+%{?__cxx:CXX="%{__cxx}"} \\\
+CPPFLAGS="${CPPFLAGS:-%{rpmcppflags}}" \\\
+CFLAGS="${CFLAGS:-%{rpmcflags}}" \\\
+FFLAGS="${FFLAGS:-%{rpmcflags}}" \\\
+FCFLAGS="${FCFLAGS:-%{rpmcflags}}" \\\
+CXXFLAGS="${CXXFLAGS:-%{rpmcxxflags}}" \\\
+LDFLAGS="${LDFLAGS:-%{rpmldflags}}" \\\
+%{__cmake} \\\
+       -DCMAKE_VERBOSE_MAKEFILE=ON \\\
+       -DCMAKE_BUILD_TYPE=%{!?debug:Release}%{?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="${CXXFLAGS:-%{rpmcxxflags}" \\\
+       -DCMAKE_CPP_FLAGS="${CPPFLAGS:-%{rpmcppflags}}" \\\
+       -DCMAKE_C_FLAGS="${CFLAGS:-%{rpmcflags}}" \\\
+%if "%{_lib}" == "lib64" \
+       -DLIB_SUFFIX=64 \\\
+%endif \
+       -DBUILD_SHARED_LIBS:BOOL=ON \\\
+%{nil}
 
 %scons { \
 %{__scons} \
@@ -350,7 +371,7 @@ CXXFLAGS="%{rpmcxxflags}" \
 %{nil}
 
 # Location of autoconf macros
-%_aclocaldir   %{expand:%%global _aclocaldir %(aclocal --print-ac-dir || echo ERROR)}%_aclocaldir
+%_aclocaldir   %{expand:%%global _aclocaldir %(aclocal --print-ac-dir 2>/dev/null || echo ERROR)}%_aclocaldir
 
 # Location of omf files
 %_omf_dest_dir %{expand:%%global _omf_dest_dir %(scrollkeeper-config --omfdir || echo ERROR)}%_omf_dest_dir
@@ -400,6 +421,15 @@ CXXFLAGS="%{rpmcxxflags}" \
 # If non-empty "debug" macro defined, add "dbg" suffix to release number
 %_rpmfilename          %%{NAME}-%%{VERSION}-%%{RELEASE}%{?debug:dbg}.%%{ARCH}.rpm
 
+# Bootstrap release macros.
+# Usage:
+#      %bcond_with     bootstrap
+#      Release:        %{bootstrap_release 1}
+#
+# Package will have release 1 if built normally,
+# 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
@@ -417,6 +447,11 @@ CXXFLAGS="%{rpmcxxflags}" \
 # Requires: name = version (version based on querying package %2)
 %requires_eq_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)}}
 
+# Requires: name >= version
+%requires_ge()         %{!?1:ERROR}%{?2:ERROR}%{?1:%{!?2:%{expand:%%requires_ge_to %1 %1}}}
+# 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
 
 # kernel version-release handling
@@ -619,15 +654,22 @@ 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() { \
+       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 }}
 
 #-----------------------------------------------------------------
@@ -705,11 +747,13 @@ fi; \
 
 #-----------------------------------------------------------------
 # Update icon cache
-# requires: gtk+
+# BuildRequires:  rpmbuild(macros) >= 1.596
+# Requires:  hicolor-icon-theme
 #
 %update_icon_cache() {{ \
+       %{!?1:%{error:%{0}: Required icon dir missing}exit 1} \
        umask 022; \
-       /usr/bin/gtk-update-icon-cache -qf %{_datadir}/icons/%1; \
+       [ -x /usr/bin/gtk-update-icon-cache ] && /usr/bin/gtk-update-icon-cache -qf %{_datadir}/icons/%1 || :; \
 };} \
 %{nil}
 
@@ -727,6 +771,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
@@ -796,7 +850,9 @@ 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}
 
 # helper macro
 %__php_api_requires(v:) Requires: php%{-v*}(%{expand:%1}) = %{expand:%{%{!?2:%{1}}%{?2}}}
@@ -806,13 +862,13 @@ fi; \
 %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 -v %php_major_version 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 -v %php_major_version thread-safety _zend_zts}
 
 # for php pdo modules (php-pecl-PDO_*)
 %requires_php_pdo_module %{__php_api_requires PDO_API php_pdo_api_version}
@@ -987,7 +1043,7 @@ 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
+%_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
 #
@@ -1022,7 +1078,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
@@ -1033,12 +1089,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 \
@@ -1046,7 +1106,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
@@ -1205,11 +1265,25 @@ fi \
 # Directory where arch-specific (JNI) version-independent jars are installed.
 %_jnidir               %{_libdir}/java
 
-%java_home             %{expand:%%global java_home %([ -f %{_javadir}-utils/java-functions ] || { echo ERROR; exit 0; }; unset JAVA_HOME; . %{_javadir}-utils/java-functions; set_jvm; echo ${JAVA_HOME:-ERROR})}%java_home
+
+# JDK selection. Set this to name of the JDK implementation to use
+# insead of the system default
+#%use_jdk              icedtea6
+
+# expands to the value with right jdk for BuildRequires header
+# 'jdk' if %%use_jdk is not defined,  jdk(%%use_jdk) otherwise
+# The requirement will not replace current 'default' JDK
+%required_jdk  jdk%{?use_jdk:(%{use_jdk})}
+
+%buildrequires_jdk BuildRequires: %required_jdk
+
+%java_home             %{expand:%%global java_home %([ -f %{_javadir}-utils/java-functions ] || { echo ERROR; exit 0; }; %{!?use_jdk:unset JAVA_HOME; . %{_javadir}-utils/java-functions; set_jvm}%{?use_jdk:JAVA_HOME=%{_jvmdir}/%{use_jdk}}; echo ${JAVA_HOME:-ERROR})}%java_home
+
+%_javasrcdir   %{_usrsrc}/java
 
 %ant                   JAVA_HOME=%{java_home} CLASSPATH=$CLASSPATH ant
 %jar                   %{java_home}/bin/jar
-%java                  %{expand:%%global java %([ -f %{_javadir}-utils/java-functions ] || { echo ERROR; exit 0; }; unset JAVACMD; . %{_javadir}-utils/java-functions; set_javacmd; echo $JAVACMD)}%java
+%java                  %{expand:%%global java %([ -f %{_javadir}-utils/java-functions ] || { echo ERROR; exit 0; }; %{!?use_jdk:unset JAVACMD; . %{_javadir}-utils/java-functions; set_javacmd}%{?use_jdk:JAVACMD=%{java_home}/bin/java}; echo $JAVACMD)}%java
 %javac                 %{java_home}/bin/javac
 %javadoc               %{java_home}/bin/javadoc
 
@@ -1324,10 +1398,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
@@ -1349,7 +1424,7 @@ echo -e "</dependencies>\\n" >> %{_mavendepmapdir}/maven2-depmap.xml
 %__pear_install_log \
 tee install.log \
 # make post message of optional packages \
-grep 'can optionally use' 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-,;s,^channel://.*/,,' > 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 \
@@ -1357,10 +1432,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 %{php_pear_dir}/pearcmd.php
 
-%pear_install(a:n:zD) \
+%pear_install(a:d:n:zD) \
 %__pear \\\
        -c %{builddir}/pearrc \\\
        -d doc_dir=/docs \\\
@@ -1369,6 +1445,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 \\\
@@ -1382,27 +1459,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 \
@@ -1411,6 +1490,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>
@@ -1793,15 +1887,122 @@ 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.533
+# BuildRequires:       rpmbuild(macros) >= 1.565
 
-%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}
 
-# vim:ts=4 sw=4 noet ft=spec
+# Hook to register nagios object based plugins in Nagios NRPE daemon config.
+#
+# Author: Elan Ruusamäe <glen@pld-linux.org>
+#
+# Usage:
+#  -a NAME  -- add command named NAME
+#  -d NAME  -- remove command named NAME
+#  -f FILE  -- specify plugin configuration FILE to extract command definition from
+#
+# Sample:
+# %triggerin -- nagios-nrpe
+# %nagios_nrpe -a %{plugin} -f %{_sysconfdir}/%{plugin}.cfg
+#
+# %triggerun -- nagios-nrpe
+# %nagios_nrpe -d %{plugin} -f %{_sysconfdir}/%{plugin}.cfg
+#
+# Requirements:
+# Requires:                    grep
+# Requires:                    sed >= 4.0
+# BuildRequires:       rpmbuild(macros) >= 1.552
+%nagios_nrpe(a:d:c:f:) {\
+       m=$(md5sum < /etc/nagios/nrpe.cfg); \
+       %{-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; \
+               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; \
+       fi;} \
+       if [ "$m" != "$(md5sum < /etc/nagios/nrpe.cfg)" ]; then \
+               %service -q nrpe restart; \
+       fi; \
+}%{nil}
+
+# Import or update Cacti template.
+#
+# Author: Elan Ruusamäe <glen@pld-linux.org>
+#
+# Usage:
+# %cacti_import_template XMLFILE
+#  XMLFILE -- XML template to import
+#
+# Sample:
+# %post
+# %cacti_import_template %{resourcedir}/cacti_host_template_varnish.xml
+#
+# Requires:    cacti >= 0.8.7e-8
+# BuildRequires:       rpmbuild(macros) >= 1.554
+
+%cacti_import_template() {\
+/usr/share/cacti/cli/import_template.php --filename=%1 || :; \
+}%{nil}
+
+# pre/post script for -upstart subpackages
+#
+# Author: Jacek Konieczny <jajcus@jajcus.net>
+#
+# Usage:
+#      %upstart_post service_name
+#   %upstart_postun service_name
+#
+# Sample:
+# %post upstart
+# %upstart_post %{name}
+#
+# %postun upstart
+# %upstart_postun %{name}
+#
+# Requirements:
+# BuildRequires:       rpmbuild(macros) >= 1.560
+# Requires:                    rc-scripts >= 0.4.3
+
+# 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 \
+       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; }; \
+       fi
+
+# EOF
This page took 0.134285 seconds and 4 git commands to generate.