################################################################################
#
# distutils.cygclass - wrapper for various py*-distutils cygclasses
#
# Part of cygport - Cygwin packaging application
# Copyright (C) 2006-2016 Yaakov Selkowitz
# Provided by the Cygwin Ports project <http://sourceware.org/cygwinports/>
#
# cygport is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# cygport is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with cygport.  If not, see <http://www.gnu.org/licenses/>.
#
################################################################################

#****h* Cygclasses/distutils.cygclass
#  SYNOPSIS
#  inherit distutils
#  DESCRIPTION
#  Compatibility wrapper for python-distutils.cygclass. python3-distutils.cygclass.
#  or pypy-distutils.cygclass.
#  INHERITS
#  python-distutils.cygclass in most scenarios, OR python3-distutils.cygclass
#  if PN begins with "python3-*" or python3.cygclass has already been inherit()ed,
#  OR pypy-distutils.cygclass if PN begins with "pypy-*" or pypy.cygclass has
#  already been inherit()ed.
#  WARNING
#  distutils.cygclass can only be used with one of python, python3, or pypy.
#  If you wish to build a module for both python and python3 from the same
#  source simultaneously, use distutils-multi.cygclass.
#****

case ${PN} in
	python-*)
		_pyinterp=python
		;;
	python3-*)
		inform "Using Python 3.x ..."
		_pyinterp=python3
		;;
	pypy-*)
		inform "Using PyPy ..."
		_pyinterp=pypy
		;;
	*)	if inherited python && ! inherited python3 && ! inherited pypy
		then
			_pyinterp=python
		elif inherited python3 && ! inherited python && ! inherited pypy
		then
			inform "Using Python 3.x ..."
			_pyinterp=python3
		elif inherited pypy && ! inherited python && ! inherited python3
		then
			inform "Using PyPy ..."
			_pyinterp=pypy
		elif inherited python && inherited python3
		then
			warning "Both python.cygclass and python3.cygclass have been inherited!"
			warning "Perhaps you want to use distutils-multi.cygclass instead?"
			error "distutils.cygclass: incompatible use of both python and python3"
		else
			_pyinterp=python
		fi
esac

inherit ${_pyinterp}-distutils

#****C* distutils.cygclass/distutils_compile
#  DESCRIPTION
#  Wrapper for python_distutils_compile/python3_distutils_compile/pypy_distutils_compile
#****
distutils_compile() {
	${_pyinterp}_distutils_compile "$@"
}

#****I* distutils.cygclass/distutils_install
#  DESCRIPTION
#  Wrapper for python_distutils_install/python3_distutils_install/pypy_distutils_install
#****
distutils_install() {
	${_pyinterp}_distutils_install "$@"
}

readonly -f distutils_compile distutils_install
