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