SRCDIR = ..
include config_db

OUTFILES = init.sql perms.sql init.sh install.sh

clean:
	$(RM)	-f init.sql install.sh init.sh *~ err.log install.log perms.sql

all: $(OUTFILES)

install: all
	$(CDIR)/install.sh
	
init.sql: init.sql.dist
	sed -e "s:_PGLIB_:$(PGLIB):g; \
				s:_DBUSER_:$(DBUSER):g; \
				s:_DBPASS_:$(DBPASS):g" < $< > $@

perms.sql:	perms.sql.dist
	sed -e "s:_DBUSER_:$(DBUSER):g" < $< > $@

install.sh: install.sh.dist
	sed -e  "s:_PGUSER_:$(PGUSER):g" < $< > $@
	chmod +x $(CDIR)/install.sh

init.sh: init.sh.dist
	sed -e	"s:_PGUSER_:$(PGUSER):g; \
				s:_PGBIN_:$(PGBIN):g; \
				s:_PGARGS_:$(PGARGS):g; \
				s:_PGHOME_:$(PGHOME):g; \
				s:_PSQL_:$(PSQL):g; \
				s:_DBNAME_:$(DBNAME):g; \
				s:_CDIR_:$(CDIR):g" < $< > $@;
	chmod +x $(CDIR)/init.sh

