Project

General

Profile

1
selfDir_3d1bc249 := $(dir $(lastword $(MAKEFILE_LIST)))
2

    
3
vegxMaps := $(wildcard map.VegX.*.csv)
4
vegbienMaps := $(subst .VegX.,.VegBIEN.,$(vegxMaps))
5

    
6
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
#####
14

    
15
all: _not_file # empty rule since must be first target in file
16

    
17
.SUFFIXES:
18

    
19
_not_file:
20
.PHONY: _not_file
21

    
22
all := $(wildcard output.*) $(vegbienMaps)
23

    
24
clean: _not_file
25
	$(RM) $(all)
26

    
27
#####
28

    
29
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
ifdef db
40

    
41
ifndef dbEngine
42
$(error dbEngine variable must be set. Possible values: MySQL, PostgreSQL)
43
endif
44

    
45
mapEnv := in_engine=$(dbEngine) in_database=$(db)
46

    
47
all: _not_file $(vegbienMaps:%=from_db-%)
48

    
49
from_db-%: % _not_file
50
	env $(mapEnv) $(map2vegbien) $<
51

    
52
##
53

    
54
install: _not_file all db
55

    
56
uninstall: _not_file rm_db clean
57

    
58
bienPassword := $(shell cat $(util)/bien_password)
59
mysql := mysql --user=root --password='$(bienPassword)'
60

    
61
db: $(db).sql _not_file
62
	-$(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

    
66
rm_db: _not_file
67
	-echo "REVOKE ALL ON $(db).* FROM 'bien'@'localhost';"|$(mysql)
68
	echo "DROP DATABASE IF EXISTS $(db);"|$(mysql)
69
# ignore errors about no such grant being defined
70

    
71
#####
72

    
73
else
74
$(error db variable must be set)
75
endif
(5-5/17)