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
ifneq ($(filter _with_db_%,$(MAKECMDGOALS)),)
31
include util/vegbien_dest
32
endif
33

    
34
with_db = $(MAKE) _with_db_$@
35

    
36
#####
37

    
38
install: _not_file core inputs test
39
	@$(done)
40

    
41
uninstall: _not_file rm_inputs rm_core
42

    
43
reinstall: _not_file uninstall install
44

    
45
#####
46

    
47
core: _not_file $(call forOs,postgres) postgres_user db
48
	@$(done)
49

    
50
rm_core: _not_file rm_db rm_postgres_user
51

    
52
reinstall_core: _not_file rm_core core
53

    
54
postgres-Linux: _not_file
55
	-sudo apt-get install python-dev libpq-dev
56
	-sudo apt-get install python-pip && sudo pip install psycopg2
57

    
58
postgres-Darwin: _not_file # TODO: implement this
59

    
60
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
mysql-Linux: _not_file
103
	$(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
	@$(wait)
108
	-sudo apt-get install mysql-server mysql-client python-mysqldb
109

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

    
127
mysql-: _not_file # other OSes
128

    
129
mysqlAsAdmin = mysql --user=root --password='$(out_password)'
130

    
131
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

    
140
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

    
147
#####
148

    
149
test: _not_file test-map
150
	@$(done)
151

    
152
test-%: _not_file
153
	./test/$(*F)
(1-1/3)