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