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