Project

General

Profile

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