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