Update plone3 skeleton
[zope-bootstrap.git] / Makefile.master
index 6d9a7f6..4d69e96 100644 (file)
 # -*- makefile -*-
 
-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
-PIL_VERSION    ?= 1.1.6
-PIL_URL        ?= http://effbot.org/downloads/Imaging-$(PIL_VERSION).tar.gz
+#
+# The master makefile sets up the follosing customizable (double-colon) targtets.
+#
+# debdepends::
+#     This optional target may be used by the user to install the necessary 
+#     system requirements via 'aptitude'. Must be called as root
+#
+# setup::
+#     Called for basic setup. Executed before installing the basic eggs
+#
+# eggs::
+#     Called to install eggs
+#
+# buildout::
+#     Called to install the buildout (e.g. call paster create)
+#
+# init-hook::
+#     Called after the buildout is installed but BEFORE bootstraping
+#
+# update-hook::
+#     Called BEFORE updating the buildout (e.g. before calling bin/buildout)
+#
+# bootstrap::
+#     Called to bootstrap the buildout. Here you can add actions to be
+#     performed AFTER bootstraping the project whenever a bootstrap is performed
+#
+# update::
+#     Called to update the buildout (calls bin/buildout). Here you can add
+#     commands to call AFTER bin/buildout returns.
+#
+# .gitignore::
+#     Called to populate the .gitignore file. Use '@$(gitignore) <pattern>' to
+#     add a pattern
+#
+# .env::
+#     Called to add environment variables to be set when executing a shell
+#     Use @$(env) <var> <value> to add a variable settings. <var> may be
+#        PATH         Add <value> to PATH
+#        PYTHONPATH   Add <value> to PYTHONPATH
+#        <other>      Set variable to <value>
+# 
+# clean::
+#     Called to clean up all unimportant generated files. This includes all files
+#     which may be recreated by calling 'init'
+#
+# shorthelp::
+#     Called to provide an overview of important target (this is the default target)
+#
+# fullhelp::
+#     Called to create the list of supplementary targets.
+#
+# varhelp::
+#     Called to create the list of Makefile variables.
+#
 
 ###########################################################################
 
-PYTHON_DIR=python
 BASEDIR=$(shell pwd)
 
-PYTHON       = $(BASEDIR)/$(PYTHON_DIR)/bin/python
-EASY_INSTALL = $(BASEDIR)/$(PYTHON_DIR)/bin/easy_install
-PASTER       = $(BASEDIR)/$(PYTHON_DIR)/bin/paster
-
-default: update-nonet
-
-.PHONY: python-unpack python-build python setuptools eggs pil-unpack pil-build pil buildout \
-       bootstrap update update-nonet shell init otherinit
-
-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
-       tar -C $(PYTHON_DIR) -xzf $(PYTHON_DIR)/python.tgz
-       rm -f $(PYTHON_DIR)/python.tgz
-
-python-build: $(PYTHON)
-$(PYTHON):
-       cd $(PYTHON_DIR)/Python-$(PYTHON_VERSION) && ./configure --prefix=$(BASEDIR)/$(PYTHON_DIR)
-       cd $(PYTHON_DIR)/Python-$(PYTHON_VERSION) && make
-       cd $(PYTHON_DIR)/Python-$(PYTHON_VERSION) && make install
-
-python: python-unpack python-build
-
-setuptools: $(EASY_INSTALL)
-$(EASY_INSTALL):
-       mkdir $(PYTHON_DIR)/Extensions
-       wget $(SETUPTOOLS_URL) -O $(PYTHON_DIR)/Extensions/ez_setup.py
-       cd $(PYTHON_DIR)/Extensions && $(PYTHON) ez_setup.py
-
-eggs:
-       $(EASY_INSTALL) ZopeSkel
-       $(EASY_INSTALL) zc.buildout
-
-pil-unpack: $(PYTHON_DIR)/Extensions/Imaging-$(PIL_VERSION)/README
-$(PYTHON_DIR)/Extensions/Imaging-$(PIL_VERSION)/README:
-       wget $(PIL_URL) -O $(PYTHON_DIR)/Extensions/pil.tgz
-       tar -C $(PYTHON_DIR)/Extensions -xzf $(PYTHON_DIR)/Extensions/pil.tgz
-       rm -f $(PYTHON_DIR)/Extensions/pil.tgz
-
-pil-build: $(PYTHON_DIR)/bin/pilconvert.py
-$(PYTHON_DIR)/bin/pilconvert.py:
-       cd $(PYTHON_DIR)/Extensions/Imaging-$(PIL_VERSION) && $(PYTHON) setup.py install
-
-pil: pil-unpack pil-build
-
-buildout: buildout.cfg
-buildout.cfg:
-       $(PASTER) create --no-interactive -t plone3_buildout . zope_password=admin
-
-bootstrap: 
-       sed -i -e '1s/^#!.*\/python/#!$(subst /,\/,$(PYTHON))/' $(PYTHON_DIR)/bin/*
-       $(PYTHON) bootstrap.py
-
-.gitignore:
-       @echo "python/" >.gitignore
-       @echo "var/" >>.gitignore
-       @echo "bin/" >>.gitignore
-       @echo "develop-eggs/" >>.gitignore
-       @echo "downloads/" >>.gitignore
-       @echo "eggs/" >>.gitignore
-       @echo "fake-eggs/" >>.gitignore
-       @echo "parts/" >>.gitignore
-       @echo "/.installed.cfg" >>.gitignore
-       @echo "*.pyc" >>.gitignore
+DLCACHE ?= dlcache
+
+default: shorthelp
+.PHONY: default
+
+# Usage:
+#     @$(httpget) <url> [<target>]
+#
+# Download <url> to <target>. If <target> is missing, <target> defaults to
+# the last component of the <url>.
+#
+# If the file exists in $(DLCACHE), it is retrieved from there instead.
+define httpget
+    _httpget() {                                                               \
+       name="$${1##*/}";                                                       \
+       target="$$2";                                                           \
+       [ -n "$$target" ] || target="$$name";                                   \
+       cache="$(BASEDIR)/$(DLCACHE)/$$name";                                   \
+       if [ -r "$$cache" ]; then                                               \
+           echo "Fetching '$$name' from cache.";                               \
+       else                                                                    \
+           [ -z "$(HTTPGET_NONET)" ] || ( echo "Missing '$$1'."; exit 2 );     \
+           echo "Downloading '$$1'.";                                          \
+           wget -O "$$cache" "$$1";                                            \
+       fi;                                                                     \
+       cp "$$cache" "$$target";                                                \
+    };                                                                         \
+    _httpget
+endef
+
+###########################################################################
+# Customization targets
+
+shorthelp::
+       @echo
+       @echo "SUMMARY"
+       @echo
+       @echo "    Makefile for bootstraping and maintaining a buildout. Most important"
+       @echo "    targets are:"
+       @echo
+       @echo "        init"
+       @echo "        update-nonet"
+       @echo
+       @echo
+       @echo "MAIN TARGETS"
+       @echo
+       @echo "    shorthelp (default target)"
+       @echo "    help"
+       @echo "        Summary of important targets / complete help."
+       @echo
+       @echo "    debdepends"
+       @echo "        Install debian packages via 'aptitude' needed to satisy build"
+       @echo "        dependencies. MUST BE CALLED AS ROOT (e.g. with sudo)."
+       @echo
+       @echo "    init"
+       @echo "    init-nonet"
+       @echo "        Initialize buildout. Call this to either bootstrap a new project"
+       @echo "        or to initialize a new working copy. Missing packages will be"
+       @echo "        downloaded from the internet (init target) or from an up-to-date"
+       @echo "        download cache (init-nonet). The download cache normaly resides in"
+       @echo "        './dlcache'"
+       @echo
+       @echo "    update"
+       @echo "    update-nonet"
+       @echo "        Update the buildout. Calls './bin/buildout' (update target) or "
+       @echo "        './bin/buildout -No (update-nonet target)."
+       @echo
+       @echo "    shell"
+       @echo "        Spawn an interactive subshell with the environment set up correctly"
+       @echo "        for the local buildout."
+       @echo
+       @echo "    clean"
+       @echo "        Remove all unimportant (!) generated files (the remaining files are"
+       @echo "        those which may be changed and should be managed as part of the"
+       @echo "        project source-code). calling 'make init' or 'make init-nonet' will"
+       @echo "        rebuild the development environment."
+       @echo
+.PHONY: shorthelp
+
+fullhelp::
+       @echo
+       @echo "SUPPLEMENTARY TARGETS"
+       @echo
+       @echo "    cleancache"
+       @echo "        purge the download cache"
+       @echo
+       @echo "    upgrade"
+       @echo "        Reinitializes the buildout. This is like calling"
+       @echo "        'make clean cleancache init'. Use this target to upgrade to a new"
+       @echo "        python or extension (e.g. PIL) version (after changing the version"
+       @echo "        in the project Makefile) or to upgrade the component eggs. This"
+       @echo "        target purges the download cache to ensure, no obsolete files are"
+       @echo "        left."
+       @echo
+.PHONY: fullhelp
+
+varhelp::
+       @echo
+       @echo "MAKEFILE VARIABLES"
+       @echo
+       @echo "    DLCACHE ($(DLCACHE))"
+       @echo "        Name of the download-cache subdirectory. This directory may be"
+       @echo "        persisted e.g. by checking into version control (together with"
+       @echo "        the source code or into as a separate repository or by saving into"
+       @echo "        an archive. A persistent cache allows the setup to be completely"
+       @echo "        reproducible and network independent."
+       @echo
+.PHONY: varhelp
+
+debdepends::
+.PHONY: debdepends
+
+setup::
+       mkdir -p $(DLCACHE) $(DLCACHE)/pip
+.PHONY: setup
+
+eggs::
+.PHONY: eggs
+
+buildout::
+.PHONY: buildout
+
+init-hook::
+.PHONY: init-hook
+
+update-hook::
+.PHONY: update-hook
+
+bootstrap::
+.PHONY: bootstrap
+
+update:: update-hook
+.PHONY: update
+
+define gitignore
+    _gitignore () {                                            \
+       [ -r .gitignore ] || touch .gitignore;                  \
+       grep -qxF "$$1" .gitignore || echo "$$1" >>.gitignore;  \
+    };                                                         \
+    _gitignore
+endef
+.gitignore::
+       @echo "Updating .gitignore."
+       @$(gitignore) "/.env"
+
+define env
+    _env () {                                                  \
+       [ -r .env ] || touch .env;                              \
+       case "$$1" in                                           \
+       PATH|PYTHONPATH) line="export $$1=\"$$2:\$$$$1\"" ;;    \
+       *) line="export $$1=\"$$2\"" ;;                         \
+       esac;                                                   \
+       grep -qxF "$$line" .env || echo "$$line" >>.env;        \
+    };                                                         \
+    _env
+endef
+.env::
+       @echo "Updating .env."
+
+clean::
+       rm -f .env
+.PHONY: clean
+
+###########################################################################
+# user targets
+
+init: setup eggs buildout init-hook update-hook bootstrap update .gitignore .env
+.PHONY: init
+
+init-nonet: HTTPGET_NONET=1
+init-nonet: init
+.PHONY: init-nonet
 
 shell:
-       @PATH=$(BASEDIR)/$(PYTHON_DIR)/bin:$(BASEDIR)/bin:$$PATH $$SHELL
+       @eval "`cat .env`"; $$SHELL
+.PHONY: shell
 
-init: python setuptools pil eggs buildout otherinit otherupdate bootstrap update .gitignore
+update-nonet: update
+.PHONY: update-nonet
 
-otherinit::
+cleancache:
+       rm -rf $(DLCACHE)/*
+.PHONY: cleancache
 
-update: otherupdate
-       bin/buildout
+upgrade: clean cleancache init
+.PHONY: upgrade
 
-update-nonet: otherupdate
-       bin/buildout -No
+help:
+       @[ -n `which less` ] && $(MAKE) -s shorthelp fullhelp varhelp | less \
+               || $(MAKE) -s shorthelp fullhelp varhelp
+.PHONY: help
\ No newline at end of file