Merge pull request #4853 from StevenHessing/noddos
[feed/packages.git] / lang / python / python / files / python-host.mk
1 #
2 # Copyright (C) 2015-2016 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 ifneq ($(__python_host_mk_inc),1)
9 __python_host_mk_inc=1
10
11 # For PYTHON_VERSION
12 $(call include_mk, python-version.mk)
13
14 HOST_PYTHON_DIR:=$(STAGING_DIR_HOSTPKG)
15 HOST_PYTHON_INC_DIR:=$(HOST_PYTHON_DIR)/include/python$(PYTHON_VERSION)
16 HOST_PYTHON_LIB_DIR:=$(HOST_PYTHON_DIR)/lib/python$(PYTHON_VERSION)
17
18 HOST_PYTHON_PKG_DIR:=$(HOST_PYTHON_DIR)/lib/python$(PYTHON_VERSION)/site-packages
19
20 HOST_PYTHON_BIN:=$(HOST_PYTHON_DIR)/bin/python$(PYTHON_VERSION)
21
22 HOST_PYTHONPATH:=$(HOST_PYTHON_LIB_DIR):$(HOST_PYTHON_PKG_DIR)
23
24 define HostPython
25 if [ "$(strip $(3))" == "HOST" ]; then \
26 export PYTHONPATH="$(HOST_PYTHONPATH)"; \
27 export PYTHONDONTWRITEBYTECODE=0; \
28 else \
29 export PYTHONPATH="$(PYTHONPATH)"; \
30 export PYTHONDONTWRITEBYTECODE=1; \
31 export _python_sysroot="$(STAGING_DIR)"; \
32 export _python_prefix="/usr"; \
33 export _python_exec_prefix="/usr"; \
34 fi; \
35 export PYTHONOPTIMIZE=""; \
36 $(1) \
37 $(HOST_PYTHON_BIN) $(2);
38 endef
39
40 define host_python_settings
41 ARCH="$(HOST_ARCH)" \
42 CC="$(HOSTCC)" \
43 CCSHARED="$(HOSTCC) $(HOST_FPIC)" \
44 CXX="$(HOSTCXX)" \
45 LD="$(HOSTCC)" \
46 LDSHARED="$(HOSTCC) -shared" \
47 CFLAGS="$(HOST_CFLAGS)" \
48 CPPFLAGS="$(HOST_CPPFLAGS) -I$(HOST_PYTHON_INC_DIR)" \
49 LDFLAGS="$(HOST_LDFLAGS) -lpython$(PYTHON_VERSION) -Wl$(comma)-rpath=$(STAGING_DIR_HOSTPKG)/lib" \
50 _PYTHON_HOST_PLATFORM=linux2
51 endef
52
53 # $(1) => commands to execute before running pythons script
54 # $(2) => python script and its arguments
55 # $(3) => additional variables
56 define Build/Compile/HostPyRunHost
57 $(call HostPython, \
58 $(if $(1),$(1);) \
59 $(call host_python_settings) \
60 $(3) \
61 , \
62 $(2) \
63 , \
64 HOST \
65 )
66 endef
67
68 # Note: I shamelessly copied this from Yousong's logic (from python-packages);
69 HOST_PYTHON_PIP:=$(STAGING_DIR_HOSTPKG)/bin/pip$(PYTHON_VERSION)
70 define host_python_pip_install
71 $(call host_python_settings) \
72 $(HOST_PYTHON_PIP) install \
73 --root=$(1) \
74 --prefix=$(2) \
75 --ignore-installed \
76 $(3)
77 endef
78
79 define host_python_pip_install_host
80 $(call host_python_pip_install,$(STAGING_DIR_HOSTPKG),"",$(1))
81 endef
82
83 # $(1) => build subdir
84 # $(2) => additional arguments to setup.py
85 # $(3) => additional variables
86 define Build/Compile/HostPyMod
87 $(call Build/Compile/HostPyRunHost, \
88 cd $(HOST_BUILD_DIR)/$(strip $(1)), \
89 ./setup.py $(2), \
90 $(3))
91 endef
92
93 endif # __python_host_mk_inc