Project

General

Profile

« Previous | Next » 

Revision 621

input.Makefile: Factored as much as possible out of section for each DB engine

View differences:

inputs/input.Makefile
96 96

  
97 97
mapEnv := in_engine=$(dbEngine) in_database=$(db)
98 98

  
99
%.ref: %.ref.sql
100
	$(inputDbAsBien) $(db) <$< >$@
101
.PRECIOUS: %.ref
102

  
99 103
####
100 104

  
101
ifeq ($(dbEngine),MySQL)
105
install: _always db ;
102 106

  
103
bienPassword := $(shell cat $(root)/config/bien_password)
104
mysqlAs = mysql --user=$(1) --password='$(bienPassword)'
105
mysqlAsRoot := $(call mysqlAs,root)
106
mysqlAsBien := $(call mysqlAs,bien)
107
uninstall: _always rm_db ;
107 108

  
109
####
110

  
108 111
import-%: maps/VegBIEN.%.csv _always
109 112
	-$(import_cmd)
110 113
import_cmd = (set -x; "time" env commit=1 $(map) $<) \
111 114
$(if $(n),,>>$(log)) 2>&1$(if $(n),|tee -a $(log))
112 115

  
113
%.ref: %.ref.sql
114
	$(mysqlAsBien) $(db) <$< >$@
115
.PRECIOUS: %.ref
116
####
116 117

  
117
###
118
test/import.out: $(vegbienMaps) _always
119
	env test=1 n=$(test_n) $(map) $(+_) >$@ 2>&1 || { e=$$?; cat $@; exit $$e;}
120
.PRECIOUS: test/import.out
118 121

  
119
install: _always db ;
122
####
120 123

  
121
uninstall: _always rm_db ;
124
# Each DB engine needs var $(dbAsBien) and targets db, rm_db
122 125

  
126
ifeq ($(dbEngine),MySQL)
127

  
128
bienPassword := $(shell cat $(root)/config/bien_password)
129
mysqlAs = mysql --user=$(1) --password='$(bienPassword)'
130
mysqlAsRoot := $(call mysqlAs,root)
131
dbAsBien := $(call mysqlAs,bien)
132

  
123 133
db: src.$(db).sql _always
124 134
	-$(mysqlAsRoot) <$<
125 135
	echo "GRANT SELECT ON $(db).* TO 'bien'@'localhost';"|$(mysqlAsRoot)
......
130 140
	echo "DROP DATABASE IF EXISTS $(db);"|$(mysqlAsRoot)
131 141
# ignore errors if grant not defined
132 142

  
133
###
143
####
134 144

  
135 145
else
136 146
$(error dbEngine variable must be one of the following: MySQL, PostgreSQL)
137 147
endif
138 148

  
139
####
140

  
141
test/import.out: $(vegbienMaps) _always
142
	env test=1 n=$(test_n) $(map) $(+_) >$@ 2>&1 || { e=$$?; cat $@; exit $$e;}
143
.PRECIOUS: test/import.out
144

  
145 149
#####
146 150

  
147 151
else

Also available in: Unified diff