2 # Copyright (C) 2006-2016 OpenWrt.org
4 # This is free software, licensed under the GNU General Public License v2.
5 # See /LICENSE for more information.
8 # Note: include this after `include $(TOPDIR)/rules.mk in your package Makefile
10 python_mk_path
:=$(dir $(lastword
$(MAKEFILE_LIST
)))
11 include $(python_mk_path
)python-host.mk
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
)
18 PYTHON_PKG_DIR
:=/usr
/lib
/python
$(PYTHON_VERSION
)/site-packages
20 PYTHON
:=python
$(PYTHON_VERSION
)
22 PYTHONPATH
:=$(PYTHON_LIB_DIR
):$(STAGING_DIR
)/$(PYTHON_PKG_DIR
):$(PKG_INSTALL_DIR
)/$(PYTHON_PKG_DIR
)
24 # These configure args are needed in detection of path to Python header files
27 _python_sysroot
="$(STAGING_DIR)" \
28 _python_prefix
="/usr" \
29 _python_exec_prefix
="/usr"
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
40 define Package
/$(1)-src
43 DEPENDS
:=$$$$(foreach dep
,$$$$(filter +python-
%,$$$$(DEPENDS
)),$$$$(dep
)-src
)
46 define Package
/$(1)-src
/description
47 $(call Package
/$(1)/description
).
48 (Contains the Python sources for this package
).
51 # Add default PyPackage filespec none defined
52 ifndef PyPackage
/$(1)/filespec
53 define PyPackage
/$(1)/filespec
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
/ ; \
67 ifndef Package
/$(1)/install
68 $(call shexport
,PyPackage
/$(1)/filespec
)
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)"
79 define Package
/$(1)-src
/install
80 $$(call Package
/$(1)/install,$$(1),sources
)
82 endif # Package/$(1)/install
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
92 CCSHARED
="$(TARGET_CC) $(FPIC)" \
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)" \
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)), \
116 find
$(PKG_INSTALL_DIR
) -name
"*\.exe" | xargs
rm -f
119 define PyBuild
/Compile
/Default
120 $(foreach pkg
,$(HOST_PYTHON_PACKAGE_BUILD_DEPENDS
),
121 $(call host_python_pip_install_host
,$(pkg
))
123 $(call Build
/Compile
/PyMod
,, \
124 install --prefix="/usr" --root
="$(PKG_INSTALL_DIR)" \
125 --single-version-externally-managed \
129 PyBuild
/Compile
=$(PyBuild
/Compile
/Default
)
131 ifeq ($(BUILD_VARIANT
),python
)
133 $(call PyBuild
/Compile
)