#-------------------------------------------------------------------------
#
# Makefile for the plpgsql shared object
#
# $PostgreSQL: pgsql/src/pl/plpgsql/src/Makefile,v 1.31 2007/07/15 22:18:24 tgl Exp $
#
#-------------------------------------------------------------------------

subdir = src/pl/plpgpsm/src
top_builddir = ../../../..
include $(top_builddir)/src/Makefile.global

# Shared library parameters
NAME= plpgpsm

override CPPFLAGS := -I$(srcdir) $(CPPFLAGS)
SHLIB_LINK = $(filter -lintl, $(LIBS)) $(BE_DLLLIBS)
rpath =

OBJS = pl_gram.o pl_handler.o pl_comp.o pl_exec.o pl_funcs.o

REGRESS_OPTS = --dbname=$(PL_TESTDB) --load-language=plpgpsm
REGRESS = plpgpsm

all: all-lib

# Shared library stuff
include $(top_srcdir)/src/Makefile.shlib

install: installdirs all install-lib

installdirs: installdirs-lib

uninstall: uninstall-lib

installcheck: submake
	$(top_builddir)/src/test/regress/pg_regress --inputdir=$(srcdir) --psqldir=$(PSQLDIR) $(REGRESS_OPTS) $(REGRESS)

.PHONY: submake
submake:
	$(MAKE) -C $(top_builddir)/src/test/regress pg_regress$(X)

# Force these dependencies to be known even without dependency info built:
pl_gram.o pl_handler.o pl_comp.o pl_exec.o pl_funcs.o: plpgpsm.h $(srcdir)/pl_gram.h

# pl_scan is compiled as part of pl_gram
pl_gram.o: $(srcdir)/pl_scan.c

# See notes in src/backend/parser/Makefile about the following two rules

$(srcdir)/pl_gram.h: $(srcdir)/pl_gram.c ;

$(srcdir)/pl_gram.c: gram.y
ifdef BISON
	$(BISON) -d $(BISONFLAGS) -o $@ $<
else
	@$(missing) bison $< $@
endif

# Because we use %option case-insensitive, flex's results could vary
# depending on what the compile-time locale setting is.  Hence, force
# it to see LC_CTYPE=C to ensure consistent build results.

$(srcdir)/pl_scan.c: scan.l
ifdef FLEX
	LC_CTYPE=C $(FLEX) $(FLEXFLAGS) -o'$@' $<
else
	@$(missing) flex $< $@
endif

distprep: $(srcdir)/pl_scan.c $(srcdir)/pl_gram.h $(srcdir)/pl_gram.c

# pl_gram.c, pl_gram.h, and pl_scan.c are in the distribution tarball,
# so they are not cleaned here.
clean distclean: clean-lib
	rm -f $(OBJS)

maintainer-clean: clean
	rm -f $(srcdir)/pl_gram.c $(srcdir)/pl_gram.h $(srcdir)/pl_scan.c

