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