treewide: use $(STAGING_DIR)/host instead of $(STAGING_DIR_HOST), sync with changes...
[feed/packages.git] / lang / python3 / files / python3-package.mk
1 #
2 # Copyright (C) 2007-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 PYTHON3_VERSION_MAJOR:=3
9 PYTHON3_VERSION_MINOR:=5
10 PYTHON3_VERSION_MICRO:=0
11
12 PYTHON3_VERSION:=$(PYTHON3_VERSION_MAJOR).$(PYTHON3_VERSION_MINOR)
13
14 PYTHON3_DIR:=$(STAGING_DIR)/usr
15 PYTHON3_BIN_DIR:=$(PYTHON3_DIR)/bin
16 PYTHON3_INC_DIR:=$(PYTHON3_DIR)/include/python$(PYTHON3_VERSION)
17 PYTHON3_LIB_DIR:=$(PYTHON3_DIR)/lib/python$(PYTHON3_VERSION)
18
19 PYTHON3_PKG_DIR:=/usr/lib/python$(PYTHON3_VERSION)/site-packages
20
21 PYTHON3:=python$(PYTHON3_VERSION)
22
23 HOST_PYTHON3_LIB_DIR:=$(STAGING_DIR)/host/lib/python$(PYTHON3_VERSION)
24 HOST_PYTHON3_BIN:=$(STAGING_DIR)/host/bin/python3
25
26 PYTHON3PATH:=$(PYTHON3_LIB_DIR):$(STAGING_DIR)/$(PYTHON3_PKG_DIR):$(PKG_INSTALL_DIR)/$(PYTHON3_PKG_DIR)
27 define HostPython3
28 ( export PYTHONPATH="$(PYTHON3PATH)"; \
29 export PYTHONOPTIMIZE=""; \
30 export PYTHONDONTWRITEBYTECODE=1; \
31 export _python_sysroot="$(STAGING_DIR)"; \
32 export _python_prefix="/usr"; \
33 export _python_exec_prefix="/usr"; \
34 $(1) \
35 $(HOST_PYTHON3_BIN) $(2); \
36 )
37 endef
38
39 # These configure args are needed in detection of path to Python header files
40 # using autotools.
41 CONFIGURE_ARGS += \
42 _python_sysroot="$(STAGING_DIR)" \
43 _python_prefix="/usr" \
44 _python_exec_prefix="/usr"
45
46 PKG_USE_MIPS16:=0
47 # This is required in addition to PKG_USE_MIPS16:=0 because otherwise MIPS16
48 # flags are inherited from the Python base package (via sysconfig module)
49 ifdef CONFIG_USE_MIPS16
50 TARGET_CFLAGS += -mno-mips16 -mno-interlink-mips16
51 endif
52
53 define Py3Package
54
55 # Add default PyPackage filespec none defined
56 ifndef Py3Package/$(1)/filespec
57 define Py3Package/$(1)/filespec
58 +|$(PYTHON3_PKG_DIR)
59 endef
60 endif
61
62 $(call shexport,Py3Package/$(1)/filespec)
63
64 define Package/$(1)/install
65 find $(PKG_INSTALL_DIR) -name "*\.pyc" -o -name "*\.pyo" | xargs rm -f
66 @echo "$$$$$$$$$$(call shvar,Py3Package/$(1)/filespec)" | ( \
67 IFS='|'; \
68 while read fop fspec fperm; do \
69 fop=`echo "$$$$$$$$fop" | tr -d ' \t\n'`; \
70 if [ "$$$$$$$$fop" = "+" ]; then \
71 if [ ! -e "$(PKG_INSTALL_DIR)$$$$$$$$fspec" ]; then \
72 echo "File not found '$(PKG_INSTALL_DIR)$$$$$$$$fspec'"; \
73 exit 1; \
74 fi; \
75 dpath=`dirname "$$$$$$$$fspec"`; \
76 if [ -n "$$$$$$$$fperm" ]; then \
77 dperm="-m$$$$$$$$fperm"; \
78 else \
79 dperm=`stat -c "%a" $(PKG_INSTALL_DIR)$$$$$$$$dpath`; \
80 fi; \
81 mkdir -p $$$$$$$$$dperm $$(1)$$$$$$$$dpath; \
82 echo "copying: '$$$$$$$$fspec'"; \
83 cp -fpR $(PKG_INSTALL_DIR)$$$$$$$$fspec $$(1)$$$$$$$$dpath/; \
84 if [ -n "$$$$$$$$fperm" ]; then \
85 chmod -R $$$$$$$$fperm $$(1)$$$$$$$$fspec; \
86 fi; \
87 elif [ "$$$$$$$$fop" = "-" ]; then \
88 echo "removing: '$$$$$$$$fspec'"; \
89 rm -fR $$(1)$$$$$$$$fspec; \
90 elif [ "$$$$$$$$fop" = "=" ]; then \
91 echo "setting permissions: '$$$$$$$$fperm' on '$$$$$$$$fspec'"; \
92 chmod -R $$$$$$$$fperm $$(1)$$$$$$$$fspec; \
93 fi; \
94 done; \
95 )
96 $(call Py3Package/$(1)/install,$$(1))
97 endef
98 endef
99
100 # $(1) => build subdir
101 # $(2) => additional arguments to setup.py
102 # $(3) => additional variables
103 define Build/Compile/Py3Mod
104 $(INSTALL_DIR) $(PKG_INSTALL_DIR)/$(PYTHON3_PKG_DIR)
105 $(call HostPython3, \
106 cd $(PKG_BUILD_DIR)/$(strip $(1)); \
107 CC="$(TARGET_CC)" \
108 CCSHARED="$(TARGET_CC) $(FPIC)" \
109 LD="$(TARGET_CC)" \
110 LDSHARED="$(TARGET_CC) -shared" \
111 CFLAGS="$(TARGET_CFLAGS)" \
112 CPPFLAGS="$(TARGET_CPPFLAGS) -I$(PYTHON3_INC_DIR)" \
113 LDFLAGS="$(TARGET_LDFLAGS) -lpython$(PYTHON3_VERSION)" \
114 _PYTHON_HOST_PLATFORM=linux2 \
115 __PYVENV_LAUNCHER__="/usr/bin/$(PYTHON3)" \
116 $(3) \
117 , \
118 ./setup.py $(2) \
119 )
120 find $(PKG_INSTALL_DIR) -name "*\.pyc" -o -name "*\.pyo" | xargs rm -f
121 endef
122