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