1 |
256
|
aaronmk
|
selfDir_3d1bc249 := $(dir $(lastword $(MAKEFILE_LIST)))
|
2 |
250
|
aaronmk
|
|
3 |
264
|
aaronmk
|
vegxMaps := $(wildcard map.VegX.*.csv)
|
4 |
|
|
vegbienMaps := $(subst .VegX.,.VegBIEN.,$(vegxMaps))
|
5 |
247
|
aaronmk
|
|
6 |
353
|
aaronmk
|
table = $(shell s="$(*F)"; echo "$${s\#\#*.}")# remove sort order prefix
|
7 |
|
|
|
8 |
264
|
aaronmk
|
root := ../..
|
9 |
339
|
aaronmk
|
map := env out_database=vegbien $(root)/map
|
10 |
264
|
aaronmk
|
|
11 |
250
|
aaronmk
|
#####
|
12 |
|
|
|
13 |
256
|
aaronmk
|
all: _not_file # empty rule since must be first target in file
|
14 |
247
|
aaronmk
|
|
15 |
|
|
.SUFFIXES:
|
16 |
|
|
|
17 |
|
|
_not_file:
|
18 |
|
|
.PHONY: _not_file
|
19 |
250
|
aaronmk
|
|
20 |
264
|
aaronmk
|
all := $(wildcard output.*) $(vegbienMaps)
|
21 |
256
|
aaronmk
|
|
22 |
|
|
clean: _not_file
|
23 |
|
|
$(RM) $(all)
|
24 |
|
|
|
25 |
250
|
aaronmk
|
#####
|
26 |
|
|
|
27 |
264
|
aaronmk
|
reinstall: _not_file uninstall install
|
28 |
|
|
|
29 |
|
|
#####
|
30 |
|
|
|
31 |
|
|
map.VegBIEN.%.csv: map.VegX.%.csv
|
32 |
353
|
aaronmk
|
$(root)/bin/join_sort <$< $(root)/mappings/VegX-VegBIEN.$(table).csv >$@
|
33 |
264
|
aaronmk
|
.PRECIOUS: map.VegBIEN.%.csv
|
34 |
|
|
|
35 |
339
|
aaronmk
|
logs := $(wildcard *.log)
|
36 |
|
|
|
37 |
|
|
rm_logs: _not_file
|
38 |
|
|
$(RM) $(logs)
|
39 |
|
|
|
40 |
264
|
aaronmk
|
#####
|
41 |
|
|
|
42 |
256
|
aaronmk
|
ifdef db
|
43 |
|
|
|
44 |
260
|
aaronmk
|
ifndef dbEngine
|
45 |
|
|
$(error dbEngine variable must be set. Possible values: MySQL, PostgreSQL)
|
46 |
|
|
endif
|
47 |
|
|
|
48 |
264
|
aaronmk
|
mapEnv := in_engine=$(dbEngine) in_database=$(db)
|
49 |
256
|
aaronmk
|
|
50 |
283
|
aaronmk
|
all: _not_file $(vegbienMaps:map.VegBIEN.%.csv=import-%)
|
51 |
256
|
aaronmk
|
|
52 |
339
|
aaronmk
|
log = $*$(if $(n),.n=$(n),).log
|
53 |
|
|
|
54 |
283
|
aaronmk
|
import-%: map.VegBIEN.%.csv _not_file
|
55 |
361
|
aaronmk
|
(set -x; "time" env commit=1 $(mapEnv) $(map) $<) 2>&1 | tee -a $(log)
|
56 |
256
|
aaronmk
|
|
57 |
264
|
aaronmk
|
##
|
58 |
256
|
aaronmk
|
|
59 |
268
|
aaronmk
|
install: _not_file db
|
60 |
256
|
aaronmk
|
|
61 |
268
|
aaronmk
|
uninstall: _not_file rm_db
|
62 |
256
|
aaronmk
|
|
63 |
272
|
aaronmk
|
bienPassword := $(shell cat $(root)/config/bien_password)
|
64 |
264
|
aaronmk
|
mysql := mysql --user=root --password='$(bienPassword)'
|
65 |
|
|
|
66 |
256
|
aaronmk
|
db: $(db).sql _not_file
|
67 |
255
|
aaronmk
|
-$(mysql) <$<
|
68 |
|
|
echo "GRANT SELECT ON $(db).* TO 'bien'@'localhost';"|$(mysql)
|
69 |
|
|
# ignore errors in db import so that GRANT will still be run
|
70 |
250
|
aaronmk
|
|
71 |
256
|
aaronmk
|
rm_db: _not_file
|
72 |
255
|
aaronmk
|
-echo "REVOKE ALL ON $(db).* FROM 'bien'@'localhost';"|$(mysql)
|
73 |
250
|
aaronmk
|
echo "DROP DATABASE IF EXISTS $(db);"|$(mysql)
|
74 |
255
|
aaronmk
|
# ignore errors about no such grant being defined
|
75 |
250
|
aaronmk
|
|
76 |
256
|
aaronmk
|
#####
|
77 |
|
|
|
78 |
|
|
else
|
79 |
|
|
$(error db variable must be set)
|
80 |
|
|
endif
|