Project

General

Profile

1
# Terminal
2
esc = '['
3
reset = $(esc)'0m'
4
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

    
9
# OS
10
os = $(shell uname)
11
forOs = $(patsubst %,%-$(filter Linux Darwin,$(os)),$(1))
12

    
13
# Env
14
export PGOPTIONS = --client-min-messages=WARNING
15

    
16
#####
17

    
18
all: _not_file install
19

    
20
.SUFFIXES:
21

    
22
_not_file:
23
.PHONY: _not_file
24

    
25
%/: _not_file
26
	$(if $(wildcard $@/Makefile*),$(MAKE) --directory=$@,)
27

    
28
#####
29

    
30
with_db = $(MAKE) _with_db_$@
31

    
32
#####
33

    
34
install: _not_file core inputs test
35
	@$(done)
36

    
37
uninstall: _not_file rm_inputs rm_core
38

    
39
reinstall: _not_file uninstall install
40

    
41
#####
42

    
43
core: _not_file $(call forOs,postgres) postgres_user db
44
	@$(done)
45

    
46
rm_core: _not_file rm_db rm_postgres_user
47

    
48
reinstall_core: _not_file rm_core core
49

    
50
postgres-Linux: _not_file
51
	-sudo apt-get install python-dev libpq-dev
52
	-sudo apt-get install python-pip && sudo pip install psycopg2
53

    
54
postgres-Darwin: _not_file # TODO: implement this
55

    
56
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
bienPassword = $(shell cat util/bien_password)
63

    
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
	@echo $(emph)"At \"Enter password for new role:\", enter $(bienPassword)"$(end_emph)
71
	-$($@_cmd)
72
# ignore errors about user existing
73
_with_db_postgres_user_cmd = $(asPostgresAdmin) createuser --no-superuser \
74
--no-createdb --no-createrole --pwprompt "bien"
75

    
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
mysql-Linux: _not_file
100
	$(with_db)
101
# sub-make will include vegbien_dest
102
_with_db_mysql-Linux: _not_file
103
	@echo $(emph)"At prompt for MySQL root password, enter $(bienPassword)"$(end_emph)
104
	@$(wait)
105
	-sudo apt-get install mysql-server mysql-client python-mysqldb
106

    
107
mysql-Darwin: _not_file
108
	@echo $(emph)'Installing MySQLdb Python driver on Mac OS X 10.7 (may work on other versions):'$(end_emph)
109
	@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
	@$(wait)
123

    
124
mysql-: _not_file # other OSes
125

    
126
mysqlAsAdmin = mysql --user=root --password='$(bienPassword)'
127

    
128
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
_with_db_mysql_user_cmd = echo "CREATE USER 'bien'@'localhost' \
135
IDENTIFIED BY '$(bienPassword)';"|$(mysqlAsAdmin)
136

    
137
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

    
144
#####
145

    
146
test: _not_file test-map
147
	@$(done)
148

    
149
test-%: _not_file
150
	./test/$(*F)
(1-1/3)