
# Included from file macros.rpm-build/cmake
# Macros for cmake
#
%__cmake cmake
%_cmake__builddir %_target_platform
%_cmake_skip_rpath -DCMAKE_SKIP_RPATH:BOOL=ON

%cmake \
    mkdir -p %_cmake__builddir; \
    %__cmake \\\
        -DCMAKE_SKIP_INSTALL_RPATH:BOOL=yes \\\
        -DCMAKE_C_FLAGS:STRING='%optflags' \\\
        -DCMAKE_CXX_FLAGS:STRING='%optflags' \\\
        -DCMAKE_Fortran_FLAGS:STRING='%optflags' \\\
        -DCMAKE_INSTALL_PREFIX=%prefix \\\
        -DINCLUDE_INSTALL_DIR:PATH=%_includedir \\\
        -DLIB_INSTALL_DIR:PATH=%_libdir \\\
        -DSYSCONF_INSTALL_DIR:PATH=%_sysconfdir \\\
        -DSHARE_INSTALL_PREFIX:PATH=%_datadir \\\
        -DLIB_DESTINATION=%_lib \\\
        -DLIB_SUFFIX="%_libsuff" \\\
    -S . -B "%_cmake__builddir"

# Notice: this macro affects _cmake__builddir, effectively preventing further
# out-of-source builds. Maintainers opting to build in-source are not
# interested in those, though.
%cmake_insource \
    %define _cmake__builddir . \
    %cmake

%cmake_build %__cmake --build "%_cmake__builddir" --parallel %_smp_build_ncpus

%cmake_install DESTDIR="%buildroot" %__cmake --install "%_cmake__builddir"

# Deprecated macro; do not use in new packages.
# This macro only works with -G'Unix Makefiles', when cmake uses make(1).
%cmakeinstall_std \
    %makeinstall_std -C "%_cmake__builddir"

# Included from file macros.rpm-build/control
# control(8) macros

%_controldir	%_sysconfdir/control.d/facilities

# in %%pre section.
%pre_control()	\
if [ $1 -ge 2 ]; then \
	/usr/sbin/control-dump %* \
fi \
%nil

# in %%post section.
%post_control(s:)	\
if [ $1 -ge 2 ]; then \
	/usr/sbin/control-restore %* \
else \
	for facility in %*; do \
		/usr/sbin/control "$facility" %{-s*}%{!-s:public} \
	done \
fi \
%nil

# Included from file macros.rpm-build/licenses
%gpl2only GPLv2
%gpl2plus GPLv2+
%gpl3only GPLv3
%gpl3plus GPLv3+
%lgpl2only LGPLv2
%lgpl21only LGPLv2.1
%lgpl2plus LGPLv2+
%lgpl21plus LGPLv2.1+
%lgpl3only LGPLv3
%lgpl3plus LGPLv3+
%bsd_orig BSD (original)
%bsd BSD (revised)
%bsdstyle BSD-style
%mit MIT/X Consortium
%mpl MPL
%w3cl W3C
%asl Apache
%jpackage_license JPackage
%sendmail_license Sendmail
%artistic_license Artistic
%perl_license Perl (GPL or Artistic)
%fdl FDL
%lppl LPPL
%ccbysa30 CC-BY-SA-3.0
%ccby30 CC-BY-3.0
%ccbysa25 CC-BY-SA-2.5
%ccby25 CC-BY-2.5
%epl Erlang Public License
%pubdomain Public domain
%distributable Distributable, non-free

# Not sure whether these ones should exist at all. Too clumsy names and vague
# semantics.
%gpllgpl2only GPLv2, LGPLv2
%gpllgpl2plus GPLv2+, LGPLv2+
%gpllgpl3only GPLv3, LGPLv3
%gpllgpl3plus GPLv3+, LGPLv3+

# Included from file macros.rpm-build/perl5-alt-rpm-macros
%_perl_req_method	normal
%set_perl_req_method()	%global _perl_req_method %*

#_perl_lib_path		%nil
%add_perl_lib_path()	%global _perl_lib_path %{?_perl_lib_path} %*

# perl library paths
%perl_vendor_privlib	%(eval "`%__perl -V:installvendorlib`"; echo "$installvendorlib")
%perl_vendor_archlib	%(eval "`%__perl -V:installvendorarch`"; echo "$installvendorarch")
%perl_vendor_autolib	%perl_vendor_archlib/auto

# MDK compatibility
%perl_vendorlib		%perl_vendor_privlib
%perl_vendorarch	%perl_vendor_archlib
%makeinstall_std	%make_install install DESTDIR=%buildroot

# mandirs
%perl_vendor_man1dir	%_man1dir
%perl_vendor_man3dir	%_man3dir

# build with the same optimization as perl
%perl_vendor_optflags	%(eval "`%__perl -V:optimize`"; echo "$optimize")

# automate various rpmbuild stages
# MM stands for ExtUtils::MakeMaker
# MB stands for Module::Build

# %%build helpers
%perl_vendor_build \
_perl_vendor_MB_build() { \
	: writing Build script \
	%__perl Build.PL installdirs=vendor "$@" </dev/null \
	%__perl -e '$req=require"./_build/prereqs";' \\\
		-e 'while (my ($k, $v) = each %%{$$req{requires}})	{ print "perl($k)>=$v\\n" }' \\\
		-e 'while (my ($k, $v) = each %%{$$req{recommends}})	{ print "perl($k)>=$v\\n" }' | tee .perl.req \
	: running Build script \
	%__perl Build \
	%{?!_without_test:%{?!_disable_test:: running tests; LD_BIND_NOW=1 PERL_DL_NONLAZY=1 %__perl Build test %{?_enable_debug:test_verbose=1}}} \
} \
_perl_vendor_MM_build() { \
	%{?_without_smp:NPROCS=1; : NOTE: SMP-incompatible} \
	%{?_disable_smp:NPROCS=1; : NOTE: SMP-incompatible} \
	: looking for PREREQ dependencies \
	%__perl Makefile.PL PRINT_PREREQ=1 "$@" </dev/null | tee .perl.req \
	: writing Makefile \
	%__perl Makefile.PL PREFIX=%_prefix INSTALLDIRS=vendor "$@" </dev/null \
	: running make \
	%make_build OPTIMIZE="%{!?_enable_debug:%perl_vendor_optflags}%{?_enable_debug:%optflags}%{?_enable_Werror: -Werror}" CP="%__cp -p" \\\
		OTHERLDFLAGS="-lperl -lpthread $EXTRA_LIBS" \
	%{?!_without_test:%{?!_disable_test:: running tests; LD_BIND_NOW=1 PERL_DL_NONLAZY=1 %__make test CP="%__cp -p" %{?_enable_debug:TEST_VERBOSE=1} </dev/null}} \
} \
_perl_vendor_fixin() { \
	find . -type f -print0 | xargs -r0 %__subst -p \\\
	'1s,^#![[:space:]]*\\([^[:space:]]*/\\)\\?perl\\([^/[:alpha:][:space:]][^/[:space:]]*\\)\\?\\([[:space:]]\\|$\\),#!%__perl\\3,' \
} \
_perl_vendor_check_dso() { \
	: checking for undefined symbols \
	BLIBS="$BLIBS${BLIBS:+ }$(find $PWD/blib -type f -name '*.so' ||:)" \
	[ -n "$BLIBS" ] || return 0 \
	echo 'int main(){return 0;}' >ldtest.c \
	gcc -Wl,--no-as-needed ldtest.c ${LD_LIBRARY_PATH:+-L$LD_LIBRARY_PATH} -lperl $BLIBS $EXTRA_BLIBS \
	LD_BIND_NOW=1 ./a.out \
	rm -f ldtest.c ./a.out \
} \
perl_vendor_build() { \
	export PERL_EXTUTILS_AUTOINSTALL="${PERL_EXTUTILS_AUTOINSTALL:---skip}" \
	export XSUBPP_STATIC_XS=${XSUBPP_STATIC_XS:-1} \
		_perl_vendor_fixin \
	if %__grep -qs -Ew '(dist|module)_name' Build.PL; then \
		_perl_vendor_MB_build "$@" \
	else \
		_perl_vendor_MM_build "$@" \
	fi \
		#_perl_vendor_check_dso \
} \
perl_vendor_build

# %%install helpers
%perl_vendor_install \
_perl_vendor_MB_install() { \
	: installing \
	%__perl Build install destdir=%buildroot installdirs=vendor "$@" </dev/null \
} \
_perl_vendor_MM_install() { \
	: installing \
	%make_install UNINST=undef CP="%__cp -p" \\\
		DESTDIR=%buildroot PREFIX=%_prefix INSTALLDIRS=vendor \\\
		INSTALLMAN1DIR=%buildroot%perl_vendor_man1dir \\\
		INSTALLMAN3DIR=%buildroot%perl_vendor_man3dir \\\
 		pure_install "$@" </dev/null \
} \
_perl_vendor_check_buildroot() { \
	: prompting for files that contain /usr/local \
	find %buildroot -type f -exec %__grep -FH /usr/local {} ';' \
	: prompting for files that contain /tmp \
	find %buildroot -type f -not -name .packlist -exec %__grep -FH /tmp '{}' ';' \
} \
_perl_vendor_save_prereq() { \
	if %__grep -F 'perl(' .perl.req >&2; then \
	   %__grep -F 'perl(' .perl.req >>%buildroot/.perl.req; fi \
} \
perl_vendor_install() { \
	if %__grep -qs -Ew '(dist|module)_name' Build.PL; then \
		_perl_vendor_MB_install "$@" \
	else \
		_perl_vendor_MM_install "$@" \
	fi \
		_perl_vendor_check_buildroot \
		_perl_vendor_save_prereq \
} \
perl_vendor_install

# sugar
%perl_fix_local %__subst -p 's,/usr/local\\>,/usr,g'
%CPAN() http://search.cpan.org/dist/%1/%nil

# Included from file macros.rpm-build/python
# Версия: $Id: python 378 2004-10-05 12:21:51Z cray $
# -*- coding: utf-8 -*-

# Override __python_version macro provided by rpm-build 
%__python_version	%(LC_ALL=C %__python -c 'import sys; print "%%u.%%u" %% sys.version_info[0:2]' 2>/dev/null || echo 2.7)
%_python_version %__python_version
%python_version_nodots() %(LC_ALL=C %1 -c "import sys; sys.stdout.write('{0.major}{0.minor}'.format(sys.version_info))" 2>/dev/null || echo unknown)

%_target_python_libdir %_target_libdir
%_python_set_noarch() %global _target_python_libdir %_target_libdir_noarch
%_python_set_arch() %global _target_python_libdir %_target_libdir
%_python_lib_path	""
%_python_req_method	slight
%_python_req_skip	""
%_python_compile_method	ALL
%_python_compile_exclude	%_defaultdocdir
%_python_compile_include	%_target_libdir %_target_libdir_noarch
# Where we really expect normal Python modules:
%_python_compile_include_restricted %python_libdir %python_sitelibdir %python_sitelibdir_noarch
%_python_compile_deep	20
%_python_compile_skip_x	1
%_python_compile_clean	1

%set_python_req_method()	%global _python_req_method %1
%set_python_compile_method()	%global _python_compile_method %1

%add_python_req_skip()	%global _python_req_skip %_python_req_skip %*
%add_python_lib_path()	%global _python_lib_path %_python_lib_path %*
%add_python_compile_exclude() %global _python_compile_exclude %_python_compile_exclude %*
%add_python_compile_include() %global _python_compile_include %_python_compile_include %*

# _check_python_version_internal <версия_с_точкой> <версия_без_точки>
#
#       Проверить указание ключа сборки --with pythonXY, Должна вызываться
#       для всех поддерживаемых версий питон
#
#       Если при сборке было указан ключ --with pythonXY, то определить
#       переменную __python_package_version, равную <версии_с_точкой>, и
#       внести кляузу 
#
#		BuildPreReq: python = X.Y
#
# 	в пакет.
#
#       В случае одновременного использования двух разных ключей --with
#       pythonXY инициируется аварийная остановка сборки
#
%_check_python_version_internal() \
%{expand: %{expand:%%{?_with_python%{2}:%%{?__python_package_version:%%%%{error:Only one python version can be selected at a time}}}}} \
%(echo %{expand:%%{?_with_python%{2}:%%{?__python_package_version:BuildConflicts: python = %{1}}}}) \
%(echo %{expand:%%{?_with_python%{2}:BuildPreReq: python = %{1}}}) \
%{expand: %{expand:%%{?_with_python%{2}:%%{!?__python_package_version:%%%%global __python_package_version %1}}}} \
%{expand: %{expand:%%{?_with_python%{2}:%%%%global __python_version %1}}}


# _check_python_version <версия_с_точкой>
#
#	Обертка для функции _check_python_version_internal
#
%_check_python_version() \
%{expand: %%_check_python_version_internal %{1} %(echo %1 | sed -e 's/\\.//g')}

# _bind_python_version_internal <имя_модуля> <версия_с_точкой>
#
# 	Привязывает сборку к определенной версии питона путем создания доп.
# 	файла c именем %_sourcedir/<имя_модуля>.rpmreq и включения его в
# 	список Source пакета (как Source100: would be ought for everything)

%_bind_python_version() \
%(echo %%global _with_python%{2} --with-python%{2} | sed -e 's/\\.//g' >%_sourcedir/%{1}.rpmreq) \
%(echo Source9999: %{1}.rpmreq)

# check_bound_python_version <имя_модуля>
#
#       Проверяет наличие файла %_sourcedir/<имя_модуля>.rpmreq и, если он
#       есть, привязывает данную сборку к указанной в этом файле версии
#       питона.
#
%_check_bound_python_version() \
%{expand: %(test -f %_sourcedir/%{1}.rpmreq && cat %_sourcedir/%{1}.rpmreq)} \
%(test -f %_sourcedir/%{1}.rpmreq && echo Source9999: %{1}.rpmreq) \
%_check_python_version 2.2 \
%_check_python_version 2.3 \
%_check_python_version 2.4 \
%_check_python_version 2.5 \
%_check_python_version 2.6 \
%_check_python_version 2.7

%_forget_bound_python_version() \
%{expand: %{expand: %%%%global __python_package_version %%%%nil}} \
%{expand: %(test -f %_sourcedir/%{1}.rpmreq && rm -f %_sourcedir/%{1}.rpmreq)}

%_setup_python_module_internal()        \
%{expand: %%global modulename %{1}} \
%{expand: %%{?_with_python_auto: %%_forget_bound_python_version %modulename}} \
%_check_python_version 2.2 \
%_check_python_version 2.3 \
%_check_python_version 2.4 \
%_check_python_version 2.5 \
%_check_python_version 2.6 \
%_check_python_version 2.7 \
%{expand: %{expand: %%{!?__python_package_version:%%{!?__python_disable_bind_version:%%{!?_with_python_auto:%%%%_check_bound_python_version %%modulename}}}}} \
%{expand: %{expand: %%{?__python_package_version:%%{!?__python_disable_bind_version:%%{!?_with_python_auto:%%%%_bind_python_version %%modulename %%__python_package_version}}}}} \
%{expand: %%global __python %%(which python%%__python_version 2>/dev/null || echo /bin/false)} \
%{expand: %{expand: %%{!?__python_package_version:%%%%global __python_package_version %%%%nil}}} \
%{expand: %%global __python_module_prefix python%%{__python_package_version}-module} \
%{expand: %%global packagename %%{__python_module_prefix}-%%{modulename}}

%setup_std_python_package_deps() \
%{expand: %%{!?modulename:%%_setup_python_module_internal %{*}}} \
%(echo "Requires: python = %__python_version") \
%(echo "BuildPreReq: python-devel = %__python_version") \
%(echo "BuildPreReq: rpm-build-python >= 0.8") \
%(echo "Provides: python%__python_version-module-%modulename = %version-%release") \
%nil


# setup_python_module <имя_модуля>
#
# 	Функция, инициирующая спек. Должна указываться в начале спека
#	для инициализации параметров сборки.
#
# 	Проверяет указанные ключа сборки --with pythonXY и/или with
# 	--python_auto, и устанавливает сборочные зависимости пакета. Кроме
# 	этого, определяет переменные packagename и __python_package_version
# 	(в зависимости от ключей и прочих параметров сборки).
#
%setup_python_module() \
%{expand: %%{!?__python_package_version:%%_setup_python_module_internal %{*}}} \
%{expand: %%setup_std_python_package_deps}

# setup_python_module_loose <имя_модуля>
#
# 	Альтернатива setup_python_module, не использующая генерацию .rpmreq
# 	файла и не выполняющая проверку его наличия
#
%setup_python_module_loose() \
%{expand: %%global __python_disable_bind_version 1} \
%{expand: %%setup_python_module %{*}}

%setup_python_subpackage() \
%{expand: %%_setup_python_module_internal %{*}}

%__python_deps_internal() \
for mod in %{*}; do \
    echo -n "python%__python_version($mod) "; \
done; unset mod;\
%nil

# py_requires <имя_модуля1> [<имя_модуля2> ...]
#
#	Добавляет зависимость на указанные модули python. Формируемые
# 	зависимости имеют вид: pythonX.Y(имя_модуля1) [pythonX.Y(имя_модуля2)...]
# 	где X.Y - текущая (выбранная) версия python
#
%py_requires() \
Requires: %(%{expand: %%__python_deps_internal %{*}}) \
%nil

# py_provides <имя_модуля1> [<имя_модуля2> ...]
#
# 	Позволяет принудительно указать предоставляемые модули python. Формируемые
# 	"provides" имеют вид: pythonX.Y(имя_модуля1) [pythonX.Y(имя_модуля2)...]
# 	где X.Y - текущая (выбранная) версия python
#
%py_provides() \
Provides: %(%{expand: %%__python_deps_internal %{*}}) \
%nil

# py_dependencies <имя_модуля1> [<имя_модуля2> ...]
#
# 	Формирует список модулей питон для использования, например,
# 	в тегах BuildRequires или Obsoletes, н-р, так:
# 	BuildRequires: %py_dependencies module1 module2 module3
# 	что будет преобразовано в
# 	BuildRequires: pythonX.Y(module1) pythonX.Y(module2) pythonX.Y(module3)
#
%py_dependencies() %(%{expand: %%__python_deps_internal %{*}})

%__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%__python_version-module-${mod} $verstr "; \
  unset mod; unset verstr; \
done; \
%nil

# py_package_requires <pypackage1> [[>= <pypackage1_version>] [<pypackage2> ...]]
#
# 	Аналогично py_requires, но оперирует не модулями python, а
# 	пакетами модулей python, возможно, с указанием версий (<, <=, =, =>, >).
# 	Например, строчка 
# 	%py_package_requires pack1 pack2 >= 1.0-alt1 pack3
# 	даст три зависимости:
#    		pythonX.Y-module-pack1
#    		pythonX.Y-module-pack2 >= 1.0-alt1
#    		pythonX.Y-module-pack3
# где X.Y - текущая (выбранная) версия python.
%py_package_requires() \
Requires: %(%{expand: %%__python_package_deps_internal %{*}}) \
%nil

#  py_package_provides <pypackage1> [[>= <pypackage1_version>] [<pypackage2> ...]]
#
# 	Аналогично py_package_requires, но формирует не списки Requires, а списки
# 	Provides
#
%py_package_provides() \
Provides: %(%{expand: %%__python_package_deps_internal %{*}}) \
%nil

# py_package_dependencies <pypackage1> [[>= <pypackage1_version>] [<pypackage2> ...]]
#
# 	Аналогично py_package_requires, но формирует только список, без указания
# 	RPM-предиката, то есть, подходит для использования, например, так
# 	BuildRequires: %py_package_dependencies pack1 pack2 >= 1.2-alt1 pack3
# 	ВНИМАНИЕ: НЕ ТЕСТИРОВАЛОСЬ! ;-)
#
%py_package_dependencies() %(%{expand: %%__python_package_deps_internal %{*}})

# Заголовочные файлы для компиляции расширений на C
%python_includedir %_includedir/python%__python_version

# Модули Python, включенные в официальный релиз
%python_libdir %_target_python_libdir/python%__python_version

# Модули Python, установленные в дополнение к официальному релизу
%python_sitelibdir %python_libdir/site-packages

# архитектурно-независимые модули Python, установленные в дополнение к официальному релизу
%python_sitelibdir_noarch %_target_libdir_noarch/python%__python_version/site-packages

# Библиотеки расширений для языка Python
%python_dynlibdir %python_libdir/lib-dynload

# Утилиты на языке Python
%python_tooldir %python_libdir/tools

# python_module_declare <путь к модулю>
#
#	Декларировать что данный модуль может быть распилен на
#	составляющие подмодули.
#

%_python_module_declared ""
%python_module_declare() %global _python_module_declared %1 %_python_module_declared  

# python_req_hier
#
#	Включить поиск иерархических зависимостей
#
%python_req_hier %global _python_req_hier yes
#
#	Выключить поиск иерархических зависимостей
#
%python_req_nohier %undefine _python_req_hier

# traditional build/install macros
%python_setup() \
	%global _buildrequires_build %_buildrequires_build %python_setup_buildrequires \
	CFLAGS="${CFLAGS:-%optflags}" ; export CFLAGS ; \
	CXXFLAGS="${CXXFLAGS:-%optflags}" ; export CXXFLAGS ; \
	FFLAGS="${FFLAGS:-%optflags}" ; export FFLAGS ; \
	%__python setup.py
%python_build %{python_setup:} build
%python_build_debug %{python_setup:} build --debug
%python_install	%{python_setup:} install --skip-build --root=%buildroot --force
%python_build_install %{python_setup:} install --root=%buildroot --force
# Let's assume that in most cases setuptools are used or make no harm
# if those traditional Python build/install macros are used (overridable):
%python_setup_buildrequires python-module-setuptools

##################################################
# Handling of the ABI dep
#
# For python-2.x, we re-use the already present name borrowed from Fedora
# (looking like: python(abi) = 2.7).

# %%_python_version is the ABI version in the target system.
# It is set to the version from the build system in order
# to guarantee the match between the built package contents
# and the properties of the target system.
# That's fine for building Python2 modules.
%python_ABI_dep python(abi) = %_python_version

%__libpython %_libdir/libpython%_python_version.so
%_files_to_ld_preload_python %files_requiring_python_ABI%(for d in %_python_compile_include_restricted; do echo -n " $d/*"; done)
%files_requiring_python_ABI %nil

# libpython*.so (which is to be ld_preloaded) resides in python-devel
%requires_python_ABI_for_files() \
BuildPreReq: python-devel \
Requires: %python_ABI_dep \
%global files_requiring_python_ABI %files_requiring_python_ABI %* \
%nil

# Included from file macros.rpm-build/python3
##################################################
# The "properties" of the build environment (__*)
# (i.e., what we are using for compilation):
%__python3 /usr/bin/python3
%__python3_version %(LC_ALL=C %__python3 -c 'import sys; print("{0}.{1}".format(sys.version_info[0],sys.version_info[1]))' 2>/dev/null || echo unknown)
%__python3_abiflags %(%__python3-config --abiflags 2>/dev/null || echo unknown)

##################################################
# The "properties" of the target system (_*)
# (for which we are building).
# Normally, the target properties must be set according to
# the "properties" of the build environment:
# otherwise, there will be a mismatch between the real built package contents
# and the wished target system. An exception is building python3 package
# itself: then we should override the target "properties", because
# the present python3 in the build environment doesn't matter.

%_python3_abiflags %__python3_abiflags
%_python3_extension_suffix %(%__python3-config --extension-suffix 2>/dev/null || echo .so)
# According to our new ALT Sisyphus policy,
# there is only a single version of python3.
# So, %%_python3_version should not matter.
# TODO: redefine it to constant 3.
# Before that, we need to know where and how it is used in packages.
# It seems it is only used to export RPM_PYTHON3_VERSION
# (which only is used to determine the fallback value for RPM_PYTHON3_COMPILE_INCLUDE
# and might be used in some external packages...
# As for RPM_PYTHON3_COMPILE_INCLUDE, having the path with minor version there
# must matter only for the build of python3 itself,
# and can be modified just in its spec.
# No need to handle it in the general case here.)
%_python3_version %__python3_version
# A macro which will be used to guarantee the match between the ABIs
# (make sure to redefine it when building a new python3 package in its spec)
%_python3_abi_version %__python3_version

# traditional build/install macros
%python3_setup() \
	%global _buildrequires_build %_buildrequires_build %python3_setup_buildrequires \
	CFLAGS="${CFLAGS:-%optflags}" ; export CFLAGS ; \
	CXXFLAGS="${CXXFLAGS:-%optflags}" ; export CXXFLAGS ; \
	FFLAGS="${FFLAGS:-%optflags}" ; export FFLAGS ; \
	%__python3 setup.py
%python3_build %{python3_setup:} build
%python3_build_debug %{python3_setup:} build --debug
%python3_install	%{python3_setup:} install --skip-build --root=%buildroot --force
%python3_build_install %{python3_setup:} install --root=%buildroot --force
# Let's assume that in most cases setuptools are used or make no harm
# if those traditional Python3 build/install macros are used (overridable):
%python3_setup_buildrequires python3-module-setuptools

# When building the python3 distribution itself, set this to its specific minor-versioned location:
#_python3_path %%python3_libdir %%python3_libdir_noarch
# (or perhaps simply unset it).
# Otherwise, we care just about python3/site-packages/ (without the minor version;
# anything outside site-packages/ is disallowed anyway):
%_python3_path %python3_sitelibdir %python3_sitelibdir_noarch
%add_python3_path()	%global _python3_path %_python3_path %* \
			%global _python_compile_exclude %_python_compile_exclude %*

# Additional paths where our deps are allowed to be located:
%_python3_import_path %nil
%allow_python3_import_path()	%global _python3_import_path %_python3_import_path %*

%_python3_req_hier yes
#
#	Включить поиск иерархических зависимостей
#
%python3_req_hier %global _python3_req_hier yes
#
#	Выключить поиск иерархических зависимостей
#
%python3_req_nohier %undefine _python3_req_hier

%_target_python3_libdir %_target_libdir
%_python3_set_noarch() %global _target_python3_libdir %_target_libdir_noarch
%_python3_set_arch() %global _target_python3_libdir %_target_libdir

%_python3_lib_path	""
%_python3_req_method	slight
%_python3_req_skip	""
%_python3_compile_exclude	%_defaultdocdir
%_python3_compile_include	%_python3_path
%_python3_compile_deep	20
%_python3_compile_skip_x	1
%_python3_compile_clean	1

%set_python3_req_method()	%global _python3_req_method %1

%add_python3_req_skip()	%global _python3_req_skip %_python3_req_skip %*
%add_python3_lib_path()	%{expand:%%add_python3_path %*} \
                        %global _python3_lib_path %_python3_lib_path %*
%add_python3_compile_exclude() %global _python3_compile_exclude %_python3_compile_exclude %*
%add_python3_compile_include() %global _python3_compile_include %_python3_compile_include %*
# TODO: consider declaring them for python (non 3) compile_exclude
# (as is done in %%add_python3_path), too:
#			       %global _python_compile_exclude %_python_compile_exclude %*
#
# The problem is: can people have a single path with mixed Python2/3 stuff?
# This is not crucial for python.req/prov because it seems to have a smart filter.

# Заголовочные файлы для компиляции расширений на C
%__python3_includedir %_includedir/python%__python3_version%__python3_abiflags

# Модули Python3, включенные в официальный релиз
%__python3_libdir %_target_libdir/python%__python3_version
%__python3_dynlibdir %python3_libdir/lib-dynload
%__python3_tooldir %python3_libdir/Tools
# The _noarch location is not used as of now in the python3-3.3.1-alt4 distribution
# (for targets when it is different from %%python3_libdir); we define it for adaptability
# to the future (and for internal use by brp-fix_python3_site-packages_location):
%__python3_libdir_noarch %_target_libdir_noarch/python%__python3_version

# Compatibility macros (which might have been used in other packages).
# TODO: check and switch other packages to %__* build system macros
# (for overall clarity of the system of macros).
%python3_libdir %__python3_libdir
%python3_dynlibdir %__python3_dynlibdir

# Модули Python3, установленные в дополнение к официальному релизу
%python3_sitelibdir %_target_python3_libdir/python3/site-packages

# архитектурно-независимые модули Python3, установленные в дополнение к официальному релизу
%python3_sitelibdir_noarch %_target_libdir_noarch/python3/site-packages

%__python3_deps_internal() \
for mod in %{*}; do \
    echo -n "python3($mod)${rpm_python3_deps_constraint:+ $rpm_python3_deps_constraint} "; \
done; unset mod;\
%nil

%__python3_req_constraint %(%__python3 %_rpmlibdir/python3.req.constraint.py %buildroot %_python3_import_path)

# py3_requires <имя_модуля1> [<имя_модуля2> ...]
#
#	Добавляет зависимость на указанные модули Python3. Формируемые
# 	зависимости имеют вид: python3(имя_модуля1) [python3(имя_модуля2)...]
#
%py3_requires() \
Requires: %(rpm_python3_deps_constraint='%__python3_req_constraint'; %{expand: %%__python3_deps_internal %{*}}) \
%nil

# py3_provides <имя_модуля1> [<имя_модуля2> ...]
#
# 	Позволяет принудительно указать предоставляемые модули Python3. Формируемые
# 	"provides" имеют вид: python3(имя_модуля1) [python3(имя_модуля2)...]
#
%py3_provides() \
Provides: %(%{expand: %%__python3_deps_internal %{*}}) \
%nil

##################################################
# Handling of the ABI dep
#
# It's an ALT Sisyphus special name
# (looking like: python3.3-ABI(64bit)).

# What follows next is a computation of the suffix, which is
# new-arch-ABI-proof and which can be generally useful in all RPM specs
# (not python-specific).
#
# If a new weird arch-ABI arises, at least, we'll have
# a weird suffix here, not coinciding with another existing one:
#
# if "%_lib" == "lib", then empty string;
# otherwise, for example,
# if "%_lib" == "lib64", then "(64bit)" (without the quotation marks).
%ABI_suffix %(s="%_lib"; s=${s#lib}; echo "${s:+(${s}bit)}")

# %%_python3_abi_version is the ABI version in the target system.
# It is set to the version from the build system in order
# to guarantee the match between the built package contents
# and the properties of the target system
# That's fine for building Python3 modules.
# If one is building python3 package itself,
# one should override %%_python3_abi_version.
%python3_ABI_dep python%_python3_abi_version-ABI%ABI_suffix

%__libpython3 %_libdir/libpython%_python3_abi_version%_python3_abiflags.so
%_files_to_ld_preload_python3 %files_requiring_python3_ABI%(for d in %_python3_compile_include; do echo -n " $d/*"; done)
%files_requiring_python3_ABI %nil

# libpython3*.so (which is to be ld_preloaded) resides in python3-devel
%requires_python3_ABI_for_files() \
BuildPreReq: python3-devel \
Requires: %python3_ABI_dep \
%global files_requiring_python3_ABI %files_requiring_python3_ABI %* \
%nil

# Included from file macros.rpm-build/qt3
%_qt3dir /usr/lib/qt3

# Included from file macros.rpm-build/qt4
%_qt4dir %_libdir/qt4
%qmake_qt4 \
    __qmake_qt4() \
    { \
	CPPFLAGS="${CPPFLAGS:-%optflags -DPIC -fPIC}" ; export CPPFLAGS ; \\\
	%_qt4dir/bin/qmake \\\
	QMAKE_CFLAGS="${CFLAGS:-%optflags -DPIC -fPIC}" \\\
	QMAKE_CXXFLAGS="${CXXFLAGS:-%optflags -DPIC -fPIC}" \\\
	"$@" \
    } \
    __qmake_qt4

# Included from file macros.rpm-build/qt5
# partially copied from ALT

%qmake_qt5 \
    __qmake_qt5() \
    { \
        export CPPFLAGS="%optflags %optflags_shared" ; \\\
        %_qt5_qmake \\\
        QMAKE_CFLAGS="%optflags %optflags_shared" \\\
        QMAKE_CXXFLAGS="%optflags %optflags_shared" \\\
        "$@" \
    } \
    __qmake_qt5

%install_qt5_base \
    __install_qt5_base() \
    { \
	make install INSTALL_ROOT=%buildroot "$@" \
    }\
    __install_qt5_base


# Included from file macros.rpm-build/tts
%_ttsdir	/etc/tts.d
%tts_unregister	/usr/sbin/tts-unregister

# Included from file macros.rpm-build/webserver-common
%webserver_group			_webserver
%webserver_webmaster		webmaster

%webserver_datadir		%_var/www
%webserver_htdocsdir		%webserver_datadir/html
%webserver_htdocsaddondir	%webserver_htdocsdir/addon-modules
%webserver_manualaddonsdir	%webserver_datadir/manual-addons
%webserver_cgibindir		%webserver_datadir/cgi-bin
%webserver_iconsdir		%webserver_datadir/icons
%webserver_iconssmalldir		%webserver_iconsdir/small
%webserver_vhostdir		%webserver_datadir/vhosts
%webserver_webappsdir		%webserver_datadir/webapps
%webserver_uploadsdir		%webserver_datadir/uploads

# 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.intro/macros.intro.backport
# Introduced for ALT Linux and already applied in Sisyphus macros
# Collected by Vitaly Lipatov <lav@etersoft.ru>
# These macros will be packed in rpm-build-compat package (only on ALT)

# introduced since rpm-4.0.4-alt98.28
# https://bugzilla.altlinux.org/show_bug.cgi?id=22710
%_aclocaldir %_datadir/aclocal
# Subsys dir placed in various dirs
%_locksubsysdir %_var/lock/subsys

%_rpmlibdir %_prefix/lib/rpm

# introduced 23.12.2008 in rpm 4.0.4-alt96.13
%_rpmmacrosdir    %_rpmlibdir/macros.d

# introduced in rpm 4.0.4-alt83
# https://bugzilla.altlinux.org/show_bug.cgi?id=13925
%autoreconf %__autoreconf

# introduced in rpm 4.0.4-alt60
# https://bugzilla.altlinux.org/show_bug.cgi?id=9067
%_liconsdir %_datadir/icons/hicolor/48x48/apps
%_miconsdir %_datadir/icons/hicolor/16x16/apps
%_niconsdir %_datadir/icons/hicolor/32x32/apps

# introduced in rpm 4.0.4-alt55
#  + Add macros: %_desktopdir, %_pixmapsdir (#8767)
%_desktopdir %_datadir/applications
%_pixmapsdir %_datadir/pixmaps

# introduced in rpm 4.0.4-alt54
#  + Added %__autoreconf macro (#8307)
%__autoreconf autoreconf -fisv

# introduced in rpm 4.0.4-alt42
%_x11x11dir %{_x11dir}/lib/X11
%_pkgconfigdir %{_libdir}/pkgconfig

# makeinstall_std was added in 4.0.4-alt96.16
%makeinstall_std %make_install DESTDIR=%buildroot install

%_cachedir %_var/cache

# 
%_omfdir %_datadir/omf

# add in rpm-build-python 0.33.1-alt1
# https://bugzilla.altlinux.org/show_bug.cgi?id=13941
%python_build	\
	%__python setup.py build
%python_install	\
	%__python setup.py install --skip-build --root=%buildroot
# TODO: need to be add (ALT bug #31808)
%python_check %__python setup.py check

# introduced in rpm-macros-qt4-4.8.4-alt3 21.03.2013
%qmake_qt4 \
  CPPFLAGS="${CPPFLAGS:-%optflags}" ; export CPPFLAGS ; \
  %_qt4dir/bin/qmake \\\
  QMAKE_CFLAGS="${CFLAGS:-%optflags}" \\\
  QMAKE_CXXFLAGS="${CXXFLAGS:-%optflags}" \\\
  QMAKE_LFLAGS="%{?ldflags}"

# introduced in 4.0.4-alt100.62
%EVR	%{?epoch:%epoch:}%{version}-%{release}

# updated in 4.0.4-alt176
# systemd.
%_binfmtdir            /lib/binfmt.d
%_env_dir              /lib/environment.d
%_journal_catalogdir   /usr/lib/systemd/catalog
%_modprobedir          /lib/modprobe.d
%_modules_loaddir      /lib/modules-load.d
%_presetdir            /lib/systemd/system-preset
%_user_presetdir       /usr/lib/systemd/user-preset
%_sysctldir            /lib/sysctl.d
%_sysusersdir          /lib/sysusers.d
%_systemd_dir          /lib/systemd
%_tmpfilesdir          /lib/tmpfiles.d
%_user_unitdir         /usr/lib/systemd/user
%_udev_hwdbdir         /lib/udev/hwdb.d
%_udev_rulesdir                /lib/udev/rules.d
%_gen_dir              /lib/systemd/system-generators
%_user_gen_dir         /usr/lib/systemd/user-generators
%_env_gen_dir          /lib/systemd/system-environment-generators
%_user_env_gen_dir     /usr/lib/systemd/user-environment-generators

# compat with systemd upstream.
%_environmentdir       %_env_dir
%_journalcatalogdir    %_journal_catalogdir
%_modulesloaddir       %_modules_loaddir
%_userunitdir          %_user_unitdir
%_userpresetdir                %_user_presetdir
%_udevhwdbdir          %_udev_hwdbdir
%_udevrulesdir         %_udev_rulesdir
%_systemd_util_dir     %_systemd_dir
%_systemdgeneratordir                  %_gen_dir
%_systemdusergeneratordir              %_user_gen_dir
%_systemd_system_env_generator_dir     %_env_gen_dir
%_systemd_user_env_generator_dir       %_user_env_gen_dir


# Included from file macros.base/macros.compat
# ALT compatibility on other platforms

%prefix %_prefix

%update_menus :
%update_desktopdb :
%clean_menus :
%clean_desktopdb :

%post_ldconfig /sbin/ldconfig
%postun_ldconfig /sbin/ldconfig

# See also perl -pi -e
#%__subst sed -i -e

# FIXME: use sed -i if possible
# Use own subst macros. Works everywhere
%__subst %_bindir/subst

# not all rpm have getncpus
%__nprocs	%(epm print info -c 2>/dev/null || echo 1)

%_smp_build_ncpus	${NPROCS:-%__nprocs}
%_smp_mflags	-j%_smp_build_ncpus

# TODO: see #13937
%makeinstall_std make INSTALL="install -p" DESTDIR=%buildroot install

# due buggy on some systems (Debian)
%_sysconfdir /etc
# due buggy on some systems (ALT)
%_localstatedir /var

# _sharedstatedir is broken on some early systems (f.i. ALT Linux p6)
# https://bugzilla.redhat.com/show_bug.cgi?id=185862
%_sharedstatedir /var/lib

# due mismatch between configure (datadir/doc) and spec docdir in some systems (SUSE, Slackware)
# deprecated:
%_defaultdocdir %_datadir/doc
%_docdir %_datadir/doc

# deprecated (see https://bugzilla.altlinux.org/show_bug.cgi?id=24290):
%_initrddir %_initddir
%_initdir %_initddir

# deprecated
%_runtimedir /var/run

%_rundir /var/run
%_logdir /var/log

# Mdk compatibility
%_iconsdir %_datadir/icons

%_man1dir %_mandir/man1
%_man2dir %_mandir/man2
%_man3dir %_mandir/man3
%_man4dir %_mandir/man4
%_man5dir %_mandir/man5
%_man6dir %_mandir/man6
%_man7dir %_mandir/man7
%_man8dir %_mandir/man8
%_man9dir %_mandir/man9
%_manndir %_mandir/mann

%_menudir %_prefix/lib/menu


##########################################

# in %%post section.
%install_info   /usr/sbin/install_info

# in %%preun section.
%uninstall_info /usr/sbin/uninstall_info


%optflags_default	-O2
%optflags_shared	-fPIC -DPIC

%remove_optflags(a:f:t:p:w:W:d:g:O:A:C:D:E:H:i:M:n:P:U:u:l:s:X:B:I:L:b:V:m:x:c:S:E:o:v:) \
%global optflags %(opt="%optflags"; for f in %{**}; do opt="$(echo "$opt"|sed -e "s/ $f//g;s/$f //g")"; done; echo "$opt")

%add_optflags(a:f:t:p:w:W:d:g:O:A:C:D:E:H:i:M:n:P:U:u:l:s:X:B:I:L:b:V:m:x:c:S:E:o:v:) \
%global optflags %{optflags} %{**}


##########################################

# Set with/without default value.
%def_with() %{expand:%%{!?_with_%{1}: %%{!?_without_%{1}: %%global _with_%{1} --with-%{1}}}}
%def_without() %{expand:%%{!?_with_%{1}: %%{!?_without_%{1}: %%global _without_%{1} --without-%{1}}}}

# Set enable/disable default value.
%def_enable() %{expand:%%{!?_enable_%{1}: %%{!?_disable_%{1}: %%global _enable_%{1} --enable-%{1}}}}
%def_disable() %{expand:%%{!?_enable_%{1}: %%{!?_disable_%{1}: %%global _disable_%{1} --disable-%{1}}}}

# Set with/without value.
%force_with() %{expand:%%global _with_%{1} --with-%{1}}
%force_without() %{expand:%%global _without_%{1} --without-%{1}}

# Set enable/disable value.
%force_enable() %{expand:%%global _enable_%{1} --enable-%{1}}
%force_disable() %{expand:%%global _disable_%{1} --disable-%{1}}

# Check whether both _with_%{1} and _without_%{1} are defined.
%check_def() %{expand:%%{?_with_%{1}: %%{?_without_%{1}: %%{error: both _with_%{1} and _without_%{1} are defined}}}} \
	%{expand:%%{?_enable_%{1}: %%{?_disable_%{1}: %%{error: both _enable_%{1} and _disable_%{1} are defined}}}}

# Check for defined/undefined.
%defined() %{expand:%%{?%{1}:1}%%{!?%{1}:0}}
%undefined() %{expand:%%{?%{1}:0}%%{!?%{1}:1}}

# ifdef/ifndef.
%ifdef() %if %{expand:%%{?%{1}:1}%%{!?%{1}:0}}
%ifndef() %if %{expand:%%{?%{1}:0}%%{!?%{1}:1}}

# Check for with/without.
%with() %{expand:%%{?_with_%{1}:1}%%{!?_with_%{1}:0}}
%without() %{expand:%%{?_without_%{1}:1}%%{!?_without_%{1}:0}}

# if_with/if_without.
%if_with() %if %{expand:%%{?_with_%{1}:1}%%{!?_with_%{1}:0}}
%if_without() %if %{expand:%%{?_without_%{1}:1}%%{!?_without_%{1}:0}}

# Check for enabled/disabled.
%enabled() %{expand:%%{?_enable_%{1}:1}%%{!?_enable_%{1}:0}}
%disabled() %{expand:%%{?_disable_%{1}:1}%%{!?_disable_%{1}:0}}

# if_enabled/if_disabled.
%if_enabled() %if %{expand:%%{?_enable_%{1}:1}%%{!?_enable_%{1}:0}}
%if_disabled() %if %{expand:%%{?_disable_%{1}:1}%%{!?_disable_%{1}:0}}

# substitute with/without/enable/disable macros.
%subst_with() %{expand:%%{?_with_%{1}:%%{_with_%{1}}}} %{expand:%%{?_without_%{1}:%%{_without_%{1}}}}
%subst_enable() %{expand:%%{?_enable_%{1}:%%{_enable_%{1}}}} %{expand:%%{?_disable_%{1}:%%{_disable_%{1}}}}

################################################

%_qt5_prefix %_libdir/qt5
%_qt5_translationdir %_datadir/qt5/translations
%_qt5_qmake %_qt5_prefix/bin/qmake

# logrotate configs.
%_logrotatedir %{_sysconfdir}/logrotate.d


# usage: if_feature FEATURE [version]
# examples:
#    if_feature sip5
#    if_feature icu 6.5
# details: mix if_with and if_ver_gteq
%if_feature() %if (%{expand:%%{?feature_%{1}:1}%%{!?feature_%{1}:0}}) && ( "00" != "0%{expand:%%{?feature_%{1}:%%{feature_%{1}}}}" ) && ( 0%{!?2:1} || ( 0%{?2:1} && "%(rpmvercmp '0%{expand:%%{feature_%{1}}}' '0%{?2:%2}')" >= "0" ) )
%if_notfeature() %if !(%{expand:%%{?feature_%{1}:1}%%{!?feature_%{1}:0}}) || !( "00" != "0%{expand:%%{?feature_%{1}:%%{feature_%{1}}}}" ) && ( 0%{!?2:1} || ( 0%{?2:1} && "%(rpmvercmp '0%{expand:%%{feature_%{1}}}' '0%{?2:%2}')" >= "0" ) )


%brp_strip_none()		%global _brp_strip_none %{?_brp_strip_none} %*

# Included from file macros.base/macros.rpm
# ALT compatibility on other platforms (rpm based)

# canonical name, but can be skipped yet
%_initddir %_sysconfdir/rc.d/init.d

#%post_service() \
#if [ "$RPM_INSTALL_ARG1" = "1" ] ; then \
#chkconfig --add %1 || : \
#else \
#%_initddir/%1 condrestart || : \
#fi

#%preun_service() \
#if [ "$RPM_INSTALL_ARG1" != "0" ]; then \
#%_initddir/%1 condstop ||: \
#chkconfig --del %1 || : \
#fi

%post_service() \
	test -x /sbin/chkconfig && chkconfig --add %1 || : \
	%_initddir/%1 condrestart || : \
%nil

%preun_service() \
	test -x /sbin/chkconfig && chkconfig --del %1 || : \
	%_initddir/%1 condstop || : \
%nil

# Start service only after manual install
# 1 - 1st install, 2 - update package
%start_service() \
	[ -z "$DURING_INSTALL" ] && [ "$1" = "1" ] && %_initddir/%{1} start || : \
%nil

# PLD compatibility (-f removed as redhat specific extension)
%groupadd /usr/sbin/groupadd -r
%useradd /usr/sbin/useradd -r
#%userremove userdel
#%groupremove groupdel

%set_verify_elf_method #
%add_verify_elf_skiplist #
%set_strip_method #
%set_gcc_version #

# FIXME in some way?
%add_findprov_lib_path #
%add_findprov_skiplist #
%add_findreq_skiplist #
%filter_from_requires #

# it is better to install rpm-build-fonts instead
%_fontpathdir %_sysconfdir/X11/fontpath.d
%_fontsdir %_datadir/fonts
%_bitmapfontsdir %_fontsdir/../bitmap-fonts
%_type1fontsdir %_fontsdir/Type1
%_ttffontsdir %_fontsdir/TTF
%_otffontsdir %_fontsdir/OTF

%kernel_src %_usrsrc/kernel/sources


# Helper macroses for fonts packages in ALT Linux.
# Check to ALT Linux font policy: http://www.freesource.info/wiki/Altlinux/Policy/Fonts
# Modified: remove X scale file creating

# for use in %%install section (use with name of font family)
# %%build helpers
#############################################################
%ttf_fonts_install() \
%global __currentfontsdir %_ttffontsdir/%{1} \
mkdir -p %buildroot%__currentfontsdir \
cat <<EOF >%{1}.files \
%%dir %__currentfontsdir \
EOF\
install -p -m644 *.ttf %buildroot%__currentfontsdir/ \
find %buildroot%__currentfontsdir/ -name "*.ttf" | sed -e 's|%buildroot\\(.*\\)|"\\1"|g' >>%{1}.files \
%nil

#############################################################
%otf_fonts_install() \
%global __currentfontsdir %_otffontsdir/%{1} \
mkdir -p %buildroot%__currentfontsdir \
cat <<EOF >%{1}.files \
%%dir %__currentfontsdir \
EOF\
install -p -m644 *.otf %buildroot%__currentfontsdir/ \
find %buildroot%__currentfontsdir/ -name "*.otf" | sed -e 's|%buildroot\\(.*\\)|"\\1"|g' >>%{1}.files \
%nil


# for use in %%post section
%post_fonts \
%_bindir/fc-cache %__currentfontsdir || : \
%nil

# for use in %%postun section
%postun_fonts \
if [ "$1" = "0" ]; then \
%_bindir/fc-cache --system-only || : \
fi \
%nil

# use %%files -f %fname.files in your spec

##############################################################
%_locksubsysdir %_var/lock/subsys

# macro for init scripts configs
%_sysconfigdir %_sysconfdir/sysconfig

# target libdir
%_target_libdir_noarch	/usr/lib
%_target_libdir	%{expand:%%{?_target_libdir_%_target_cpu}%%{!?_target_libdir_%_target_cpu:%%_libdir}}

%_cachedir	%{_var}/cache

# Included from file macros.distro/macros.rhel
# (from /usr/lib/rpm/*/macros), I believe it is Fedora compatible names
# systemd
%_presetdir	/usr/lib/systemd/system-preset
%_unitdir	/usr/lib/systemd/system
%systemd_unitdir	/usr/lib/systemd/system

%__python_package_prefix python26
%__python3_package_prefix python34


# Included from file macros.distro/macros.rhel.8

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

# udev dirs exists since CentOS 6, but we need this macro in CentOS 5 too
%_udevhwdbdir /usr/lib/udev/hwdb.d
%_udevrulesdir /usr/lib/udev/rules.d

%__python_package_prefix python27
%__python3_package_prefix python36

# from rpm-macros-features
%feature_vulkan 1
%feature_vkd3d 1
%feature_faudio 1
%feature_pcap 1
%feature_llvm 18
%feature_opencl 1
