Project

General

Profile

« Previous | Next » 

Revision 622

input.Makefile: Detect DB engine automatically from SQL file available in src subdir

View differences:

inputs/SALVIAS/Makefile
1
dbEngine := MySQL
2
db := salvias_plots
3

  
4 1
include ../input.Makefile
inputs/input.Makefile
92 92

  
93 93
#####
94 94

  
95
ifdef db
95
dbFile := $(firstword $(wildcard src/*.sql))
96 96

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

  
99
dbFileBasename := $(basename $(notdir $(dbFile)))
100
dbEngineExt := $(subst .,,$(suffix $(dbFileBasename)))
101
db := $(basename $(dbFileBasename))
102

  
99 103
%.ref: %.ref.sql
100 104
	$(inputDbAsBien) $(db) <$< >$@
101 105
.PRECIOUS: %.ref
......
123 127

  
124 128
# Each DB engine needs var $(dbAsBien) and targets db, rm_db
125 129

  
126
ifeq ($(dbEngine),MySQL)
130
ifeq ($(dbEngineExt),my)
127 131

  
132
dbEngine := MySQL
133

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

  
133
db: src.$(db).sql _always
139
db: $(dbFile) _always
134 140
	-$(mysqlAsRoot) <$<
135 141
	echo "GRANT SELECT ON $(db).* TO 'bien'@'localhost';"|$(mysqlAsRoot)
136 142
# ignore errors in db import so that GRANT will still be run
......
143 149
####
144 150

  
145 151
else
146
$(error dbEngine variable must be one of the following: MySQL, PostgreSQL)
152
$(error The DB engine extension "$(dbEngineExt)" for $(dbFile) must be one of\
153
the following: my, pg)
147 154
endif
148 155

  
149 156
#####
150 157

  
158
# Must come after dbEngine is set
159
mapEnv := in_engine=$(dbEngine) in_database=$(db)
160

  
151 161
else
152
$(error db variable must be set)
162
$(error The src subdir must contain a file <db_name>.{my|pg}.sql)
153 163
endif
154 164

  
155 165
#####

Also available in: Unified diff