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