Split python into a host and target build. Also add a HostPython macro to convenientl...
[openwrt/svn-archive/archive.git] / lang / python / files / python-package.mk
1 #
2 # Copyright (C) 2007 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.6
9
10 PYTHON_DIR:=$(STAGING_DIR)/usr
11 PYTHON_BIN_DIR:=$(PYTHON_DIR)/bin
12 PYTHON_INC_DIR:=$(PYTHON_DIR)/include/python$(PYTHON_VERSION)
13 PYTHON_LIB_DIR:=$(PYTHON_DIR)/lib/python$(PYTHON_VERSION)
14
15 PYTHON_PKG_DIR:=/usr/lib/python$(PYTHON_VERSION)/site-packages
16
17 PYTHON:=python$(PYTHON_VERSION)
18
19 HOST_PYTHON_BIN:=$(STAGING_DIR)/usr/bin/hostpython
20
21 define HostPython
22 ( export PYTHONPATH="$(PYTHON_LIB_DIR):$(STAGING_DIR)/$(PYTHON_PKG_DIR)"; \
23 export PYTHONOPTIMIZE=""; \
24 export PYTHONDONTWRITEBYTECODE=1; \
25 $(1) \
26 $(HOST_PYTHON_BIN) $(2); \
27 )
28 endef
29
30 define PyPackage
31 $(call shexport,PyPackage/$(1)/filespec)
32
33 define Package/$(1)/install
34 @$(SH_FUNC) getvar $$(call shvar,PyPackage/$(1)/filespec) | ( \
35 IFS='|'; \
36 while read fop fspec fperm; do \
37 if [ "$$$$$$$$fop" = "+" ]; then \
38 dpath=`dirname "$$$$$$$$fspec"`; \
39 if [ -n "$$$$$$$$fperm" ]; then \
40 dperm="-m$$$$$$$$fperm"; \
41 else \
42 dperm=`stat -c "%a" $(PKG_INSTALL_DIR)$$$$$$$$dpath`; \
43 fi; \
44 mkdir -p $$$$$$$$$dperm $$(1)$$$$$$$$dpath; \
45 echo "copying: '$$$$$$$$fspec'"; \
46 cp -fpR $(PKG_INSTALL_DIR)$$$$$$$$fspec $$(1)$$$$$$$$dpath/; \
47 if [ -n "$$$$$$$$fperm" ]; then \
48 chmod -R $$$$$$$$fperm $$(1)$$$$$$$$fspec; \
49 fi; \
50 elif [ "$$$$$$$$fop" = "-" ]; then \
51 echo "removing: '$$$$$$$$fspec'"; \
52 rm -fR $$(1)$$$$$$$$fspec; \
53 elif [ "$$$$$$$$fop" = "=" ]; then \
54 echo "setting permissions: '$$$$$$$$fperm' on '$$$$$$$$fspec'"; \
55 chmod -R $$$$$$$$fperm $$(1)$$$$$$$$fspec; \
56 fi; \
57 done; \
58 )
59 $(call PyPackage/$(1)/install,$$(1))
60 endef
61 endef
62
63 # $(1) => build subdir
64 # $(2) => additional arguments to setup.py
65 # $(3) => additional variables
66 define Build/Compile/PyMod
67 $(call HostPython, \
68 cd $(PKG_BUILD_DIR)/$(strip $(1)); \
69 CFLAGS="$(TARGET_CFLAGS)" \
70 CPPFLAGS="$(TARGET_CPPFLAGS)" \
71 LDFLAGS="$(TARGET_LDFLAGS)" \
72 $(3) \
73 , \
74 ./setup.py $(2) \
75 )
76 find $(PKG_INSTALL_DIR) -name "*\.pyc" -o -name "*\.pyo" | xargs rm -f
77 endef