
# Included from file macros.distr_vendor

# The distribution info how it was be retrieved via distro_info
%_distro_pkgtype rpm
%_distro_name ALTLinux
%_distro_version p8


# Included from file macros.intro/macros.intro
# Introduced for ALT Linux macros.
# Collected by Vitaly Lipatov <lav@etersoft.ru>
# I guess these macros are not defined in Sisyphus in the package build time
# These macros will be packed in rpm-build-intro package

# NOTE!
# Don't forget copy the same to macros.intro.backport

# for discussion:
%make_install_std %makeinstall_std

# If macros is component related (like kde, java, perl), use name like %name_somedir
# If macros for some dir, use name like %_omfdir

%kde_docdir %_docdir/HTML
%gtk_docdir %_datadir/gtk-doc/html
%java_dir %_datadir/java
%java_docdir %_datadir/javadoc

%_kdedocdir %_docdir/HTML
%_gtkdocdir %_datadir/gtk-doc/html
%_javadir %_datadir/java
%_javadocdir %_datadir/javadoc

# various for prev. distro...
# FIXME: on other platforms only
%rpmcflags %optflags
# due error on SUSE
#%rpmldflags %nil
%rpmcxxflags %optflags

# Normalize source file permissions
%fix_permissions \
find ./ -type d -print0 | xargs -0 chmod 0775 \
find ./ -type f -print0 | xargs -0 chmod 0664

# Remove unneeded repository info (since rpm-build-compat 1.5)
%remove_repo_info \
find ./ -type d -name .svn -print0 | xargs -0 --no-run-if-empty rm -rfv {} \; \
find ./ -type d -name CVS -print0 | xargs -0 --no-run-if-empty rm -rfv {} \; \
find ./ \\( -name '*.DS_Store' -o -name '*.DS_Store.gz' \\) -print -delete \
%nil

# macro for init scripts configs (/etc/default in Debian/Ubuntu)
%_sysconfigdir %_sysconfdir/sysconfig

# 32bit libs placement dir (inside 64bit package too)
%_lib32dir %_prefix/lib

# path to /etc/sudoers extension dir
%_sudoersdir %_sysconfdir/sudoers.d

# cups lib dir
%_cupslibdir %_prefix/lib/cups

%_metainfodir %_datadir/metainfo

# TODO: need to be add (ALT bug #31808)
%python_check %__python setup.py check
%python3_check %__python3 setup.py check

# TODO: setyp.py test runs unit tests
%python_test %__python setup.py test
%python3_test %__python3 setup.py test

# will need python3-module-sphinx
%python3_build_doc %make -C doc html SPHINXBUILD=sphinx-build-3

%__python_package_prefix python-module
%__python3_package_prefix python3-module

# obsoleted name
%_ln_sr() \
ln -sf --relative "%{1}" "%{2}" || ln -sf "%(echo '%{1}' | sed -e 's!%buildroot!!g')" "%{2}" \
%nil

# ln -sr %buildroot%_somedir/file %buildroot%_newdir/file
%__ln_sr() \
ln -sf --relative "%{1}" "%{2}" || ln -sf "%(echo '%{1}' | sed -e 's!%buildroot!!g')" "%{2}" \
%nil

# TODO: fix in rpm-build-python (remove %__python_version)
%__FIXED_python_package_deps_internal() \
args="%{*}"; \
set $args ''; \
while test $# -gt 1; do \
  mod=$1; shift; \
  if test $# -gt 1; then \
    if test "x$1" = "x<" -o "x$1" = "x<=" -o "x$1" = "x=" -o "x$1" = "x>=" -o "x$1" = "x>"; then \
      verstr="$1 $2"; shift; shift; \
    fi; \
  fi; \
  echo -n "%__python_package_prefix-${mod} $verstr "; \
  unset mod; unset verstr; \
done; \
%nil

%__python3_package_deps_internal() \
args="%{*}"; \
set $args ''; \
while test $# -gt 1; do \
  mod=$1; shift; \
  if test $# -gt 1; then \
    if test "x$1" = "x<" -o "x$1" = "x<=" -o "x$1" = "x=" -o "x$1" = "x>=" -o "x$1" = "x>"; then \
      verstr="$1 $2"; shift; shift; \
    fi; \
  fi; \
  echo -n "%__python3_package_prefix-${mod} $verstr "; \
  unset mod; unset verstr; \
done; \
%nil

# TODO
%py_use() \
BuildRequires: %(%{expand: %%__FIXED_python_package_deps_internal %{*}}) \
Requires: %(%{expand: %%__FIXED_python_package_deps_internal %{*}}) \
%nil

%py3_use() \
BuildRequires: %(%{expand: %%__python3_package_deps_internal %{*}}) \
Requires: %(%{expand: %%__python3_package_deps_internal %{*}}) \
%nil

%py3_buildrequires() \
BuildRequires: %(%{expand: %%__python3_package_deps_internal %{*}}) \
%nil

%python3_prune() \
for i in %buildroot%python3_sitelibdir/ %buildroot%python3_sitelibdir_noarch/ ; do \
    find $i -name "tests" -type d -print0 | xargs -0 rm -rfv \
    find $i -name "test" -type d -print0 | xargs -0 rm -rfv \
done \
%nil

%__lib_devel_use_internal() \
args="%{*}"; \
set $args ''; \
while test $# -gt 1; do \
  mod=$1; shift; \
  if test $# -gt 1; then \
    if test "x$1" = "x<" -o "x$1" = "x<=" -o "x$1" = "x=" -o "x$1" = "x>=" -o "x$1" = "x>"; then \
      verstr="$1 $2"; shift; shift; \
    fi; \
  fi; \
  echo -n "lib${mod}-devel $verstr "; \
  unset mod; unset verstr; \
done; \
%nil

%__lib_use_internal() \
args="%{*}"; \
set $args ''; \
while test $# -gt 1; do \
  mod=$1; shift; \
  if test $# -gt 1; then \
    if test "x$1" = "x<" -o "x$1" = "x<=" -o "x$1" = "x=" -o "x$1" = "x>=" -o "x$1" = "x>"; then \
      verstr="$1 $2"; shift; shift; \
    fi; \
  fi; \
  echo -n "lib${mod} $verstr "; \
  unset mod; unset verstr; \
done; \
%nil

# F.i. %lib_use rync > 5 will generate BR: librsync-devel > 5 and R: librsync >5
%lib_use() \
BuildRequires: %(%{expand: %%__lib_devel_use_internal %{*}}) \
Requires: %(%{expand: %%__lib_use_internal %{*}}) \
%nil

# OBSOLETED since python2 is away
%python3_dirsetup \
%if_with python3 \
rm -rf ../python3 \
cp -a . ../python3 \
%endif \
%nil

#find ../python3 -name "*.py" | xargs %__subst "s|^#!/usr/bin/env python$|#!/usr/bin/python3|g"

# OBSOLETED since python2 is away
%python3_dirbuild() \
%if_with python3 \
cd ../python3 \
%python3_build %{*} \
cd - >/dev/null \
%endif \
%nil

# OBSOLETED since python2 is away
%python3_dirbuild_debug() \
%if_with python3 \
cd ../python3 \
%python3_build_debug %{*} \
cd - >/dev/null \
%endif \
%nil

# OBSOLETED since python2 is away
%python3_dirinstall() \
%if_with python3 \
cd ../python3 \
%python3_install %{*} \
cd - >/dev/null \
%endif \
%nil

# OBSOLETED since python2 is away
%python3_dircheck() \
%if_with python3 \
cd ../python3 \
%python3_check %{*} \
cd - >/dev/null \
%endif \
%nil

# OBSOLETED since python2 is away
%python3_dirtest() \
%if_with python3 \
cd ../python3 \
%python3_test %{*} \
cd - >/dev/null \
%endif \
%nil

# Use: # Source-url: %__pypi_url %modulename
%__pypi_url() https://pypi.io/packages/source/%(echo %{1} | cut -c1)/%{1}/%{1}-%version.tar.gz %nil

%_userunitdir %_prefix/lib/systemd/user

# override __nprocs in depend of system memory size, __nprocs and a process size (in MB)
# __nprocs = max(min(round(MAX/NEED)-1,NPROC),1)
# uses distr_vendor from rpm-build-intro
# use with suggested compiler process size
# Note: hack: divided by 4 if memory more than 42G (see https://lists.altlinux.org/pipermail/devel/2018-July/204969.html)
%_tune_parallel_build_by_procsize() \
BuildRequires(pre): /proc \
%global __nprocs %(M=%(epm print info -m) ; N=$(($M/%{1})); [ "$M" -ge 42000 ] && N=$(($N/4)) ; [ "$N" -gt 0 ] || N=1; [ "$N" -lt %__nprocs ] || N=%__nprocs ;  echo "$N") \
%nil

# from Fedora
%_pkgdocdir %_docdir/%name-%version

# @zerg's macros for versions comparing
# https://bugzilla.altlinux.org/6010
%if_ver_gt() %if "%(rpmvercmp '%1' '%2')" > "0"
%if_ver_gteq() %if "%(rpmvercmp '%1' '%2')" >= "0"
%if_ver_lt() %if "%(rpmvercmp '%2' '%1')" > "0"
%if_ver_lteq() %if "%(rpmvercmp '%2' '%1')" >= "0"
%if_ver_eq() %if "%(rpmvercmp '%1' '%2')" == "0"
%if_ver_not_gt() %if "%(rpmvercmp '%1' '%2')" <= "0"
%if_ver_not_gteq() %if "%(rpmvercmp '%1' '%2')" < "0"
%if_ver_not_lt() %if "%(rpmvercmp '%2' '%1')" <= "0"
%if_ver_not_lteq() %if "%(rpmvercmp '%2' '%1')" < "0"
%if_ver_not_eq() %if "%(rpmvercmp '%1' '%2')" != "0"


# Included from file macros.distro/macros.alt
# Platform and version dependend macros (ALT Linux only)
# These macros introduced for ALT and packed for ALT Linux only
# These macros will packed in rpm-build-intro package on ALT

# Start service only after manual install
# this case is never run due no tty under rpm process install
# 1 - 1st install, 2 - update package
%start_service() \
        false && [ -z "$DURING_INSTALL" ] && [ "$1" = "1" ] && %_initddir/%{1} start || : \
%nil

# PLD compatibility
%groupadd /usr/sbin/groupadd -r -f
%useradd /usr/sbin/useradd -r
#%userremove userdel
#%groupremove groupdel

