Fix -nonet targets (zope3-buildout)
[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_CACHE_FILES);                                                        \
52         echo "$(PIP) install --download-cache="$(DLCACHE)/pip" $(PIP_OPTS) $$1";        \
53         $(PIP) install --download-cache="$(DLCACHE)/pip" $(PIP_OPTS) "$$1";             \
54         cd $(DLCACHE)/pip;                                                              \
55         for file in *.tar.gz; do                                                        \
56             name="$${file##*%2F}";                                                      \
57             if [ "$$name" != "$$file" -a ! -r "$$name" ]; then                          \
58                 ln -s $$file $$name || exit 1;                                          \
59             fi;                                                                         \
60         done                                                                            \
61     };                                                                                  \
62     _install
63 endef
64
65 ###########################################################################
66
67 python-unpack: $(PYTHON_DIR)/Python-$(PYTHON_VERSION)/README
68 $(PYTHON_DIR)/Python-$(PYTHON_VERSION)/README:
69         mkdir -p $(PYTHON_DIR)
70         @$(httpget) $(PYTHON_URL) $(PYTHON_DIR)/python.tgz
71         tar -C $(PYTHON_DIR) -xzf $(PYTHON_DIR)/python.tgz
72         rm -f $(PYTHON_DIR)/python.tgz
73 .PHONY: python-unpack
74
75 python-build: $(PYTHON)
76 $(PYTHON):
77         cd $(PYTHON_DIR)/Python-$(PYTHON_VERSION) && ./configure --prefix=$(BASEDIR)/$(PYTHON_DIR)
78         cd $(PYTHON_DIR)/Python-$(PYTHON_VERSION) && make
79         cd $(PYTHON_DIR)/Python-$(PYTHON_VERSION) && make install
80 .PHONY: python-build
81
82 python-rebuild: python-clean python-build
83 .PHONY: python-rebuild
84
85 python-clean:
86         cd $(PYTHON_DIR)/Python-$(PYTHON_VERSION) && make clean
87         rm -f $(PYTHON)
88 .PHONY: python-clean
89
90 python: python-unpack python-build
91 .PHONY: python
92
93 setuptools: $(BASEDIR)/$(PYTHON_DIR)/bin/easy_install
94 $(BASEDIR)/$(PYTHON_DIR)/bin/easy_install:
95         mkdir -p $(PYTHON_DIR)/Extensions
96         @$(httpget) $(SETUPTOOLS_URL) $(PYTHON_DIR)/Extensions/ez_setup.py
97         @(                                                                                                              \
98             if [ -r $(DLCACHE)/setuptools-*.egg ]; then                                                                 \
99                 name="`cd $(DLCACHE); echo setuptools-*.egg`";                                                          \
100                 echo "Fetching '$$name' from cache.";                                                                   \
101                 cp "$(DLCACHE)/$$name" $(PYTHON_DIR)/Extensions;                                                        \
102             else                                                                                                        \
103                 echo "Downloading setuptools.";                                                                         \
104                 ( cd $(PYTHON_DIR)/Extensions && $(PYTHON) -c 'import ez_setup; ez_setup.download_setuptools()' );      \
105                 cp $(PYTHON_DIR)/Extensions/setuptools-*.egg $(DLCACHE);                                                \
106             fi;                                                                                                         \
107         )
108         cd $(PYTHON_DIR)/Extensions && $(PYTHON) ez_setup.py
109 .PHONY: setuptools
110
111 pip: $(PIP)
112 $(PIP):
113         @$(dlegg) pip
114         $(EASY_INSTALL) $(DLCACHE)/pip-*.egg
115 .PHONY: pip
116
117 pybase: python setuptools pip
118 .PHONY: pybase
119
120 ###########################################################################
121
122 debdepends::
123         aptitude install build-essential zlibc
124
125 eggs::
126         @$(install) zc.buildout
127
128 .gitignore::
129         @$(gitignore) /python/
130
131 .env::
132         @$(env) PATH $(BASEDIR)/$(PYTHON_DIR)/bin
133
134 clean:: python-clean
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