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