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