1
|
selfDir_3d1bc249 := $(dir $(lastword $(MAKEFILE_LIST)))
|
2
|
|
3
|
# Make
|
4
|
subMake = $(MAKE) $(@F) --directory=$(@D)
|
5
|
+_ = $(+:_%=)
|
6
|
addBeforeExt = $(basename $(2))$(1)$(suffix $(2))
|
7
|
|
8
|
# Commands
|
9
|
CP = cp -p
|
10
|
DIFF = diff --unified=2
|
11
|
|
12
|
tablesSort := plots organisms stems
|
13
|
vegxMaps := $(wildcard $(tablesSort:%=map.VegX.%.csv))
|
14
|
tables := $(vegxMaps:map.VegX.%.csv=%)
|
15
|
vegbienMaps := $(subst .VegX.,.VegBIEN.,$(vegxMaps))
|
16
|
|
17
|
root := $(selfDir_3d1bc249)..
|
18
|
psqlAsBien := $(root)/bin/psql_vegbien
|
19
|
|
20
|
# Config
|
21
|
test_n ?= 2
|
22
|
|
23
|
#####
|
24
|
|
25
|
all: _always maps ;
|
26
|
|
27
|
.SUFFIXES:
|
28
|
|
29
|
_always:
|
30
|
.PHONY: _always
|
31
|
|
32
|
clean: _always
|
33
|
$(RM) $(all)
|
34
|
|
35
|
remake: _always clean all ;
|
36
|
|
37
|
%.out: % _always
|
38
|
./$* >$@
|
39
|
.PRECIOUS: %.out
|
40
|
|
41
|
all += $(wildcard *.out)
|
42
|
|
43
|
$(root)/%: _always
|
44
|
+$(subMake)
|
45
|
|
46
|
#####
|
47
|
|
48
|
reinstall: _always uninstall install ;
|
49
|
|
50
|
#####
|
51
|
|
52
|
maps: $(vegbienMaps) _always ;
|
53
|
|
54
|
all += $(vegbienMaps)
|
55
|
|
56
|
map.VegBIEN.%.csv: map.VegX.%.csv $(root)/mappings/VegX-VegBIEN.%.csv
|
57
|
$(root)/bin/join_sort <$+ >$@
|
58
|
.PRECIOUS: map.VegBIEN.%.csv
|
59
|
|
60
|
#####
|
61
|
|
62
|
import: _always $(addprefix import-,$(tables)) verify ;
|
63
|
|
64
|
log = $*$(if $(n),.n=$(n),).log
|
65
|
|
66
|
logs := $(wildcard *.log)
|
67
|
|
68
|
rm_logs: _always
|
69
|
$(RM) $(logs)
|
70
|
|
71
|
#####
|
72
|
|
73
|
verify: _always $(addprefix verify-,$(tables)) ;
|
74
|
|
75
|
verify-%: verify.%.ref verify.%.out _always
|
76
|
$(DIFF) $(+_)
|
77
|
|
78
|
%.out: %.sql _always
|
79
|
$(psqlAsBien) --no-align --field-separator=' ' --pset=footer=off <$< >$@
|
80
|
.PRECIOUS: %.out
|
81
|
|
82
|
#####
|
83
|
|
84
|
test: _always $(addprefix test-,$(tables)) ;
|
85
|
|
86
|
test-%: test.%.out _always
|
87
|
$(DIFF) $(<:.out=.ref) $<
|
88
|
|
89
|
accept-%: _always
|
90
|
$(CP) $* $(*:.out=.ref)
|
91
|
|
92
|
#####
|
93
|
|
94
|
ifdef db
|
95
|
|
96
|
mapEnv := in_engine=$(dbEngine) in_database=$(db)
|
97
|
|
98
|
####
|
99
|
|
100
|
ifeq ($(dbEngine),MySQL)
|
101
|
|
102
|
bienPassword := $(shell cat $(root)/config/bien_password)
|
103
|
mysqlAs = mysql --user=$(1) --password='$(bienPassword)'
|
104
|
mysqlAsRoot := $(call mysqlAs,root)
|
105
|
mysqlAsBien := $(call mysqlAs,bien)
|
106
|
|
107
|
import-%: map.VegBIEN.%.csv _always
|
108
|
-$(import_cmd)
|
109
|
import_cmd = (set -x; "time" env commit=1 $(map) $<) \
|
110
|
$(if $(n),,>>$(log)) 2>&1$(if $(n),|tee -a $(log))
|
111
|
|
112
|
%.ref: %.ref.sql
|
113
|
$(mysqlAsBien) $(db) <$< >$@
|
114
|
.PRECIOUS: %.ref
|
115
|
|
116
|
###
|
117
|
|
118
|
install: _always db ;
|
119
|
|
120
|
uninstall: _always rm_db ;
|
121
|
|
122
|
db: src.$(db).sql _always
|
123
|
-$(mysqlAsRoot) <$<
|
124
|
echo "GRANT SELECT ON $(db).* TO 'bien'@'localhost';"|$(mysqlAsRoot)
|
125
|
# ignore errors in db import so that GRANT will still be run
|
126
|
|
127
|
rm_db: _always
|
128
|
-echo "REVOKE ALL ON $(db).* FROM 'bien'@'localhost';"|$(mysqlAsRoot)
|
129
|
echo "DROP DATABASE IF EXISTS $(db);"|$(mysqlAsRoot)
|
130
|
# ignore errors if grant not defined
|
131
|
|
132
|
###
|
133
|
|
134
|
else
|
135
|
$(error dbEngine variable must be one of the following: MySQL, PostgreSQL)
|
136
|
endif
|
137
|
|
138
|
####
|
139
|
|
140
|
test.%.out: map.VegBIEN.%.csv _always
|
141
|
env test=1 n=$(test_n) $(map) $< >$@ 2>&1 || { e=$$?; cat $@; exit $$e;}
|
142
|
.PRECIOUS: test.%.out
|
143
|
|
144
|
#####
|
145
|
|
146
|
else
|
147
|
$(error db variable must be set)
|
148
|
endif
|
149
|
|
150
|
#####
|
151
|
|
152
|
# Must come after mapEnv is set
|
153
|
map := env $(mapEnv) out_database=vegbien $(root)/map
|