Update plone3 skeleton
[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 unimportant generated files. This includes all files
46 #     which may be recreated by calling 'init'
47 #
48 # shorthelp::
49 #     Called to provide an overview of important target (this is the default target)
50 #
51 # fullhelp::
52 #     Called to create the list of supplementary targets.
53 #
54 # varhelp::
55 #     Called to create the list of Makefile variables.
56 #
57
58 ###########################################################################
59
60 BASEDIR=$(shell pwd)
61
62 DLCACHE ?= dlcache
63
64 default: shorthelp
65 .PHONY: default
66
67 # Usage:
68 #     @$(httpget) <url> [<target>]
69 #
70 # Download <url> to <target>. If <target> is missing, <target> defaults to
71 # the last component of the <url>.
72 #
73 # If the file exists in $(DLCACHE), it is retrieved from there instead.
74 define httpget
75     _httpget() {                                                                \
76         name="$${1##*/}";                                                       \
77         target="$$2";                                                           \
78         [ -n "$$target" ] || target="$$name";                                   \
79         cache="$(BASEDIR)/$(DLCACHE)/$$name";                                   \
80         if [ -r "$$cache" ]; then                                               \
81             echo "Fetching '$$name' from cache.";                               \
82         else                                                                    \
83             [ -z "$(HTTPGET_NONET)" ] || ( echo "Missing '$$1'."; exit 2 );     \
84             echo "Downloading '$$1'.";                                          \
85             wget -O "$$cache" "$$1";                                            \
86         fi;                                                                     \
87         cp "$$cache" "$$target";                                                \
88     };                                                                          \
89     _httpget
90 endef
91
92 ###########################################################################
93 # Customization targets
94
95 shorthelp::
96         @echo
97         @echo "SUMMARY"
98         @echo
99         @echo "    Makefile for bootstraping and maintaining a buildout. Most important"
100         @echo "    targets are:"
101         @echo
102         @echo "        init"
103         @echo "        update-nonet"
104         @echo
105         @echo
106         @echo "MAIN TARGETS"
107         @echo
108         @echo "    shorthelp (default target)"
109         @echo "    help"
110         @echo "        Summary of important targets / complete help."
111         @echo
112         @echo "    debdepends"
113         @echo "        Install debian packages via 'aptitude' needed to satisy build"
114         @echo "        dependencies. MUST BE CALLED AS ROOT (e.g. with sudo)."
115         @echo
116         @echo "    init"
117         @echo "    init-nonet"
118         @echo "        Initialize buildout. Call this to either bootstrap a new project"
119         @echo "        or to initialize a new working copy. Missing packages will be"
120         @echo "        downloaded from the internet (init target) or from an up-to-date"
121         @echo "        download cache (init-nonet). The download cache normaly resides in"
122         @echo "        './dlcache'"
123         @echo
124         @echo "    update"
125         @echo "    update-nonet"
126         @echo "        Update the buildout. Calls './bin/buildout' (update target) or "
127         @echo "        './bin/buildout -No (update-nonet target)."
128         @echo
129         @echo "    shell"
130         @echo "        Spawn an interactive subshell with the environment set up correctly"
131         @echo "        for the local buildout."
132         @echo
133         @echo "    clean"
134         @echo "        Remove all unimportant (!) generated files (the remaining files are"
135         @echo "        those which may be changed and should be managed as part of the"
136         @echo "        project source-code). calling 'make init' or 'make init-nonet' will"
137         @echo "        rebuild the development environment."
138         @echo
139 .PHONY: shorthelp
140
141 fullhelp::
142         @echo
143         @echo "SUPPLEMENTARY TARGETS"
144         @echo
145         @echo "    cleancache"
146         @echo "        purge the download cache"
147         @echo
148         @echo "    upgrade"
149         @echo "        Reinitializes the buildout. This is like calling"
150         @echo "        'make clean cleancache init'. Use this target to upgrade to a new"
151         @echo "        python or extension (e.g. PIL) version (after changing the version"
152         @echo "        in the project Makefile) or to upgrade the component eggs. This"
153         @echo "        target purges the download cache to ensure, no obsolete files are"
154         @echo "        left."
155         @echo
156 .PHONY: fullhelp
157
158 varhelp::
159         @echo
160         @echo "MAKEFILE VARIABLES"
161         @echo
162         @echo "    DLCACHE ($(DLCACHE))"
163         @echo "        Name of the download-cache subdirectory. This directory may be"
164         @echo "        persisted e.g. by checking into version control (together with"
165         @echo "        the source code or into as a separate repository or by saving into"
166         @echo "        an archive. A persistent cache allows the setup to be completely"
167         @echo "        reproducible and network independent."
168         @echo
169 .PHONY: varhelp
170
171 debdepends::
172 .PHONY: debdepends
173
174 setup::
175         mkdir -p $(DLCACHE) $(DLCACHE)/pip
176 .PHONY: setup
177
178 eggs::
179 .PHONY: eggs
180
181 buildout::
182 .PHONY: buildout
183
184 init-hook::
185 .PHONY: init-hook
186
187 update-hook::
188 .PHONY: update-hook
189
190 bootstrap::
191 .PHONY: bootstrap
192
193 update:: update-hook
194 .PHONY: update
195
196 define gitignore
197     _gitignore () {                                             \
198         [ -r .gitignore ] || touch .gitignore;                  \
199         grep -qxF "$$1" .gitignore || echo "$$1" >>.gitignore;  \
200     };                                                          \
201     _gitignore
202 endef
203 .gitignore::
204         @echo "Updating .gitignore."
205         @$(gitignore) "/.env"
206
207 define env
208     _env () {                                                   \
209         [ -r .env ] || touch .env;                              \
210         case "$$1" in                                           \
211         PATH|PYTHONPATH) line="export $$1=\"$$2:\$$$$1\"" ;;    \
212         *) line="export $$1=\"$$2\"" ;;                         \
213         esac;                                                   \
214         grep -qxF "$$line" .env || echo "$$line" >>.env;        \
215     };                                                          \
216     _env
217 endef
218 .env::
219         @echo "Updating .env."
220
221 clean::
222         rm -f .env
223 .PHONY: clean
224
225 ###########################################################################
226 # user targets
227
228 init: setup eggs buildout init-hook update-hook bootstrap update .gitignore .env
229 .PHONY: init
230
231 init-nonet: HTTPGET_NONET=1
232 init-nonet: init
233 .PHONY: init-nonet
234
235 shell:
236         @eval "`cat .env`"; $$SHELL
237 .PHONY: shell
238
239 update-nonet: update
240 .PHONY: update-nonet
241
242 cleancache:
243         rm -rf $(DLCACHE)/*
244 .PHONY: cleancache
245
246 upgrade: clean cleancache init
247 .PHONY: upgrade
248
249 help:
250         @[ -n `which less` ] && $(MAKE) -s shorthelp fullhelp varhelp | less \
251                 || $(MAKE) -s shorthelp fullhelp varhelp
252 .PHONY: help