Project

General

Profile

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