]> git.pld-linux.org Git - packages/rpm-build-macros.git/blobdiff - rpm.macros
autotag: make git complatible (however needs to be in package dir)
[packages/rpm-build-macros.git] / rpm.macros
index 3443913e2ef93a61a49a88d09f8274621bcbdd2a..9bcf7a7d3b57f768f0311ba589eb7b141a799d0c 100644 (file)
@@ -37,7 +37,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 \
@@ -503,7 +503,7 @@ 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}; \
+       %{!?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"; \
@@ -521,7 +521,9 @@ CXXFLAGS="%{rpmcxxflags}" \
                                        l=${l#/usr/share/man/}; \
                                        l=${l#/usr/X11R6/man/}; \
                                else \
-                                       l=$m; \
+                                       l=${a#$RPM_BUILD_ROOT$i/}; \
+                                       l=${l%/*}; \
+                                       l="$l/$m"; \
                                fi; \
                                rm -f $a; \
                                echo ".so $l" > $a; \
@@ -552,7 +554,7 @@ CXXFLAGS="%{rpmcxxflags}" \
 #
 %__spec_install_post_strip {%{!?debug: \
 %{!?no_install_post_strip:__spec_install_post_strip() { \
-%{!?debug:set +x}; \
+%{!?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); \
@@ -560,7 +562,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; \
@@ -623,7 +625,7 @@ fi; }; __spec_install_post_strip } } }
 #
 %__spec_install_post_chrpath {%{!?debug: \
 %{!?no_install_post_chrpath: __spec_install_post_chrpath() { \
-%{!?debug:set +x}; \
+%{!?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 \
@@ -676,7 +678,7 @@ fi; }; __spec_install_post_chrpath } } }
 #
 %__spec_install_post_check_so { \
 __spec_install_post_check_so() { \
-%{!?debug:set +x}; \
+%{!?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 \
@@ -686,6 +688,30 @@ __spec_install_post_check_so() { \
        %{!?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
 #
@@ -694,7 +720,7 @@ __spec_install_post_check_so() { \
 #%no_install_post_compress_modules     1
 %__spec_install_post_compress_modules { \
 %{!?no_install_post_compress_modules: __spec_install_post_compress_modules() { \
-%{!?debug:set +x}; \
+%{!?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 \
@@ -1003,11 +1029,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}; \
+%{!?debug:set +x;} \
 local a b c=0 t=0; \
 if [ -d "$RPM_BUILD_ROOT" ]; then \
        find "$RPM_BUILD_ROOT" -name '*.pyc' > __rpm_pyc; \
@@ -1244,8 +1274,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
 #
@@ -1448,7 +1477,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 \\\
@@ -1616,6 +1645,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                                                                                                               \
@@ -1651,13 +1719,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                           \
@@ -1665,7 +1733,11 @@ for cfg in ${cfgs:-dist}; do                                        \
 done                                                                                                                           \
 %{?-C:cd -}                                                                                                                    \
 }                                                                                                                                      \
-compile %{*}\
+if [ -r "%{_kernelsrcdir}/.config" ]; then     \
+       compile %{*}                                                    \
+else                                                                           \
+       compile_old %{*}                                                \
+fi                                                                                     \
 %{nil}
 
 
@@ -1694,7 +1766,18 @@ compile %{*}\
 %define ModprobeD $RPM_BUILD_ROOT%{_sysconfdir}/modprobe.d/%{_kernel_ver} \
                                                                                                                                        \
 __install_kernel_modules() {                                                                           \
-%{!?debug:set +x}; \
+%{!?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                                                                                    \
@@ -1710,7 +1793,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
@@ -1754,6 +1841,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>
 #
@@ -1875,7 +1965,7 @@ io.open("/etc/shells", "w"):write(s)\
 
 %py_lint() \
 __py_lint() { \
-%{!?debug:set +x}; \
+%{!?debug:set +x;} \
 find "$@" -type f -name '*.py' | python -c ' \
 import sys \
 import compiler \
@@ -1984,10 +2074,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
@@ -2039,4 +2134,118 @@ else: \
 };} \
 %{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.044586 seconds and 4 git commands to generate.