################################################################################
#
# python-distutils.cygclass - for building Python 2.x modules with Distutils
#
# 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/python-distutils.cygclass
#  DESCRIPTION
#  Distutils is the most common method for building and installing Python
#  libraries and programs.  The build is defined by a setup.py file in the
#  top source directory, which controls the installation of files and the
#  building of C Python extensions.  Many such packages are hosted on the
#  Python Package Index (PyPI, previously known as Cheeseshop).
#
#  This cygclass handles the building of Python 2.x distutils-based packages.
#  INHERITS
#  python.cygclass
#  REQUIRES
#  python
#****
inherit python

ORIG_PN=${ORIG_PN:-${PN#python-}}

#****o* python-distutils.cygclass/HOMEPAGE (python-distutils)
#  DESCRIPTION
#  Default homepage of the Python module on the Python Package Index.
#****
HOMEPAGE="http://pypi.python.org/pypi/${ORIG_PN}"

#****o* python-distutils.cygclass/SRC_URI (python-distutils)
#  DESCRIPTION
#  Download location of the Python module on the Python Package Index.
#****
SRC_URI="http://pypi.python.org/packages/source/${ORIG_PN:0:1}/${ORIG_PN}/${ORIG_PN}-${PV}.tar.gz"

#****C* python-distutils.cygclass/python_distutils_compile
#  SYNOPSIS
#  python_distutils_compile [OPTIONS]
#  DESCRIPTION
#  Runs the setup.py 'config' and 'build' commands.  All arguments are passed
#  to the setup.py 'build' command.
#****
python_distutils_compile() {
	if [ ! -e setup.py ]
	then
		error "No Python Distutils module detected"
	fi

	${PYTHON} setup.py config || error "setup.py config failed"
	${PYTHON} setup.py build "${@}" || error "setup.py build failed"
}

#****I* python-distutils.cygclass/python_distutils_install
#  SYNOPSIS
#  python_distutils_install [OPTIONS]
#  DESCRIPTION
#  Runs the setup.py 'install' phase, setting the root argument to install
#  into $D, followed by python_optimize.  All arguments are passed to the
#  setup.py 'install' command.
#****
python_distutils_install() {
	if [ ! -e setup.py ]
	then
		error "No Python Distutils module detected"
	fi

	${PYTHON} setup.py "${@}" install -O0 --root=${D} || error "setup.py install failed"

	if [ -d ${D}${PYTHON_SITELIB} ]
	then
		python_optimize ${PYTHON_SITELIB}
	fi
}

#****o* python-distutils.cygclass/src_compile (python-distutils)
#  DEFINITION
src_compile() {
	lndirs
	cd ${B}
	python_distutils_compile
}
#****

#****o* python-distutils.cygclass/src_install (python-distutils)
#  DEFINITION
src_install() {
	cd ${B}
	python_distutils_install
}
#****

readonly -f python_distutils_compile python_distutils_install
