2 # Copyright (C) 2017 OpenWrt.org
4 # This is free software, licensed under the GNU General Public License v2.
5 # See /LICENSE for more information.
8 # Note: include this after `include $(TOPDIR)/rules.mk in your package Makefile
9 # if `python3-package.mk` is included, this will already be included
11 ifneq ($(__python3_host_mk_inc
),1)
12 __python3_host_mk_inc
=1
15 python3_mk_path
:=$(dir $(lastword
$(MAKEFILE_LIST
)))
16 include $(python3_mk_path
)python3-version.mk
18 HOST_PYTHON3_DIR
:=$(STAGING_DIR_HOSTPKG
)
19 HOST_PYTHON3_INC_DIR
:=$(HOST_PYTHON3_DIR
)/include/python
$(PYTHON3_VERSION
)
20 HOST_PYTHON3_LIB_DIR
:=$(HOST_PYTHON3_DIR
)/lib
/python
$(PYTHON3_VERSION
)
22 HOST_PYTHON3_PKG_DIR
:=$(HOST_PYTHON3_DIR
)/lib
/python
$(PYTHON3_VERSION
)/site-packages
24 HOST_PYTHON3_BIN
:=$(HOST_PYTHON3_DIR
)/bin
/python
$(PYTHON3_VERSION
)
26 HOST_PYTHON3PATH
:=$(HOST_PYTHON3_LIB_DIR
):$(HOST_PYTHON3_PKG_DIR
)
29 if
[ "$(strip $(3))" == "HOST" ]; then \
30 export PYTHONPATH
="$(HOST_PYTHON3PATH)"; \
31 export PYTHONDONTWRITEBYTECODE
=0; \
33 export PYTHONPATH
="$(PYTHON3PATH)"; \
34 export PYTHONDONTWRITEBYTECODE
=1; \
35 export _python_sysroot
="$(STAGING_DIR)"; \
36 export _python_prefix
="/usr"; \
37 export _python_exec_prefix
="/usr"; \
39 export PYTHONOPTIMIZE
=""; \
41 $(HOST_PYTHON3_BIN
) $(2);
44 define host_python3_settings
47 CCSHARED
="$(HOSTCC) $(HOST_FPIC)" \
50 LDSHARED
="$(HOSTCC) -shared" \
51 CFLAGS
="$(HOST_CFLAGS)" \
52 CPPFLAGS
="$(HOST_CPPFLAGS) -I$(HOST_PYTHON3_INC_DIR)" \
53 LDFLAGS
="$(HOST_LDFLAGS) -lpython$(PYTHON3_VERSION) -Wl$(comma)-rpath=$(STAGING_DIR_HOSTPKG)/lib" \
54 _PYTHON_HOST_PLATFORM
=linux2
57 # $(1) => commands to execute before running pythons script
58 # $(2) => python script and its arguments
59 # $(3) => additional variables
60 define Build
/Compile
/HostPy3RunHost
63 $(call host_python3_settings
) \
72 # Note: I shamelessly copied this from Yousong's logic (from python-packages);
73 HOST_PYTHON3_PIP
:=$(STAGING_DIR_HOSTPKG
)/bin
/pip
$(PYTHON3_VERSION
)
74 define host_python3_pip_install
75 $(call host_python3_settings
) \
76 $(HOST_PYTHON3_PIP
) install \
83 define host_python3_pip_install_host
84 $(call host_python3_pip_install
,$(STAGING_DIR_HOSTPKG
),"",$(1))
87 # $(1) => build subdir
88 # $(2) => additional arguments to setup.py
89 # $(3) => additional variables
90 define Build
/Compile
/HostPy3Mod
91 $(call Build
/Compile
/HostPy3RunHost
, \
92 cd
$(HOST_BUILD_DIR
)/$(strip $(1)), \
97 endif # __python3_host_mk_inc