BASEDIR=$(shell pwd)
+DLCACHE ?= dlcache
+
default: update-nonet
.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="$(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) <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; \
+ }
+endef
+define dlegg
+ $(_dlegg); _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_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
.PHONY: debdepends
setup::
+ mkdir -p $(DLCACHE) $(DLCACHE)/pip
.PHONY: setup
eggs::
bootstrap::
sed -i -e '1s/^#!.*\/python/#!$(subst /,\/,$(PYTHON))/' $(PYTHON_DIR)/bin/*
-# $(PYTHON) bootstrap.py
$(PYTHON) -c 'from zc.buildout.buildout import main; main(["bootstrap"])'
update:: update-hook
_gitignore
endef
.gitignore::
- @echo "Updating .gitignore"
+ @echo "Updating .gitignore."
@$(gitignore) "*.pyc"
@$(gitignore) "*.egg-info/"
@$(gitignore) "/.env"
+ @$(gitignore) "/$(DLCACHE)/"
define env
_env () { \
_env
endef
.env::
- @echo "Updating .env"
+ @echo "Updating .env."
clean::
rm -f .gitignore .env
###########################################################################
# 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 -Novvvvv | sed -ne 's/^Picked: //p' | sort | uniq
+ @bin/buildout -vvvvv | sed -ne 's/^Picked: //p' | sort | uniq
shell:
@eval "`cat .env`"; $$SHELL