python3: sync makefiles with python package
[feed/packages.git] / lang / python3 / files / 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 ifneq ($(__python3_host_mk_inc),1)
9 __python3_host_mk_inc=1
10
11 # For PYTHON3_VERSION
12 $(call include_mk, python3-version.mk)
13
14 # Compatibility fallback for older OpenWrt and LEDE versions
15 ifeq ($(STAGING_DIR_HOSTPKG),)
16 $(warning STAGING_DIR_HOSTPKG is unset - falling back to $$(STAGING_DIR)/host)
17 STAGING_DIR_HOSTPKG := $(STAGING_DIR)/host
18 endif
19
20 HOST_PYTHON3_DIR:=$(STAGING_DIR_HOSTPKG)
21 HOST_PYTHON3_INC_DIR:=$(HOST_PYTHON3_DIR)/include/python$(PYTHON3_VERSION)
22 HOST_PYTHON3_LIB_DIR:=$(HOST_PYTHON3_DIR)/lib/python$(PYTHON3_VERSION)
23
24 HOST_PYTHON3_PKG_DIR:=$(HOST_PYTHON3_DIR)/lib/python$(PYTHON3_VERSION)/site-packages
25
26 HOST_PYTHON3_BIN:=$(HOST_PYTHON3_DIR)/bin/python$(PYTHON3_VERSION)
27
28 HOST_PYTHON3PATH:=$(HOST_PYTHON3_LIB_DIR):$(HOST_PYTHON3_PKG_DIR)
29
30 define HostPython3
31 if [ "$(strip $(3))" == "HOST" ]; then \
32 export PYTHONPATH="$(HOST_PYTHON3PATH)"; \
33 export PYTHONDONTWRITEBYTECODE=0; \
34 else \
35 export PYTHONPATH="$(PYTHON3PATH)"; \
36 export PYTHONDONTWRITEBYTECODE=1; \
37 export _python_sysroot="$(STAGING_DIR)"; \
38 export _python_prefix="/usr"; \
39 export _python_exec_prefix="/usr"; \
40 fi; \
41 export PYTHONOPTIMIZE=""; \
42 $(1) \
43 $(HOST_PYTHON3_BIN) $(2);
44 endef
45
46 # $(1) => commands to execute before running pythons script
47 # $(2) => python script and its arguments
48 # $(3) => additional variables
49 define Build/Compile/HostPy3RunHost
50 $(call HostPython3, \
51 $(if $(1),$(1);) \
52 CC="$(HOSTCC)" \
53 CCSHARED="$(HOSTCC) $(HOST_FPIC)" \
54 CXX="$(HOSTCXX)" \
55 LD="$(HOSTCC)" \
56 LDSHARED="$(HOSTCC) -shared" \
57 CFLAGS="$(HOST_CFLAGS)" \
58 CPPFLAGS="$(HOST_CPPFLAGS) -I$(HOST_PYTHON3_INC_DIR)" \
59 LDFLAGS="$(HOST_LDFLAGS) -lpython$(PYTHON3_VERSION) -Wl$(comma)-rpath=$(STAGING_DIR_HOSTPKG)/lib" \
60 _PYTHON_HOST_PLATFORM=linux2 \
61 $(3) \
62 , \
63 $(2) \
64 , \
65 HOST \
66 )
67 endef
68
69
70 # $(1) => build subdir
71 # $(2) => additional arguments to setup.py
72 # $(3) => additional variables
73 define Build/Compile/HostPy3Mod
74 $(call Build/Compile/HostPy3RunHost, \
75 cd $(HOST_BUILD_DIR)/$(strip $(1)), \
76 ./setup.py $(2), \
77 $(3))
78 endef
79
80 define HostPy3/Compile/Default
81 $(call Build/Compile/HostPy3Mod,,\
82 install --root="$(HOST_BUILD_PREFIX)" --prefix="" \
83 --single-version-externally-managed \
84 )
85 endef
86
87 ifeq ($(BUILD_VARIANT),python3)
88 define Host/Compile
89 $(call HostPy3/Compile/Default)
90 endef
91
92 define Host/Install
93 endef
94 endif # python3
95
96 endif # __python3_host_mk_inc