47c573846372ecd126b5a20ed6169727ea8f21ca
[zope-bootstrap.git] / Makefile.buildout
1 # -*- makefile -*-
2
3 # Usage:
4 #     @$(buildout_opt) <cfg-file> [set|add|append|remove] <section> <variable> [<value>]
5 #
6 # Change setting for <variable> in <section>. Actions are
7 #
8 #    set       Set <variable> to <value> replacing any existing value
9 #    add       If <variable> is unset, set to <value>
10 #    append    Append <value> to the end of the current value of <variable>
11 #    remove    Remove any assignment to <variable>
12 #
13 define buildout_opt
14     _buildout_getopt_() {                                                                       \
15         sed -n -e "/^\[$$1\]/,/^\[/ba" -eb -e:a -e "/^$$2 *=/,/^\([^ \t]\|\$$\)/p" $$cfgfile |  \
16             sed -e '$$d';                                                                       \
17     };                                                                                          \
18     _buildout_haveopt() {                                                                       \
19         [ -n "`_buildout_getopt_ "$$1" "$$2"`" ];                                               \
20     };                                                                                          \
21     _buildout_getopt() {                                                                        \
22         _buildout_checkopt_ "$$1" "$$2" | -e '1s/[^=]* *= *//';                                 \
23     };                                                                                          \
24     _buildout_addopt() {                                                                        \
25         sed -i -e "/\[$$1\]/ba" -eb -e:a -ea\\ -e "$$2 = $$3" $$cfgfile;                        \
26     };                                                                                          \
27     _buildout_replaceopt() {                                                                    \
28         sed -i -e "/^\[$$1\]/,/^\[/ba" -eb -e:a                                                 \
29             -e "/^$$2 *=/,/^\([^ \t]\|\$$\)/bb" -eb -e:b                                        \
30             -e "/^$$2 *=/bc" -ebd -e:c                                                          \
31             -ec\\ -e "$$2 = $$3" -eb -e:d                                                       \
32             -e "/^\([^ \t]\|\$$\)/b" -ed                                                        \
33                 $$cfgfile;                                                                      \
34     };                                                                                          \
35     _buildout_appendopt() {                                                                     \
36         sed -i -e "/^\[$$1\]/,/^\[/ba" -eb -e:a                                                 \
37             -e "/^$$2 *=/,/^\([^ \t]\|\$$\)/bb" -eb -e:b                                        \
38             -e /^\([^ \t]\|$$\)/bc -eb -e:c                                                     \
39             -ei\\ -e "    $$3"                                                                  \
40                 $$cfgfile;                                                                      \
41     };                                                                                          \
42     _buildout_removeopt() {                                                                     \
43         sed -i -e "/^\[$$1\]/,/^\[/ba" -eb -e:a                                                 \
44             -e "/^$$2 *=/,/^\([^ \t]\|\$$\)/bb" -eb -e:b                                        \
45             -e "/^\([^ \t]\|\$$\)/b" -ed                                                        \
46                 $$cfgfile;                                                                      \
47     };                                                                                          \
48     _buildout_opt_set() {                                                                       \
49         if _buildout_haveopt "$$1" "$$2"; then                                                  \
50             _buildout_replaceopt "$$1" "$$2" "$$3";                                             \
51         else                                                                                    \
52             _buildout_addopt "$$1" "$$2" "$$3";                                                 \
53         fi;                                                                                     \
54     };                                                                                          \
55     _buildout_opt_add() {                                                                       \
56         if ! _buildout_haveopt "$$1" "$$2"; then                                                \
57             _buildout_addopt "$$1" "$$2" "$$3";                                                 \
58         fi;                                                                                     \
59     };                                                                                          \
60     _buildout_opt_append() {                                                                    \
61         if builout_haveopt "$$1" "$$2"; then                                                    \
62             _buildout_appendopt "$$1" "$$2" "$$3";                                              \
63         else                                                                                    \
64             _buildouT_addopt "$$1" "$$2" "$$3";                                                 \
65         fi;                                                                                     \
66     };                                                                                          \
67     _builout_opt_remove() {                                                                     \
68         if buildout_haveopt "$$1" "$$2"; then                                                   \
69             _buildout_removeopt "$$1" "$$2";                                                    \
70         fi;                                                                                     \
71     };                                                                                          \
72     _buildout_opt() {                                                                           \
73         echo "$$1: option '[$$3]/$$4' $$2 '$$5'";                                               \
74         cfgfile="$$1";                                                                          \
75         _buildout_opt_$$2 "$$3" "$$4" "$$5";                                                    \
76     };                                                                                          \
77     _buildout_opt
78 endef
79
80 buildout-net.cfg: buildout.cfg
81         @$(buildout_opt) buildout.cfg add buildout download_cache $(DLCACHE)/downloads
82         @$(buildout_opt) buildout.cfg add buildout extends-cache $(DLCACHE)/extends
83         @$(buildout_opt) buildout.cfg set buildout install_from_cache true
84         @$(buildout_opt) buildout.cfg set buildout newest true
85         mkdir -p $(DLCACHE)/downloads $(DLCACHE)/extends
86         @(                                      \
87             echo "[buildout]";                  \
88             echo "extends = buildout.cfg";      \
89             echo "install-from-cache = false";  \
90             echo "newest = true";               \
91         ) >  buildout-net.cfg
92
93 BUILDOUT_OPTS = -c buildout-net.cfg
94
95 init-nonet: BUILDOUT_OPTS =
96 update-nonet: BUILDOUT_OPTS =
97
98 bootstrap::
99         sed -i -e '1s/^#!.*\/python/#!$(subst /,\/,$(PYTHON))/' $(PYTHON_DIR)/bin/*
100         $(PYTHON) -c 'from zc.buildout.buildout import main; main(["bootstrap"])'
101
102 .gitignore::
103         @$(gitignore) "/buildout-net.cfg"