# -*- makefile -*- # # 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) ' to # add a pattern # # .env:: # Called to add environment variables to be set when executing a shell # Use @$(env) to add a variable settings. may be # PATH Add to PATH # PYTHONPATH Add to PYTHONPATH # Set variable to # # clean:: # Called to clean up all generated files # ########################################################################### BASEDIR=$(shell pwd) DLCACHE ?= dlcache default: update-nonet .PHONY: default # Usage: # @$(httpget) [] # # Download to . If is missing, defaults to # the last component of the . # # If the file exists in $(DLCACHE), it is retrieved from there instead. define httpget _httpget() { \ name="$${1##*/}"; \ target="$$2"; \ [ -n "$$target" ] || target="$$name"; \ cache="$(DLCACHE)/$$name"; \ if [ -r "$$cache" ]; then \ echo "Fetching '$$name' from cache."; \ else \ [ -z "$(NONET)" ] || ( echo "Missing '$$1'."; exit 2 ); \ echo "Downloading '$$1'."; \ wget -O "$$cache" "$$1"; \ fi; \ cp "$$cache" "$$target"; \ }; \ _httpget endef # Usage: # @$(dlegg) # # Downloads egg to '$(DLCACHE)/-*.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; \ } endef define dlegg $(_dlegg); _dlegg endef # Usage: # @$(install) # # Downloads egg to '$(DLCACHE)/-*.egg' and installs it unless a file # with that name already exists. define install _install() { \ echo $(PIP_CACHE_FILES); \ echo "$(PIP) install --download-cache="$(DLCACHE)/pip" $(PIP_OPTS) $$1"; \ $(PIP) install --download-cache="$(DLCACHE)/pip" $(PIP_OPTS) "$$1"; \ }; \ _install endef ########################################################################### # Customization targets 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:: sed -i -e '1s/^#!.*\/python/#!$(subst /,\/,$(PYTHON))/' $(PYTHON_DIR)/bin/* $(PYTHON) -c 'from zc.buildout.buildout import main; main(["bootstrap"])' update:: update-hook bin/buildout $(BUILDOUT_OPTS) define gitignore _gitignore () { \ [ -r .gitignore ] || touch .gitignore; \ grep -qxF "$$1" .gitignore || echo "$$1" >>.gitignore; \ }; \ _gitignore endef .gitignore:: @echo "Updating .gitignore." @$(gitignore) "*.pyc" @$(gitignore) "*.egg-info/" @$(gitignore) "/.env" @$(gitignore) "/$(DLCACHE)/" 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 .gitignore .env .PHONY: clean ########################################################################### # internal targets prepare-pipcache: @( \ 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 \ ) PIP_CACHE_FILES := $(shell cd $(DLCACHE)/pip; ls *.tar.gz | grep -vF '%2F') do-init-nonet: PIP_OPTS = --no-index $(patsubst %,--find-link=file://$(BASEDIR)/$(DLCACHE)/pip/%,$(PIP_CACHE_FILES)) do-init-nonet: BUILDOUT_OPTS = -N do-init-nonet: NONET=1 do-init-nonet: init ########################################################################### # user targets init: setup eggs buildout init-hook update-hook bootstrap update .gitignore .env init-nonet: prepare-pipcache @$(MAKE) do-init-nonet versions: @echo "# Add the following lines to [versions] in buildout.cfg to pin all packages" @bin/buildout -vvvvv | sed -ne 's/^Picked: //p' | sort | uniq shell: @eval "`cat .env`"; $$SHELL update-nonet: BUILDOUT_OPTS=-No update-nonet: update