1 |
784
|
aaronmk
|
##### Vars/functions
|
2 |
|
|
|
3 |
244
|
aaronmk
|
# Make
|
4 |
247
|
aaronmk
|
SHELL := /bin/bash
|
5 |
625
|
aaronmk
|
pathParts = $(shell path="$(1)"; echo "$${path%%/*}" "$${path\#*/}")
|
6 |
739
|
aaronmk
|
topDir = $(word 1,$(pathParts))
|
7 |
|
|
subPath = $(word 2,$(pathParts))
|
8 |
625
|
aaronmk
|
subMake = $(MAKE) $(call subPath,$@) --directory=$(call topDir,$@)
|
9 |
244
|
aaronmk
|
|
10 |
245
|
aaronmk
|
# OS
|
11 |
247
|
aaronmk
|
os := $(shell uname)
|
12 |
245
|
aaronmk
|
forOs = $(patsubst %,%-$(filter Linux Darwin,$(os)),$(1))
|
13 |
|
|
|
14 |
241
|
aaronmk
|
# Terminal
|
15 |
247
|
aaronmk
|
esc := '['
|
16 |
|
|
reset := $(esc)'0m'
|
17 |
|
|
emph := $(esc)'7m '
|
18 |
|
|
endEmph := ' '$(reset)
|
19 |
245
|
aaronmk
|
|
20 |
|
|
# User interaction
|
21 |
|
|
|
22 |
|
|
confirm = $(shell read -p $(emph)"$(1) (y/n)"$(endEmph) REPLY; \
|
23 |
|
|
test "$REPLY" = y && echo t)
|
24 |
|
|
|
25 |
|
|
getPassword = $(shell read -s -p $(emph)"Enter your $(1) password:"$(endEmph) \
|
26 |
|
|
REPLY; echo >&2; echo -n "$REPLY")
|
27 |
|
|
|
28 |
247
|
aaronmk
|
wait := read -p $(emph)'Press ENTER to continue:'$(endEmph) REPLY
|
29 |
245
|
aaronmk
|
|
30 |
249
|
aaronmk
|
done = echo; echo $(emph)"Finished $@"$(endEmph); echo
|
31 |
235
|
aaronmk
|
|
32 |
335
|
aaronmk
|
# File editing
|
33 |
|
|
sudoAppend = echo $$'$(2)'|sudo tee -a $(1) >/dev/null
|
34 |
|
|
|
35 |
784
|
aaronmk
|
##### Environment
|
36 |
|
|
|
37 |
225
|
aaronmk
|
export PGOPTIONS = --client-min-messages=WARNING
|
38 |
|
|
|
39 |
784
|
aaronmk
|
##### General targets
|
40 |
225
|
aaronmk
|
|
41 |
414
|
aaronmk
|
all:
|
42 |
228
|
aaronmk
|
|
43 |
1260
|
aaronmk
|
.SUFFIXES: # turn off built-in suffix rules
|
44 |
|
|
.SECONDARY: # don't automatically delete intermediate files
|
45 |
225
|
aaronmk
|
|
46 |
383
|
aaronmk
|
_always:
|
47 |
|
|
.PHONY: _always
|
48 |
202
|
aaronmk
|
|
49 |
1274
|
aaronmk
|
remake: _always clean
|
50 |
|
|
$(MAKE)
|
51 |
|
|
# re-run make so that cache of existing files is reset
|
52 |
|
|
|
53 |
1288
|
aaronmk
|
%/remake: _always
|
54 |
|
|
$(MAKE) $(@D)/clean
|
55 |
|
|
$(MAKE) $(@D)/
|
56 |
|
|
# re-run make so that cache of existing files is reset
|
57 |
|
|
|
58 |
402
|
aaronmk
|
define subdirTargets
|
59 |
|
|
$(subdir): _always
|
60 |
|
|
+$$(subMake)
|
61 |
388
|
aaronmk
|
|
62 |
402
|
aaronmk
|
$(subdir)%: _always
|
63 |
|
|
+$$(subMake)
|
64 |
|
|
endef
|
65 |
|
|
$(foreach subdir,$(wildcard */),$(eval $(subdirTargets)))
|
66 |
388
|
aaronmk
|
|
67 |
416
|
aaronmk
|
Makefile: ;
|
68 |
|
|
|
69 |
414
|
aaronmk
|
%: $(addsuffix %,$(dir $(shell echo */Makefile))) _always ;
|
70 |
|
|
|
71 |
784
|
aaronmk
|
##### Installation
|
72 |
241
|
aaronmk
|
|
73 |
411
|
aaronmk
|
install: _always core mysql inputs/install test
|
74 |
241
|
aaronmk
|
@$(done)
|
75 |
202
|
aaronmk
|
|
76 |
418
|
aaronmk
|
uninstall: _always inputs/uninstall rm_mysql rm_core ;
|
77 |
241
|
aaronmk
|
|
78 |
418
|
aaronmk
|
reinstall: _always uninstall install ;
|
79 |
225
|
aaronmk
|
|
80 |
784
|
aaronmk
|
##### Core: VegBIEN DB and dependencies
|
81 |
202
|
aaronmk
|
|
82 |
383
|
aaronmk
|
core: _always $(call forOs,python postgres) postgres_user db
|
83 |
241
|
aaronmk
|
@$(done)
|
84 |
235
|
aaronmk
|
|
85 |
418
|
aaronmk
|
rm_core: _always rm_db rm_postgres_user ;
|
86 |
241
|
aaronmk
|
|
87 |
418
|
aaronmk
|
reinstall_core: _always rm_core core ;
|
88 |
241
|
aaronmk
|
|
89 |
784
|
aaronmk
|
##### Python
|
90 |
|
|
|
91 |
383
|
aaronmk
|
python-Linux: _always
|
92 |
1255
|
aaronmk
|
-sudo apt-get install python python-dev python-dateutil python-profiler\
|
93 |
|
|
python-pip
|
94 |
284
|
aaronmk
|
|
95 |
383
|
aaronmk
|
python-Darwin: _always
|
96 |
284
|
aaronmk
|
@echo $(emph)'Installing python-dateutil on Mac OS X:'$(endEmph)
|
97 |
|
|
@echo 'Download it: http://labix.org/download/python-dateutil/python-dateutil-1.5.tar.gz'
|
98 |
|
|
@echo 'Extract the archive'
|
99 |
|
|
@echo 'Change to the directory of the extracted files'
|
100 |
|
|
@echo 'Run python setup.py build'
|
101 |
|
|
@echo 'Run sudo python setup.py install'
|
102 |
|
|
@echo "Run python -c 'import dateutil'"
|
103 |
|
|
@$(wait)
|
104 |
|
|
|
105 |
784
|
aaronmk
|
##### PostgreSQL
|
106 |
|
|
|
107 |
337
|
aaronmk
|
editPhppgadminApacheConf = echo $$'1\n,s/\# \(allow from all\)/\1/\nwq'|\
|
108 |
336
|
aaronmk
|
sudo ed --loose-exit-status --verbose /etc/phppgadmin/apache.conf
|
109 |
334
|
aaronmk
|
|
110 |
|
|
apacheConf := /etc/apache2/apache2.conf
|
111 |
|
|
apacheConfPhppgadminLine := Include /etc/phppgadmin/apache.conf
|
112 |
|
|
editApacheConfForPhppgadmin =\
|
113 |
|
|
$(if $(shell grep -F "$(apacheConfPhppgadminLine)" $(apacheConf)),,\
|
114 |
|
|
$(call sudoAppend,$(apacheConf),\n$(apacheConfPhppgadminLine)))
|
115 |
|
|
|
116 |
335
|
aaronmk
|
nonApacheOnPort80 = $(shell sudo lsof -i :80|tail -n +2|grep -v -F apache2)
|
117 |
336
|
aaronmk
|
editApachePortsConf = echo $$'1\n,s/\\b80\\b/8080/g\nwq'|\
|
118 |
|
|
sudo ed --loose-exit-status --verbose /etc/apache2/ports.conf
|
119 |
334
|
aaronmk
|
|
120 |
383
|
aaronmk
|
postgres-Linux: _always
|
121 |
329
|
aaronmk
|
-sudo apt-get install postgresql libpq-dev phppgadmin
|
122 |
336
|
aaronmk
|
$(editPhppgadminApacheConf)
|
123 |
334
|
aaronmk
|
$(editApacheConfForPhppgadmin)
|
124 |
336
|
aaronmk
|
$(if $(nonApacheOnPort80),$(editApachePortsConf))
|
125 |
334
|
aaronmk
|
-sudo apache2ctl restart
|
126 |
284
|
aaronmk
|
-sudo pip install psycopg2
|
127 |
334
|
aaronmk
|
# ignore errors if conf files already edited
|
128 |
235
|
aaronmk
|
|
129 |
383
|
aaronmk
|
postgres-Darwin: _always
|
130 |
254
|
aaronmk
|
@echo $(emph)'Installing PostgreSQL on Mac OS X:'$(endEmph)
|
131 |
|
|
@echo 'Download it using the topmost "Mac OS X" link at http://http://www.enterprisedb.com/products-services-training/pgdownload'
|
132 |
|
|
@echo 'Open the disk image'
|
133 |
|
|
@echo 'Run the installer in it'
|
134 |
|
|
@$(wait)
|
135 |
235
|
aaronmk
|
|
136 |
418
|
aaronmk
|
postgres-: _always ; # other OSes
|
137 |
241
|
aaronmk
|
|
138 |
247
|
aaronmk
|
psqlOpts := --set ON_ERROR_STOP=1 --quiet
|
139 |
249
|
aaronmk
|
psqlAsAdmin := sudo -u postgres psql $(psqlOpts)
|
140 |
274
|
aaronmk
|
psqlAsBien := ./bin/psql_vegbien $(psqlOpts)
|
141 |
272
|
aaronmk
|
bienPassword := $(shell cat config/bien_password)
|
142 |
241
|
aaronmk
|
|
143 |
383
|
aaronmk
|
postgres_user: _always
|
144 |
249
|
aaronmk
|
-echo "CREATE USER bien PASSWORD '$(bienPassword)';"|$(psqlAsAdmin)
|
145 |
364
|
aaronmk
|
# ignore errors if user exists
|
146 |
241
|
aaronmk
|
|
147 |
383
|
aaronmk
|
rm_postgres_user: _always
|
148 |
241
|
aaronmk
|
echo "DROP USER IF EXISTS bien;"|$(psqlAsAdmin)
|
149 |
|
|
|
150 |
784
|
aaronmk
|
##### VegBIEN DB
|
151 |
241
|
aaronmk
|
|
152 |
389
|
aaronmk
|
db: _always schemas/vegbien.sql
|
153 |
383
|
aaronmk
|
-$($@_create_cmd)
|
154 |
389
|
aaronmk
|
$(psqlAsBien) <schemas/vegbien.sql
|
155 |
364
|
aaronmk
|
# ignore errors if database exists
|
156 |
383
|
aaronmk
|
db_create_cmd = echo "CREATE DATABASE vegbien OWNER bien ENCODING 'UTF8' \
|
157 |
381
|
aaronmk
|
TEMPLATE template1;"|$(psqlAsAdmin)
|
158 |
241
|
aaronmk
|
|
159 |
383
|
aaronmk
|
rm_db: _always
|
160 |
241
|
aaronmk
|
echo "DROP DATABASE IF EXISTS vegbien;"|$(psqlAsAdmin)
|
161 |
|
|
|
162 |
418
|
aaronmk
|
reinstall_db: _always rm_db db ;
|
163 |
241
|
aaronmk
|
|
164 |
389
|
aaronmk
|
empty_db: _always schemas/vegbien_empty.sql
|
165 |
|
|
$(psqlAsBien) <schemas/vegbien_empty.sql
|
166 |
241
|
aaronmk
|
|
167 |
784
|
aaronmk
|
##### MySQL
|
168 |
241
|
aaronmk
|
|
169 |
383
|
aaronmk
|
mysql: _always $(call forOs,mysql) mysql_user
|
170 |
241
|
aaronmk
|
@$(done)
|
171 |
|
|
|
172 |
418
|
aaronmk
|
rm_mysql: _always rm_mysql_user ;
|
173 |
241
|
aaronmk
|
|
174 |
383
|
aaronmk
|
mysql-Linux: _always
|
175 |
244
|
aaronmk
|
@echo $(emph)"If asked for MySQL root password, enter $(bienPassword)"$(endEmph)
|
176 |
238
|
aaronmk
|
@$(wait)
|
177 |
237
|
aaronmk
|
-sudo apt-get install mysql-server mysql-client python-mysqldb
|
178 |
235
|
aaronmk
|
|
179 |
383
|
aaronmk
|
mysql-Darwin: _always
|
180 |
244
|
aaronmk
|
@echo $(emph)'Installing MySQLdb Python driver on Mac OS X 10.7 (may work on other versions):'$(endEmph)
|
181 |
235
|
aaronmk
|
@echo 'Download it using "latest version" link at http://sourceforge.net/projects/mysql-python/files/'
|
182 |
|
|
@echo 'Extract the archive'
|
183 |
|
|
@echo '(From http://www.rustyrazorblade.com/2011/11/installing-mysqldb-on-macos-lion/:)'
|
184 |
284
|
aaronmk
|
@echo 'Run ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib'
|
185 |
|
|
@echo 'Run ln -s /usr/local/mysql/lib /usr/local/mysql/lib/mysql'
|
186 |
235
|
aaronmk
|
@echo '(From http://blog.infoentropy.com/MySQL-python_EnvironmentError_mysql_config_not_found:)'
|
187 |
|
|
@echo 'Edit site.cfg and change the line like "mysql_config = " to "mysql_config = /usr/local/mysql/bin/mysql_config"'
|
188 |
|
|
@echo '(From http://www.mangoorange.com/2008/08/01/installing-python-mysqldb-122-on-mac-os-x/:)'
|
189 |
|
|
@echo 'Change to the directory of the extracted files'
|
190 |
284
|
aaronmk
|
@echo 'Run python setup.py clean'
|
191 |
|
|
@echo 'Run python setup.py build'
|
192 |
235
|
aaronmk
|
@echo 'Run sudo python setup.py install'
|
193 |
|
|
@echo "Run python -c 'import MySQLdb'"
|
194 |
238
|
aaronmk
|
@$(wait)
|
195 |
235
|
aaronmk
|
|
196 |
383
|
aaronmk
|
mysql-: _always # other OSes
|
197 |
235
|
aaronmk
|
|
198 |
247
|
aaronmk
|
mysqlAsRoot := mysql --user=root --password='$(bienPassword)'
|
199 |
235
|
aaronmk
|
|
200 |
383
|
aaronmk
|
mysql_user: _always
|
201 |
241
|
aaronmk
|
-$($@_cmd)
|
202 |
364
|
aaronmk
|
# ignore errors if user exists
|
203 |
244
|
aaronmk
|
mysql_user_cmd = echo "CREATE USER 'bien'@'localhost' IDENTIFIED BY \
|
204 |
245
|
aaronmk
|
'$(bienPassword)';"|$(mysqlAsRoot)
|
205 |
202
|
aaronmk
|
|
206 |
383
|
aaronmk
|
rm_mysql_user: _always
|
207 |
245
|
aaronmk
|
-echo "DROP USER 'bien'@'localhost';"|$(mysqlAsRoot)
|
208 |
364
|
aaronmk
|
# ignore errors if user exists
|
209 |
202
|
aaronmk
|
|
210 |
784
|
aaronmk
|
##### Datasources
|
211 |
202
|
aaronmk
|
|
212 |
418
|
aaronmk
|
inputs: _always inputs/all ;
|
213 |
245
|
aaronmk
|
|
214 |
418
|
aaronmk
|
import: _always inputs/import ;
|
215 |
250
|
aaronmk
|
|
216 |
418
|
aaronmk
|
verify: _always inputs/verify ;
|
217 |
1241
|
aaronmk
|
@$(done)
|
218 |
386
|
aaronmk
|
|
219 |
879
|
aaronmk
|
test: _always inputs/test ;
|
220 |
397
|
aaronmk
|
@$(done)
|