1 ################################################################################
3 # python2.cygclass - functions for installing Python 2 modules
5 # Part of cygport - Cygwin packaging application
6 # Copyright (C) 2006-2020 Cygport authors
7 # Provided by the Cygwin project <https://cygwin.com/>
9 # cygport is free software: you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation, either version 3 of the License, or
12 # (at your option) any later version.
14 # cygport is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with cygport. If not, see <https://www.gnu.org/licenses/>.
22 ################################################################################
24 #****h* Cygclasses/python2.cygclass
28 # Python is a general-purpose, interpreted programming language used in a
29 # wide variety of software. It comes with a large standard library, and is
30 # easily extendible with modules written in Python and/or C/C++. Programs
31 # can also embed a Python interpreter for use with their own extensions.
33 # This cygclass provides definitions and some install helpers which can be used
34 # by any Python-based package. Python modules and programs are built in a
35 # number of ways, so this cygclass does not provide any build functions. The
36 # two most common build systems for Python packages are Distutils and autotools.
38 # python2.cygclass is for the 2.x versions of CPython. For the 3.x versions,
39 # see python3.cygclass.
41 # python-wheel.cygclass, python2-distutils.cygclass, pygtk.cygclass
46 error "python2.cyclass: python2 was sunsetted on 1 January, 2020. Please use python3 instead."
48 # cross-compiling is not (yet?) supported
49 __cross_compiling_error
51 check_prog_req python2
53 #****d* python2.cygclass/PYTHON2
55 # Absolute path to the Python interpreter.
57 PYTHON2=/usr/bin/python2
59 #****d* python2.cygclass/PYTHON2_VERSION
61 # The major.minor version of the current Python interpreter.
63 PYTHON2_VERSION=$(${PYTHON2} -c 'from distutils.sysconfig import * ; print get_python_version();')
65 #****d* python2.cygclass/PYTHON2_INCLUDEDIR
67 # Path containing the Python C library headers.
69 PYTHON2_INCLUDEDIR=$(${PYTHON2} -c 'from distutils.sysconfig import * ; print get_python_inc();')
71 #****d* python2.cygclass/PYTHON2_LIB
73 # Path containing the Python standard library.
75 # Never install third-party extensions into PYTHON2_LIB; use PYTHON2_SITELIB instead.
77 PYTHON2_LIB=$(${PYTHON2} -c 'from distutils.sysconfig import * ; print get_python_lib(0,1);')
79 #****d* python2.cygclass/PYTHON2_SITELIB
81 # Installation path for all Python extension modules.
83 PYTHON2_SITELIB=$(${PYTHON2} -c 'from distutils.sysconfig import * ; print get_python_lib(0,0);')
85 #****d* python2.cygclass/LIBPYTHON2
87 # Link flags for the Python C library. This definition must be properly quoted.
89 LIBPYTHON2="-L${PYTHON2_LIB}/config -lpython${PYTHON2_VERSION}"
91 #****I* python2.cygclass/python2into
93 # python2into SUBDIRECTORY
95 # Subdirectory of PYTHON2_SITELIB into which dopython2 should install. This is
96 # usually unnecessary.
101 error "python2into accepts exactly one argument";
105 /*) error "python2into argument should be only a subdirectory" ;;
108 _python2into_dir=${1};
111 #****I* python2.cygclass/dopython2
113 # [python2into SUBDIRECTORY]
114 # dopython2 MODULE1 [MODULE2] ...
116 # Installs the given Python module(s) (.py or .dll) into PYTHON2_SITELIB under $D,
117 # or a subdirectory thereof if python2into was previously called.
124 if defined _python2into_dir
126 pydir=${PYTHON2_SITELIB}/${_python2into_dir}
128 pydir=${PYTHON2_SITELIB}
137 error "dopython2: ${i}: file not found"
141 *.dll|*.la) mode=0755 ;;
145 __doinstall ${mode} ${i} ${pydir} || error "dopython2 ${i} failed"
149 #****I* python2.cygclass/python2_optimize
151 # python2_optimize DIRECTORY [DIRECTORY] ...
153 # Bytecode-compile all Python modules found in the given directories under $D.
155 # Python modules installed with distutils_install are automatically compiled,
156 # as are those installed by automake-based packages *if* they have been declared
157 # as _PYTHON files (in which case a py-compile script will be present in $S).
158 # Some automake-based packages mistakenly declare these as _DATA instead, in
159 # which case either the Makefile.am must be patched or this function called
167 if [ ! -d ${D}${pyd} ]
169 error "directory ${pyd} does not exist"
172 inform "Compiling ${pyd}..."
173 ${PYTHON2} ${PYTHON2_LIB}/compileall.py -f -q -d ${pyd} ${D}${pyd}
174 ${PYTHON2} -O ${PYTHON2_LIB}/compileall.py -f -q -d ${pyd} ${D}${pyd}
178 #****I* python2.cygclass/python2_fix_shebang
180 # python2_fix_shebang SCRIPT [SCRIPT ...]
182 # Fixes the designated interpreter of SCRIPT to PYTHON2. This would be necessary
183 # if the original uses an incorrect path (e.g. /usr/local/bin) or an
184 # incorrectly versioned binary. SCRIPT need not be prefixed by $D.
186 python2_fix_shebang() {
189 __fix_shebang ${PYTHON2} ${D}/${f#${D}}
193 readonly -f python2into dopython2 python2_optimize python2_fix_shebang