Переглянути джерело

python: add capability to install python packages for the host

Some python packages (e.g. cffi) compile one or more shared libraries
as part of their setup process. When these packages are setup
dependencies of other packages (e.g. cryptography), these packages (and
their shared libraries) will need to be loaded on the host system.

This adds a makefile, similar to python-package.mk, to simplify
installing python packages on the host.

Signed-off-by: Jeffery To <jeffery.to@gmail.com>
Jeffery To 9 роки тому
джерело
коміт
b12d7b6db1
2 змінених файлів з 57 додано та 1 видалено
  1. 4
    1
      lang/python/Makefile
  2. 53
    0
      lang/python/files/python-host.mk

+ 4
- 1
lang/python/Makefile Переглянути файл

@@ -138,7 +138,10 @@ define Build/InstallDev
138 138
 	$(INSTALL_DIR) $(STAGING_DIR)/mk/
139 139
 	$(INSTALL_DIR) $(1)/usr/include/ $(1)/usr/lib/ $(1)/usr/lib/pkgconfig
140 140
 	$(INSTALL_DIR) $(1)/usr/lib/python$(PYTHON_VERSION)/
141
-	$(INSTALL_DATA) ./files/python-package.mk $(STAGING_DIR)/mk/
141
+	$(INSTALL_DATA) \
142
+		./files/python-package.mk \
143
+		./files/python-host.mk \
144
+		$(STAGING_DIR)/mk/
142 145
 	$(CP) \
143 146
 		$(PKG_INSTALL_DIR)/usr/include/python$(PYTHON_VERSION) \
144 147
 		$(1)/usr/include/

+ 53
- 0
lang/python/files/python-host.mk Переглянути файл

@@ -0,0 +1,53 @@
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:=/lib/python$(PYTHON_VERSION)/site-packages
11
+
12
+HOST_PYTHONPATH:=$(HOST_PYTHON_LIB_DIR):$(STAGING_DIR_HOST)/$(HOST_PYTHON_PKG_DIR)
13
+define HostHostPython
14
+	(	export PYTHONPATH="$(HOST_PYTHONPATH)"; \
15
+		export PYTHONOPTIMIZE=""; \
16
+		export PYTHONDONTWRITEBYTECODE=1; \
17
+		export _python_sysroot="$(STAGING_DIR_HOST)"; \
18
+		export _python_prefix=""; \
19
+		export _python_exec_prefix=""; \
20
+		$(1) \
21
+		$(HOST_PYTHON_BIN) $(2); \
22
+	)
23
+endef
24
+
25
+# These configure args are needed in detection of path to Python header files
26
+# using autotools.
27
+HOST_CONFIGURE_ARGS += \
28
+	_python_sysroot="$(STAGING_DIR_HOST)" \
29
+	_python_prefix="" \
30
+	_python_exec_prefix=""
31
+
32
+# $(1) => build subdir
33
+# $(2) => additional arguments to setup.py
34
+# $(3) => additional variables
35
+define Build/Compile/HostPyMod
36
+	$(call HostHostPython, \
37
+		cd $(HOST_BUILD_DIR)/$(strip $(1)); \
38
+		CC="$(HOSTCC)" \
39
+		CCSHARED="$(HOSTCC) $(HOST_FPIC)" \
40
+		CXX="$(HOSTCXX)" \
41
+		LD="$(HOSTCC)" \
42
+		LDSHARED="$(HOSTCC) -shared" \
43
+		CFLAGS="$(HOST_CFLAGS)" \
44
+		CPPFLAGS="$(HOST_CPPFLAGS) -I$(HOST_PYTHON_INC_DIR)" \
45
+		LDFLAGS="$(HOST_LDFLAGS) -lpython$(PYTHON_VERSION)" \
46
+		_PYTHON_HOST_PLATFORM=linux2 \
47
+		__PYVENV_LAUNCHER__="/usr/bin/$(PYTHON)" \
48
+		$(3) \
49
+		, \
50
+		./setup.py $(2) \
51
+	)
52
+endef
53
+