Fix clean target
[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
7 ###########################################################################
8
9 PYTHON_DIR ?= python
10
11 PYTHON       = $(BASEDIR)/$(PYTHON_DIR)/bin/python
12 EASY_INSTALL = $(BASEDIR)/$(PYTHON_DIR)/bin/easy_install
13 PIP          = $(BASEDIR)/$(PYTHON_DIR)/bin/pip
14 PASTER       = $(BASEDIR)/$(PYTHON_DIR)/bin/paster
15
16 # Usage:
17 #     @$(dlegg) <package>
18 #
19 # Downloads egg to '$(DLCACHE)/<package>-*.egg' unless a file with that name
20 # already exists.
21 #
22 # THIS DOES NOT WORK WITH ALL PACKAGES !!! USE WITH CARE
23 define dlegg
24     _dlegg() {                                                          \
25         if [ -r $(DLCACHE)/$$1-*.egg ]; then                            \
26             name="`cd $(DLCACHE); echo $$1-*.egg`";                     \
27             echo "Fetching '$$name' from cache.";                       \
28         else                                                            \
29             [ -z "$(NONET)" ] || ( echo "Missing '$$1'."; exit 2 );     \
30             $(EASY_INSTALL) -zmaxd $(DLCACHE) $$1;                      \
31             name="`cd $(DLCACHE); echo $$1-*.egg`";                     \
32             if [ -d $(DLCACHE)/$$name ]; then                           \
33                 cd $(DLCACHE)/$$name;                                   \
34                 zip -r ../$$name.zip .;                                 \
35                 cd ..;                                                  \
36                 rm -r $$name;                                           \
37                 mv $$name.zip $$name;                                   \
38             fi;                                                         \
39         fi;                                                             \
40     };                                                                  \
41     _dlegg
42 endef
43
44 # Usage:
45 #     @$(install) <package>
46 #
47 # Downloads egg to '$(DLCACHE)/<package>-*.egg' and installs it unless a file
48 # with that name already exists.
49 define install
50     _install() {                                                                        \
51         echo "$(PIP) install --download-cache="$(DLCACHE)/pip" $(PIP_OPTS) $$1";        \
52         $(PIP) install --download-cache="$(DLCACHE)/pip" $(PIP_OPTS) "$$1";             \
53         cd $(DLCACHE)/pip;                                                              \
54         for file in *.tar.gz; do                                                        \
55             name="$${file##*%2F}";                                                      \
56             if [ "$$name" != "$$file" -a ! -r "$$name" ]; then                          \
57                 ln -s $$file $$name || exit 1;                                          \
58             fi;                                                                         \
59         done                                                                            \
60     };                                                                                  \
61     _install
62 endef
63
64 ###########################################################################
65
66 python-unpack: $(PYTHON_DIR)/Python-$(PYTHON_VERSION)/README
67 $(PYTHON_DIR)/Python-$(PYTHON_VERSION)/README:
68         mkdir -p $(PYTHON_DIR)
69         @$(httpget) $(PYTHON_URL) $(PYTHON_DIR)/python.tgz
70         tar -C $(PYTHON_DIR) -xzf $(PYTHON_DIR)/python.tgz
71         rm -f $(PYTHON_DIR)/python.tgz
72 .PHONY: python-unpack
73
74 python-build: $(PYTHON)
75 $(PYTHON):
76         cd $(PYTHON_DIR)/Python-$(PYTHON_VERSION) && ./configure --prefix=$(BASEDIR)/$(PYTHON_DIR)
77         cd $(PYTHON_DIR)/Python-$(PYTHON_VERSION) && make
78         cd $(PYTHON_DIR)/Python-$(PYTHON_VERSION) && make install
79 .PHONY: python-build
80
81 python-rebuild: python-clean python-build
82 .PHONY: python-rebuild
83
84 python-clean:
85         cd $(PYTHON_DIR)/Python-$(PYTHON_VERSION) && make clean
86         rm -f $(PYTHON)
87 .PHONY: python-clean
88
89 python: python-unpack python-build
90 .PHONY: python
91
92 setuptools: $(BASEDIR)/$(PYTHON_DIR)/bin/easy_install
93 $(BASEDIR)/$(PYTHON_DIR)/bin/easy_install:
94         mkdir -p $(PYTHON_DIR)/Extensions
95         @$(httpget) $(SETUPTOOLS_URL) $(PYTHON_DIR)/Extensions/ez_setup.py
96         @(                                                                                                              \
97             if [ -r $(DLCACHE)/setuptools-*.egg ]; then                                                                 \
98                 name="`cd $(DLCACHE); echo setuptools-*.egg`";                                                          \
99                 echo "Fetching '$$name' from cache.";                                                                   \
100                 cp "$(DLCACHE)/$$name" $(PYTHON_DIR)/Extensions;                                                        \
101             else                                                                                                        \
102                 echo "Downloading setuptools.";                                                                         \
103                 ( cd $(PYTHON_DIR)/Extensions && $(PYTHON) -c 'import ez_setup; ez_setup.download_setuptools()' );      \
104                 cp $(PYTHON_DIR)/Extensions/setuptools-*.egg $(DLCACHE);                                                \
105             fi;                                                                                                         \
106         )
107         cd $(PYTHON_DIR)/Extensions && $(PYTHON) ez_setup.py
108 .PHONY: setuptools
109
110 pip: $(PIP)
111 $(PIP):
112         @$(dlegg) pip
113         $(EASY_INSTALL) $(DLCACHE)/pip-*.egg
114 .PHONY: pip
115
116 pybase: python setuptools pip
117 .PHONY: pybase
118
119 ###########################################################################
120
121 debdepends::
122         aptitude install build-essential zlibc
123
124 eggs::
125         @$(install) zc.buildout
126
127 .gitignore::
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 help::
143         @echo "    python-rebuild"
144         @echo "        recompile python from source. This may be needed after"
145         @echo "        upgrading the host distribution."
146         @echo