python,python3: export mk files outside of python package dirs
[feed/packages.git] / lang / python / python3-host.mk
1 #
2 # Copyright (C) 2017 OpenWrt.org
3 #
4 # This is free software, licensed under the GNU General Public License v2.
5 # See /LICENSE for more information.
6 #
7
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
10
11 ifneq ($(__python3_host_mk_inc),1)
12 __python3_host_mk_inc=1
13
14 # For PYTHON3_VERSION
15 python3_mk_path:=$(dir $(lastword $(MAKEFILE_LIST)))
16 include $(python3_mk_path)python3-version.mk
17
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)
21
22 HOST_PYTHON3_PKG_DIR:=$(HOST_PYTHON3_DIR)/lib/python$(PYTHON3_VERSION)/site-packages
23
24 HOST_PYTHON3_BIN:=$(HOST_PYTHON3_DIR)/bin/python$(PYTHON3_VERSION)
25
26 HOST_PYTHON3PATH:=$(HOST_PYTHON3_LIB_DIR):$(HOST_PYTHON3_PKG_DIR)
27
28 define HostPython3
29 if [ "$(strip $(3))" == "HOST" ]; then \
30 export PYTHONPATH="$(HOST_PYTHON3PATH)"; \
31 export PYTHONDONTWRITEBYTECODE=0; \
32 else \
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"; \
38 fi; \
39 export PYTHONOPTIMIZE=""; \
40 $(1) \
41 $(HOST_PYTHON3_BIN) $(2);
42 endef
43
44 define host_python3_settings
45 ARCH="$(HOST_ARCH)" \
46 CC="$(HOSTCC)" \
47 CCSHARED="$(HOSTCC) $(HOST_FPIC)" \
48 CXX="$(HOSTCXX)" \
49 LD="$(HOSTCC)" \
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
55 endef
56
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
61 $(call HostPython3, \
62 $(if $(1),$(1);) \
63 $(call host_python3_settings) \
64 $(3) \
65 , \
66 $(2) \
67 , \
68 HOST \
69 )
70 endef
71
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 \
77 --root=$(1) \
78 --prefix=$(2) \
79 --ignore-installed \
80 $(3)
81 endef
82
83 define host_python3_pip_install_host
84 $(call host_python3_pip_install,$(STAGING_DIR_HOSTPKG),"",$(1))
85 endef
86
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)), \
93 ./setup.py $(2), \
94 $(3))
95 endef
96
97 endif # __python3_host_mk_inc