Project

General

Profile

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