PG_CONFIG ?= pg_config
EXTENSION = pg_repack
TMPDIR ?= "/tmp"
bindir := $(shell $(PG_CONFIG) --bindir)

ifeq ($(OS),Windows_NT)
ts-ext:
	@mkdir "$(TMPDIR)/~@#$%^-_(){}" "$(TMPDIR)/~@#$%" "$(TMPDIR)/~@"
	@$(bindir)/psql -c "CREATE TABLESPACE \"1testts\" LOCATION '$(TMPDIR)/~@#$%^-_(){}'"
	@$(bindir)/psql -c "CREATE TABLESPACE \"test ts\" LOCATION '$(TMPDIR)/~@#$%'"
	@$(bindir)/psql -c "CREATE TABLESPACE \"test\"\"ts\" LOCATION '$(TMPDIR)/~@'"
else
ts-ext:
	@mkdir $(TMPDIR)/1testts $(TMPDIR)/test\ ts $(TMPDIR)/test\"ts
	@$(bindir)/psql -c "CREATE TABLESPACE \"1testts\" LOCATION '$(TMPDIR)/1testts'"
	@$(bindir)/psql -c "CREATE TABLESPACE \"test ts\" LOCATION '$(TMPDIR)/test ts'"
	@$(bindir)/psql -c "CREATE TABLESPACE \"test\"\"ts\" LOCATION '$(TMPDIR)/test\"ts'"
endif

pre-setup:
	@$(bindir)/psql -c "alter system set autovacuum = off;" -c "select pg_reload_conf();"

ts: ts-ext
	@mkdir $(TMPDIR)/testts
	@$(bindir)/psql -c "CREATE TABLESPACE testts LOCATION '$(TMPDIR)/testts'"

check installcheck: pre-setup ts
	$(MAKE) -C regress $@
	@$(bindir)/psql -c "alter system set autovacuum to default;" -c "select pg_reload_conf();"
