1
|
esc = '['
|
2
|
reset = $(esc)'0m'
|
3
|
highlight = $(esc)'7m'
|
4
|
wait = read -p $(highlight)'Press ENTER to continue:'$(reset) REPLY
|
5
|
|
6
|
os = $(shell uname)
|
7
|
forOs = $(patsubst %,%-$(filter Linux Darwin,$(os)),$(1))
|
8
|
|
9
|
export PGOPTIONS = --client-min-messages=WARNING
|
10
|
|
11
|
psqlOpts = --set ON_ERROR_STOP=1 --quiet
|
12
|
asAdmin = sudo -u postgres
|
13
|
psqlAdmin = $(asAdmin) psql $(psqlOpts)
|
14
|
psqlDbUser = ./util/psql_vegbien $(psqlOpts)
|
15
|
|
16
|
|
17
|
all: _not_file install
|
18
|
|
19
|
.SUFFIXES:
|
20
|
|
21
|
_not_file:
|
22
|
.PHONY: _not_file
|
23
|
|
24
|
|
25
|
ifneq ($(filter _user _mysql-Linux,$(MAKECMDGOALS)),)
|
26
|
include util/vegbien_dest
|
27
|
endif
|
28
|
|
29
|
|
30
|
install: _not_file deps user db
|
31
|
|
32
|
uninstall: _not_file rm_db rm_user
|
33
|
|
34
|
reinstall: _not_file uninstall install
|
35
|
|
36
|
|
37
|
deps: _not_file $(call forOs,postgres mysql)
|
38
|
|
39
|
postgres-Linux: _not_file
|
40
|
-sudo apt-get install python-dev libpq-dev
|
41
|
-sudo apt-get install python-pip && sudo pip install psycopg2
|
42
|
|
43
|
postgres-Darwin: _not_file
|
44
|
|
45
|
mysql-Linux: _not_file
|
46
|
$(MAKE) _$@
|
47
|
_mysql-Linux: _not_file
|
48
|
@echo $(highlight)"At prompt for MySQL root password, enter $(out_password)"$(reset)
|
49
|
@$(wait)
|
50
|
-sudo apt-get install mysql-server mysql-client python-mysqldb
|
51
|
|
52
|
mysql-Darwin: _not_file
|
53
|
@echo $(highlight)'Installing MySQLdb Python driver on Mac OS X 10.7 (may work on other versions):'$(reset)
|
54
|
@echo 'Download it using "latest version" link at http://sourceforge.net/projects/mysql-python/files/'
|
55
|
@echo 'Extract the archive'
|
56
|
@echo '(From http://www.rustyrazorblade.com/2011/11/installing-mysqldb-on-macos-lion/:)'
|
57
|
@echo 'Run sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib'
|
58
|
@echo 'Run sudo ln -s /usr/local/mysql/lib /usr/local/mysql/lib/mysql'
|
59
|
@echo '(From http://blog.infoentropy.com/MySQL-python_EnvironmentError_mysql_config_not_found:)'
|
60
|
@echo 'Edit site.cfg and change the line like "mysql_config = " to "mysql_config = /usr/local/mysql/bin/mysql_config"'
|
61
|
@echo '(From http://www.mangoorange.com/2008/08/01/installing-python-mysqldb-122-on-mac-os-x/:)'
|
62
|
@echo 'Change to the directory of the extracted files'
|
63
|
@echo 'Run sudo python setup.py clean'
|
64
|
@echo 'Run sudo python setup.py build'
|
65
|
@echo 'Run sudo python setup.py install'
|
66
|
@echo "Run python -c 'import MySQLdb'"
|
67
|
@$(wait)
|
68
|
|
69
|
# Catch-alls for other OSes
|
70
|
mysql-:
|
71
|
postgres-:
|
72
|
|
73
|
reinstall_db: _not_file rm_db db
|
74
|
|
75
|
empty_db: _not_file
|
76
|
$(psqlDbUser) <../mappings/schemas/vegbien_empty.sql
|
77
|
|
78
|
user: _not_file
|
79
|
$(MAKE) _$@
|
80
|
_user: _not_file
|
81
|
@echo $(highlight)"At sudo password prompt, enter *your* password"$(reset)
|
82
|
@sudo -v
|
83
|
@echo $(highlight)"At prompt \"Enter password for new role:\", enter $(out_password)"$(reset)
|
84
|
-$(_user_cmd)
|
85
|
# ignore errors about existing user
|
86
|
_user_cmd = $(asAdmin) createuser --no-superuser --no-createdb --no-createrole \
|
87
|
--pwprompt "$(out_user)"
|
88
|
|
89
|
rm_user: _not_file
|
90
|
echo "DROP USER bien;"|$(psqlAdmin)
|
91
|
|
92
|
db: _not_file
|
93
|
$(psqlAdmin) <../mappings/schemas/vegbien.sql
|
94
|
|
95
|
rm_db: _not_file
|
96
|
echo "DROP DATABASE vegbien;"|$(psqlAdmin)
|
97
|
|
98
|
|
99
|
test: test-map
|
100
|
|
101
|
test-%: _not_file
|
102
|
./test/$(*F)
|