Project

General

Profile

« Previous | Next » 

Revision 241

scripts/Makefile: Added inputs

View differences:

Makefile
1
# Terminal
1 2
esc = '['
2 3
reset = $(esc)'0m'
3
highlight = $(esc)'7m'
4
wait = read -p $(highlight)'Press ENTER to continue:'$(reset) REPLY
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
5 8

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

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

  
11
psqlOpts = --set ON_ERROR_STOP=1 --quiet
12
asAdmin = sudo -u postgres
13
psqlAdmin = $(asAdmin) psql $(psqlOpts)
14
psqlDbUser = ./util/psql_vegbien $(psqlOpts)
16
#####
15 17

  
16

  
17 18
all: _not_file install
18 19

  
19 20
.SUFFIXES:
......
21 22
_not_file:
22 23
.PHONY: _not_file
23 24

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

  
25
ifneq ($(filter _user _mysql-Linux,$(MAKECMDGOALS)),)
28
#####
29

  
30
ifneq ($(filter _with_db_%,$(MAKECMDGOALS)),)
26 31
include util/vegbien_dest
27 32
endif
28 33

  
34
with_db = $(MAKE) _with_db_$@
29 35

  
30
install: _not_file deps user db
36
#####
31 37

  
32
uninstall: _not_file rm_db rm_user
38
install: _not_file core inputs test
39
	@$(done)
33 40

  
41
uninstall: _not_file rm_inputs rm_core
42

  
34 43
reinstall: _not_file uninstall install
35 44

  
45
#####
36 46

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

  
50
rm_core: _not_file rm_db rm_postgres_user
51

  
52
reinstall_core: _not_file rm_core core
53

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

  
43
postgres-Darwin: _not_file
58
postgres-Darwin: _not_file # TODO: implement this
44 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

  
45 102
mysql-Linux: _not_file
46
	$(MAKE) _$@
47
_mysql-Linux: _not_file
48
	@echo $(highlight)"At prompt for MySQL root password, enter $(out_password)"$(reset)
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)
49 107
	@$(wait)
50 108
	-sudo apt-get install mysql-server mysql-client python-mysqldb
51 109

  
52 110
mysql-Darwin: _not_file
53
	@echo $(highlight)'Installing MySQLdb Python driver on Mac OS X 10.7 (may work on other versions):'$(reset)
111
	@echo $(emph)'Installing MySQLdb Python driver on Mac OS X 10.7 (may work on other versions):'$(end_emph)
54 112
	@echo 'Download it using "latest version" link at http://sourceforge.net/projects/mysql-python/files/'
55 113
	@echo 'Extract the archive'
56 114
	@echo '(From http://www.rustyrazorblade.com/2011/11/installing-mysqldb-on-macos-lion/:)'
......
66 124
	@echo "Run python -c 'import MySQLdb'"
67 125
	@$(wait)
68 126

  
69
# Catch-alls for other OSes
70
mysql-:
71
postgres-:
127
mysql-: _not_file # other OSes
72 128

  
73
reinstall_db: _not_file rm_db db
129
mysqlAsAdmin = mysql --user=root --password='$(out_password)'
74 130

  
75
empty_db: _not_file
76
	$(psqlDbUser) <../mappings/schemas/vegbien_empty.sql
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)
77 139

  
78
user: _not_file
79
	$(MAKE) _$@
80
_user: _not_file
81
	@echo $(highlight)"At sudo password prompt, enter *your* password"$(reset)
82
	@sudo -v
83
	@echo $(highlight)"At prompt \"Enter password for new role:\", enter $(out_password)"$(reset)
84
	-$(_user_cmd)
85
# ignore errors about existing user
86
_user_cmd = $(asAdmin) createuser --no-superuser --no-createdb --no-createrole \
87
--pwprompt "$(out_user)"
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
88 146

  
89
rm_user: _not_file
90
	echo "DROP USER bien;"|$(psqlAdmin)
147
#####
91 148

  
92
db: _not_file
93
	$(psqlAdmin) <../mappings/schemas/vegbien.sql
149
test: _not_file test-map
150
	@$(done)
94 151

  
95
rm_db: _not_file
96
	echo "DROP DATABASE vegbien;"|$(psqlAdmin)
97

  
98

  
99
test: test-map
100

  
101 152
test-%: _not_file
102 153
	./test/$(*F)

Also available in: Unified diff