python: fix HostPython host/target selection
[feed/packages.git] / lang / python / files / python-host.mk
1 #
2 # Copyright (C) 2015 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 HOST_PYTHON_INC_DIR:=$(STAGING_DIR_HOST)/include/python$(PYTHON_VERSION)
9
10 HOST_PYTHON_PKG_DIR:=/usr/lib/python$(PYTHON_VERSION)/site-packages
11
12 HOST_PYTHONPATH:=$(HOST_PYTHON_LIB_DIR):$(STAGING_DIR_HOST)/$(HOST_PYTHON_PKG_DIR)
13 define HostPython
14 ifeq ($(strip $(3)),HOST)
15 LOCAL_PYTHONPATH:=$(HOST_PYTHONPATH)
16 LOCAL_STAGING_DIR:=$(STAGING_DIR_HOST)
17 else
18 LOCAL_PYTHONPATH:=$(PYTHONPATH)
19 LOCAL_STAGING_DIR:=$(STAGING_DIR)
20 endif
21 ( export PYTHONPATH="$(LOCAL_PYTHONPATH)"; \
22 export PYTHONOPTIMIZE=""; \
23 export PYTHONDONTWRITEBYTECODE=1; \
24 export _python_sysroot="$(LOCAL_STAGING_DIR)/usr"; \
25 export _python_prefix="/usr"; \
26 export _python_exec_prefix="/usr"; \
27 $(1) \
28 $(HOST_PYTHON_BIN) $(2); \
29 )
30 endef
31
32 # These configure args are needed in detection of path to Python header files
33 # using autotools.
34 HOST_CONFIGURE_ARGS += \
35 _python_sysroot="$(STAGING_DIR_HOST)/usr" \
36 _python_prefix="/usr" \
37 _python_exec_prefix="/usr"
38
39 # $(1) => build subdir
40 # $(2) => additional arguments to setup.py
41 # $(3) => additional variables
42 define Build/Compile/HostPyMod
43 $(call HostPython, \
44 cd $(HOST_BUILD_DIR)/$(strip $(1)); \
45 CC="$(HOSTCC)" \
46 CCSHARED="$(HOSTCC) $(HOST_FPIC)" \
47 CXX="$(HOSTCXX)" \
48 LD="$(HOSTCC)" \
49 LDSHARED="$(HOSTCC) -shared" \
50 CFLAGS="$(HOST_CFLAGS)" \
51 CPPFLAGS="$(HOST_CPPFLAGS) -I$(HOST_PYTHON_INC_DIR)" \
52 LDFLAGS="$(HOST_LDFLAGS) -lpython$(PYTHON_VERSION)" \
53 _PYTHON_HOST_PLATFORM=linux2 \
54 __PYVENV_LAUNCHER__="/usr/bin/$(PYTHON)" \
55 $(3) \
56 , \
57 ./setup.py $(2) \
58 , \
59 HOST \
60 )
61 endef
62