1
|
root := .
|
2
|
include lib/common.Makefile
|
3
|
|
4
|
|
5
|
##### Vars/functions
|
6
|
|
7
|
# Make
|
8
|
SHELL := /bin/bash
|
9
|
subMake = $(MAKE) $(call subPath,$@) --directory=$(call topDir,$@)
|
10
|
|
11
|
# Paths
|
12
|
bin := bin
|
13
|
|
14
|
##### Environment
|
15
|
|
16
|
export PGOPTIONS = --client-min-messages=WARNING
|
17
|
|
18
|
##### General targets
|
19
|
|
20
|
remake: _always clean
|
21
|
$(MAKE)
|
22
|
# re-run make so that cache of existing files is reset
|
23
|
|
24
|
%/remake: _always
|
25
|
$(MAKE) $(@D)/clean
|
26
|
$(MAKE) $(@D)/
|
27
|
# re-run make so that cache of existing files is reset
|
28
|
|
29
|
%-remake: _always
|
30
|
rm -f $*
|
31
|
$(MAKE) $*
|
32
|
# re-run make so that cache of existing files is reset
|
33
|
|
34
|
%/reinstall: _always %/uninstall %/install ;
|
35
|
|
36
|
##### Installation
|
37
|
|
38
|
# public must be installed *after* inputs because some views depend on inputs
|
39
|
install: _always core mysql inputs/download inputs/install schemas/install test
|
40
|
@$(done)
|
41
|
|
42
|
uninstall: _always rm_mysql rm_core ;
|
43
|
|
44
|
reinstall: _always uninstall install ;
|
45
|
|
46
|
##### Core: VegBIEN DB and dependencies
|
47
|
|
48
|
core: _always $(call forOs,python php postgres) db
|
49
|
@$(done)
|
50
|
|
51
|
rm_core: _always rm_db ;
|
52
|
|
53
|
reinstall_core: _always rm_core core ;
|
54
|
|
55
|
##### Python
|
56
|
|
57
|
python-Linux: _always
|
58
|
-sudo apt-get --yes install python
|
59
|
-sudo apt-get --yes install python3
|
60
|
-sudo apt-get --yes install python-dev
|
61
|
-sudo apt-get --yes install python-dateutil
|
62
|
-sudo apt-get --yes install python-parallel
|
63
|
-sudo apt-get --yes install python-profiler
|
64
|
-sudo apt-get --yes install python-pip
|
65
|
-sudo apt-get --yes install pymetrics
|
66
|
-sudo pip install ordereddict
|
67
|
-sudo pip install pp
|
68
|
|
69
|
python-Darwin: _always
|
70
|
@echo $(emph)'Installing Python 3.2 on Mac OS X:'$(endEmph)
|
71
|
@echo 'Download it: http://www.python.org/ftp/python/3.2.3/python-3.2.3-macosx10.6.dmg'
|
72
|
@echo 'Open the disk image'
|
73
|
@echo 'Run the installer in it'
|
74
|
@$(wait)
|
75
|
@echo $(emph)'Installing python-dateutil on Mac OS X:'$(endEmph)
|
76
|
@echo 'Download it: http://labix.org/download/python-dateutil/python-dateutil-1.5.tar.gz'
|
77
|
@echo 'Extract the archive'
|
78
|
@echo 'Change to the directory of the extracted files'
|
79
|
@echo 'Run python setup.py build'
|
80
|
@echo 'Run sudo python setup.py install'
|
81
|
@echo "Run python -c 'import dateutil'"
|
82
|
@$(wait)
|
83
|
@echo $(emph)'Installing pip on Mac OS X:'$(endEmph)
|
84
|
@echo 'Follow the instructions at http://www.pip-installer.org/en/latest/installing.html'
|
85
|
@$(wait)
|
86
|
|
87
|
##### PHP
|
88
|
|
89
|
php-Linux: _always
|
90
|
-sudo apt-get --yes install php-http-request
|
91
|
|
92
|
php-Darwin: _always
|
93
|
@echo $(emph)'Installing PHP PEAR and HTTP_Request on Mac OS X:'$(endEmph)
|
94
|
@echo 'Download http://pear.php.net/go-pear.phar'
|
95
|
@echo 'Change to the directory of the downloaded file'
|
96
|
@echo 'Run php -d detect_unicode=0 go-pear.phar'
|
97
|
@echo 'Whenever prompted, press Enter to select default options'
|
98
|
@echo 'Add $$HOME/pear/bin to your $$PATH'
|
99
|
@echo 'Add $(HOME)/pear/share/pear to your php.ini include_path'
|
100
|
@echo 'If needed, set $$PHPRC to your php.ini'
|
101
|
@echo "Run pear install HTTP_Request"
|
102
|
@echo 'To run a php command: php -c <php.ini-path> ...'
|
103
|
@$(wait)
|
104
|
|
105
|
##### PostgreSQL
|
106
|
|
107
|
define editPhppgadmin
|
108
|
-sudo patch /etc/phppgadmin/config.inc.php lib/phpPgAdmin.config.inc.php.diff
|
109
|
sudo cp -n /usr/share/phppgadmin/login.php /usr/share/phppgadmin/login.php.old
|
110
|
-sudo patch /usr/share/phppgadmin/login.php lib/phpPgAdmin.login.php.diff
|
111
|
endef
|
112
|
# ignore errors if patch has already been applied
|
113
|
|
114
|
editPhppgadminApacheConf = echo $$'1\n,s/deny from all/allow from all/\nwq'|\
|
115
|
sudo ed --loose-exit-status --verbose /etc/phppgadmin/apache.conf
|
116
|
|
117
|
apacheConf := /etc/apache2/apache2.conf
|
118
|
apacheConfPhppgadminLine := Include /etc/phppgadmin/apache.conf
|
119
|
editApacheConfForPhppgadmin =\
|
120
|
$(if $(shell grep -F "$(apacheConfPhppgadminLine)" $(apacheConf)),,\
|
121
|
$(call sudoAppend,$(apacheConf),\n$(apacheConfPhppgadminLine)))
|
122
|
|
123
|
nonApacheOnPort80 = $(shell sudo lsof -i :80|tail -n +2|grep -v -F apache2)
|
124
|
editApachePortsConf = echo $$'1\n,s/\\b80\\b/8080/g\nwq'|\
|
125
|
sudo ed --loose-exit-status --verbose /etc/apache2/ports.conf
|
126
|
|
127
|
asAdmin := sudo -E -u postgres
|
128
|
asBien := sudo -E -u bien
|
129
|
pgVersion = "$$(env minor=1 bin/pg_version)"
|
130
|
|
131
|
linuxPostgresDir := /etc/postgresql/9.1/main
|
132
|
define pg_ctl-Linux
|
133
|
$(asAdmin) /etc/init.d/postgresql $(1)
|
134
|
sleep 2
|
135
|
endef
|
136
|
|
137
|
macPostgresDir := /Library/PostgreSQL/9.1
|
138
|
define macUsePostgresLib
|
139
|
sudo mv $(libDest) $(libDest).old||sudo rm -f $(libDest)
|
140
|
sudo ln -s $(macPostgresDir)/lib/$(1) $(libDest)
|
141
|
|
142
|
endef
|
143
|
libDest = /usr/lib/$(1)
|
144
|
|
145
|
macPostgresLibs := libcrypto libssl
|
146
|
macPostgresLibs := $(macPostgresLibs) $(macPostgresLibs:%=%.1.0.0)
|
147
|
macPostgresLibs := $(macPostgresLibs:%=%.dylib)
|
148
|
|
149
|
define pg_ctl-Darwin
|
150
|
$(asAdmin) pg_ctl -D $(macPostgresDir)/data -l $(macPostgresDir)/postgres.log $(1)
|
151
|
sleep 2
|
152
|
endef
|
153
|
|
154
|
confirmPostgresReload = $(call confirm,Modifying postgresql.conf and pg_hba.conf)
|
155
|
|
156
|
define postgresReload-Linux
|
157
|
@$(confirmPostgresReload)
|
158
|
@echo $(emph)'kernel.shmmax must be set to at least 4GB minus 1 byte:'$(endEmph)
|
159
|
@echo 'Append the following to /etc/sysctl.conf:'
|
160
|
@echo 'kernel.shmmax=4294967295'
|
161
|
@$(wait)
|
162
|
chmod a+r schemas/*.conf || $(asBien) chmod a+r schemas/*.conf
|
163
|
-$(asAdmin) mv -n $(linuxPostgresDir)/postgresql.conf $(linuxPostgresDir)/postgresql.conf.old
|
164
|
$(asAdmin) cp --preserve=timestamps schemas/postgresql.conf $(linuxPostgresDir)/postgresql.conf
|
165
|
-$(asAdmin) mv -n $(linuxPostgresDir)/pg_hba.conf $(linuxPostgresDir)/pg_hba.conf.old
|
166
|
$(asAdmin) cp --preserve=timestamps schemas/pg_hba.conf $(linuxPostgresDir)/pg_hba.conf
|
167
|
$(call pg_ctl-Linux,restart)
|
168
|
|
169
|
endef
|
170
|
|
171
|
define postgresReload-Darwin
|
172
|
@$(confirmPostgresReload)
|
173
|
chmod a+r schemas/*.conf
|
174
|
-$(asAdmin) mv -n $(macPostgresDir)/data/postgresql.conf $(macPostgresDir)/data/postgresql.conf.old
|
175
|
$(asAdmin) cp schemas/postgresql.Mac.conf $(macPostgresDir)/data/postgresql.conf
|
176
|
-$(asAdmin) mv -n $(macPostgresDir)/data/pg_hba.conf $(macPostgresDir)/data/pg_hba.conf.old
|
177
|
$(asAdmin) cp schemas/pg_hba.Mac.conf $(macPostgresDir)/data/pg_hba.conf
|
178
|
$(call pg_ctl-Darwin,restart)
|
179
|
|
180
|
endef
|
181
|
|
182
|
postgres_reload: _always
|
183
|
$($(call forOs,postgresReload))
|
184
|
|
185
|
postgres-Linux: _always
|
186
|
-sudo apt-get --yes install postgresql
|
187
|
-sudo apt-get --yes install postgresql-contrib
|
188
|
-sudo apt-get --yes install postgresql-plpython3-$(pgVersion)
|
189
|
-sudo apt-get --yes install libpq-dev
|
190
|
-sudo apt-get --yes install postgresql-$(pgVersion)-postgis
|
191
|
-sudo apt-get --yes install phppgadmin
|
192
|
$(editPhppgadmin)
|
193
|
$(editPhppgadminApacheConf)
|
194
|
$(editApacheConfForPhppgadmin)
|
195
|
$(if $(nonApacheOnPort80),$(editApachePortsConf))
|
196
|
-sudo apache2ctl restart
|
197
|
-sudo pip install psycopg2
|
198
|
-$(MAKE) $(postgresReload-Linux)
|
199
|
# run pg_version inline because it needs postgresql to be installed first
|
200
|
# ignore errors if conf files already edited
|
201
|
|
202
|
postgres-Darwin: _always
|
203
|
@echo $(emph)'Installing PostgreSQL on Mac OS X:'$(endEmph)
|
204
|
@echo 'Download it using the topmost "Mac OS X" link at http://http://www.enterprisedb.com/products-services-training/pgdownload'
|
205
|
@echo 'Open the disk image'
|
206
|
@echo 'Run the installer in it'
|
207
|
@$(wait)
|
208
|
$(foreach lib,$(macPostgresLibs),$(call macUsePostgresLib,$(lib)))
|
209
|
-$(MAKE) $(postgresReload-Darwin)
|
210
|
|
211
|
postgres-: _always ; # other OSes
|
212
|
|
213
|
psqlOpts := --set ON_ERROR_STOP=1 --quiet
|
214
|
psqlAsAdmin := $(asAdmin) psql $(psqlOpts)
|
215
|
# -E preserves env vars so PGOPTIONS is passed to psql
|
216
|
psqlAsAdminVegbien := $(psqlAsAdmin) vegbien
|
217
|
psqlNoSearchPath := env no_search_path=1 bin/psql_script_vegbien
|
218
|
bienPassword := $(shell cat config/bien_password)
|
219
|
bienReadPassword := $(shell cat config/bien_read_password)
|
220
|
|
221
|
##### VegBIEN DB
|
222
|
|
223
|
#### DB and users
|
224
|
|
225
|
confirmRmDb = $(call confirm,WARNING: This will delete your entire VegBIEN\
|
226
|
DB!,This includes all archived imports and staging tables.)
|
227
|
|
228
|
confirmRmPublicSchema = $(call confirm,WARNING: This will delete the current\
|
229
|
public schema of your VegBIEN DB!,To save it: make schemas/rotate)
|
230
|
|
231
|
rmPublicSchema := $(call rmSchemaCmd,public)
|
232
|
|
233
|
db: mk_db rm_initial_public _always ;
|
234
|
|
235
|
mk_db: _always
|
236
|
-echo "CREATE USER public_;"|$(psqlAsAdmin)
|
237
|
-echo "CREATE USER bien PASSWORD '$(bienPassword)';"|$(psqlAsAdmin)
|
238
|
-echo "CREATE USER bien_read PASSWORD '$(bienReadPassword)' IN ROLE bien \
|
239
|
NOINHERIT;"|$(psqlAsAdmin)
|
240
|
-echo "CREATE DATABASE vegbien WITH OWNER bien TEMPLATE template1 \
|
241
|
ENCODING 'UTF8' LC_COLLATE 'en_US.UTF-8' LC_CTYPE 'en_US.UTF-8';"|$(psqlAsAdmin)
|
242
|
-echo "CREATE EXTENSION hstore SCHEMA pg_catalog;"|$(psqlAsAdminVegbien)
|
243
|
-$(asAdmin) createlang plpython3u vegbien
|
244
|
# ignore errors if user/database/etc. exists
|
245
|
|
246
|
rm_initial_public: _always
|
247
|
@$(confirmRmPublicSchema)
|
248
|
echo $(rmPublicSchema)|$(psqlAsAdminVegbien)
|
249
|
# drop public schema *as admin* because it starts out owned by postgres
|
250
|
|
251
|
rm_db: _always
|
252
|
@$(confirmRmDb)
|
253
|
echo "DROP DATABASE IF EXISTS vegbien;"|$(psqlAsAdmin)
|
254
|
echo "DROP USER IF EXISTS bien_read;"|$(psqlAsAdmin)
|
255
|
echo "DROP USER IF EXISTS bien;"|$(psqlAsAdmin)
|
256
|
echo "DROP USER IF EXISTS public_;"|$(psqlAsAdmin)
|
257
|
|
258
|
reinstall_db: _always rm_db db ;
|
259
|
|
260
|
#### Schemas
|
261
|
|
262
|
schemas := temp functions py_functions public
|
263
|
schemas/install: $(schemas:%=schemas/%/install) ;
|
264
|
|
265
|
schemasReversed := public py_functions functions temp
|
266
|
schemas/uninstall: $(schemasReversed:%=schemas/%/uninstall) ;
|
267
|
|
268
|
### public
|
269
|
|
270
|
schemas/public/install: schemas/vegbien.sql _always
|
271
|
-echo $(call mkSchemaCmd,public)|$(psqlNoSearchPath)
|
272
|
<$< $(psqlNoSearchPath)
|
273
|
# ignore errors if schema exists
|
274
|
# public schema will be owned by bien
|
275
|
# don't include public in the search_path
|
276
|
|
277
|
schemas/public/uninstall: _always
|
278
|
@$(confirmRmPublicSchema)
|
279
|
echo $(rmPublicSchema)|$(psqlNoSearchPath)
|
280
|
|
281
|
schemas/rename/%: _always
|
282
|
echo 'ALTER SCHEMA public RENAME TO "$*";'|$(psqlNoSearchPath)
|
283
|
$(MAKE) schemas/public/install
|
284
|
|
285
|
schemas/rotate: _always schemas/rename/public.$(version) ;
|
286
|
|
287
|
### py_functions
|
288
|
|
289
|
schemas/py_functions/install: schemas/py_functions.sql _always
|
290
|
-<$< env public= $(psqlAsAdminVegbien)
|
291
|
# ignore errors if schema exists
|
292
|
|
293
|
### Others
|
294
|
|
295
|
schemas/%/install: schemas/%.sql _always
|
296
|
-<$< $(psqlNoSearchPath)
|
297
|
# ignore errors if schema exists
|
298
|
|
299
|
schemas/%/uninstall: _always
|
300
|
echo $(call rmSchemaCmd,$*)|$(psqlNoSearchPath)
|
301
|
|
302
|
# Needed on Ubuntu 12.04 (also other Linuxes?) because %/reinstall is ignored.
|
303
|
schemas/temp/reinstall: _always schemas/temp/uninstall schemas/temp/install ;
|
304
|
|
305
|
##### MySQL
|
306
|
|
307
|
mysql: _always $(call forOs,mysql) mysql_user
|
308
|
@$(done)
|
309
|
|
310
|
rm_mysql: _always rm_mysql_user ;
|
311
|
|
312
|
mysql-Linux: _always
|
313
|
@echo $(emph)"If asked for MySQL root password, enter $(bienPassword)"$(endEmph)
|
314
|
@$(wait)
|
315
|
-sudo apt-get --yes install mysql-server mysql-client python-mysqldb
|
316
|
|
317
|
mysql-Darwin: _always
|
318
|
@echo $(emph)'Installing MySQLdb Python driver on Mac OS X 10.7 (may work on other versions):'$(endEmph)
|
319
|
@echo 'Download it using "latest version" link at http://sourceforge.net/projects/mysql-python/files/'
|
320
|
@echo 'Extract the archive'
|
321
|
@echo '(From http://www.rustyrazorblade.com/2011/11/installing-mysqldb-on-macos-lion/:)'
|
322
|
@echo 'Run ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib'
|
323
|
@echo 'Run ln -s /usr/local/mysql/lib /usr/local/mysql/lib/mysql'
|
324
|
@echo '(From http://blog.infoentropy.com/MySQL-python_EnvironmentError_mysql_config_not_found:)'
|
325
|
@echo 'Edit site.cfg and change the line like "mysql_config = " to "mysql_config = /usr/local/mysql/bin/mysql_config"'
|
326
|
@echo '(From http://www.mangoorange.com/2008/08/01/installing-python-mysqldb-122-on-mac-os-x/:)'
|
327
|
@echo 'Change to the directory of the extracted files'
|
328
|
@echo 'Run python setup.py clean'
|
329
|
@echo 'Run python setup.py build'
|
330
|
@echo 'Run sudo python setup.py install'
|
331
|
@echo "Run python -c 'import MySQLdb'"
|
332
|
@$(wait)
|
333
|
|
334
|
mysql-: _always # other OSes
|
335
|
|
336
|
mysqlAsRoot := mysql --user=root --password='$(bienPassword)'
|
337
|
|
338
|
mysql_user: _always
|
339
|
-$($@_cmd)
|
340
|
# ignore errors if user exists
|
341
|
mysql_user_cmd = echo "CREATE USER 'bien'@'localhost' IDENTIFIED BY \
|
342
|
'$(bienPassword)';"|$(mysqlAsRoot)
|
343
|
|
344
|
rm_mysql_user: _always
|
345
|
-echo "DROP USER 'bien'@'localhost';"|$(mysqlAsRoot)
|
346
|
# ignore errors if user exists
|
347
|
|
348
|
##### Datasources
|
349
|
|
350
|
inputs: _always inputs/all ;
|
351
|
|
352
|
inputs/install: _always
|
353
|
echo '. bin/reinstall_all; wait'|bash -s
|
354
|
|
355
|
import: _always import-msg inputs/import ;
|
356
|
import-msg: _always
|
357
|
@echo $(emph)"To import all inputs at once:"$(endEmph) . bin/import_all
|
358
|
@echo
|
359
|
|
360
|
verify: _always inputs/verify
|
361
|
@$(done)
|
362
|
|
363
|
test: _always inputs/test
|
364
|
@$(done)
|
365
|
|
366
|
##### Testing
|
367
|
|
368
|
test-all: _always remake test missing_mappings
|
369
|
@$(done)
|
370
|
|
371
|
##### Subdir forwarding
|
372
|
|
373
|
# Must come last so overridden targets are not forwarded
|
374
|
|
375
|
define subdirTargets
|
376
|
$(subdir): _always
|
377
|
+$$(subMake)
|
378
|
|
379
|
$(subdir)%: _always
|
380
|
+$$(subMake)
|
381
|
.PRECIOUS: $(subdir)% # let subdir's Makefile decide whether to delete on error
|
382
|
|
383
|
$(subdir)reinstall: _always $(subdir)uninstall $(subdir)install ;
|
384
|
endef
|
385
|
$(foreach subdir,$(wildcard */),$(eval $(subdirTargets)))
|
386
|
|
387
|
Makefile: ;
|
388
|
|
389
|
%: $(addsuffix %,$(dir $(shell echo */Makefile))) _always ;
|
390
|
|
391
|
#### Maps validation
|
392
|
|
393
|
termsSubdirs := $(call no/,$(call wildcard/,inputs/*/))
|
394
|
|
395
|
include lib/mappings.Makefile
|