python: add include guard for python-host.mk and include in Makefile
[feed/packages.git] / lang / 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 # Compatibility fallback for older OpenWrt and LEDE versions
12 ifeq ($(STAGING_DIR_HOSTPKG),)
13 $(warning STAGING_DIR_HOSTPKG is unset - falling back to $$(STAGING_DIR)/host)
14 STAGING_DIR_HOSTPKG := $(STAGING_DIR)/host
15 endif
16
17 HOST_PYTHON_DIR:=$(STAGING_DIR_HOSTPKG)
18 HOST_PYTHON_INC_DIR:=$(HOST_PYTHON_DIR)/include/python$(PYTHON_VERSION)
19 HOST_PYTHON_LIB_DIR:=$(HOST_PYTHON_DIR)/lib/python$(PYTHON_VERSION)
20
21 HOST_PYTHON_PKG_DIR:=/lib/python$(PYTHON_VERSION)/site-packages
22
23 HOST_PYTHON_BIN:=$(HOST_PYTHON_DIR)/bin/python$(PYTHON_VERSION)
24
25 HOST_PYTHONPATH:=$(HOST_PYTHON_LIB_DIR):$(STAGING_DIR_HOSTPKG)/$(HOST_PYTHON_PKG_DIR)
26
27 define HostPython
28 if [ "$(strip $(3))" == "HOST" ]; then \
29 export PYTHONPATH="$(HOST_PYTHONPATH)"; \
30 export PYTHONDONTWRITEBYTECODE=0; \
31 else \
32 export PYTHONPATH="$(PYTHONPATH)"; \
33 export PYTHONDONTWRITEBYTECODE=1; \
34 export _python_sysroot="$(STAGING_DIR)"; \
35 export _python_prefix="/usr"; \
36 export _python_exec_prefix="/usr"; \
37 fi; \
38 export PYTHONOPTIMIZE=""; \
39 $(1) \
40 $(HOST_PYTHON_BIN) $(2);
41 endef
42
43 # $(1) => commands to execute before running pythons script
44 # $(2) => python script and its arguments
45 # $(3) => additional variables
46 define Build/Compile/HostPyRunHost
47 $(call HostPython, \
48 $(if $(1),$(1);) \
49 CC="$(HOSTCC)" \
50 CCSHARED="$(HOSTCC) $(HOST_FPIC)" \
51 CXX="$(HOSTCXX)" \
52 LD="$(HOSTCC)" \
53 LDSHARED="$(HOSTCC) -shared" \
54 CFLAGS="$(HOST_CFLAGS)" \
55 CPPFLAGS="$(HOST_CPPFLAGS) -I$(HOST_PYTHON_INC_DIR)" \
56 LDFLAGS="$(HOST_LDFLAGS) -lpython$(PYTHON_VERSION) -Wl$(comma)-rpath=$(STAGING_DIR_HOSTPKG)/lib" \
57 _PYTHON_HOST_PLATFORM=linux2 \
58 $(3) \
59 , \
60 $(2) \
61 , \
62 HOST \
63 )
64 endef
65
66
67 # $(1) => build subdir
68 # $(2) => additional arguments to setup.py
69 # $(3) => additional variables
70 define Build/Compile/HostPyMod
71 $(call Build/Compile/HostPyRunHost, \
72 cd $(HOST_BUILD_DIR)/$(strip $(1)), \
73 ./setup.py $(2), \
74 $(3))
75 endef
76
77 endif # __python_host_mk_inc