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