Project

General

Profile

1 236 aaronmk
esc = '['
2 235 aaronmk
reset = $(esc)'0m'
3
highlight = $(esc)'7m'
4 238 aaronmk
wait = read -p $(highlight)'Press ENTER to continue:'$(reset) REPLY
5 235 aaronmk
6
os = $(shell uname)
7
forOs = $(patsubst %,%-$(filter Linux Darwin,$(os)),$(1))
8
9 225 aaronmk
export PGOPTIONS = --client-min-messages=WARNING
10
11
psqlOpts = --set ON_ERROR_STOP=1 --quiet
12 227 aaronmk
asAdmin = sudo -u postgres
13
psqlAdmin = $(asAdmin) psql $(psqlOpts)
14 225 aaronmk
psqlDbUser = ./util/psql_vegbien $(psqlOpts)
15
16 149 aaronmk
17 235 aaronmk
all: _not_file install
18 228 aaronmk
19 225 aaronmk
.SUFFIXES:
20
21 235 aaronmk
_not_file:
22
.PHONY: _not_file
23 202 aaronmk
24
25 238 aaronmk
ifneq ($(filter _user _mysql-Linux,$(MAKECMDGOALS)),)
26
include util/vegbien_dest
27
endif
28
29
30 235 aaronmk
install: _not_file deps user db
31 202 aaronmk
32 235 aaronmk
uninstall: _not_file rm_db rm_user
33 202 aaronmk
34 235 aaronmk
reinstall: _not_file uninstall install
35 225 aaronmk
36 202 aaronmk
37 235 aaronmk
deps: _not_file $(call forOs,postgres mysql)
38
39
postgres-Linux: _not_file
40 237 aaronmk
	-sudo apt-get install python-dev libpq-dev
41
	-sudo apt-get install python-pip && sudo pip install psycopg2
42 235 aaronmk
43
postgres-Darwin: _not_file
44
45
mysql-Linux: _not_file
46 238 aaronmk
	$(MAKE) _$@
47
_mysql-Linux: _not_file
48
	@echo $(highlight)"At prompt for MySQL root password, enter $(out_password)"$(reset)
49
	@$(wait)
50 237 aaronmk
	-sudo apt-get install mysql-server mysql-client python-mysqldb
51 235 aaronmk
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 238 aaronmk
	@$(wait)
68 235 aaronmk
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 225 aaronmk
	$(psqlDbUser) <../mappings/schemas/vegbien_empty.sql
77 202 aaronmk
78 235 aaronmk
user: _not_file
79 228 aaronmk
	$(MAKE) _$@
80 235 aaronmk
_user: _not_file
81
	@echo $(highlight)"At sudo password prompt, enter *your* password"$(reset)
82 227 aaronmk
	@sudo -v
83 235 aaronmk
	@echo $(highlight)"At prompt \"Enter password for new role:\", enter $(out_password)"$(reset)
84 228 aaronmk
	-$(_user_cmd)
85 202 aaronmk
# ignore errors about existing user
86 228 aaronmk
_user_cmd = $(asAdmin) createuser --no-superuser --no-createdb --no-createrole \
87
--pwprompt "$(out_user)"
88 202 aaronmk
89 235 aaronmk
rm_user: _not_file
90 225 aaronmk
	echo "DROP USER bien;"|$(psqlAdmin)
91 202 aaronmk
92 235 aaronmk
db: _not_file
93 225 aaronmk
	$(psqlAdmin) <../mappings/schemas/vegbien.sql
94 202 aaronmk
95 235 aaronmk
rm_db: _not_file
96 225 aaronmk
	echo "DROP DATABASE vegbien;"|$(psqlAdmin)
97 202 aaronmk
98
99 176 aaronmk
test: test-map
100 149 aaronmk
101 235 aaronmk
test-%: _not_file
102 176 aaronmk
	./test/$(*F)