Revision 368
Added by Aaron Marcuse-Kubitza almost 13 years ago
input.Makefile | ||
---|---|---|
1 | 1 |
selfDir_3d1bc249 := $(dir $(lastword $(MAKEFILE_LIST))) |
2 | 2 |
|
3 |
# 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 |
|
|
3 | 11 |
vegxMaps := $(wildcard map.VegX.*.csv) |
4 | 12 |
vegbienMaps := $(subst .VegX.,.VegBIEN.,$(vegxMaps)) |
13 |
tables := $(vegbienMaps:map.VegBIEN.%.csv=%) |
|
5 | 14 |
|
6 |
table = $(shell s="$(*F)"; echo "$${s\#\#*.}")# remove sort order prefix |
|
15 |
root := $(selfDir_3d1bc249).. |
|
16 |
psqlAsBien := $(root)/bin/psql_vegbien |
|
7 | 17 |
|
8 |
root := ../.. |
|
9 |
map := env out_database=vegbien $(root)/map |
|
10 |
|
|
11 | 18 |
##### |
12 | 19 |
|
13 |
all: _not_file # empty rule since must be first target in file
|
|
20 |
all: _not_file maps import verify
|
|
14 | 21 |
|
15 | 22 |
.SUFFIXES: |
16 | 23 |
|
17 | 24 |
_not_file: |
18 | 25 |
.PHONY: _not_file |
19 | 26 |
|
20 |
all := $(wildcard output.*) $(vegbienMaps) |
|
21 |
|
|
22 | 27 |
clean: _not_file |
23 | 28 |
$(RM) $(all) |
24 | 29 |
|
30 |
rm-%: _not_file |
|
31 |
$(RM) $* |
|
32 |
|
|
33 |
%.out: % _not_file |
|
34 |
./$* >$@ |
|
35 |
.PRECIOUS: %.out |
|
36 |
|
|
25 | 37 |
##### |
26 | 38 |
|
27 | 39 |
reinstall: _not_file uninstall install |
28 | 40 |
|
29 | 41 |
##### |
30 | 42 |
|
43 |
maps: $(vegbienMaps) _not_file |
|
44 |
|
|
45 |
all += $(vegbienMaps) |
|
46 |
|
|
31 | 47 |
map.VegBIEN.%.csv: map.VegX.%.csv |
32 | 48 |
$(root)/bin/join_sort <$< $(root)/mappings/VegX-VegBIEN.$(table).csv >$@ |
33 | 49 |
.PRECIOUS: map.VegBIEN.%.csv |
34 | 50 |
|
51 |
##### |
|
52 |
|
|
53 |
import: _not_file $(addprefix import-,$(tables)) |
|
54 |
|
|
55 |
log = $*$(if $(n),.n=$(n),).log |
|
56 |
|
|
35 | 57 |
logs := $(wildcard *.log) |
36 | 58 |
|
59 |
all += $(logs) |
|
60 |
|
|
37 | 61 |
rm_logs: _not_file |
38 | 62 |
$(RM) $(logs) |
39 | 63 |
|
40 | 64 |
##### |
41 | 65 |
|
66 |
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 |
|
|
42 | 84 |
ifdef db |
43 | 85 |
|
44 |
ifndef dbEngine |
|
45 |
$(error dbEngine variable must be set. Possible values: MySQL, PostgreSQL) |
|
46 |
endif |
|
47 |
|
|
48 | 86 |
mapEnv := in_engine=$(dbEngine) in_database=$(db) |
49 | 87 |
|
50 |
all: _not_file $(vegbienMaps:map.VegBIEN.%.csv=import-%)
|
|
88 |
####
|
|
51 | 89 |
|
52 |
log = $*$(if $(n),.n=$(n),).log
|
|
90 |
ifeq ($(dbEngine),MySQL)
|
|
53 | 91 |
|
92 |
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 |
|
|
54 | 97 |
import-%: map.VegBIEN.%.csv _not_file |
55 | 98 |
$(importCmd) |
56 |
importCmd = (set -x; "time" env commit=1 $(mapEnv) $(map) $<) \
|
|
57 |
$(if $(n),,>>$(log)) 2>&1 $(if $(n),| tee -a $(log))
|
|
99 |
importCmd = (set -x; "time" env commit=1 $(map) $<) \ |
|
100 |
$(if $(n),,>>$(log)) 2>&1$(if $(n),|tee -a $(log))
|
|
58 | 101 |
|
59 |
##
|
|
102 |
all += $(wildcard *.out)
|
|
60 | 103 |
|
104 |
%.ref.out: %.ref.sql |
|
105 |
$(mysqlAsBien) --skip-column-names $(db) <$< >$@ |
|
106 |
.PRECIOUS: %.ref.out |
|
107 |
|
|
108 |
### |
|
109 |
|
|
61 | 110 |
install: _not_file db |
62 | 111 |
|
63 | 112 |
uninstall: _not_file rm_db |
64 | 113 |
|
65 |
bienPassword := $(shell cat $(root)/config/bien_password) |
|
66 |
mysql := mysql --user=root --password='$(bienPassword)' |
|
67 |
|
|
68 | 114 |
db: $(db).sql _not_file |
69 |
-$(mysql) <$< |
|
70 |
echo "GRANT SELECT ON $(db).* TO 'bien'@'localhost';"|$(mysql) |
|
115 |
-$(mysqlAsRoot) <$<
|
|
116 |
echo "GRANT SELECT ON $(db).* TO 'bien'@'localhost';"|$(mysqlAsRoot)
|
|
71 | 117 |
# ignore errors in db import so that GRANT will still be run |
72 | 118 |
|
73 | 119 |
rm_db: _not_file |
74 |
-echo "REVOKE ALL ON $(db).* FROM 'bien'@'localhost';"|$(mysql) |
|
75 |
echo "DROP DATABASE IF EXISTS $(db);"|$(mysql) |
|
120 |
-echo "REVOKE ALL ON $(db).* FROM 'bien'@'localhost';"|$(mysqlAsRoot)
|
|
121 |
echo "DROP DATABASE IF EXISTS $(db);"|$(mysqlAsRoot)
|
|
76 | 122 |
# ignore errors if grant not defined |
77 | 123 |
|
124 |
### |
|
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 |
|
|
78 | 136 |
##### |
79 | 137 |
|
80 | 138 |
else |
81 | 139 |
$(error db variable must be set) |
82 | 140 |
endif |
141 |
|
|
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 |
Also available in: Unified diff
input.Makefile: Added rules to verify inserted data and run tests