Update plone3 skeleton
[zope-bootstrap.git] / Makefile.pybase
index af6dc8a..325c39d 100644 (file)
@@ -3,21 +3,69 @@
 PYTHON_VERSION  ?= 2.4.6
 PYTHON_URL      ?= http://www.python.org/ftp/python/$(PYTHON_VERSION)/Python-$(PYTHON_VERSION).tgz
 SETUPTOOLS_URL  ?= http://peak.telecommunity.com/dist/ez_setup.py
+PYTHON_DIR      ?= python
 
 ###########################################################################
 
-PYTHON_DIR=python
-
 PYTHON       = $(BASEDIR)/$(PYTHON_DIR)/bin/python
 EASY_INSTALL = $(BASEDIR)/$(PYTHON_DIR)/bin/easy_install
+PIP          = $(BASEDIR)/$(PYTHON_DIR)/bin/pip
 PASTER       = $(BASEDIR)/$(PYTHON_DIR)/bin/paster
 
+# Usage:
+#     @$(dlegg) <package>
+#
+# Downloads egg to '$(DLCACHE)/<package>-*.egg' unless a file with that name
+# already exists.
+#
+# THIS DOES NOT WORK WITH ALL PACKAGES !!! USE WITH CARE
+define dlegg
+    _dlegg() {                                                         \
+       if [ -r $(DLCACHE)/$$1-*.egg ]; then                            \
+           name="`cd $(DLCACHE); echo $$1-*.egg`";                     \
+           echo "Fetching '$$name' from cache.";                       \
+       else                                                            \
+           [ -z "$(NONET)" ] || ( echo "Missing '$$1'."; exit 2 );     \
+           $(EASY_INSTALL) -zmaxd $(DLCACHE) $$1;                      \
+           name="`cd $(DLCACHE); echo $$1-*.egg`";                     \
+           if [ -d $(DLCACHE)/$$name ]; then                           \
+               cd $(DLCACHE)/$$name;                                   \
+               zip -r ../$$name.zip .;                                 \
+               cd ..;                                                  \
+               rm -r $$name;                                           \
+               mv $$name.zip $$name;                                   \
+           fi;                                                         \
+       fi;                                                             \
+    };                                                                 \
+    _dlegg
+endef
+
+# Usage:
+#     @$(install) <package>
+#
+# Downloads egg to '$(DLCACHE)/<package>-*.egg' and installs it unless a file
+# with that name already exists.
+define install
+    _install() {                                                                       \
+       echo "$(PIP) install --download-cache="$(DLCACHE)/pip" $(PIP_OPTS) $$1";        \
+       $(PIP) install --download-cache="$(DLCACHE)/pip" $(PIP_OPTS) "$$1";             \
+       cd $(DLCACHE)/pip;                                                              \
+       for file in *.tar.gz; do                                                        \
+           name="$${file##*%2F}";                                                      \
+           if [ "$$name" != "$$file" -a ! -r "$$name" ]; then                          \
+               ln -s $$file $$name || exit 1;                                          \
+           fi;                                                                         \
+       done                                                                            \
+    };                                                                                 \
+    _install
+endef
+
 ###########################################################################
 
 python-unpack: $(PYTHON_DIR)/Python-$(PYTHON_VERSION)/README
 $(PYTHON_DIR)/Python-$(PYTHON_VERSION)/README:
-       mkdir $(PYTHON_DIR)
-       wget "$(PYTHON_URL)" -O $(PYTHON_DIR)/python.tgz
+       mkdir -p $(PYTHON_DIR)
+       @$(httpget) $(PYTHON_URL) $(PYTHON_DIR)/python.tgz
        tar -C $(PYTHON_DIR) -xzf $(PYTHON_DIR)/python.tgz
        rm -f $(PYTHON_DIR)/python.tgz
 .PHONY: python-unpack
@@ -40,14 +88,31 @@ python-clean:
 python: python-unpack python-build
 .PHONY: python
 
-setuptools: $(EASY_INSTALL)
-$(EASY_INSTALL):
-       mkdir $(PYTHON_DIR)/Extensions
-       wget $(SETUPTOOLS_URL) -O $(PYTHON_DIR)/Extensions/ez_setup.py
+setuptools: $(BASEDIR)/$(PYTHON_DIR)/bin/easy_install
+$(BASEDIR)/$(PYTHON_DIR)/bin/easy_install:
+       mkdir -p $(PYTHON_DIR)/Extensions
+       @$(httpget) $(SETUPTOOLS_URL) $(PYTHON_DIR)/Extensions/ez_setup.py
+       @(                                                                                                              \
+           if [ -r $(DLCACHE)/setuptools-*.egg ]; then                                                                 \
+               name="`cd $(DLCACHE); echo setuptools-*.egg`";                                                          \
+               echo "Fetching '$$name' from cache.";                                                                   \
+               cp "$(DLCACHE)/$$name" $(PYTHON_DIR)/Extensions;                                                        \
+           else                                                                                                        \
+               echo "Downloading setuptools.";                                                                         \
+               ( cd $(PYTHON_DIR)/Extensions && $(PYTHON) -c 'import ez_setup; ez_setup.download_setuptools()' );      \
+               cp $(PYTHON_DIR)/Extensions/setuptools-*.egg $(DLCACHE);                                                \
+           fi;                                                                                                         \
+       )
        cd $(PYTHON_DIR)/Extensions && $(PYTHON) ez_setup.py
 .PHONY: setuptools
 
-pybase: python setuptools
+pip: $(PIP)
+$(PIP):
+       @$(dlegg) pip
+       $(EASY_INSTALL) $(DLCACHE)/pip-*.egg
+.PHONY: pip
+
+pybase: python setuptools pip
 .PHONY: pybase
 
 ###########################################################################
@@ -56,14 +121,41 @@ debdepends::
        aptitude install build-essential zlibc
 
 eggs::
-       $(EASY_INSTALL) zc.buildout
+       @$(install) zc.buildout
 
 .gitignore::
-       @$(gitignore) /python/
+       @$(gitignore) "*.pyc"
+       @$(gitignore) "/python/"
 
 .env::
        @$(env) PATH $(BASEDIR)/$(PYTHON_DIR)/bin
 
-clean:: python-clean
+clean::
+       rm -rf "$(PYTHON_DIR)"
 
 setup:: pybase
+
+PIP_CACHE_FILES := $(shell cd $(DLCACHE)/pip; ls *.tar.gz | grep -vF '%2F')
+
+init-nonet: PIP_OPTS  = --no-index $(patsubst %,--find-link=file://$(BASEDIR)/$(DLCACHE)/pip/%,$(PIP_CACHE_FILES))
+
+fullhelp::
+       @echo "    python-rebuild"
+       @echo "        recompile python from source. This may be needed after"
+       @echo "        upgrading the host distribution."
+       @echo
+
+varhelp::
+       @echo "    PYTHON_VERSION ($(PYTHON_VERSION))"
+       @echo "        Python version to download and compile."
+       @echo
+       @echo "    PYTHON_URL ($(PYTHON_URL))"
+       @echo "        URL to download python from. The default value is automatically"
+       @echo "        generated from PYTHON_VERSION."
+       @echo
+       @echo "    SETUPTOOLS_URL ($(SETUPTOOLS_URL))"
+       @echo "        URL to download 'ez_setup.py' from."
+       @echo
+       @echo "    PYTHON_DIR ($(PYTHON_DIR))"
+       @echo "        Name of subdirectory for the local python installation."
+       @echo