1 |
5459
|
aaronmk
|
root := .
|
2 |
3762
|
aaronmk
|
include lib/common.Makefile
|
3 |
|
|
|
4 |
|
|
|
5 |
784
|
aaronmk
|
##### Vars/functions
|
6 |
|
|
|
7 |
244
|
aaronmk
|
# Make
|
8 |
247
|
aaronmk
|
SHELL := /bin/bash
|
9 |
625
|
aaronmk
|
subMake = $(MAKE) $(call subPath,$@) --directory=$(call topDir,$@)
|
10 |
244
|
aaronmk
|
|
11 |
4607
|
aaronmk
|
# Paths
|
12 |
|
|
bin := bin
|
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 |
1745
|
aaronmk
|
done = echo; echo $(emph)"Finished $@"$(endEmph); echo
|
23 |
245
|
aaronmk
|
|
24 |
247
|
aaronmk
|
wait := read -p $(emph)'Press ENTER to continue:'$(endEmph) REPLY
|
25 |
245
|
aaronmk
|
|
26 |
2090
|
aaronmk
|
confirm = $(if $(shell read -p $(emph)"$(1)"$(endEmph)$$'$(if\
|
27 |
|
|
$(2),\n$(2))\nContinue? (y/n) ' REPLY; test "$$REPLY" = y && echo t),,\
|
28 |
|
|
$(error Aborting))
|
29 |
235
|
aaronmk
|
|
30 |
335
|
aaronmk
|
# File editing
|
31 |
|
|
sudoAppend = echo $$'$(2)'|sudo tee -a $(1) >/dev/null
|
32 |
|
|
|
33 |
2091
|
aaronmk
|
# DB
|
34 |
|
|
mkSchemaCmd = 'CREATE SCHEMA $(1);'
|
35 |
3380
|
aaronmk
|
rmSchemaCmd = 'DROP SCHEMA IF EXISTS "$(1)" CASCADE;'
|
36 |
2091
|
aaronmk
|
|
37 |
784
|
aaronmk
|
##### Environment
|
38 |
|
|
|
39 |
225
|
aaronmk
|
export PGOPTIONS = --client-min-messages=WARNING
|
40 |
|
|
|
41 |
784
|
aaronmk
|
##### General targets
|
42 |
225
|
aaronmk
|
|
43 |
1274
|
aaronmk
|
remake: _always clean
|
44 |
|
|
$(MAKE)
|
45 |
|
|
# re-run make so that cache of existing files is reset
|
46 |
|
|
|
47 |
1288
|
aaronmk
|
%/remake: _always
|
48 |
|
|
$(MAKE) $(@D)/clean
|
49 |
|
|
$(MAKE) $(@D)/
|
50 |
|
|
# re-run make so that cache of existing files is reset
|
51 |
|
|
|
52 |
1813
|
aaronmk
|
%-remake: _always
|
53 |
|
|
rm -f $*
|
54 |
|
|
$(MAKE) $*
|
55 |
|
|
# re-run make so that cache of existing files is reset
|
56 |
|
|
|
57 |
2981
|
aaronmk
|
%/reinstall: _always %/uninstall %/install ;
|
58 |
|
|
|
59 |
784
|
aaronmk
|
##### Installation
|
60 |
241
|
aaronmk
|
|
61 |
3377
|
aaronmk
|
install: _always core mysql inputs/download inputs/install test
|
62 |
241
|
aaronmk
|
@$(done)
|
63 |
202
|
aaronmk
|
|
64 |
418
|
aaronmk
|
uninstall: _always inputs/uninstall rm_mysql rm_core ;
|
65 |
241
|
aaronmk
|
|
66 |
418
|
aaronmk
|
reinstall: _always uninstall install ;
|
67 |
225
|
aaronmk
|
|
68 |
784
|
aaronmk
|
##### Core: VegBIEN DB and dependencies
|
69 |
202
|
aaronmk
|
|
70 |
1746
|
aaronmk
|
core: _always $(call forOs,python php postgres) db
|
71 |
241
|
aaronmk
|
@$(done)
|
72 |
235
|
aaronmk
|
|
73 |
1746
|
aaronmk
|
rm_core: _always rm_db ;
|
74 |
241
|
aaronmk
|
|
75 |
418
|
aaronmk
|
reinstall_core: _always rm_core core ;
|
76 |
241
|
aaronmk
|
|
77 |
784
|
aaronmk
|
##### Python
|
78 |
|
|
|
79 |
383
|
aaronmk
|
python-Linux: _always
|
80 |
2618
|
aaronmk
|
-sudo apt-get install python
|
81 |
|
|
-sudo apt-get install python-dev
|
82 |
|
|
-sudo apt-get install python-dateutil
|
83 |
|
|
-sudo apt-get install python-parallel
|
84 |
|
|
-sudo apt-get install python-profiler
|
85 |
|
|
-sudo apt-get install python-pip
|
86 |
|
|
-sudo apt-get install pymetrics
|
87 |
3156
|
aaronmk
|
-sudo pip install ordereddict
|
88 |
1845
|
aaronmk
|
-sudo pip install pp
|
89 |
284
|
aaronmk
|
|
90 |
383
|
aaronmk
|
python-Darwin: _always
|
91 |
284
|
aaronmk
|
@echo $(emph)'Installing python-dateutil on Mac OS X:'$(endEmph)
|
92 |
|
|
@echo 'Download it: http://labix.org/download/python-dateutil/python-dateutil-1.5.tar.gz'
|
93 |
|
|
@echo 'Extract the archive'
|
94 |
|
|
@echo 'Change to the directory of the extracted files'
|
95 |
|
|
@echo 'Run python setup.py build'
|
96 |
|
|
@echo 'Run sudo python setup.py install'
|
97 |
|
|
@echo "Run python -c 'import dateutil'"
|
98 |
|
|
@$(wait)
|
99 |
3156
|
aaronmk
|
@echo $(emph)'Installing pip on Mac OS X:'$(endEmph)
|
100 |
|
|
@echo 'Follow the instructions at http://www.pip-installer.org/en/latest/installing.html'
|
101 |
|
|
@$(wait)
|
102 |
284
|
aaronmk
|
|
103 |
1599
|
aaronmk
|
##### PHP
|
104 |
|
|
|
105 |
|
|
php-Linux: _always
|
106 |
|
|
-sudo apt-get install php-http-request
|
107 |
|
|
|
108 |
|
|
php-Darwin: _always
|
109 |
1600
|
aaronmk
|
@echo $(emph)'Installing PHP PEAR and HTTP_Request on Mac OS X:'$(endEmph)
|
110 |
|
|
@echo 'Download http://pear.php.net/go-pear.phar'
|
111 |
|
|
@echo 'Change to the directory of the downloaded file'
|
112 |
|
|
@echo 'Run php -d detect_unicode=0 go-pear.phar'
|
113 |
|
|
@echo 'Whenever prompted, press Enter to select default options'
|
114 |
|
|
@echo 'Add $$HOME/pear/bin to your $$PATH'
|
115 |
|
|
@echo 'Add $(HOME)/pear/share/pear to your php.ini include_path'
|
116 |
1665
|
aaronmk
|
@echo 'If needed, set $$PHPRC to your php.ini'
|
117 |
1600
|
aaronmk
|
@echo "Run pear install HTTP_Request"
|
118 |
|
|
@echo 'To run a php command: php -c <php.ini-path> ...'
|
119 |
1599
|
aaronmk
|
@$(wait)
|
120 |
|
|
|
121 |
784
|
aaronmk
|
##### PostgreSQL
|
122 |
|
|
|
123 |
1970
|
aaronmk
|
editPhppgadminApacheConf = echo $$'1\n,s/deny from all/allow from all/\nwq'|\
|
124 |
336
|
aaronmk
|
sudo ed --loose-exit-status --verbose /etc/phppgadmin/apache.conf
|
125 |
334
|
aaronmk
|
|
126 |
|
|
apacheConf := /etc/apache2/apache2.conf
|
127 |
|
|
apacheConfPhppgadminLine := Include /etc/phppgadmin/apache.conf
|
128 |
|
|
editApacheConfForPhppgadmin =\
|
129 |
|
|
$(if $(shell grep -F "$(apacheConfPhppgadminLine)" $(apacheConf)),,\
|
130 |
|
|
$(call sudoAppend,$(apacheConf),\n$(apacheConfPhppgadminLine)))
|
131 |
|
|
|
132 |
335
|
aaronmk
|
nonApacheOnPort80 = $(shell sudo lsof -i :80|tail -n +2|grep -v -F apache2)
|
133 |
336
|
aaronmk
|
editApachePortsConf = echo $$'1\n,s/\\b80\\b/8080/g\nwq'|\
|
134 |
|
|
sudo ed --loose-exit-status --verbose /etc/apache2/ports.conf
|
135 |
334
|
aaronmk
|
|
136 |
4752
|
aaronmk
|
pgVersion = "$$(env minor=1 bin/pg_version)"
|
137 |
|
|
|
138 |
383
|
aaronmk
|
postgres-Linux: _always
|
139 |
2618
|
aaronmk
|
-sudo apt-get install postgresql
|
140 |
4752
|
aaronmk
|
-sudo apt-get install postgresql-plpython-$(pgVersion)
|
141 |
2618
|
aaronmk
|
-sudo apt-get install libpq-dev
|
142 |
4752
|
aaronmk
|
-sudo apt-get install postgresql-$(pgVersion)-postgis
|
143 |
2618
|
aaronmk
|
-sudo apt-get install phppgadmin
|
144 |
336
|
aaronmk
|
$(editPhppgadminApacheConf)
|
145 |
334
|
aaronmk
|
$(editApacheConfForPhppgadmin)
|
146 |
336
|
aaronmk
|
$(if $(nonApacheOnPort80),$(editApachePortsConf))
|
147 |
334
|
aaronmk
|
-sudo apache2ctl restart
|
148 |
284
|
aaronmk
|
-sudo pip install psycopg2
|
149 |
2619
|
aaronmk
|
# run pg_version inline because it needs postgresql to be installed first
|
150 |
334
|
aaronmk
|
# ignore errors if conf files already edited
|
151 |
235
|
aaronmk
|
|
152 |
383
|
aaronmk
|
postgres-Darwin: _always
|
153 |
254
|
aaronmk
|
@echo $(emph)'Installing PostgreSQL on Mac OS X:'$(endEmph)
|
154 |
|
|
@echo 'Download it using the topmost "Mac OS X" link at http://http://www.enterprisedb.com/products-services-training/pgdownload'
|
155 |
|
|
@echo 'Open the disk image'
|
156 |
|
|
@echo 'Run the installer in it'
|
157 |
|
|
@$(wait)
|
158 |
235
|
aaronmk
|
|
159 |
418
|
aaronmk
|
postgres-: _always ; # other OSes
|
160 |
241
|
aaronmk
|
|
161 |
247
|
aaronmk
|
psqlOpts := --set ON_ERROR_STOP=1 --quiet
|
162 |
1980
|
aaronmk
|
psqlAsAdmin := sudo -E -u postgres psql $(psqlOpts)
|
163 |
|
|
# -E preserves env vars so PGOPTIONS is passed to psql
|
164 |
2624
|
aaronmk
|
psqlAsAdminVegbien := $(psqlAsAdmin) vegbien
|
165 |
1519
|
aaronmk
|
psqlAsBien := bin/psql_vegbien $(psqlOpts)
|
166 |
272
|
aaronmk
|
bienPassword := $(shell cat config/bien_password)
|
167 |
241
|
aaronmk
|
|
168 |
784
|
aaronmk
|
##### VegBIEN DB
|
169 |
241
|
aaronmk
|
|
170 |
1967
|
aaronmk
|
#### DB and bien user
|
171 |
|
|
|
172 |
2090
|
aaronmk
|
confirmRmDb = $(call confirm,WARNING: This will delete your entire VegBIEN\
|
173 |
3374
|
aaronmk
|
DB!,This includes all archived imports and staging tables.)
|
174 |
2089
|
aaronmk
|
|
175 |
2633
|
aaronmk
|
confirmRmPublicSchema = $(call confirm,WARNING: This will delete the current\
|
176 |
|
|
public schema of your VegBIEN DB!,To save it: make schemas/rotate)
|
177 |
2089
|
aaronmk
|
|
178 |
2091
|
aaronmk
|
rmPublicSchema := $(call rmSchemaCmd,public)
|
179 |
1967
|
aaronmk
|
|
180 |
6023
|
aaronmk
|
db: mk_db rm_initial_public inputs/.TNRS/install schemas/install _always ;
|
181 |
1967
|
aaronmk
|
|
182 |
|
|
mk_db: _always
|
183 |
1745
|
aaronmk
|
-echo "CREATE USER bien PASSWORD '$(bienPassword)';"|$(psqlAsAdmin)
|
184 |
2037
|
aaronmk
|
-echo "CREATE DATABASE vegbien WITH OWNER bien TEMPLATE template1 \
|
185 |
1940
|
aaronmk
|
ENCODING 'UTF8' LC_COLLATE 'en_US.UTF-8' LC_CTYPE 'en_US.UTF-8';"|$(psqlAsAdmin)
|
186 |
2627
|
aaronmk
|
-bin/postgres_vegbien createlang plpythonu
|
187 |
|
|
# ignore errors if user/database/etc. exists
|
188 |
2091
|
aaronmk
|
|
189 |
|
|
rm_initial_public: _always
|
190 |
2089
|
aaronmk
|
@$(confirmRmPublicSchema)
|
191 |
2624
|
aaronmk
|
echo $(rmPublicSchema)|$(psqlAsAdminVegbien)
|
192 |
1967
|
aaronmk
|
# drop public schema *as admin* because it starts out owned by postgres
|
193 |
241
|
aaronmk
|
|
194 |
383
|
aaronmk
|
rm_db: _always
|
195 |
1748
|
aaronmk
|
@$(confirmRmDb)
|
196 |
|
|
echo "DROP DATABASE IF EXISTS vegbien;"|$(psqlAsAdmin)
|
197 |
|
|
echo "DROP USER IF EXISTS bien;"|$(psqlAsAdmin)
|
198 |
241
|
aaronmk
|
|
199 |
418
|
aaronmk
|
reinstall_db: _always rm_db db ;
|
200 |
241
|
aaronmk
|
|
201 |
2631
|
aaronmk
|
#### Schemas
|
202 |
1967
|
aaronmk
|
|
203 |
2980
|
aaronmk
|
schemas := temp functions py_functions public
|
204 |
2631
|
aaronmk
|
schemas/install: $(schemas:%=schemas/%/install) ;
|
205 |
|
|
|
206 |
2980
|
aaronmk
|
schemasReversed := public py_functions functions temp
|
207 |
2631
|
aaronmk
|
schemas/uninstall: $(schemasReversed:%=schemas/%/uninstall) ;
|
208 |
|
|
|
209 |
|
|
### public
|
210 |
|
|
|
211 |
|
|
schemas/public/install: schemas/vegbien.sql _always
|
212 |
6088
|
aaronmk
|
-echo $(call mkSchemaCmd,public)|env public= $(psqlAsBien)
|
213 |
2036
|
aaronmk
|
<$< $(psqlAsBien)
|
214 |
1967
|
aaronmk
|
# ignore errors if schema exists
|
215 |
|
|
# public schema will be owned by bien
|
216 |
6088
|
aaronmk
|
# don't include public in the search_path
|
217 |
1967
|
aaronmk
|
|
218 |
2631
|
aaronmk
|
schemas/public/uninstall: _always
|
219 |
2089
|
aaronmk
|
@$(confirmRmPublicSchema)
|
220 |
6089
|
aaronmk
|
echo $(rmPublicSchema)|env public= $(psqlAsBien)
|
221 |
1967
|
aaronmk
|
|
222 |
5678
|
aaronmk
|
schemas/rename/%: _always
|
223 |
|
|
echo 'ALTER SCHEMA public RENAME TO "$*";'|$(psqlAsBien)
|
224 |
|
|
$(MAKE) schemas/public/install
|
225 |
|
|
|
226 |
5679
|
aaronmk
|
schemas/rotate: _always schemas/rename/public.$(version) ;
|
227 |
2034
|
aaronmk
|
|
228 |
2631
|
aaronmk
|
### py_functions
|
229 |
2091
|
aaronmk
|
|
230 |
2631
|
aaronmk
|
schemas/py_functions/install: schemas/py_functions.sql _always
|
231 |
3376
|
aaronmk
|
-<$< $(psqlAsAdminVegbien)
|
232 |
|
|
# ignore errors if schema exists
|
233 |
2631
|
aaronmk
|
|
234 |
|
|
### Others
|
235 |
|
|
|
236 |
|
|
schemas/%/install: schemas/%.sql _always
|
237 |
3376
|
aaronmk
|
-<$< $(psqlAsBien)
|
238 |
|
|
# ignore errors if schema exists
|
239 |
2091
|
aaronmk
|
|
240 |
3393
|
aaronmk
|
schemas/%/uninstall: _always
|
241 |
2631
|
aaronmk
|
echo $(call rmSchemaCmd,$*)|$(psqlAsBien)
|
242 |
2624
|
aaronmk
|
|
243 |
2983
|
aaronmk
|
# Needed on Ubuntu 12.04 (also other Linuxes?) because %/reinstall is ignored.
|
244 |
|
|
schemas/temp/reinstall: _always schemas/temp/uninstall schemas/temp/install ;
|
245 |
|
|
|
246 |
784
|
aaronmk
|
##### MySQL
|
247 |
241
|
aaronmk
|
|
248 |
383
|
aaronmk
|
mysql: _always $(call forOs,mysql) mysql_user
|
249 |
241
|
aaronmk
|
@$(done)
|
250 |
|
|
|
251 |
418
|
aaronmk
|
rm_mysql: _always rm_mysql_user ;
|
252 |
241
|
aaronmk
|
|
253 |
383
|
aaronmk
|
mysql-Linux: _always
|
254 |
244
|
aaronmk
|
@echo $(emph)"If asked for MySQL root password, enter $(bienPassword)"$(endEmph)
|
255 |
238
|
aaronmk
|
@$(wait)
|
256 |
237
|
aaronmk
|
-sudo apt-get install mysql-server mysql-client python-mysqldb
|
257 |
235
|
aaronmk
|
|
258 |
383
|
aaronmk
|
mysql-Darwin: _always
|
259 |
244
|
aaronmk
|
@echo $(emph)'Installing MySQLdb Python driver on Mac OS X 10.7 (may work on other versions):'$(endEmph)
|
260 |
235
|
aaronmk
|
@echo 'Download it using "latest version" link at http://sourceforge.net/projects/mysql-python/files/'
|
261 |
|
|
@echo 'Extract the archive'
|
262 |
|
|
@echo '(From http://www.rustyrazorblade.com/2011/11/installing-mysqldb-on-macos-lion/:)'
|
263 |
284
|
aaronmk
|
@echo 'Run ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib'
|
264 |
|
|
@echo 'Run ln -s /usr/local/mysql/lib /usr/local/mysql/lib/mysql'
|
265 |
235
|
aaronmk
|
@echo '(From http://blog.infoentropy.com/MySQL-python_EnvironmentError_mysql_config_not_found:)'
|
266 |
|
|
@echo 'Edit site.cfg and change the line like "mysql_config = " to "mysql_config = /usr/local/mysql/bin/mysql_config"'
|
267 |
|
|
@echo '(From http://www.mangoorange.com/2008/08/01/installing-python-mysqldb-122-on-mac-os-x/:)'
|
268 |
|
|
@echo 'Change to the directory of the extracted files'
|
269 |
284
|
aaronmk
|
@echo 'Run python setup.py clean'
|
270 |
|
|
@echo 'Run python setup.py build'
|
271 |
235
|
aaronmk
|
@echo 'Run sudo python setup.py install'
|
272 |
|
|
@echo "Run python -c 'import MySQLdb'"
|
273 |
238
|
aaronmk
|
@$(wait)
|
274 |
235
|
aaronmk
|
|
275 |
383
|
aaronmk
|
mysql-: _always # other OSes
|
276 |
235
|
aaronmk
|
|
277 |
247
|
aaronmk
|
mysqlAsRoot := mysql --user=root --password='$(bienPassword)'
|
278 |
235
|
aaronmk
|
|
279 |
383
|
aaronmk
|
mysql_user: _always
|
280 |
241
|
aaronmk
|
-$($@_cmd)
|
281 |
364
|
aaronmk
|
# ignore errors if user exists
|
282 |
244
|
aaronmk
|
mysql_user_cmd = echo "CREATE USER 'bien'@'localhost' IDENTIFIED BY \
|
283 |
245
|
aaronmk
|
'$(bienPassword)';"|$(mysqlAsRoot)
|
284 |
202
|
aaronmk
|
|
285 |
383
|
aaronmk
|
rm_mysql_user: _always
|
286 |
245
|
aaronmk
|
-echo "DROP USER 'bien'@'localhost';"|$(mysqlAsRoot)
|
287 |
364
|
aaronmk
|
# ignore errors if user exists
|
288 |
202
|
aaronmk
|
|
289 |
784
|
aaronmk
|
##### Datasources
|
290 |
202
|
aaronmk
|
|
291 |
418
|
aaronmk
|
inputs: _always inputs/all ;
|
292 |
245
|
aaronmk
|
|
293 |
1542
|
aaronmk
|
import: _always import-msg inputs/import ;
|
294 |
|
|
import-msg: _always
|
295 |
1550
|
aaronmk
|
@echo $(emph)"To import all inputs at once:"$(endEmph) . bin/import_all
|
296 |
1542
|
aaronmk
|
@echo
|
297 |
250
|
aaronmk
|
|
298 |
1458
|
aaronmk
|
verify: _always inputs/verify
|
299 |
1241
|
aaronmk
|
@$(done)
|
300 |
386
|
aaronmk
|
|
301 |
1458
|
aaronmk
|
test: _always inputs/test
|
302 |
397
|
aaronmk
|
@$(done)
|
303 |
1458
|
aaronmk
|
|
304 |
|
|
##### Testing
|
305 |
|
|
|
306 |
1743
|
aaronmk
|
test-all: _always remake test missing_mappings
|
307 |
1458
|
aaronmk
|
@$(done)
|
308 |
1967
|
aaronmk
|
|
309 |
|
|
##### Subdir forwarding
|
310 |
|
|
|
311 |
|
|
# Must come last so overridden targets are not forwarded
|
312 |
|
|
|
313 |
|
|
define subdirTargets
|
314 |
|
|
$(subdir): _always
|
315 |
|
|
+$$(subMake)
|
316 |
|
|
|
317 |
|
|
$(subdir)%: _always
|
318 |
|
|
+$$(subMake)
|
319 |
|
|
.PRECIOUS: $(subdir)% # let subdir's Makefile decide whether to delete on error
|
320 |
|
|
|
321 |
|
|
$(subdir)reinstall: _always $(subdir)uninstall $(subdir)install ;
|
322 |
|
|
endef
|
323 |
|
|
$(foreach subdir,$(wildcard */),$(eval $(subdirTargets)))
|
324 |
|
|
|
325 |
|
|
Makefile: ;
|
326 |
|
|
|
327 |
|
|
%: $(addsuffix %,$(dir $(shell echo */Makefile))) _always ;
|
328 |
1999
|
aaronmk
|
|
329 |
|
|
#### Maps validation
|
330 |
|
|
|
331 |
4607
|
aaronmk
|
termsSubdirs := $(call no/,$(call wildcard/,inputs/*/))
|
332 |
|
|
|
333 |
3764
|
aaronmk
|
include lib/mappings.Makefile
|