python,python3: export mk files outside of python package dirs
[feed/packages.git] / lang / python / 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 # Note: include this after `include $(TOPDIR)/rules.mk in your package Makefile
9 python3_mk_path:=$(dir $(lastword $(MAKEFILE_LIST)))
10 include $(python3_mk_path)python3-host.mk
11
12 PYTHON3_DIR:=$(STAGING_DIR)/usr
13 PYTHON3_BIN_DIR:=$(PYTHON3_DIR)/bin
14 PYTHON3_INC_DIR:=$(PYTHON3_DIR)/include/python$(PYTHON3_VERSION)
15 PYTHON3_LIB_DIR:=$(PYTHON3_DIR)/lib/python$(PYTHON3_VERSION)
16
17 PYTHON3_PKG_DIR:=/usr/lib/python$(PYTHON3_VERSION)/site-packages
18
19 PYTHON3:=python$(PYTHON3_VERSION)
20
21 PYTHON3PATH:=$(PYTHON3_LIB_DIR):$(STAGING_DIR)/$(PYTHON3_PKG_DIR):$(PKG_INSTALL_DIR)/$(PYTHON3_PKG_DIR)
22
23 # These configure args are needed in detection of path to Python header files
24 # using autotools.
25 CONFIGURE_ARGS += \
26 _python_sysroot="$(STAGING_DIR)" \
27 _python_prefix="/usr" \
28 _python_exec_prefix="/usr"
29
30 PKG_USE_MIPS16:=0
31 # This is required in addition to PKG_USE_MIPS16:=0 because otherwise MIPS16
32 # flags are inherited from the Python base package (via sysconfig module)
33 ifdef CONFIG_USE_MIPS16
34 TARGET_CFLAGS += -mno-mips16 -mno-interlink-mips16
35 endif
36
37 define Py3Package
38
39 define Package/$(1)-src
40 $(call Package/$(1))
41 TITLE+= (sources)
42 DEPENDS:=$$$$(foreach dep,$$$$(filter +python3-%,$$$$(DEPENDS)),$$$$(dep)-src)
43 endef
44
45 define Package/$(1)-src/description
46 $(call Package/$(1)/description).
47 (Contains the Python3 sources for this package).
48 endef
49
50 # Add default PyPackage filespec none defined
51 ifndef Py3Package/$(1)/filespec
52 define Py3Package/$(1)/filespec
53 +|$(PYTHON3_PKG_DIR)
54 endef
55 endif
56
57 ifndef Py3Package/$(1)/install
58 define Py3Package/$(1)/install
59 if [ -d $(PKG_INSTALL_DIR)/usr/bin ]; then \
60 $(INSTALL_DIR) $$(1)/usr/bin ; \
61 $(CP) $(PKG_INSTALL_DIR)/usr/bin/* $$(1)/usr/bin/ ; \
62 fi
63 endef
64 endif
65
66 ifndef Package/$(1)/install
67 $(call shexport,Py3Package/$(1)/filespec)
68
69 define Package/$(1)/install
70 $(call Py3Package/$(1)/install,$$(1))
71 find $(PKG_INSTALL_DIR) -name "*\.exe" | xargs rm -f
72 if [ -e files/python3-package-install.sh ] ; then \
73 $(SHELL) files/python3-package-install.sh \
74 "$(PKG_INSTALL_DIR)" "$$(1)" \
75 "$(HOST_PYTHON3_BIN)" "$$(2)" \
76 "$$$$$$$$$$(call shvar,Py3Package/$(1)/filespec)" ; \
77 elif [ -e $(STAGING_DIR)/mk/python3-package-install.sh ] ; then \
78 $(SHELL) $(STAGING_DIR)/mk/python3-package-install.sh \
79 "$(PKG_INSTALL_DIR)" "$$(1)" \
80 "$(HOST_PYTHON3_BIN)" "$$(2)" \
81 "$$$$$$$$$$(call shvar,Py3Package/$(1)/filespec)" ; \
82 else \
83 echo "No 'python3-package-install.sh' script found" ; \
84 exit 1 ; \
85 fi
86 endef
87
88 define Package/$(1)-src/install
89 $$(call Package/$(1)/install,$$(1),sources)
90 endef
91 endif # Package/$(1)/install
92 endef
93
94 # $(1) => commands to execute before running pythons script
95 # $(2) => python script and its arguments
96 # $(3) => additional variables
97 define Build/Compile/HostPy3RunTarget
98 $(call HostPython3, \
99 $(if $(1),$(1);) \
100 CC="$(TARGET_CC)" \
101 CCSHARED="$(TARGET_CC) $(FPIC)" \
102 CXX="$(TARGET_CXX)" \
103 LD="$(TARGET_CC)" \
104 LDSHARED="$(TARGET_CC) -shared" \
105 CFLAGS="$(TARGET_CFLAGS)" \
106 CPPFLAGS="$(TARGET_CPPFLAGS) -I$(PYTHON3_INC_DIR)" \
107 LDFLAGS="$(TARGET_LDFLAGS) -lpython$(PYTHON3_VERSION)" \
108 _PYTHON_HOST_PLATFORM=linux2 \
109 __PYVENV_LAUNCHER__="/usr/bin/$(PYTHON3)" \
110 $(3) \
111 , \
112 $(2) \
113 )
114 endef
115
116 # $(1) => build subdir
117 # $(2) => additional arguments to setup.py
118 # $(3) => additional variables
119 define Build/Compile/Py3Mod
120 $(INSTALL_DIR) $(PKG_INSTALL_DIR)/$(PYTHON3_PKG_DIR)
121 $(call Build/Compile/HostPy3RunTarget, \
122 cd $(PKG_BUILD_DIR)/$(strip $(1)), \
123 ./setup.py $(2), \
124 $(3))
125 find $(PKG_INSTALL_DIR) -name "*\.exe" | xargs rm -f
126 endef
127
128 define Py3Build/Compile/Default
129 $(foreach pkg,$(HOST_PYTHON3_PACKAGE_BUILD_DEPENDS),
130 $(call host_python3_pip_install_host,$(pkg))
131 )
132 $(call Build/Compile/Py3Mod,, \
133 install --prefix="/usr" --root="$(PKG_INSTALL_DIR)" \
134 --single-version-externally-managed \
135 )
136 endef
137
138 Py3Build/Compile=$(Py3Build/Compile/Default)
139
140 ifeq ($(BUILD_VARIANT),python3)
141 define Build/Compile
142 $(call Py3Build/Compile)
143 endef
144 endif # python3