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
|
$(out_cmd)
|
80
|
.PRECIOUS: %.out
|
81
|
out_cmd = $(psqlAsBien) --no-align --field-separator=' ' --pset=footer=off \
|
82
|
--pset=null=NULL <$< >$@
|
83
|
|
84
|
#####
|
85
|
|
86
|
test: _always $(addprefix test-,$(tables)) ;
|
87
|
|
88
|
test-%: test.%.out _always
|
89
|
$(DIFF) $(<:.out=.ref) $<
|
90
|
|
91
|
accept-%: _always
|
92
|
$(CP) $* $(*:.out=.ref)
|
93
|
|
94
|
#####
|
95
|
|
96
|
ifdef db
|
97
|
|
98
|
mapEnv := in_engine=$(dbEngine) in_database=$(db)
|
99
|
|
100
|
####
|
101
|
|
102
|
ifeq ($(dbEngine),MySQL)
|
103
|
|
104
|
bienPassword := $(shell cat $(root)/config/bien_password)
|
105
|
mysqlAs = mysql --user=$(1) --password='$(bienPassword)'
|
106
|
mysqlAsRoot := $(call mysqlAs,root)
|
107
|
mysqlAsBien := $(call mysqlAs,bien)
|
108
|
|
109
|
import-%: map.VegBIEN.%.csv _always
|
110
|
-$(import_cmd)
|
111
|
import_cmd = (set -x; "time" env commit=1 $(map) $<) \
|
112
|
$(if $(n),,>>$(log)) 2>&1$(if $(n),|tee -a $(log))
|
113
|
|
114
|
%.ref: %.ref.sql
|
115
|
$(mysqlAsBien) $(db) <$< >$@
|
116
|
.PRECIOUS: %.ref
|
117
|
|
118
|
###
|
119
|
|
120
|
install: _always db ;
|
121
|
|
122
|
uninstall: _always rm_db ;
|
123
|
|
124
|
db: src.$(db).sql _always
|
125
|
-$(mysqlAsRoot) <$<
|
126
|
echo "GRANT SELECT ON $(db).* TO 'bien'@'localhost';"|$(mysqlAsRoot)
|
127
|
# ignore errors in db import so that GRANT will still be run
|
128
|
|
129
|
rm_db: _always
|
130
|
-echo "REVOKE ALL ON $(db).* FROM 'bien'@'localhost';"|$(mysqlAsRoot)
|
131
|
echo "DROP DATABASE IF EXISTS $(db);"|$(mysqlAsRoot)
|
132
|
# ignore errors if grant not defined
|
133
|
|
134
|
###
|
135
|
|
136
|
else
|
137
|
$(error dbEngine variable must be one of the following: MySQL, PostgreSQL)
|
138
|
endif
|
139
|
|
140
|
####
|
141
|
|
142
|
test.%.out: map.VegBIEN.%.csv _always
|
143
|
env test=1 n=$(test_n) $(map) $< >$@ 2>&1 || { e=$$?; cat $@; exit $$e;}
|
144
|
.PRECIOUS: test.%.out
|
145
|
|
146
|
#####
|
147
|
|
148
|
else
|
149
|
$(error db variable must be set)
|
150
|
endif
|
151
|
|
152
|
#####
|
153
|
|
154
|
# Must come after mapEnv is set
|
155
|
map := env $(mapEnv) out_database=vegbien $(root)/map
|