Update plone3 skeleton
[zope-bootstrap.git] / Makefile.pybase
1 # -*- makefile -*-
2
3 PYTHON_VERSION  ?= 2.4.6
4 PYTHON_URL      ?= http://www.python.org/ftp/python/$(PYTHON_VERSION)/Python-$(PYTHON_VERSION).tgz
5 SETUPTOOLS_URL  ?= http://peak.telecommunity.com/dist/ez_setup.py
6 PYTHON_DIR      ?= python
7
8 ###########################################################################
9
10 PYTHON       = $(BASEDIR)/$(PYTHON_DIR)/bin/python
11 EASY_INSTALL = $(BASEDIR)/$(PYTHON_DIR)/bin/easy_install
12 PIP          = $(BASEDIR)/$(PYTHON_DIR)/bin/pip
13 PASTER       = $(BASEDIR)/$(PYTHON_DIR)/bin/paster
14
15 # Usage:
16 #     @$(dlegg) <package>
17 #
18 # Downloads egg to '$(DLCACHE)/<package>-*.egg' unless a file with that name
19 # already exists.
20 #
21 # THIS DOES NOT WORK WITH ALL PACKAGES !!! USE WITH CARE
22 define dlegg
23     _dlegg() {                                                          \
24         if [ -r $(DLCACHE)/$$1-*.egg ]; then                            \
25             name="`cd $(DLCACHE); echo $$1-*.egg`";                     \
26             echo "Fetching '$$name' from cache.";                       \
27         else                                                            \
28             [ -z "$(NONET)" ] || ( echo "Missing '$$1'."; exit 2 );     \
29             $(EASY_INSTALL) -zmaxd $(DLCACHE) $$1;                      \
30             name="`cd $(DLCACHE); echo $$1-*.egg`";                     \
31             if [ -d $(DLCACHE)/$$name ]; then                           \
32                 cd $(DLCACHE)/$$name;                                   \
33                 zip -r ../$$name.zip .;                                 \
34                 cd ..;                                                  \
35                 rm -r $$name;                                           \
36                 mv $$name.zip $$name;                                   \
37             fi;                                                         \
38         fi;                                                             \
39     };                                                                  \
40     _dlegg
41 endef
42
43 # Usage:
44 #     @$(install) <package>
45 #
46 # Downloads egg to '$(DLCACHE)/<package>-*.egg' and installs it unless a file
47 # with that name already exists.
48 define install
49     _install() {                                                                        \
50         echo "$(PIP) install --download-cache="$(DLCACHE)/pip" $(PIP_OPTS) $$1";        \
51         $(PIP) install --download-cache="$(DLCACHE)/pip" $(PIP_OPTS) "$$1";             \
52         cd $(DLCACHE)/pip;                                                              \
53         for file in *.tar.gz; do                                                        \
54             name="$${file##*%2F}";                                                      \
55             if [ "$$name" != "$$file" -a ! -r "$$name" ]; then                          \
56                 ln -s $$file $$name || exit 1;                                          \
57             fi;                                                                         \
58         done                                                                            \
59     };                                                                                  \
60     _install
61 endef
62
63 ###########################################################################
64
65 python-unpack: $(PYTHON_DIR)/Python-$(PYTHON_VERSION)/README
66 $(PYTHON_DIR)/Python-$(PYTHON_VERSION)/README:
67         mkdir -p $(PYTHON_DIR)
68         @$(httpget) $(PYTHON_URL) $(PYTHON_DIR)/python.tgz
69         tar -C $(PYTHON_DIR) -xzf $(PYTHON_DIR)/python.tgz
70         rm -f $(PYTHON_DIR)/python.tgz
71 .PHONY: python-unpack
72
73 python-build: $(PYTHON)
74 $(PYTHON):
75         cd $(PYTHON_DIR)/Python-$(PYTHON_VERSION) && ./configure --prefix=$(BASEDIR)/$(PYTHON_DIR)
76         cd $(PYTHON_DIR)/Python-$(PYTHON_VERSION) && make
77         cd $(PYTHON_DIR)/Python-$(PYTHON_VERSION) && make install
78 .PHONY: python-build
79
80 python-rebuild: python-clean python-build
81 .PHONY: python-rebuild
82
83 python-clean:
84         cd $(PYTHON_DIR)/Python-$(PYTHON_VERSION) && make clean
85         rm -f $(PYTHON)
86 .PHONY: python-clean
87
88 python: python-unpack python-build
89 .PHONY: python
90
91 setuptools: $(BASEDIR)/$(PYTHON_DIR)/bin/easy_install
92 $(BASEDIR)/$(PYTHON_DIR)/bin/easy_install:
93         mkdir -p $(PYTHON_DIR)/Extensions
94         @$(httpget) $(SETUPTOOLS_URL) $(PYTHON_DIR)/Extensions/ez_setup.py
95         @(                                                                                                              \
96             if [ -r $(DLCACHE)/setuptools-*.egg ]; then                                                                 \
97                 name="`cd $(DLCACHE); echo setuptools-*.egg`";                                                          \
98                 echo "Fetching '$$name' from cache.";                                                                   \
99                 cp "$(DLCACHE)/$$name" $(PYTHON_DIR)/Extensions;                                                        \
100             else                                                                                                        \
101                 echo "Downloading setuptools.";                                                                         \
102                 ( cd $(PYTHON_DIR)/Extensions && $(PYTHON) -c 'import ez_setup; ez_setup.download_setuptools()' );      \
103                 cp $(PYTHON_DIR)/Extensions/setuptools-*.egg $(DLCACHE);                                                \
104             fi;                                                                                                         \
105         )
106         cd $(PYTHON_DIR)/Extensions && $(PYTHON) ez_setup.py
107 .PHONY: setuptools
108
109 pip: $(PIP)
110 $(PIP):
111         @$(dlegg) pip
112         $(EASY_INSTALL) $(DLCACHE)/pip-*.egg
113 .PHONY: pip
114
115 pybase: python setuptools pip
116 .PHONY: pybase
117
118 ###########################################################################
119
120 debdepends::
121         aptitude install build-essential zlibc
122
123 eggs::
124         @$(install) zc.buildout
125
126 .gitignore::
127         @$(gitignore) "*.pyc"
128         @$(gitignore) "/python/"
129
130 .env::
131         @$(env) PATH $(BASEDIR)/$(PYTHON_DIR)/bin
132
133 clean::
134         rm -rf "$(PYTHON_DIR)"
135
136 setup:: pybase
137
138 PIP_CACHE_FILES := $(shell cd $(DLCACHE)/pip; ls *.tar.gz | grep -vF '%2F')
139
140 init-nonet: PIP_OPTS  = --no-index $(patsubst %,--find-link=file://$(BASEDIR)/$(DLCACHE)/pip/%,$(PIP_CACHE_FILES))
141
142 fullhelp::
143         @echo "    python-rebuild"
144         @echo "        recompile python from source. This may be needed after"
145         @echo "        upgrading the host distribution."
146         @echo
147
148 varhelp::
149         @echo "    PYTHON_VERSION ($(PYTHON_VERSION))"
150         @echo "        Python version to download and compile."
151         @echo
152         @echo "    PYTHON_URL ($(PYTHON_URL))"
153         @echo "        URL to download python from. The default value is automatically"
154         @echo "        generated from PYTHON_VERSION."
155         @echo
156         @echo "    SETUPTOOLS_URL ($(SETUPTOOLS_URL))"
157         @echo "        URL to download 'ez_setup.py' from."
158         @echo
159         @echo "    PYTHON_DIR ($(PYTHON_DIR))"
160         @echo "        Name of subdirectory for the local python installation."
161         @echo