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 |
371
|
aaronmk
|
DIFF = diff --unified=2 $(+:_%=)
|
8 |
368
|
aaronmk
|
|
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 |
369
|
aaronmk
|
verify-%: verify.%.ref verify.%.out _not_file
|
69 |
368
|
aaronmk
|
$(DIFF)
|
70 |
|
|
|
71 |
370
|
aaronmk
|
%.out: %.sql _not_file
|
72 |
371
|
aaronmk
|
$(psqlAsBien) --no-align --field-separator=' ' --pset=footer=off <$< >$@
|
73 |
370
|
aaronmk
|
.PRECIOUS: %.out
|
74 |
369
|
aaronmk
|
|
75 |
370
|
aaronmk
|
all += $(wildcard *.out)
|
76 |
368
|
aaronmk
|
|
77 |
|
|
#####
|
78 |
|
|
|
79 |
|
|
test: _not_file $(addprefix test-,$(tables))
|
80 |
|
|
|
81 |
369
|
aaronmk
|
test-%: test.%.ref test.%.out _not_file
|
82 |
368
|
aaronmk
|
$(DIFF)
|
83 |
|
|
|
84 |
369
|
aaronmk
|
all += $(filter-out %.ref,$(wildcard test.*.out))
|
85 |
368
|
aaronmk
|
|
86 |
|
|
#####
|
87 |
|
|
|
88 |
256
|
aaronmk
|
ifdef db
|
89 |
|
|
|
90 |
264
|
aaronmk
|
mapEnv := in_engine=$(dbEngine) in_database=$(db)
|
91 |
256
|
aaronmk
|
|
92 |
368
|
aaronmk
|
####
|
93 |
256
|
aaronmk
|
|
94 |
368
|
aaronmk
|
ifeq ($(dbEngine),MySQL)
|
95 |
339
|
aaronmk
|
|
96 |
368
|
aaronmk
|
bienPassword := $(shell cat $(root)/config/bien_password)
|
97 |
|
|
mysqlAs = mysql --user=$(1) --password='$(bienPassword)'
|
98 |
|
|
mysqlAsRoot := $(call mysqlAs,root)
|
99 |
|
|
mysqlAsBien := $(call mysqlAs,bien)
|
100 |
|
|
|
101 |
283
|
aaronmk
|
import-%: map.VegBIEN.%.csv _not_file
|
102 |
365
|
aaronmk
|
$(importCmd)
|
103 |
368
|
aaronmk
|
importCmd = (set -x; "time" env commit=1 $(map) $<) \
|
104 |
|
|
$(if $(n),,>>$(log)) 2>&1$(if $(n),|tee -a $(log))
|
105 |
256
|
aaronmk
|
|
106 |
369
|
aaronmk
|
%.ref: %.ref.sql
|
107 |
371
|
aaronmk
|
$(mysqlAsBien) $(db) <$< >$@
|
108 |
369
|
aaronmk
|
.PRECIOUS: %.ref
|
109 |
368
|
aaronmk
|
|
110 |
|
|
###
|
111 |
|
|
|
112 |
268
|
aaronmk
|
install: _not_file db
|
113 |
256
|
aaronmk
|
|
114 |
268
|
aaronmk
|
uninstall: _not_file rm_db
|
115 |
256
|
aaronmk
|
|
116 |
369
|
aaronmk
|
db: src.$(db).sql _not_file
|
117 |
368
|
aaronmk
|
-$(mysqlAsRoot) <$<
|
118 |
|
|
echo "GRANT SELECT ON $(db).* TO 'bien'@'localhost';"|$(mysqlAsRoot)
|
119 |
255
|
aaronmk
|
# ignore errors in db import so that GRANT will still be run
|
120 |
250
|
aaronmk
|
|
121 |
256
|
aaronmk
|
rm_db: _not_file
|
122 |
368
|
aaronmk
|
-echo "REVOKE ALL ON $(db).* FROM 'bien'@'localhost';"|$(mysqlAsRoot)
|
123 |
|
|
echo "DROP DATABASE IF EXISTS $(db);"|$(mysqlAsRoot)
|
124 |
365
|
aaronmk
|
# ignore errors if grant not defined
|
125 |
250
|
aaronmk
|
|
126 |
368
|
aaronmk
|
###
|
127 |
|
|
|
128 |
|
|
else
|
129 |
|
|
$(error dbEngine variable must be one of the following: MySQL, PostgreSQL)
|
130 |
|
|
endif
|
131 |
|
|
|
132 |
|
|
####
|
133 |
|
|
|
134 |
|
|
test.%.out: map.VegBIEN.%.csv _not_file
|
135 |
|
|
env n=2 $(map) $< >$@ 2>&1
|
136 |
|
|
.PRECIOUS: test.%.out
|
137 |
|
|
|
138 |
256
|
aaronmk
|
#####
|
139 |
|
|
|
140 |
|
|
else
|
141 |
|
|
$(error db variable must be set)
|
142 |
|
|
endif
|
143 |
368
|
aaronmk
|
|
144 |
|
|
#####
|
145 |
|
|
|
146 |
|
|
# Must come after mapEnv is set
|
147 |
|
|
map := env $(mapEnv) out_database=vegbien $(root)/map
|