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