# plx - PGXS build
MODULE_big = plx
OBJS = src/plx_core.o src/plx_transpile.o src/plx_strbuild.o src/plx_dialect_ruby.o src/plx_dialect_php.o src/plx_dialect_js.o src/plx_dialect_python.o src/plx_dialect_cobol.o src/plx_dialect_plsql.o src/plx_dialect_ts.o src/plx_dialect_tsql.o src/plx_dialect_go.o src/plx_parse_brace.o

EXTENSION = plx
DATA = plx--1.0.sql plx--1.1.sql plx--1.1.1.sql plx--1.2.sql plx--1.2.1.sql plx--1.2.2.sql plx--1.3.0.sql plx--1.3.1.sql plx--1.3.2.sql plx--2.0.0.sql plx--1.0--1.1.sql plx--1.1--1.1.1.sql plx--1.1.1--1.2.sql plx--1.2--1.2.1.sql plx--1.2.1--1.2.2.sql plx--1.2.2--1.3.0.sql plx--1.3.0--1.3.1.sql plx--1.3.1--1.3.2.sql plx--1.3.2--2.0.0.sql

# pg_regress suite (make installcheck). test/run_corpus.py is an additional
# Ruby corpus runner, and test/differential.py checks each dialect against a
# plpgsql reference (make differentialcheck).
REGRESS = plxruby plxphp plxjs plxpython3 plxcobol plxplsql plxts plxtsql plxgo plx_features plx_output plx_strbuild plx_errors
REGRESS_OPTS = --inputdir=test --outputdir=test

# Point at the source-built PG 18 (not any distro pg_config on PATH).
PG_CONFIG ?= /usr/local/pgsql/bin/pg_config
PGXS := $(shell $(PG_CONFIG) --pgxs)
include $(PGXS)

# PGXS does not track header dependencies; declare them so a header change
# rebuilds every object (the shared enum/struct layout must stay consistent).
$(OBJS): src/plx.h src/plx_int.h src/plx_engine.h

PLX_PYTHON ?= python3

# Differential check: run every dialect's version of a program against the
# plpgsql the same program would have been written in, and require them to
# agree. Needs the extension installed and a running server, like installcheck.
.PHONY: differentialcheck
differentialcheck:
	PLX_PSQL="$(shell $(PG_CONFIG) --bindir)/psql" $(PLX_PYTHON) test/differential.py

# Check META.json against the PGXN Meta Spec. PGXN validates at upload time,
# which is after a release is tagged and published, so check it before then.
# Needs no server.
.PHONY: metacheck
metacheck:
	$(PLX_PYTHON) test/check_meta.py
