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
map := env out_database=vegbien $(root)/map
8

    
9
#####
10

    
11
all: _not_file # empty rule since must be first target in file
12

    
13
.SUFFIXES:
14

    
15
_not_file:
16
.PHONY: _not_file
17

    
18
all := $(wildcard output.*) $(vegbienMaps)
19

    
20
clean: _not_file
21
	$(RM) $(all)
22

    
23
#####
24

    
25
reinstall: _not_file uninstall install
26

    
27
#####
28

    
29
map.VegBIEN.%.csv: map.VegX.%.csv
30
	$(root)/bin/join_sort <$< $(root)/mappings/VegX-VegBIEN.$(*F).csv >$@
31
.PRECIOUS: map.VegBIEN.%.csv
32

    
33
logs := $(wildcard *.log)
34

    
35
rm_logs: _not_file
36
	$(RM) $(logs)
37

    
38
#####
39

    
40
ifdef db
41

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

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

    
48
all: _not_file $(vegbienMaps:map.VegBIEN.%.csv=import-%)
49

    
50
log = $*$(if $(n),.n=$(n),).log
51

    
52
import-%: map.VegBIEN.%.csv _not_file
53
	(set -x; time env commit=1 $(mapEnv) $(map) $<) 2>&1 | tee -a $(log)
54

    
55
##
56

    
57
install: _not_file db
58

    
59
uninstall: _not_file rm_db
60

    
61
bienPassword := $(shell cat $(root)/config/bien_password)
62
mysql := mysql --user=root --password='$(bienPassword)'
63

    
64
db: $(db).sql _not_file
65
	-$(mysql) <$<
66
	echo "GRANT SELECT ON $(db).* TO 'bien'@'localhost';"|$(mysql)
67
# ignore errors in db import so that GRANT will still be run
68

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

    
74
#####
75

    
76
else
77
$(error db variable must be set)
78
endif
    (1-1/1)