Project

General

Profile

1 256 aaronmk
selfDir_3d1bc249 := $(dir $(lastword $(MAKEFILE_LIST)))
2 250 aaronmk
3 264 aaronmk
vegxMaps := $(wildcard map.VegX.*.csv)
4
vegbienMaps := $(subst .VegX.,.VegBIEN.,$(vegxMaps))
5 247 aaronmk
6 264 aaronmk
root := ../..
7
scripts := $(root)/scripts
8
util := $(scripts)/util
9
mappings := $(root)/mappings
10
map := $(scripts)/bien_map
11
map2vegbien := env out_database=vegbien $(map)
12
13 250 aaronmk
#####
14
15 256 aaronmk
all: _not_file # empty rule since must be first target in file
16 247 aaronmk
17
.SUFFIXES:
18
19
_not_file:
20
.PHONY: _not_file
21 250 aaronmk
22 264 aaronmk
all := $(wildcard output.*) $(vegbienMaps)
23 256 aaronmk
24
clean: _not_file
25
	$(RM) $(all)
26
27 250 aaronmk
#####
28
29 264 aaronmk
reinstall: _not_file uninstall install
30
31
#####
32
33
map.VegBIEN.%.csv: map.VegX.%.csv
34
	$(util)/join_sort <$< $(mappings)/VegX-VegBIEN.$(*F).csv >$@
35
.PRECIOUS: map.VegBIEN.%.csv
36
37
#####
38
39 256 aaronmk
ifdef db
40
41 260 aaronmk
ifndef dbEngine
42
$(error dbEngine variable must be set. Possible values: MySQL, PostgreSQL)
43
endif
44
45 264 aaronmk
mapEnv := in_engine=$(dbEngine) in_database=$(db)
46 256 aaronmk
47 264 aaronmk
all: _not_file $(vegbienMaps:%=from_db-%)
48 256 aaronmk
49 264 aaronmk
from_db-%: % _not_file
50
	env $(mapEnv) $(map2vegbien) $<
51 256 aaronmk
52 264 aaronmk
##
53 256 aaronmk
54
install: _not_file all db
55
56
uninstall: _not_file rm_db clean
57
58 264 aaronmk
bienPassword := $(shell cat $(util)/bien_password)
59
mysql := mysql --user=root --password='$(bienPassword)'
60
61 256 aaronmk
db: $(db).sql _not_file
62 255 aaronmk
	-$(mysql) <$<
63
	echo "GRANT SELECT ON $(db).* TO 'bien'@'localhost';"|$(mysql)
64
# ignore errors in db import so that GRANT will still be run
65 250 aaronmk
66 256 aaronmk
rm_db: _not_file
67 255 aaronmk
	-echo "REVOKE ALL ON $(db).* FROM 'bien'@'localhost';"|$(mysql)
68 250 aaronmk
	echo "DROP DATABASE IF EXISTS $(db);"|$(mysql)
69 255 aaronmk
# ignore errors about no such grant being defined
70 250 aaronmk
71 256 aaronmk
#####
72
73
else
74
$(error db variable must be set)
75
endif