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.
|
|
|
|
#
|
|
|
|
|
2018-01-10 08:29:41 +01:00
|
|
|
# Note: include this 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_BIN_DIR:=$(PYTHON3_DIR)/bin
|
|
|
|
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
|
|
|
|
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"
|
|
|
|
|
2014-11-27 22:47:28 +01:00
|
|
|
PKG_USE_MIPS16:=0
|
|
|
|
# This is required in addition to PKG_USE_MIPS16:=0 because otherwise MIPS16
|
|
|
|
# flags are inherited from the Python base package (via sysconfig module)
|
|
|
|
ifdef CONFIG_USE_MIPS16
|
|
|
|
TARGET_CFLAGS += -mno-mips16 -mno-interlink-mips16
|
|
|
|
endif
|
|
|
|
|
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)" \
|
|
|
|
_PYTHON_HOST_PLATFORM=linux2 \
|
|
|
|
__PYVENV_LAUNCHER__="/usr/bin/$(PYTHON3)" \
|
|
|
|
PYTHONPATH="$(PYTHON3PATH)" \
|
|
|
|
PYTHONDONTWRITEBYTECODE=1 \
|
|
|
|
PYTHONOPTIMIZE="" \
|
|
|
|
_python_sysroot="$(STAGING_DIR)" \
|
|
|
|
_python_prefix="/usr" \
|
|
|
|
_python_exec_prefix="/usr"
|
|
|
|
|
|
|
|
# $(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
|
|
|
|
|
|
|
|
# $(1) => build subdir
|
|
|
|
# $(2) => additional arguments to setup.py
|
|
|
|
# $(3) => additional variables
|
|
|
|
define Python3/ModSetup
|
|
|
|
$(INSTALL_DIR) $(PKG_INSTALL_DIR)/$(PYTHON3_PKG_DIR)
|
|
|
|
$(call Python3/Run, \
|
|
|
|
$(PKG_BUILD_DIR)/$(strip $(1)), \
|
|
|
|
setup.py $(2), \
|
|
|
|
$(3))
|
|
|
|
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
|
|
|
|
|
2014-10-14 10:52:06 +02:00
|
|
|
define Py3Package
|
2015-01-19 19:22:41 +01:00
|
|
|
|
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
|
|
|
|
$(call Package/$(1)/description).
|
|
|
|
(Contains the Python3 sources for this package).
|
|
|
|
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
|
|
|
|
ifndef Py3Package/$(1)/filespec
|
|
|
|
define Py3Package/$(1)/filespec
|
|
|
|
+|$(PYTHON3_PKG_DIR)
|
|
|
|
endef
|
|
|
|
endif
|
|
|
|
|
2017-01-04 10:27:36 +01:00
|
|
|
ifndef Py3Package/$(1)/install
|
|
|
|
define Py3Package/$(1)/install
|
|
|
|
if [ -d $(PKG_INSTALL_DIR)/usr/bin ]; then \
|
2017-03-07 13:50:19 +01:00
|
|
|
$(INSTALL_DIR) $$(1)/usr/bin ; \
|
|
|
|
$(CP) $(PKG_INSTALL_DIR)/usr/bin/* $$(1)/usr/bin/ ; \
|
2017-01-04 10:27:36 +01:00
|
|
|
fi
|
|
|
|
endef
|
|
|
|
endif
|
|
|
|
|
2017-05-19 16:16:38 +02:00
|
|
|
ifndef Package/$(1)/install
|
2014-10-14 10:52:06 +02:00
|
|
|
$(call shexport,Py3Package/$(1)/filespec)
|
2014-09-24 10:08:37 +02:00
|
|
|
|
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-14 15:14:49 +02:00
|
|
|
$(SHELL) $(python3_mk_path)python-package-install.sh \
|
2018-01-10 08:43:00 +01:00
|
|
|
"$(PKG_INSTALL_DIR)" "$$(1)" \
|
2020-04-14 15:14:49 +02:00
|
|
|
"$$$$$$$$$$(call shvar,Py3Package/$(1)/filespec)"
|
|
|
|
$(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))
|
|
|
|
$(SHELL) $(python3_mk_path)python-package-install.sh \
|
|
|
|
"$(PKG_INSTALL_DIR)" "$$(1)" \
|
|
|
|
"$$$$$$$$$$(call shvar,Py3Package/$(1)/filespec)"
|
|
|
|
$$(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
|
|
|
|
2019-02-21 12:52:07 +01:00
|
|
|
PYTHON3_PKG_SETUP_DIR ?=
|
2020-04-07 09:06:27 +02:00
|
|
|
PYTHON3_PKG_SETUP_GLOBAL_ARGS ?=
|
2019-02-19 10:00:09 +01:00
|
|
|
PYTHON3_PKG_SETUP_ARGS ?= --single-version-externally-managed
|
|
|
|
PYTHON3_PKG_SETUP_VARS ?=
|
2018-01-15 21:10:49 +01:00
|
|
|
|
2017-01-04 10:27:36 +01:00
|
|
|
define Py3Build/Compile/Default
|
2019-05-29 15:45:16 +02:00
|
|
|
$(if $(HOST_PYTHON3_PACKAGE_BUILD_DEPENDS),
|
2020-04-09 17:02:14 +02:00
|
|
|
$(call HostPython3/PipInstall,$(HOST_PYTHON3_PACKAGE_BUILD_DEPENDS))
|
2017-07-19 09:19:10 +02:00
|
|
|
)
|
2020-04-09 17:28:07 +02:00
|
|
|
$(call Python3/ModSetup, \
|
2019-02-21 12:52:07 +01:00
|
|
|
$(PYTHON3_PKG_SETUP_DIR), \
|
2019-04-05 10:44:55 +02:00
|
|
|
$(PYTHON3_PKG_SETUP_GLOBAL_ARGS) \
|
2017-01-04 10:27:36 +01:00
|
|
|
install --prefix="/usr" --root="$(PKG_INSTALL_DIR)" \
|
2018-01-15 21:10:49 +01:00
|
|
|
$(PYTHON3_PKG_SETUP_ARGS), \
|
|
|
|
$(PYTHON3_PKG_SETUP_VARS) \
|
2017-01-04 10:27:36 +01:00
|
|
|
)
|
|
|
|
endef
|
|
|
|
|
2017-07-04 19:58:37 +02:00
|
|
|
Py3Build/Compile=$(Py3Build/Compile/Default)
|
|
|
|
|
2017-01-04 10:27:36 +01:00
|
|
|
ifeq ($(BUILD_VARIANT),python3)
|
|
|
|
define Build/Compile
|
2017-07-04 19:58:37 +02:00
|
|
|
$(call Py3Build/Compile)
|
2017-01-04 10:27:36 +01:00
|
|
|
endef
|
|
|
|
endif # python3
|