Rework net/nonet buildout switching
[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 "        Summary of important targets"
100         @echo
101         @echo "    help"
102         @echo "        Complete list of user-targets"
103         @echo
104         @echo "    debdepends"
105         @echo "        Install debian packages via 'aptitude' needed to satisy build"
106         @echo "        dependencies. MUST BE CALLED AS ROOT (e.g. with sudo)."
107         @echo
108         @echo "    init"
109         @echo "        Initialize buildout. Call this to either bootstrap a new project"
110         @echo "        or to initialize a new working copy. Missing packages will be"
111         @echo "        downloaded from the internet."
112         @echo
113         @echo "    init-nonet"
114         @echo "        Initialize buildout from cache. Like 'init' but does not download"
115         @echo "        any packages from the internet. Needs an up-to-date download cache."
116         @echo
117         @echo "    update"
118         @echo "        Update the buildout (calls './bin/buildout'). This target may need"
119         @echo "        network access."
120         @echo
121         @echo "    update-nonet"
122         @echo "        Update the buildout (calls './bin/buildout -No') with no network"
123         @echo "        access."
124         @echo
125         @echo "    shell"
126         @echo "        Spawn an interactive subshell with the environment set up correctly"
127         @echo "        for the local buildout."
128         @echo
129         @echo "    versions"
130         @echo "        Generate lines to be added to 'buildout.cfg' to pin all package"
131         @echo "        versions."
132         @echo
133         @echo "    clean"
134         @echo "        Remove all generated files."
135         @echo
136 .PHONY: shorthelp
137
138 help:: shorthelp
139         @echo
140         @echo "SECONDARY TARGETS"
141         @echo
142
143 debdepends::
144 .PHONY: debdepends
145
146 setup::
147         mkdir -p $(DLCACHE) $(DLCACHE)/pip
148 .PHONY: setup
149
150 eggs::
151 .PHONY: eggs
152
153 buildout::
154 .PHONY: buildout
155
156 init-hook::
157 .PHONY: init-hook
158
159 update-hook::
160 .PHONY: update-hook
161
162 bootstrap::
163 .PHONY: bootstrap
164
165 update:: update-hook
166         bin/buildout $(BUILDOUT_OPTS)
167 .PHONY: update
168
169 define gitignore
170     _gitignore () {                                             \
171         [ -r .gitignore ] || touch .gitignore;                  \
172         grep -qxF "$$1" .gitignore || echo "$$1" >>.gitignore;  \
173     };                                                          \
174     _gitignore
175 endef
176 .gitignore::
177         @echo "Updating .gitignore."
178         @$(gitignore) "*.pyc"
179         @$(gitignore) "*.egg-info/"
180         @$(gitignore) "/.env"
181
182 define env
183     _env () {                                                   \
184         [ -r .env ] || touch .env;                              \
185         case "$$1" in                                           \
186         PATH|PYTHONPATH) line="export $$1=\"$$2:\$$$$1\"" ;;    \
187         *) line="export $$1=\"$$2\"" ;;                         \
188         esac;                                                   \
189         grep -qxF "$$line" .env || echo "$$line" >>.env;        \
190     };                                                          \
191     _env
192 endef
193 .env::
194         @echo "Updating .env."
195
196 clean::
197         rm -f .gitignore .env
198 .PHONY: clean
199
200 ###########################################################################
201 # user targets
202
203 init: setup eggs buildout init-hook update-hook bootstrap update .gitignore .env
204 .PHONY: init
205
206 init-nonet: HTTPGET_NONET=1
207 init-nonet: init
208 .PHONY: init-nonet
209
210 versions:
211         @echo "# Add the following lines to [versions] in buildout.cfg to pin all packages"
212         @bin/buildout -vvvvv | sed -ne 's/^Picked: //p' | sort | uniq 
213 .PHONY: versions
214
215 shell:
216         @eval "`cat .env`"; $$SHELL
217 .PHONY: shell
218
219 update-nonet: update
220 .PHONY: update-nonet