Commit based upon d6442850bde61f0c3e7e2ae3247b4a856073c5e0
[librecmc/package-feed.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 HOST_PYTHON3_DIR:=$(STAGING_DIR_HOSTPKG)
15 HOST_PYTHON3_INC_DIR:=$(HOST_PYTHON3_DIR)/include/python$(PYTHON3_VERSION)
16 HOST_PYTHON3_LIB_DIR:=$(HOST_PYTHON3_DIR)/lib/python$(PYTHON3_VERSION)
17
18 HOST_PYTHON3_PKG_DIR:=$(HOST_PYTHON3_DIR)/lib/python$(PYTHON3_VERSION)/site-packages
19
20 HOST_PYTHON3_BIN:=$(HOST_PYTHON3_DIR)/bin/python$(PYTHON3_VERSION)
21
22 HOST_PYTHON3PATH:=$(HOST_PYTHON3_LIB_DIR):$(HOST_PYTHON3_PKG_DIR)
23
24 define HostPython3
25         if [ "$(strip $(3))" == "HOST" ]; then \
26                 export PYTHONPATH="$(HOST_PYTHON3PATH)"; \
27                 export PYTHONDONTWRITEBYTECODE=0; \
28         else \
29                 export PYTHONPATH="$(PYTHON3PATH)"; \
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_PYTHON3_BIN) $(2);
38 endef
39
40 # $(1) => commands to execute before running pythons script
41 # $(2) => python script and its arguments
42 # $(3) => additional variables
43 define Build/Compile/HostPy3RunHost
44         $(call HostPython3, \
45                 $(if $(1),$(1);) \
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                 $(3) \
56                 , \
57                 $(2) \
58                 , \
59                 HOST \
60         )
61 endef
62
63
64 # $(1) => build subdir
65 # $(2) => additional arguments to setup.py
66 # $(3) => additional variables
67 define Build/Compile/HostPy3Mod
68         $(call Build/Compile/HostPy3RunHost, \
69                 cd $(HOST_BUILD_DIR)/$(strip $(1)), \
70                 ./setup.py $(2), \
71                 $(3))
72 endef
73
74 define HostPy3/Compile/Default
75         $(call Build/Compile/HostPy3Mod,,\
76                 install --root="$(STAGING_DIR_HOSTPKG)" --prefix="" \
77                 --single-version-externally-managed \
78         )
79 endef
80
81 ifeq ($(BUILD_VARIANT),python3)
82 define Host/Compile
83         $(call HostPy3/Compile/Default)
84 endef
85
86 define Host/Install
87 endef
88 endif # python3
89
90 endif # __python3_host_mk_inc