
# 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 -rf {} \; \
find ./ -type d -name CVS -print0 | xargs -0 --no-run-if-empty rm -rf {} \;

# 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

%configure32 \
%global optflags32 %(echo "%optflags" | sed -e "s/-m64//g") \
CFLAGS="%optflags32"; export CFLAGS; \
CXXFLAGS="%optflags32"; export CXXFLAGS; \
FFLAGS="%optflags32"; export FFLAGS; \
%configure --libdir=%_lib32dir

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

# 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


# introduced 23.12.2008 in rpm 4.0.4-alt96.13 as
# %_rpmmacrosdir    %_rpmlibdir/macros.d
%_rpmmacrosdir %_sysconfdir/rpm/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-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

# from mdk
%makeinstall_std %make_install DESTDIR=%buildroot install

# 
%_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}"

# 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

# Make
# use gmake if possible
%_make_bin %(N=`which gmake 2>/dev/null` ; [ -x "$N" ] && echo "$N" || echo make)

# Check numproc for Linux and for FreeBSD
%__nprocs	%(N=`egrep -cs ^cpu[0-9]+ /proc/stat`; [ "$N" -gt 0 ] 2>/dev/null || N=`sysctl -a | egrep -i hw.ncpu | sed -e "s|.*: ||g"` ; [ "$N" -gt 0 ] 2>/dev/null && echo "$N" || echo 1)

%make_build	[ -n "$NPROCS" ] || NPROCS=%__nprocs; %_make_bin -j$NPROCS

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

%__make %_make_bin
%make %_make_bin

# 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

%_runtimedir /var/run

# Mdk compatibility
%_iconsdir %_datadir/icons
%_liconsdir %_iconsdir/mini
%_miconsdir %_iconsdir/large
%_niconsdir %_iconsdir

# altbug #9047
#%_liconsdir %_datadir/icons/hicolor/48x48/apps 
#%_miconsdir %_datadir/icons/hicolor/16x16/apps 
#%_niconsdir %_datadir/icons/hicolor/32x32/apps 

%_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}}}}


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

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

%post_service() \
	test -x /usr/sbin/update-rc.d && update-rc.d %1 defaults || : \
	%_initddir/%1 condrestart || : \
%nil

%preun_service() \
	%_initddir/%1 condstop || : \
	test -x /usr/sbin/update-rc.d && update-rc.d -f %1 remove || : \
%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
%groupadd /usr/sbin/groupadd -f
%useradd /usr/sbin/useradd
#%userremove userdel
#%groupremove groupdel

# from /usr/lib/rpm/*/macros
# systemd
%_presetdir	/lib/systemd/system-preset
%_unitdir	/lib/systemd/system

%set_verify_elf_method #
%set_strip_method #
%set_gcc_version #

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

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

%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

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

%_libexecdir %_prefix/lib

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


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

%_udevhwdbdir	/lib/udev/hwdb.d
%_udevrulesdir	/lib/udev/rules.d

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

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

# Due RPM incompatibility on Debian/Ubuntu x86_64
# See https://bugs.etersoft.ru/show_bug.cgi?id=7871
# Really 64bit Debian/Ubuntu used /usr/lib not /usr/lib64 (depricated, forbidden and unused)
# TODO: fix this back in Debian packages
%_lib lib
%_libdir %_prefix/lib
%_lib32dir %_prefix/lib32

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

%cmake \
    __cmake() \
    { \
	cd BUILD \
	cmake .. \\\
	    %{?_cmake_skip_rpath} \\\
	    -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 \\\
	    %if "%_lib" == "lib64" \
	    -DLIB_SUFFIX="64" \\\
	    %else \
	    -DLIB_SUFFIX="" \\\
	    %endif \
	    \\\
	    "$@" \
	cd - >/dev/null \
    } \
    mkdir -p BUILD; \
    __cmake

%cmake_insource \
    cmake . \\\
	%{?_cmake_skip_rpath} \\\
	-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 \\\
	%if "%_lib" == "lib64" \
	-DLIB_SUFFIX="64" \\\
	%else \
	-DLIB_SUFFIX="" \\\
	%endif \
	-DLIB_DESTINATION=%_lib

%cmake_build \
    %make_build -C BUILD

%cmake_install \
    %make_install -C BUILD

%cmakeinstall_std \
    %makeinstall_std -C BUILD

# 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

%_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 %_target_libdir/python3.2 %_target_libdir_noarch/python3.2 %_target_libdir/python3.3 %_target_libdir_noarch/python3.3
%_python_compile_include	%_target_libdir %_target_libdir_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-altlinux-compat >= 1.7.26") \
%(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() \
%(echo -n "Requires:"; %{expand: %%__python_deps_internal %{*}}) \
%nil

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

#  py_package_provides <pypackage1> [[>= <pypackage1_version>] [<pypackage2> ...]]
#
# 	Аналогично py_package_requires, но формирует не списки Requires, а списки
# 	Provides
#
%py_package_provides() \
%(echo -n "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

# traditional build/install macros
%python_build	\
	CFLAGS="${CFLAGS:-%optflags}" ; export CFLAGS ; \
	CXXFLAGS="${CXXFLAGS:-%optflags}" ; export CXXFLAGS ; \
	FFLAGS="${FFLAGS:-%optflags}" ; export FFLAGS ; \
	%__python setup.py build
%python_build_debug	\
	CFLAGS="${CFLAGS:-%optflags}" ; export CFLAGS ; \
	CXXFLAGS="${CXXFLAGS:-%optflags}" ; export CXXFLAGS ; \
	FFLAGS="${FFLAGS:-%optflags}" ; export FFLAGS ; \
	%__python setup.py build --debug
%python_install	\
	%__python setup.py install --skip-build --root=%buildroot --prefix=%_prefix
%python_build_install	\
	CFLAGS="${CFLAGS:-%optflags}" ; export CFLAGS ; \
	CXXFLAGS="${CXXFLAGS:-%optflags}" ; export CXXFLAGS ; \
	FFLAGS="${FFLAGS:-%optflags}" ; export FFLAGS ; \
	%__python setup.py install --root=%buildroot

# Included from file macros.rpm-build/python.env
# have no idea to correct use (http://bugs.etersoft.ru/show_bug.cgi?id=9477)
#%{?_python_lib_path:export RPM_PYTHON_LIB_PATH="%_python_lib_path"}
#%{?_python_module_declared:export RPM_PYTHON_MODULE_DECLARED="%_python_module_declared"}
#%{?_python_req_hier:export RPM_PYTHON_REQ_HIER="%_python_req_hier"}
#%{?_python_req_method:export RPM_PYTHON_REQ_METHOD="%_python_req_method"}
#%{?_python_req_skip:export RPM_PYTHON_REQ_SKIP="%_python_req_skip"}
#%{?_python_compile_method:export RPM_PYTHON_COMPILE_METHOD="%_python_compile_method"}
#%{?_python_compile_exclude:export RPM_PYTHON_COMPILE_EXCLUDE="%_python_compile_exclude"}
#%{?_python_compile_include:export RPM_PYTHON_COMPILE_INCLUDE="%_python_compile_include"}
#%{?_python_compile_deep:export RPM_PYTHON_COMPILE_DEEP="%_python_compile_deep"}
#%{?_python_compile_skip_x:export RPM_PYTHON_COMPILE_SKIP_X="%_python_compile_skip_x"}
#%{?_python_compile_clean:export RPM_PYTHON_COMPILE_CLEAN="%_python_compile_clean"}
#%{?__python:export RPM_PYTHON="%__python"}

# 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.distro/macros.astra
%_qt4dir %_datadir/qt4
# ALT compatibility on other platforms

# Included from file macros.distro/macros.astra.x86_64
# ALT compatibility on other platforms

%_lib lib
%_libdir %_prefix/lib/
%_lib32dir %_prefix/lib32
