Add 'upgrade' and 'cleancache' targets
[zope-bootstrap.git] / Makefile.master
1 # -*- makefile -*-
2
3 #
4 # The master makefile sets up the follosing customizable (double-colon) targtets.
5 #
6 # debdepends::
7 #     This optional target may be used by the user to install the necessary 
8 #     system requirements via 'aptitude'. Must be called as root
9 #
10 # setup::
11 #     Called for basic setup. Executed before installing the basic eggs
12 #
13 # eggs::
14 #     Called to install eggs
15 #
16 # buildout::
17 #     Called to install the buildout (e.g. call paster create)
18 #
19 # init-hook::
20 #     Called after the buildout is installed but BEFORE bootstraping
21 #
22 # update-hook::
23 #     Called BEFORE updating the buildout (e.g. before calling bin/buildout)
24 #
25 # bootstrap::
26 #     Called to bootstrap the buildout. Here you can add actions to be
27 #     performed AFTER bootstraping the project whenever a bootstrap is performed
28 #
29 # update::
30 #     Called to update the buildout (calls bin/buildout). Here you can add
31 #     commands to call AFTER bin/buildout returns.
32 #
33 # .gitignore::
34 #     Called to populate the .gitignore file. Use '@$(gitignore) <pattern>' to
35 #     add a pattern
36 #
37 # .env::
38 #     Called to add environment variables to be set when executing a shell
39 #     Use @$(env) <var> <value> to add a variable settings. <var> may be
40 #         PATH         Add <value> to PATH
41 #         PYTHONPATH   Add <value> to PYTHONPATH
42 #         <other>      Set variable to <value>
43
44 # clean::
45 #     Called to clean up all generated files
46 #
47
48 ###########################################################################
49
50 BASEDIR=$(shell pwd)
51
52 DLCACHE ?= dlcache
53
54 default: shorthelp
55 .PHONY: default
56
57 # Usage:
58 #     @$(httpget) <url> [<target>]
59 #
60 # Download <url> to <target>. If <target> is missing, <target> defaults to
61 # the last component of the <url>.
62 #
63 # If the file exists in $(DLCACHE), it is retrieved from there instead.
64 define httpget
65     _httpget() {                                                                \
66         name="$${1##*/}";                                                       \
67         target="$$2";                                                           \
68         [ -n "$$target" ] || target="$$name";                                   \
69         cache="$(DLCACHE)/$$name";                                              \
70         if [ -r "$$cache" ]; then                                               \
71             echo "Fetching '$$name' from cache.";                               \
72         else                                                                    \
73             [ -z "$(HTTPGET_NONET)" ] || ( echo "Missing '$$1'."; exit 2 );     \
74             echo "Downloading '$$1'.";                                          \
75             wget -O "$$cache" "$$1";                                            \
76         fi;                                                                     \
77         cp "$$cache" "$$target";                                                \
78     };                                                                          \
79     _httpget
80 endef
81
82 ###########################################################################
83 # Customization targets
84
85 shorthelp::
86         @echo
87         @echo "SUMMARY"
88         @echo
89         @echo "    Makefile for bootstraping and maintaining a buildout. Most important"
90         @echo "    targets are:"
91         @echo
92         @echo "        init"
93         @echo "        update-nonet"
94         @echo
95         @echo
96         @echo "MAIN TARGETS"
97         @echo
98         @echo "    shorthelp"
99         @echo "    help"
100         @echo "        Summary of important / all user targets"
101         @echo
102         @echo "    debdepends"
103         @echo "        Install debian packages via 'aptitude' needed to satisy build"
104         @echo "        dependencies. MUST BE CALLED AS ROOT (e.g. with sudo)."
105         @echo
106         @echo "    init"
107         @echo "    init-nonet"
108         @echo "        Initialize buildout. Call this to either bootstrap a new project"
109         @echo "        or to initialize a new working copy. Missing packages will be"
110         @echo "        downloaded from the internet (init target) or from an up-to-date"
111         @echo "        download cache (init-nonet). The download cache normaly resides in"
112         @echo "        './dlcache'"
113         @echo
114         @echo "    update"
115         @echo "    update-nonet"
116         @echo "        Update the buildout. Calls './bin/buildout' (update target) or "
117         @echo "        './bin/buildout -No (update-nonet target)."
118         @echo
119         @echo "    shell"
120         @echo "        Spawn an interactive subshell with the environment set up correctly"
121         @echo "        for the local buildout."
122         @echo
123         @echo "    clean"
124         @echo "        Remove all unimportant (!) generated files. This target will leave"
125         @echo "        only those files which are to be checked into version control."
126         @echo "        calling 'make init' or 'make init-nonet' will rebuild the buildout."
127         @echo
128 .PHONY: shorthelp
129
130 help:: shorthelp
131         @echo
132         @echo "SECONDARY TARGETS"
133         @echo
134         @echo "    versions"
135         @echo "        Generate lines to be added to 'buildout.cfg' to pin all package"
136         @echo "        versions."
137         @echo
138         @echo "    cleancache"
139         @echo "        purge the download cache"
140         @echo
141         @echo "    upgrade"
142         @echo "        Reinitializes the buildout. This is like calling"
143         @echo "        'make clean cleancache init'. Use this target to upgrade to a new"
144         @echo "        python or extension (e.g. PIL) version (after changing the version"
145         @echo "        in the project Makefile) or to upgrade the component eggs. This"
146         @echo "        target purges the download cache to ensure, no obsolete files are"
147         @echo "        left."
148         @echo
149
150 debdepends::
151 .PHONY: debdepends
152
153 setup::
154         mkdir -p $(DLCACHE) $(DLCACHE)/pip
155 .PHONY: setup
156
157 eggs::
158 .PHONY: eggs
159
160 buildout::
161 .PHONY: buildout
162
163 init-hook::
164 .PHONY: init-hook
165
166 update-hook::
167 .PHONY: update-hook
168
169 bootstrap::
170 .PHONY: bootstrap
171
172 update:: update-hook
173         bin/buildout $(BUILDOUT_OPTS)
174 .PHONY: update
175
176 define gitignore
177     _gitignore () {                                             \
178         [ -r .gitignore ] || touch .gitignore;                  \
179         grep -qxF "$$1" .gitignore || echo "$$1" >>.gitignore;  \
180     };                                                          \
181     _gitignore
182 endef
183 .gitignore::
184         @echo "Updating .gitignore."
185         @$(gitignore) "*.pyc"
186         @$(gitignore) "*.egg-info/"
187         @$(gitignore) "/.env"
188
189 define env
190     _env () {                                                   \
191         [ -r .env ] || touch .env;                              \
192         case "$$1" in                                           \
193         PATH|PYTHONPATH) line="export $$1=\"$$2:\$$$$1\"" ;;    \
194         *) line="export $$1=\"$$2\"" ;;                         \
195         esac;                                                   \
196         grep -qxF "$$line" .env || echo "$$line" >>.env;        \
197     };                                                          \
198     _env
199 endef
200 .env::
201         @echo "Updating .env."
202
203 clean::
204         rm -f .env
205 .PHONY: clean
206
207 ###########################################################################
208 # user targets
209
210 init: setup eggs buildout init-hook update-hook bootstrap update .gitignore .env
211 .PHONY: init
212
213 init-nonet: HTTPGET_NONET=1
214 init-nonet: init
215 .PHONY: init-nonet
216
217 versions:
218         @echo "# Add the following lines to [versions] in buildout.cfg to pin all packages"
219         @bin/buildout -vvvvv | sed -ne 's/^Picked: //p' | sort | uniq 
220 .PHONY: versions
221
222 shell:
223         @eval "`cat .env`"; $$SHELL
224 .PHONY: shell
225
226 update-nonet: update
227 .PHONY: update-nonet
228
229 cleancache:
230         rm -rf $(DLCACHE)/*
231 .PHONY: cleancache
232
233 upgrade: clean cleancache init
234 .PHONY: upgrade