Project

General

Profile

1 241 aaronmk
# Terminal
2 236 aaronmk
esc = '['
3 235 aaronmk
reset = $(esc)'0m'
4 241 aaronmk
emph = $(esc)'7m '
5
end_emph = ' '$(reset)
6
wait = read -p $(emph)'Press ENTER to continue:'$(end_emph) REPLY
7
done = echo; echo $(emph)"Finished $@"$(end_emph); echo
8 235 aaronmk
9 241 aaronmk
# OS
10 235 aaronmk
os = $(shell uname)
11
forOs = $(patsubst %,%-$(filter Linux Darwin,$(os)),$(1))
12
13 241 aaronmk
# Env
14 225 aaronmk
export PGOPTIONS = --client-min-messages=WARNING
15
16 241 aaronmk
#####
17 225 aaronmk
18 235 aaronmk
all: _not_file install
19 228 aaronmk
20 225 aaronmk
.SUFFIXES:
21
22 235 aaronmk
_not_file:
23
.PHONY: _not_file
24 202 aaronmk
25 241 aaronmk
%/: _not_file
26
	$(if $(wildcard $@/Makefile*),$(MAKE) --directory=$@,)
27 202 aaronmk
28 241 aaronmk
#####
29
30
with_db = $(MAKE) _with_db_$@
31 238 aaronmk
32 241 aaronmk
#####
33 202 aaronmk
34 241 aaronmk
install: _not_file core inputs test
35
	@$(done)
36 202 aaronmk
37 241 aaronmk
uninstall: _not_file rm_inputs rm_core
38
39 235 aaronmk
reinstall: _not_file uninstall install
40 225 aaronmk
41 241 aaronmk
#####
42 202 aaronmk
43 241 aaronmk
core: _not_file $(call forOs,postgres) postgres_user db
44
	@$(done)
45 235 aaronmk
46 241 aaronmk
rm_core: _not_file rm_db rm_postgres_user
47
48
reinstall_core: _not_file rm_core core
49
50 235 aaronmk
postgres-Linux: _not_file
51 237 aaronmk
	-sudo apt-get install python-dev libpq-dev
52
	-sudo apt-get install python-pip && sudo pip install psycopg2
53 235 aaronmk
54 241 aaronmk
postgres-Darwin: _not_file # TODO: implement this
55 235 aaronmk
56 241 aaronmk
postgres-: _not_file # other OSes
57
58
psqlOpts = --set ON_ERROR_STOP=1 --quiet
59
asPostgresAdmin = sudo -u postgres
60
psqlAsAdmin = $(asPostgresAdmin) psql $(psqlOpts)
61
psqlAsDbUser = ./util/psql_vegbien $(psqlOpts)
62 243 aaronmk
bienPassword = $(shell cat util/bien_password)
63 241 aaronmk
64
postgres_user: _not_file
65
	$(with_db)
66
# sub-make will include vegbien_dest
67
_with_db_postgres_user: _not_file
68
	@echo $(emph)"At sudo password prompt, enter *your* password"$(end_emph)
69
	@sudo -v
70 243 aaronmk
	@echo $(emph)"At \"Enter password for new role:\", enter $(bienPassword)"$(end_emph)
71 241 aaronmk
	-$($@_cmd)
72
# ignore errors about user existing
73
_with_db_postgres_user_cmd = $(asPostgresAdmin) createuser --no-superuser \
74 243 aaronmk
--no-createdb --no-createrole --pwprompt "bien"
75 241 aaronmk
76
rm_postgres_user: _not_file
77
	echo "DROP USER IF EXISTS bien;"|$(psqlAsAdmin)
78
79
#####
80
81
db: _not_file
82
	$(psqlAsAdmin) <../mappings/schemas/vegbien.sql
83
84
rm_db: _not_file
85
	echo "DROP DATABASE IF EXISTS vegbien;"|$(psqlAsAdmin)
86
87
reinstall_db: _not_file rm_db db
88
89
empty_db: _not_file
90
	$(psqlAsDbUser) <../mappings/schemas/vegbien_empty.sql
91
92
#####
93
94
inputs: _not_file $(call forOs,mysql) mysql_user $(wildcard ../../inputs/*/)
95
	@$(done)
96
97
rm_inputs: _not_file rm_mysql_user
98
99 235 aaronmk
mysql-Linux: _not_file
100 241 aaronmk
	$(with_db)
101
# sub-make will include vegbien_dest
102
_with_db_mysql-Linux: _not_file
103 243 aaronmk
	@echo $(emph)"At prompt for MySQL root password, enter $(bienPassword)"$(end_emph)
104 238 aaronmk
	@$(wait)
105 237 aaronmk
	-sudo apt-get install mysql-server mysql-client python-mysqldb
106 235 aaronmk
107
mysql-Darwin: _not_file
108 241 aaronmk
	@echo $(emph)'Installing MySQLdb Python driver on Mac OS X 10.7 (may work on other versions):'$(end_emph)
109 235 aaronmk
	@echo 'Download it using "latest version" link at http://sourceforge.net/projects/mysql-python/files/'
110
	@echo 'Extract the archive'
111
	@echo '(From http://www.rustyrazorblade.com/2011/11/installing-mysqldb-on-macos-lion/:)'
112
	@echo 'Run sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib'
113
	@echo 'Run sudo ln -s /usr/local/mysql/lib /usr/local/mysql/lib/mysql'
114
	@echo '(From http://blog.infoentropy.com/MySQL-python_EnvironmentError_mysql_config_not_found:)'
115
	@echo 'Edit site.cfg and change the line like "mysql_config = " to "mysql_config = /usr/local/mysql/bin/mysql_config"'
116
	@echo '(From http://www.mangoorange.com/2008/08/01/installing-python-mysqldb-122-on-mac-os-x/:)'
117
	@echo 'Change to the directory of the extracted files'
118
	@echo 'Run sudo python setup.py clean'
119
	@echo 'Run sudo python setup.py build'
120
	@echo 'Run sudo python setup.py install'
121
	@echo "Run python -c 'import MySQLdb'"
122 238 aaronmk
	@$(wait)
123 235 aaronmk
124 241 aaronmk
mysql-: _not_file # other OSes
125 235 aaronmk
126 243 aaronmk
mysqlAsAdmin = mysql --user=root --password='$(bienPassword)'
127 235 aaronmk
128 241 aaronmk
mysql_user: _not_file
129
	$(with_db)
130
# sub-make will include vegbien_dest
131
_with_db_mysql_user: _not_file
132
	-$($@_cmd)
133
# ignore errors about user existing
134 243 aaronmk
_with_db_mysql_user_cmd = echo "CREATE USER 'bien'@'localhost' \
135
IDENTIFIED BY '$(bienPassword)';"|$(mysqlAsAdmin)
136 202 aaronmk
137 241 aaronmk
rm_mysql_user: _not_file
138
	$(with_db)
139
# sub-make will include vegbien_dest
140
_with_db_rm_mysql_user: _not_file
141
	-echo "DROP USER 'bien'@'localhost';"|$(mysqlAsAdmin)
142
# ignore errors about user not existing
143 202 aaronmk
144 241 aaronmk
#####
145 202 aaronmk
146 241 aaronmk
test: _not_file test-map
147
	@$(done)
148 202 aaronmk
149 235 aaronmk
test-%: _not_file
150 176 aaronmk
	./test/$(*F)