]> git.pld-linux.org Git - packages/rpm-build-macros.git/blobdiff - rpm.macros
- use systemd_booted to check if system is booted using systemd
[packages/rpm-build-macros.git] / rpm.macros
index ad18aadaf456749232390ac8623b48fc835ed9d8..d41f57b696487a62410fc098924d1f9e5b9a5c8f 100644 (file)
 %{?__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_BUILD_TYPE=%{!?debug:PLD}%{?debug:Debug} \\\
        -DCMAKE_INSTALL_LIBDIR:PATH=%{_libdir} \\\
        -DCMAKE_INSTALL_PREFIX:PATH=%{_prefix} \\\
        -DINCLUDE_INSTALL_DIR:PATH=%{_includedir} \\\
        -DLIB_INSTALL_DIR:PATH=%{_libdir} \\\
        -DSHARE_INSTALL_PREFIX:PATH=%{_datadir} \\\
        -DSYSCONF_INSTALL_DIR:PATH=%{_sysconfdir} \\\
-       -DCMAKE_CXX_FLAGS="${CXXFLAGS:-%{rpmcxxflags}" \\\
-       -DCMAKE_CPP_FLAGS="${CPPFLAGS:-%{rpmcppflags}}" \\\
-       -DCMAKE_C_FLAGS="${CFLAGS:-%{rpmcflags}}" \\\
+       -DCMAKE_CXX_FLAGS_PLD="${CXXFLAGS:-%{rpmcxxflags} -DNDEBUG}" \\\
+       -DCMAKE_C_FLAGS_PLD="${CFLAGS:-%{rpmcflags} -DNDEBUG}" \\\
+       -DCMAKE_Fortran_FLAGS_PLD="${CFLAGS:-%{rpmcflags} -DNDEBUG}" \\\
+       -DCMAKE_EXE_LINKER_FLAGS_PLD="${LDFLAGS:-%{rpmldflags}}" \\\
+       -DCMAKE_SHARED_LINKER_FLAGS_PLD="${LDFLAGS:-%{rpmldflags}}" \\\
+       -DCMAKE_MODULE_LINKER_FLAGS_PLD="${LDFLAGS:-%{rpmldflags}}" \\\
 %if "%{_lib}" == "lib64" \
        -DLIB_SUFFIX=64 \\\
 %endif \
@@ -505,16 +503,29 @@ 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=$m; \
+                               fi; \
                                rm -f $a; \
-                               echo .so ${m##*/} > $a; \
-                               echo >&2 "Converted ${a#$RPM_BUILD_ROOT} from symlink to man link: ${m##*/}"; \
+                               echo ".so $l" > $a; \
+                               echo >&2 "Converted ${a#$RPM_BUILD_ROOT} from symlink to man link: $l"; \
                        done; \
                        find "$RPM_BUILD_ROOT$i" -type f -size +%{_min_compress_bytes}c -print | xargs -r %{__gzip} -9nf; \
                fi; \
@@ -541,6 +552,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); \
@@ -548,7 +560,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; \
@@ -560,20 +572,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; \
@@ -611,6 +623,7 @@ fi; }; __spec_install_post_strip } } }
 #
 %__spec_install_post_chrpath {%{!?debug: \
 %{!?no_install_post_chrpath: __spec_install_post_chrpath() { \
+%{!?debug:set +x;} \
 if [ -d "$RPM_BUILD_ROOT" ]; then \
        files=`find $RPM_BUILD_ROOT -type f ! -regex ".*ld-[0-9.]*so.*" ! -regex ".*/usr/lib[0-9]*/debug/.*" ! -regex ".*/lib/modules/.*" ! -regex ".*%{_docdir}/.*" ! -regex ".*%{_includedir}/.*" %{?_noautochrpath:! -regex "%{_noautochrpath}"}`; \
        if [ -n "$files" ]; then \
@@ -663,6 +676,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 \
@@ -680,6 +694,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;} \
        if [ -d $RPM_BUILD_ROOT/lib/modules ]; then \
                q=$(find $RPM_BUILD_ROOT/lib/modules -name '*o' -type f -print); \
                if [ "$q" ]; then \
@@ -751,9 +766,12 @@ fi; \
 # Requires:  hicolor-icon-theme
 #
 %update_icon_cache() {{ \
-       %{!?1:%{error:%{0}: Required icon dir missing}exit 1} \
-       umask 022; \
-       [ -x /usr/bin/gtk-update-icon-cache ] && /usr/bin/gtk-update-icon-cache -qf %{_datadir}/icons/%1 || :; \
+       %{!?1:%{error:%{0}: Required theme name missing}} \
+       if [ -x /usr/bin/gtk-update-icon-cache ]; then \
+               umask 022; \
+               touch --no-create %{_iconsdir}/%1; \
+               /usr/bin/gtk-update-icon-cache -qf %{_iconsdir}/%1; \
+       fi; \
 };} \
 %{nil}
 
@@ -973,11 +991,11 @@ fi \
 
 # directories
 %py3_prefix            %{expand:%%global py3_prefix %(%{__python3} -c "import sys; print(sys.prefix)" 2>/dev/null || echo ERROR)}%py3_prefix
-%py3_libdir            %{py3_prefix}/%{_lib}/python%{py3_ver}
+%py3_libdir            %{expand:%%global py3_libdir %(%{__python3} -c "import sysconfig; print(sysconfig.get_path('platstdlib'))" 2>/dev/null || echo ERROR)}%py3_libdir
+%py3_incdir            %{expand:%%global py3_incdir %(%{__python3} -c "import sysconfig; print(sysconfig.get_path('include'))" 2>/dev/null || echo ERROR)}%py3_incdir
+%py3_sitedir           %{expand:%%global py3_sitedir %(%{__python3} -c "import sysconfig; print(sysconfig.get_path('platlib'))" 2>/dev/null || echo ERROR)}%py3_sitedir
+%py3_sitescriptdir             %{expand:%%global py3_sitescriptdir %(%{__python3} -c "import sysconfig; print(sysconfig.get_path('purelib'))" 2>/dev/null || echo ERROR)}%py3_sitescriptdir
 %py3_scriptdir %{py3_prefix}/share/python%{py3_ver}
-%py3_incdir            /usr/include/python%{py3_ver}
-%py3_sitedir           %{py3_libdir}/site-packages
-%py3_sitescriptdir %{py3_scriptdir}/site-packages
 %py3_dyndir            %{py3_libdir}/lib-dynload
 
 # pure python modules compilation
@@ -985,9 +1003,11 @@ fi \
 
 %py3_ocomp             %{__python3} -O -c "import compileall; import sys; compileall.compile_dir(sys.argv[1], ddir=sys.argv[1][len('$RPM_BUILD_ROOT'):])"
 
+
 # Hardlink binary identical .pyc and .pyo files
 %__spec_install_post_py_hardlink {\
 %{!?no_install_post_py_hardlink: __spec_install_post_py_hardlink() { \
+%{!?debug:set +x;} \
 local a b c=0 t=0; \
 if [ -d "$RPM_BUILD_ROOT" ]; then \
        find "$RPM_BUILD_ROOT" -name '*.pyc' > __rpm_pyc; \
@@ -1011,12 +1031,6 @@ for d in %{py_sitescriptdir} %{py_sitedir} %*; do \
 done \
 %{nil}
 
-%py3_postclean() \
-for d in %{py3_sitescriptdir} %{py3_sitedir} %*; do \
- [ ! -d "$RPM_BUILD_ROOT$d" ] || find "$RPM_BUILD_ROOT$d" -name '*.py' -print0 | xargs -0r -l512 rm;\
-done \
-%{nil}
-
 # depmod macro
 %depmod() { \
 umask 022; \
@@ -1424,7 +1438,7 @@ echo -e "</dependencies>\\n" >> %{_mavendepmapdir}/maven2-depmap.xml
 %__pear_install_log \
 tee install.log \
 # make post message of optional packages \
-grep -E 'can optionally use|Optional feature' install.log | sed -e 's,package "pear/,package "php-pear-,g;s,^pear/,php-pear-,;s,^pear/,php-pear-,;s,^channel://.*/,,' > optional-packages.txt \
+grep -E 'can optionally use|Optional feature' install.log | sed -e 's,package "pear/,package "php-pear-,g;s,^pear/,php-pear-,;s,^pear/,php-pear-,' > optional-packages.txt \
 if [ -s optional-packages.txt ]; then \
        awk -F'"' '/use package/{print $2}' optional-packages.txt | sed -e "s,_,/,g;s,php-pear-, 'pear(,;s,$,.*)'," | tr -d '\\\n' > _noautoreq \
 else \
@@ -1637,13 +1651,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                           \
@@ -1680,6 +1694,7 @@ compile %{*}\
 %define ModprobeD $RPM_BUILD_ROOT%{_sysconfdir}/modprobe.d/%{_kernel_ver} \
                                                                                                                                        \
 __install_kernel_modules() {                                                                           \
+%{!?debug:set +x;} \
 local cfgs='%{?with_dist_kernel:%{?with_smp: smp}%{?with_up: up}}%{!?with_dist_kernel: nondist}' \
                                                                                                                                        \
 for MODULE in {%{-m*},}; do                                                                                    \
@@ -1856,30 +1871,35 @@ io.open("/etc/shells", "w"):write(s)\
 #
 # Requirements:
 # BuildRequires:       python
-# BuildRequires:       rpmbuild(macros) >= 1.469
+# BuildRequires:       rpmbuild(macros) >= 1.602
 
 %py_lint() \
 __py_lint() { \
+%{!?debug:set +x;} \
 find "$@" -type f -name '*.py' | python -c ' \
 import sys \
 import compiler \
 \
-err = 0\
+found = err = 0\
 for f in sys.stdin: \
-       fd = open(f.strip()) \
+       fd = open(f.rstrip()) \
        c = fd.read() \
        fd.close() \
+       found = found + 1 \
        try: \
                compiler.parse(c) \
        except SyntaxError, e: \
-               print "py_lint: %s: %s" % (f.strip(), e) \
+               print "py_lint: %s: %s" % (f.rstrip(), e) \
                err = err + 1\
 \
-if err: \
+if not found:\
+       print >> sys.stderr, "\\npy_lint: ERROR: No files processed.\\n" \
+       sys.exit(1) \
+elif err: \
        print >> sys.stderr, "\\npy_lint: ERROR: Syntax errors in %d files.\\n" % err \
        sys.exit(1) \
 else: \
-       print >> sys.stderr,  "py_lint: Found no syntax errors." \
+       print >> sys.stderr,  "py_lint: %d files scanned, found no syntax errors." % found \
 ' \
 }; __py_lint %* \
 %{nil}
@@ -2005,4 +2025,79 @@ else: \
                [ -f /etc/rc.d/init.d/%1 -o -f /etc/init/%1.conf ] && { echo -n "Re-"; /sbin/service %1 start; }; \
        fi
 
+# Haskell Macros
+# BuildRequires:  rpmbuild(macros) >= 1.608
+%ghcdir                ghc-%(/usr/bin/ghc --numeric-version 2>/dev/null || echo ERROR)
+
+# update /usr/lib*/ghc-*/package.conf.d/package.cache
+# Requires: ghc
+# BuildRequires:  rpmbuild(macros) >= 1.607
+#
+%ghc_pkg_recache() {{ \
+       umask 022; \
+       /usr/bin/ghc-pkg recache; \
+};} \
+%{nil}
+
+
+# pre/post script for -systemd subpackages
+#
+# Author: Bartlomiej Zimon <uzi18@o2.pl>
+#
+# Usage:
+# %systemd_post
+# %systemd_enable service_name.service
+# %systemd_preun  service_name.service
+# %systemd_postun service_name.service
+#
+# Sample:
+# %post systemd
+# %systemd_post
+# or if service must be enabled by default:
+# %post systemd
+# %systemd_post
+# %systemd_enable %{name}
+#
+# %preun systemd
+# %systemd_preun %{name}
+#
+# %postun systemd
+# %systemd_postun %{name}
+#
+# Requirements:
+# BuildRequires: rpmbuild(macros) >= 1.625
+# Requires:     systemd-units >= 37-0.10
+
+%systemd_enable() \
+       export SYSTEMD_LOG_LEVEL=warning SYSTEMD_LOG_TARGET=syslog; \
+       if [ $1 -eq 1 ]; then  \
+               /bin/systemctl --quiet enable %1 || : \
+       fi
+
+%systemd_post() \
+       export SYSTEMD_LOG_LEVEL=warning SYSTEMD_LOG_TARGET=syslog; \
+       if [ $1 -eq 1 ] && /bin/systemd_booted; then \
+               /bin/systemctl --quiet daemon-reload || : \
+       fi
+
+%systemd_preun() \
+       export SYSTEMD_LOG_LEVEL=warning SYSTEMD_LOG_TARGET=syslog; \
+       if [ $1 -eq 0 ]; then \
+               /bin/systemctl --no-reload --quiet disable %1 || : \
+               if /bin/systemd_booted; then \
+                       /bin/systemctl --quiet stop %1 || : \
+               fi \
+       fi
+
+%systemd_postun() \
+       export SYSTEMD_LOG_LEVEL=warning SYSTEMD_LOG_TARGET=syslog; \
+       if /bin/systemd_booted; then \
+               /bin/systemctl --quiet daemon-reload || : \
+               if [ $1 -ge 1 ]; then \
+                       /bin/systemctl --quiet try-restart %1 || : \
+               fi \
+       fi
+
+%systemdunitdir /lib/systemd/system
+
 # EOF
This page took 0.124493 seconds and 4 git commands to generate.