2014-09-24 10:08:37 +02:00
|
|
|
#
|
2016-04-14 10:41:48 +02:00
|
|
|
# Copyright (C) 2007-2016 OpenWrt.org
|
2014-09-24 10:08:37 +02:00
|
|
|
#
|
|
|
|
# This is free software, licensed under the GNU General Public License v2.
|
|
|
|
# See /LICENSE for more information.
|
|
|
|
#
|
|
|
|
|
2020-04-15 15:55:17 +02:00
|
|
|
# Note: include this file after `include $(TOPDIR)/rules.mk in your package Makefile
|
2020-04-10 16:22:58 +02:00
|
|
|
|
2018-01-10 08:29:41 +01:00
|
|
|
python3_mk_path:=$(dir $(lastword $(MAKEFILE_LIST)))
|
|
|
|
include $(python3_mk_path)python3-host.mk
|
2014-09-24 10:08:37 +02:00
|
|
|
|
2014-10-14 10:52:06 +02:00
|
|
|
PYTHON3_DIR:=$(STAGING_DIR)/usr
|
|
|
|
PYTHON3_INC_DIR:=$(PYTHON3_DIR)/include/python$(PYTHON3_VERSION)
|
|
|
|
PYTHON3_LIB_DIR:=$(PYTHON3_DIR)/lib/python$(PYTHON3_VERSION)
|
2014-09-24 10:08:37 +02:00
|
|
|
|
2014-10-14 10:52:06 +02:00
|
|
|
PYTHON3_PKG_DIR:=/usr/lib/python$(PYTHON3_VERSION)/site-packages
|
2014-09-24 10:08:37 +02:00
|
|
|
|
2014-10-14 10:52:06 +02:00
|
|
|
PYTHON3:=python$(PYTHON3_VERSION)
|
2014-09-24 10:08:37 +02:00
|
|
|
|
2015-01-19 19:22:41 +01:00
|
|
|
PYTHON3PATH:=$(PYTHON3_LIB_DIR):$(STAGING_DIR)/$(PYTHON3_PKG_DIR):$(PKG_INSTALL_DIR)/$(PYTHON3_PKG_DIR)
|
2014-09-24 10:08:37 +02:00
|
|
|
|
2023-06-29 10:33:25 +02:00
|
|
|
-include $(PYTHON3_LIB_DIR)/openwrt/Makefile-vars
|
2020-07-08 10:02:49 +02:00
|
|
|
|
2015-11-18 17:57:16 +01:00
|
|
|
# These configure args are needed in detection of path to Python header files
|
|
|
|
# using autotools.
|
|
|
|
CONFIGURE_ARGS += \
|
|
|
|
_python_sysroot="$(STAGING_DIR)" \
|
|
|
|
_python_prefix="/usr" \
|
|
|
|
_python_exec_prefix="/usr"
|
|
|
|
|
2020-04-10 16:22:58 +02:00
|
|
|
PYTHON3_VARS = \
|
|
|
|
CC="$(TARGET_CC)" \
|
|
|
|
CCSHARED="$(TARGET_CC) $(FPIC)" \
|
|
|
|
CXX="$(TARGET_CXX)" \
|
|
|
|
LD="$(TARGET_CC)" \
|
|
|
|
LDSHARED="$(TARGET_CC) -shared" \
|
|
|
|
CFLAGS="$(TARGET_CFLAGS)" \
|
|
|
|
CPPFLAGS="$(TARGET_CPPFLAGS) -I$(PYTHON3_INC_DIR)" \
|
|
|
|
LDFLAGS="$(TARGET_LDFLAGS) -lpython$(PYTHON3_VERSION)" \
|
2020-07-08 10:02:49 +02:00
|
|
|
_PYTHON_HOST_PLATFORM="$(_PYTHON_HOST_PLATFORM)" \
|
2023-06-29 10:33:25 +02:00
|
|
|
_PYTHON_SYSCONFIGDATA_NAME="_sysconfigdata_$(ABIFLAGS)_$(MACHDEP)_$(MULTIARCH)" \
|
2020-04-10 16:22:58 +02:00
|
|
|
PYTHONPATH="$(PYTHON3PATH)" \
|
|
|
|
PYTHONDONTWRITEBYTECODE=1 \
|
|
|
|
_python_sysroot="$(STAGING_DIR)" \
|
|
|
|
_python_prefix="/usr" \
|
2023-09-13 06:15:18 +02:00
|
|
|
_python_exec_prefix="/usr" \
|
2023-09-25 05:58:12 +02:00
|
|
|
$(CARGO_PKG_CONFIG_VARS) \
|
2023-10-08 14:24:38 +02:00
|
|
|
PYO3_CROSS_LIB_DIR="$(PYTHON3_LIB_DIR)" \
|
|
|
|
SETUPTOOLS_RUST_CARGO_PROFILE="$(CARGO_PKG_PROFILE)"
|
2020-04-10 16:22:58 +02:00
|
|
|
|
|
|
|
# $(1) => directory of python script
|
|
|
|
# $(2) => python script and its arguments
|
|
|
|
# $(3) => additional variables
|
|
|
|
define Python3/Run
|
|
|
|
cd "$(if $(strip $(1)),$(strip $(1)),.)" && \
|
|
|
|
$(PYTHON3_VARS) \
|
|
|
|
$(3) \
|
|
|
|
$(HOST_PYTHON3_BIN) $(2)
|
|
|
|
endef
|
|
|
|
|
2020-04-09 17:28:07 +02:00
|
|
|
define Python3/FixShebang
|
2020-04-14 15:14:49 +02:00
|
|
|
$(SED) "1"'!'"b;s,^#"'!'".*python.*,#"'!'"/usr/bin/python3," -i --follow-symlinks $(1)
|
|
|
|
endef
|
|
|
|
|
|
|
|
# default max recursion is 10
|
|
|
|
PYTHON3_COMPILEALL_MAX_RECURSION_LEVEL:=20
|
|
|
|
|
|
|
|
# $(1) => directory of python source files to compile
|
|
|
|
#
|
|
|
|
# XXX [So that you won't goof as I did]
|
|
|
|
# Note: Yes, I tried to use the -O & -OO flags here.
|
|
|
|
# However the generated byte-codes were not portable.
|
|
|
|
# So, we just stuck to un-optimized byte-codes,
|
|
|
|
# which is still way better/faster than running
|
|
|
|
# Python sources all the time.
|
|
|
|
#
|
|
|
|
# Setting a fixed hash seed value is less secure than using
|
|
|
|
# random seed values, but is necessary for reproducible builds
|
|
|
|
# (for now).
|
|
|
|
#
|
|
|
|
# Should revisit this when https://bugs.python.org/issue37596
|
|
|
|
# (and other related reproducibility issues) are fixed.
|
|
|
|
define Python3/CompileAll
|
|
|
|
$(call Python3/Run,, \
|
|
|
|
-m compileall -r "$(PYTHON3_COMPILEALL_MAX_RECURSION_LEVEL)" -b -d '/' $(1),
|
|
|
|
$(if $(SOURCE_DATE_EPOCH),PYTHONHASHSEED="$(SOURCE_DATE_EPOCH)")
|
|
|
|
)
|
|
|
|
endef
|
|
|
|
|
|
|
|
# $(1) => target directory
|
|
|
|
define Python3/DeleteSourceFiles
|
|
|
|
$(FIND) $(1) -type f -name '*.py' -delete
|
|
|
|
endef
|
|
|
|
|
|
|
|
# $(1) => target directory
|
|
|
|
define Python3/DeleteNonSourceFiles
|
|
|
|
$(FIND) $(1) -not -type d -not -name '*.py' -delete
|
|
|
|
endef
|
|
|
|
|
|
|
|
# $(1) => target directory
|
|
|
|
define Python3/DeleteEmptyDirs
|
|
|
|
$(FIND) $(1) -mindepth 1 -empty -type d -not -path '$(1)/CONTROL' -not -path '$(1)/CONTROL/*' -delete
|
2019-09-12 14:03:50 +02:00
|
|
|
endef
|
|
|
|
|
2020-04-10 16:22:58 +02:00
|
|
|
|
|
|
|
# Py3Package
|
|
|
|
|
2020-04-15 09:11:01 +02:00
|
|
|
define Py3Package/filespec/Default
|
|
|
|
+|$(PYTHON3_PKG_DIR)
|
|
|
|
endef
|
|
|
|
|
|
|
|
# $(1) => package name
|
|
|
|
# $(2) => src directory
|
|
|
|
# $(3) => dest directory
|
|
|
|
define Py3Package/ProcessFilespec
|
|
|
|
$(eval $(call shexport,Py3Package/$(1)/filespec))
|
|
|
|
$(SHELL) $(python3_mk_path)python-package-install.sh \
|
|
|
|
"$(2)" "$(3)" "$$$$$(call shvar,Py3Package/$(1)/filespec)"
|
|
|
|
endef
|
|
|
|
|
2014-10-14 10:52:06 +02:00
|
|
|
define Py3Package
|
2017-03-02 17:02:14 +01:00
|
|
|
define Package/$(1)-src
|
|
|
|
$(call Package/$(1))
|
2018-01-17 16:30:48 +01:00
|
|
|
DEPENDS:=
|
2019-05-27 18:43:26 +02:00
|
|
|
CONFLICTS:=
|
|
|
|
PROVIDES:=
|
|
|
|
EXTRA_DEPENDS:=
|
2017-03-02 17:02:14 +01:00
|
|
|
TITLE+= (sources)
|
2019-05-27 18:43:26 +02:00
|
|
|
USERID:=
|
2019-07-09 14:12:06 +02:00
|
|
|
MENU:=
|
2017-03-02 17:02:14 +01:00
|
|
|
endef
|
|
|
|
|
|
|
|
define Package/$(1)-src/description
|
2020-04-15 15:55:17 +02:00
|
|
|
$$(call Package/$(1)/description)
|
|
|
|
|
|
|
|
This package contains the Python source files for $(1).
|
2017-03-02 17:02:14 +01:00
|
|
|
endef
|
|
|
|
|
2020-04-10 17:18:32 +02:00
|
|
|
define Package/$(1)-src/config
|
|
|
|
depends on PACKAGE_$(1)
|
|
|
|
endef
|
|
|
|
|
2015-01-19 19:22:41 +01:00
|
|
|
# Add default PyPackage filespec none defined
|
2020-04-15 09:11:01 +02:00
|
|
|
ifeq ($(origin Py3Package/$(1)/filespec),undefined)
|
|
|
|
Py3Package/$(1)/filespec=$$(Py3Package/filespec/Default)
|
2015-01-19 19:22:41 +01:00
|
|
|
endif
|
|
|
|
|
2017-01-04 10:27:36 +01:00
|
|
|
ifndef Py3Package/$(1)/install
|
|
|
|
define Py3Package/$(1)/install
|
2020-04-15 15:55:17 +02:00
|
|
|
if [ -d $(PKG_INSTALL_DIR)/usr/bin ]; then \
|
|
|
|
$(INSTALL_DIR) $$(1)/usr/bin ; \
|
|
|
|
$(CP) $(PKG_INSTALL_DIR)/usr/bin/* $$(1)/usr/bin/ ; \
|
|
|
|
fi
|
2017-01-04 10:27:36 +01:00
|
|
|
endef
|
|
|
|
endif
|
|
|
|
|
2017-05-19 16:16:38 +02:00
|
|
|
ifndef Package/$(1)/install
|
2020-04-14 15:14:49 +02:00
|
|
|
define Package/$(1)/install
|
2019-02-18 09:23:45 +01:00
|
|
|
$$(call Py3Package/$(1)/install,$$(1))
|
2020-04-15 09:11:01 +02:00
|
|
|
$$(call Py3Package/ProcessFilespec,$(1),$(PKG_INSTALL_DIR),$$(1))
|
2020-04-14 15:14:49 +02:00
|
|
|
$(FIND) $$(1) -name '*.exe' -delete
|
|
|
|
$$(call Python3/CompileAll,$$(1))
|
|
|
|
$$(call Python3/DeleteSourceFiles,$$(1))
|
|
|
|
$$(call Python3/DeleteEmptyDirs,$$(1))
|
|
|
|
if [ -d "$$(1)/usr/bin" ]; then \
|
|
|
|
$$(call Python3/FixShebang,$$(1)/usr/bin/*) ; \
|
2019-09-12 14:03:50 +02:00
|
|
|
fi
|
2020-04-14 15:14:49 +02:00
|
|
|
endef
|
2017-03-02 17:02:14 +01:00
|
|
|
|
2020-04-14 15:14:49 +02:00
|
|
|
define Package/$(1)-src/install
|
|
|
|
$$(call Py3Package/$(1)/install,$$(1))
|
2020-04-15 09:11:01 +02:00
|
|
|
$$(call Py3Package/ProcessFilespec,$(1),$(PKG_INSTALL_DIR),$$(1))
|
2020-04-14 15:14:49 +02:00
|
|
|
$$(call Python3/DeleteNonSourceFiles,$$(1))
|
|
|
|
$$(call Python3/DeleteEmptyDirs,$$(1))
|
|
|
|
endef
|
2017-05-19 16:16:38 +02:00
|
|
|
endif # Package/$(1)/install
|
2014-09-24 10:08:37 +02:00
|
|
|
endef
|
|
|
|
|
2020-04-09 16:42:27 +02:00
|
|
|
|
2020-04-10 16:22:58 +02:00
|
|
|
# Py3Build
|
2015-01-19 19:22:41 +01:00
|
|
|
|
2023-02-17 18:13:22 +01:00
|
|
|
PYTHON3_PKG_BUILD?=1
|
|
|
|
PYTHON3_PKG_FORCE_DISTUTILS_SETUP?=
|
|
|
|
|
|
|
|
PYTHON3_PKG_SETUP_DIR?=
|
|
|
|
PYTHON3_PKG_SETUP_GLOBAL_ARGS?=
|
|
|
|
PYTHON3_PKG_SETUP_ARGS?=--single-version-externally-managed
|
|
|
|
PYTHON3_PKG_SETUP_VARS?=
|
|
|
|
|
|
|
|
PYTHON3_PKG_BUILD_CONFIG_SETTINGS?=
|
|
|
|
PYTHON3_PKG_BUILD_VARS?=$(PYTHON3_PKG_SETUP_VARS)
|
|
|
|
PYTHON3_PKG_BUILD_ARGS?=
|
|
|
|
PYTHON3_PKG_BUILD_PATH?=$(PYTHON3_PKG_SETUP_DIR)
|
|
|
|
|
|
|
|
PYTHON3_PKG_INSTALL_VARS?=
|
|
|
|
|
|
|
|
PYTHON3_PKG_WHEEL_NAME?=$(subst -,_,$(if $(PYPI_SOURCE_NAME),$(PYPI_SOURCE_NAME),$(PKG_NAME)))
|
|
|
|
PYTHON3_PKG_WHEEL_VERSION?=$(PKG_VERSION)
|
|
|
|
|
|
|
|
PYTHON3_PKG_BUILD_DIR?=$(PKG_BUILD_DIR)/$(PYTHON3_PKG_BUILD_PATH)
|
|
|
|
|
2018-01-15 21:10:49 +01:00
|
|
|
|
2020-08-15 08:33:30 +02:00
|
|
|
PYTHON3_PKG_HOST_PIP_INSTALL_ARGS = \
|
|
|
|
$(foreach req,$(HOST_PYTHON3_PACKAGE_BUILD_DEPENDS), \
|
|
|
|
--requirement \
|
|
|
|
$(if $(findstring /,$(req)),$(req),$(python3_mk_path)host-pip-requirements/$(req).txt) \
|
|
|
|
)
|
|
|
|
|
2020-05-10 13:14:25 +02:00
|
|
|
define Py3Build/FindStdlibDepends
|
2021-09-30 21:30:08 +02:00
|
|
|
$(SHELL) $(python3_mk_path)python3-find-stdlib-depends.sh -n "$(PKG_NAME)" "$(PKG_BUILD_DIR)";
|
2020-05-10 13:14:25 +02:00
|
|
|
endef
|
|
|
|
|
2021-08-25 14:59:56 +02:00
|
|
|
ifneq ($(strip $(PYPI_NAME)),)
|
|
|
|
define Py3Build/CheckHostPipVersionMatch
|
python: Add pyproject.toml-based builds for host Python packages
Using pip to install host packages with pyproject.toml-based (PEP 517)
builds is problematic:
* If build isolation is used, pip will create an isolated build
environment, install any build dependencies for the requested package,
then build the requested package.
It does not appear currently possible to have pip install the build
dependencies with hash-checking mode enabled[1].
* If build isolation is not used, any build dependencies must be
installed in the build environment before invoking pip to build the
requested package[2].
This would require creating a package dependency resolution system to
install build dependencies, and any dependencies of dependencies, in
the correct order.
* It is very difficult to patch the packages installed by pip.
This adds a new include file (python3-host-build.mk) with recipes to
install host Python packages with pyproject.toml-based builds. This is
backwards-compatible with packages that require running setup.py.
Besides addressing the above issues (the OpenWrt build system already
resolves dependencies between packages, checks all source downloads
against known hashes, and supports patching packages), host packages
also:
* Capture package licensing and maintainer information
* Enable uscan checking for package updates/CVEs
* Are a known concept for OpenWrt packagers/developers
The existing functionality of using host pip to install packages will
remain for now, but should be considered deprecated and expected to be
removed in the future.
This also updates Py3Build/CheckHostPipVersionMatch for the case where
the host-pip-requirements directory does not exist or is empty.
[1]: https://pip.pypa.io/en/stable/user_guide/#changes-to-the-pip-dependency-resolver-in-20-3-2020
[2]: https://pip.pypa.io/en/stable/cli/pip_install/#cmdoption-no-build-isolation
Signed-off-by: Jeffery To <jeffery.to@gmail.com>
2023-02-25 12:42:39 +01:00
|
|
|
if [ -d "$(python3_mk_path)host-pip-requirements" ] && \
|
|
|
|
[ -n "$$$$($(FIND) $(python3_mk_path)host-pip-requirements -maxdepth 1 -mindepth 1 -name '*.txt' -print -quit 2>/dev/null)" ]; then \
|
|
|
|
if grep -q "$(PYPI_NAME)==" $(python3_mk_path)host-pip-requirements/*.txt ; then \
|
|
|
|
if ! grep -q "$(PYPI_NAME)==$(PKG_VERSION)" $(python3_mk_path)host-pip-requirements/*.txt ; then \
|
|
|
|
printf "\nPlease update version of $(PYPI_NAME) to $(PKG_VERSION) in 'host-pip-requirements'/\n\n" ; \
|
|
|
|
exit 1 ; \
|
|
|
|
fi \
|
2021-08-25 14:59:56 +02:00
|
|
|
fi \
|
|
|
|
fi
|
|
|
|
endef
|
|
|
|
endif
|
|
|
|
|
2022-03-07 14:29:56 +01:00
|
|
|
define Py3Build/InstallBuildDepends
|
2020-08-15 08:33:30 +02:00
|
|
|
$(if $(PYTHON3_PKG_HOST_PIP_INSTALL_ARGS), \
|
|
|
|
$(call HostPython3/PipInstall,$(PYTHON3_PKG_HOST_PIP_INSTALL_ARGS)) \
|
2017-07-19 09:19:10 +02:00
|
|
|
)
|
2022-03-07 14:29:56 +01:00
|
|
|
endef
|
|
|
|
|
2023-02-17 18:13:22 +01:00
|
|
|
define Py3Build/Compile/Distutils
|
2022-03-07 14:29:56 +01:00
|
|
|
$(call Py3Build/InstallBuildDepends)
|
2023-02-17 18:13:22 +01:00
|
|
|
$(INSTALL_DIR) $(PKG_INSTALL_DIR)/$(PYTHON3_PKG_DIR)
|
|
|
|
$(call Python3/Run, \
|
|
|
|
$(PKG_BUILD_DIR)/$(strip $(PYTHON3_PKG_SETUP_DIR)), \
|
|
|
|
setup.py \
|
|
|
|
$(PYTHON3_PKG_SETUP_GLOBAL_ARGS) \
|
|
|
|
install \
|
|
|
|
--prefix="/usr" \
|
|
|
|
--root="$(PKG_INSTALL_DIR)" \
|
|
|
|
$(PYTHON3_PKG_SETUP_ARGS) \
|
|
|
|
, \
|
2018-01-15 21:10:49 +01:00
|
|
|
$(PYTHON3_PKG_SETUP_VARS) \
|
2017-01-04 10:27:36 +01:00
|
|
|
)
|
|
|
|
endef
|
|
|
|
|
2023-02-17 18:13:22 +01:00
|
|
|
define Py3Build/Compile/Default
|
|
|
|
$(call Py3Build/InstallBuildDepends)
|
|
|
|
$(call Python3/Run, \
|
|
|
|
$(PKG_BUILD_DIR), \
|
|
|
|
-m build \
|
|
|
|
--no-isolation \
|
|
|
|
--outdir "$(PYTHON3_PKG_BUILD_DIR)"/openwrt-build \
|
|
|
|
--wheel \
|
|
|
|
$(foreach setting,$(PYTHON3_PKG_BUILD_CONFIG_SETTINGS),--config-setting=$(setting)) \
|
|
|
|
$(PYTHON3_PKG_BUILD_ARGS) \
|
|
|
|
"$(PYTHON3_PKG_BUILD_DIR)" \
|
|
|
|
, \
|
|
|
|
$(PYTHON3_PKG_BUILD_VARS) \
|
|
|
|
)
|
|
|
|
endef
|
|
|
|
|
|
|
|
define Py3Build/Install/Default
|
|
|
|
$(call Python3/Run, \
|
|
|
|
$(PKG_BUILD_DIR), \
|
|
|
|
-m installer \
|
|
|
|
--destdir "$(PKG_INSTALL_DIR)" \
|
|
|
|
--no-compile-bytecode \
|
|
|
|
--prefix /usr \
|
|
|
|
"$(PYTHON3_PKG_BUILD_DIR)"/openwrt-build/$(PYTHON3_PKG_WHEEL_NAME)-$(PYTHON3_PKG_WHEEL_VERSION)-*.whl \
|
|
|
|
, \
|
|
|
|
$(PYTHON3_PKG_INSTALL_VARS) \
|
|
|
|
)
|
|
|
|
endef
|
|
|
|
|
2017-07-04 19:58:37 +02:00
|
|
|
Py3Build/Compile=$(Py3Build/Compile/Default)
|
2023-02-17 18:13:22 +01:00
|
|
|
Py3Build/Install=$(Py3Build/Install/Default)
|
2017-07-04 19:58:37 +02:00
|
|
|
|
2023-02-17 18:13:22 +01:00
|
|
|
ifeq ($(strip $(PYTHON3_PKG_FORCE_DISTUTILS_SETUP)),1)
|
|
|
|
Py3Build/Compile=$(Py3Build/Compile/Distutils)
|
|
|
|
Py3Build/Install:=:
|
|
|
|
endif
|
2020-04-17 16:09:32 +02:00
|
|
|
|
|
|
|
ifeq ($(strip $(PYTHON3_PKG_BUILD)),1)
|
2020-05-10 13:14:25 +02:00
|
|
|
ifeq ($(PY3),stdlib)
|
|
|
|
Hooks/Configure/Post+=Py3Build/FindStdlibDepends
|
|
|
|
endif
|
2021-08-25 14:59:56 +02:00
|
|
|
Hooks/Configure/Post+=Py3Build/CheckHostPipVersionMatch
|
2020-04-17 16:09:32 +02:00
|
|
|
Build/Compile=$(Py3Build/Compile)
|
2023-02-17 18:13:22 +01:00
|
|
|
Build/Install=$(Py3Build/Install)
|
2020-04-17 16:09:32 +02:00
|
|
|
endif
|