# : $Id: python 378 2004-10-05 12:21:51Z cray $
# -*- coding: koi8-r -*-
# _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

%_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 \
%{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() \
%(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 %_libdir/python%__python_version

#  Python,      
%python_sitelibdir %python_libdir/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
