Fix -nonet targets (zope3-buildout)
[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         sed -i -e '1s/^#!.*\/python/#!$(subst /,\/,$(PYTHON))/' $(PYTHON_DIR)/bin/*
164         $(PYTHON) -c 'from zc.buildout.buildout import main; main(["bootstrap"])'
165 .PHONY: bootstrap
166
167 update:: update-hook
168         bin/buildout $(BUILDOUT_OPTS)
169 .PHONY: update
170
171 define gitignore
172     _gitignore () {                                             \
173         [ -r .gitignore ] || touch .gitignore;                  \
174         grep -qxF "$$1" .gitignore || echo "$$1" >>.gitignore;  \
175     };                                                          \
176     _gitignore
177 endef
178 .gitignore::
179         @echo "Updating .gitignore."
180         @$(gitignore) "*.pyc"
181         @$(gitignore) "*.egg-info/"
182         @$(gitignore) "/.env"
183         @$(gitignore) "/.nonet.cfg"
184
185 define env
186     _env () {                                                   \
187         [ -r .env ] || touch .env;                              \
188         case "$$1" in                                           \
189         PATH|PYTHONPATH) line="export $$1=\"$$2:\$$$$1\"" ;;    \
190         *) line="export $$1=\"$$2\"" ;;                         \
191         esac;                                                   \
192         grep -qxF "$$line" .env || echo "$$line" >>.env;        \
193     };                                                          \
194     _env
195 endef
196 .env::
197         @echo "Updating .env."
198
199 clean::
200         rm -f .gitignore .env
201 .PHONY: clean
202
203 ###########################################################################
204 # user targets
205
206 init: setup eggs buildout init-hook update-hook bootstrap update .gitignore .env
207 .PHONY: init
208
209 init-nonet: HTTPGET_NONET=1
210 init-nonet: init
211 .PHONY: init-nonet
212
213 versions:
214         @echo "# Add the following lines to [versions] in buildout.cfg to pin all packages"
215         @bin/buildout -vvvvv | sed -ne 's/^Picked: //p' | sort | uniq 
216 .PHONY: versions
217
218 shell:
219         @eval "`cat .env`"; $$SHELL
220 .PHONY: shell
221
222 update-nonet: update
223 .PHONY: update-nonet