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