1# src/pl/plpython/Makefile
2
3subdir = src/pl/plpython
4top_builddir = ../../..
5include $(top_builddir)/src/Makefile.global
6
7
8# On Windows we have to remove -lpython from the link since we are
9# building our own
10ifeq ($(PORTNAME), win32)
11override python_libspec =
12endif
13
14override CPPFLAGS := -I. -I$(srcdir) $(python_includespec) $(CPPFLAGS)
15
16rpathdir = $(python_libdir)
17
18PGFILEDESC = "PL/Python - procedural language"
19
20NAME = plpython$(python_majorversion)
21
22OBJS = \
23	plpy_cursorobject.o \
24	plpy_elog.o \
25	plpy_exec.o \
26	plpy_main.o \
27	plpy_planobject.o \
28	plpy_plpymodule.o \
29	plpy_procedure.o \
30	plpy_resultobject.o \
31	plpy_spi.o \
32	plpy_subxactobject.o \
33	plpy_typeio.o \
34	plpy_util.o \
35	$(WIN32RES)
36
37DATA = $(NAME)u.control $(NAME)u--1.0.sql $(NAME)u--unpackaged--1.0.sql
38ifeq ($(python_majorversion),2)
39DATA += plpythonu.control plpythonu--1.0.sql plpythonu--unpackaged--1.0.sql
40endif
41
42# header files to install - it's not clear which of these might be needed
43# so install them all.
44INCS = 	plpython.h \
45	plpy_cursorobject.h \
46	plpy_elog.h \
47	plpy_exec.h \
48	plpy_main.h \
49	plpy_planobject.h \
50	plpy_plpymodule.h \
51	plpy_procedure.h \
52	plpy_resultobject.h \
53	plpy_spi.h \
54	plpy_subxactobject.h \
55	plpy_typeio.h \
56	plpy_util.h
57
58# Python on win32 ships with import libraries only for Microsoft Visual C++,
59# which are not compatible with mingw gcc. Therefore we need to build a
60# new import library to link with.
61ifeq ($(PORTNAME), win32)
62
63pytverstr=$(subst .,,${python_version})
64PYTHONDLL=$(subst \,/,$(WINDIR))/system32/python${pytverstr}.dll
65
66OBJS += libpython${pytverstr}.a
67
68libpython${pytverstr}.a: python${pytverstr}.def
69	dlltool --dllname python${pytverstr}.dll --def python${pytverstr}.def --output-lib libpython${pytverstr}.a
70
71python${pytverstr}.def:
72	pexports $(PYTHONDLL) > $@
73
74endif # win32
75
76
77SHLIB_LINK = $(python_libspec) $(python_additional_libs) $(filter -lintl,$(LIBS))
78
79REGRESS_OPTS = --dbname=$(PL_TESTDB)
80# Only load plpythonu with Python 2.  The test files themselves load
81# the versioned language plpython(2|3)u.
82ifeq ($(python_majorversion),2)
83REGRESS_OPTS += --load-extension=plpythonu
84endif
85
86REGRESS = \
87	plpython_schema \
88	plpython_populate \
89	plpython_test \
90	plpython_do \
91	plpython_global \
92	plpython_import \
93	plpython_spi \
94	plpython_newline \
95	plpython_void \
96	plpython_call \
97	plpython_params \
98	plpython_setof \
99	plpython_record \
100	plpython_trigger \
101	plpython_types \
102	plpython_error \
103	plpython_ereport \
104	plpython_unicode \
105	plpython_quote \
106	plpython_composite \
107	plpython_subtransaction \
108	plpython_transaction \
109	plpython_drop
110
111REGRESS_PLPYTHON3_MANGLE := $(REGRESS)
112
113include $(top_srcdir)/src/Makefile.shlib
114
115all: all-lib
116
117# Ensure parallel safety if a build is started in this directory
118$(OBJS): | submake-generated-headers
119
120install: all install-lib install-data
121
122installdirs: installdirs-lib
123	$(MKDIR_P) '$(DESTDIR)$(datadir)/extension' '$(DESTDIR)$(includedir_server)' '$(DESTDIR)$(pgxsdir)/src/pl/plpython'
124
125uninstall: uninstall-lib uninstall-data
126
127install-data: installdirs
128	$(INSTALL_DATA) $(addprefix $(srcdir)/, $(DATA)) '$(DESTDIR)$(datadir)/extension/'
129	$(INSTALL_DATA) $(addprefix $(srcdir)/, $(INCS)) '$(DESTDIR)$(includedir_server)'
130	$(INSTALL_DATA) $(srcdir)/regress-python3-mangle.mk '$(DESTDIR)$(pgxsdir)/src/pl/plpython'
131
132uninstall-data:
133	rm -f $(addprefix '$(DESTDIR)$(datadir)/extension'/, $(notdir $(DATA)))
134	rm -f $(addprefix '$(DESTDIR)$(includedir_server)'/, plpython.h plpy_util.h)
135
136.PHONY: install-data uninstall-data
137
138
139include $(srcdir)/regress-python3-mangle.mk
140
141
142check: submake-pg-regress
143	$(pg_regress_check) $(REGRESS_OPTS) $(REGRESS)
144
145installcheck: submake-pg-regress
146	$(pg_regress_installcheck) $(REGRESS_OPTS) $(REGRESS)
147
148
149.PHONY: submake-pg-regress
150submake-pg-regress: | submake-generated-headers
151	$(MAKE) -C $(top_builddir)/src/test/regress pg_regress$(X)
152
153clean distclean: clean-lib
154	rm -f $(OBJS)
155	rm -rf $(pg_regress_clean_files)
156ifeq ($(PORTNAME), win32)
157	rm -f python${pytverstr}.def
158endif
159
160
161# Force this dependency to be known even without dependency info built:
162plpy_plpymodule.o: spiexceptions.h
163
164spiexceptions.h: $(top_srcdir)/src/backend/utils/errcodes.txt generate-spiexceptions.pl
165	$(PERL) $(srcdir)/generate-spiexceptions.pl $< > $@
166
167distprep: spiexceptions.h
168
169maintainer-clean: distclean
170	rm -f spiexceptions.h
171