]> granicus.if.org Git - postgresql/commitdiff
Build src/common files as a library with -fPIC.
authorTom Lane <tgl@sss.pgh.pa.us>
Fri, 28 Sep 2018 18:28:19 +0000 (14:28 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Fri, 28 Sep 2018 18:28:19 +0000 (14:28 -0400)
Build a third version of libpgcommon.a, with -fPIC and -DFRONTEND,
as commit ea53100d5 did for src/port.  Use that in libpq to avoid
symlinking+rebuilding source files retail.

Also adjust ecpg to use the new src/port and src/common libraries.

Arrange to install these libraries, too, to simplify out-of-tree
builds of shared libraries that need any of these modules.

Discussion: https://postgr.es/m/13022.1538003440@sss.pgh.pa.us
Discussion: https://postgr.es/m/E1g5Y8r-0006vs-QA@gemulon.postgresql.org

src/Makefile.global.in
src/common/Makefile
src/interfaces/ecpg/compatlib/.gitignore
src/interfaces/ecpg/compatlib/Makefile
src/interfaces/ecpg/ecpglib/.gitignore
src/interfaces/ecpg/ecpglib/Makefile
src/interfaces/ecpg/pgtypeslib/.gitignore
src/interfaces/ecpg/pgtypeslib/Makefile
src/interfaces/libpq/.gitignore
src/interfaces/libpq/Makefile
src/port/Makefile

index 9cf0c35f8f9e2363cef6e119a476c39115c3fe46..3924c09a5a5b9668821393e8625058e8b4ddfa73 100644 (file)
@@ -534,21 +534,26 @@ libpq_srcdir = $(top_srcdir)/src/interfaces/libpq
 libpq_builddir = $(top_builddir)/src/interfaces/libpq
 endif
 
-# This macro is for use by libraries linking to libpq.  (Because libpgport
-# isn't created with the same link flags as libpq, it can't be used.)
+# How to link to libpq.  (This macro may be used as-is by backend extensions.
+# Client-side code should go through libpq_pgport or libpq_pgport_shlib,
+# instead.)
 libpq = -L$(libpq_builddir) -lpq
 
-# This macro is for use by client executables (not libraries) that use libpq.
+# libpq_pgport is for use by client executables (not libraries) that use libpq.
 # We force clients to pull symbols from the non-shared libraries libpgport
 # and libpgcommon rather than pulling some libpgport symbols from libpq just
 # because libpq uses those functions too.  This makes applications less
-# dependent on changes in libpq's usage of pgport.  To do this we link to
+# dependent on changes in libpq's usage of pgport (on platforms where we
+# don't have symbol export control for libpq).  To do this we link to
 # pgport before libpq.  This does cause duplicate -lpgport's to appear
-# on client link lines.
+# on client link lines, since that also appears in $(LIBS).
+# libpq_pgport_shlib is the same idea, but for use in client shared libraries.
 ifdef PGXS
 libpq_pgport = -L$(libdir) -lpgcommon -lpgport $(libpq)
+libpq_pgport_shlib = -L$(libdir) -lpgcommon_shlib -lpgport_shlib $(libpq)
 else
 libpq_pgport = -L$(top_builddir)/src/common -lpgcommon -L$(top_builddir)/src/port -lpgport $(libpq)
+libpq_pgport_shlib = -L$(top_builddir)/src/common -lpgcommon_shlib -L$(top_builddir)/src/port -lpgport_shlib $(libpq)
 endif
 
 # Cygwin seems to need ldap libraries to be mentioned here, too
index 687174788e50b5397c090e0a3e46dccc07d28fd6..ec8139f014e21bd6a25ab16e64fc35c551dd6c60 100644 (file)
@@ -3,17 +3,21 @@
 # Makefile
 #    Makefile for src/common
 #
-# This makefile generates two outputs:
+# These files are used by the Postgres backend, and also by frontend
+# programs.  These files provide common functionality that isn't directly
+# concerned with portability and thus doesn't belong in src/port.
+#
+# This makefile generates three outputs:
 #
 #      libpgcommon.a - contains object files with FRONTEND defined,
 #              for use by client applications
 #
-#      libpgcommon_srv.a - contains object files without FRONTEND defined,
-#              for use only by the backend binaries
+#      libpgcommon_shlib.a - contains object files with FRONTEND defined,
+#              built suitably for use in shared libraries; for use
+#              by frontend libraries
 #
-# You can also symlink/copy individual source files from this directory,
-# to compile with different options. (libpq does that, because it needs
-# to use -fPIC on some platforms.)
+#      libpgcommon_srv.a - contains object files without FRONTEND defined,
+#              for use only by the backend
 #
 # IDENTIFICATION
 #    src/common/Makefile
@@ -52,26 +56,48 @@ else
 OBJS_COMMON += sha2.o
 endif
 
+# A few files are currently only built for frontend, not server
 OBJS_FRONTEND = $(OBJS_COMMON) fe_memutils.o file_utils.o restricted_token.o
 
+# foo.o, foo_shlib.o, and foo_srv.o are all built from foo.c
+OBJS_SHLIB = $(OBJS_FRONTEND:%.o=%_shlib.o)
 OBJS_SRV = $(OBJS_COMMON:%.o=%_srv.o)
 
-all: libpgcommon.a libpgcommon_srv.a
+all: libpgcommon.a libpgcommon_shlib.a libpgcommon_srv.a
 
 # libpgcommon is needed by some contrib
 install: all installdirs
        $(INSTALL_STLIB) libpgcommon.a '$(DESTDIR)$(libdir)/libpgcommon.a'
+       $(INSTALL_STLIB) libpgcommon_shlib.a '$(DESTDIR)$(libdir)/libpgcommon_shlib.a'
 
 installdirs:
        $(MKDIR_P) '$(DESTDIR)$(libdir)'
 
 uninstall:
        rm -f '$(DESTDIR)$(libdir)/libpgcommon.a'
+       rm -f '$(DESTDIR)$(libdir)/libpgcommon_shlib.a'
 
 libpgcommon.a: $(OBJS_FRONTEND)
        rm -f $@
        $(AR) $(AROPT) $@ $^
 
+#
+# Shared library versions of object files
+#
+
+libpgcommon_shlib.a: $(OBJS_SHLIB)
+       rm -f $@
+       $(AR) $(AROPT) $@ $^
+
+# Because this uses its own compilation rule, it doesn't use the
+# dependency tracking logic from Makefile.global.  To make sure that
+# dependency tracking works anyway for the *_shlib.o files, depend on
+# their *.o siblings as well, which do have proper dependencies.  It's
+# a hack that might fail someday if there is a *_shlib.o without a
+# corresponding *.o, but there seems little reason for that.
+%_shlib.o: %.c %.o
+       $(CC) $(CFLAGS) $(CFLAGS_SL) $(CPPFLAGS) -c $< -o $@
+
 #
 # Server versions of object files
 #
@@ -87,16 +113,18 @@ libpgcommon_srv.a: $(OBJS_SRV)
 # a hack that might fail someday if there is a *_srv.o without a
 # corresponding *.o, but it works for now.
 %_srv.o: %.c %.o
-       $(CC) $(CFLAGS) $(subst -DFRONTEND ,, $(CPPFLAGS)) -c $< -o $@
+       $(CC) $(CFLAGS) $(subst -DFRONTEND,, $(CPPFLAGS)) -c $< -o $@
 
 # Dependencies of keywords.o need to be managed explicitly to make sure
 # that you don't get broken parsing code, even in a non-enable-depend build.
-# Note that gram.h isn't required for the frontend version of keywords.o.
+# Note that gram.h isn't required for the frontend versions of keywords.o.
 $(top_builddir)/src/include/parser/gram.h: $(top_srcdir)/src/backend/parser/gram.y
        $(MAKE) -C $(top_builddir)/src/backend $(top_builddir)/src/include/parser/gram.h
 
 keywords.o: $(top_srcdir)/src/include/parser/kwlist.h
+keywords_shlib.o: $(top_srcdir)/src/include/parser/kwlist.h
 keywords_srv.o: $(top_builddir)/src/include/parser/gram.h $(top_srcdir)/src/include/parser/kwlist.h
 
 clean distclean maintainer-clean:
-       rm -f libpgcommon.a libpgcommon_srv.a $(OBJS_FRONTEND) $(OBJS_SRV)
+       rm -f libpgcommon.a libpgcommon_shlib.a libpgcommon_srv.a
+       rm -f $(OBJS_FRONTEND) $(OBJS_SHLIB) $(OBJS_SRV)
index d81829ce5abd1af208b296e0040b6f22070a1f91..926385c6b97eb328b78121a80100f5f009077e1e 100644 (file)
@@ -1,7 +1,3 @@
 /compatlib.def
 /blibecpg_compatdll.def
 /exports.list
-/snprintf.c
-/strerror.c
-/strlcpy.c
-/strnlen.c
index f6a7f2178e31269182ae5c733fa0e9d82d5174c2..092e456f420b071e1216cfa117abd13d3c271a4a 100644 (file)
@@ -22,17 +22,13 @@ override CPPFLAGS := -I../include -I$(top_srcdir)/src/interfaces/ecpg/include \
        -I$(libpq_srcdir) -DFRONTEND $(CPPFLAGS)
 override CFLAGS += $(PTHREAD_CFLAGS)
 
-SHLIB_LINK_INTERNAL = -L../ecpglib -lecpg -L../pgtypeslib -lpgtypes $(libpq)
+SHLIB_LINK_INTERNAL = -L../ecpglib -lecpg -L../pgtypeslib -lpgtypes $(libpq_pgport_shlib)
 SHLIB_LINK = $(filter -lintl -lm, $(LIBS)) $(PTHREAD_LIBS)
 SHLIB_PREREQS = submake-ecpglib submake-pgtypeslib
 
 SHLIB_EXPORTS = exports.txt
 
-# Need to recompile any libpgport object files
-LIBS := $(filter-out -lpgport, $(LIBS))
-
-OBJS= informix.o snprintf.o strerror.o \
-       $(filter strlcpy.o strnlen.o, $(LIBOBJS)) $(WIN32RES)
+OBJS= informix.o $(WIN32RES)
 
 PKG_CONFIG_REQUIRES_PRIVATE = libecpg libpgtypes
 
@@ -49,9 +45,6 @@ submake-pgtypeslib:
 # Shared library stuff
 include $(top_srcdir)/src/Makefile.shlib
 
-snprintf.c strerror.c strlcpy.c strnlen.c: % : $(top_srcdir)/src/port/%
-       rm -f $@ && $(LN_S) $< .
-
 install: all installdirs install-lib
 
 installdirs: installdirs-lib
@@ -59,6 +52,6 @@ installdirs: installdirs-lib
 uninstall: uninstall-lib
 
 clean distclean: clean-lib
-       rm -f $(OBJS) snprintf.c strerror.c strlcpy.c strnlen.c
+       rm -f $(OBJS)
 
 maintainer-clean: distclean maintainer-clean-lib
index 545c106a9edf796d4690da18e6a3a6f9b2697cf8..f2bf3e7a4a597313a2ff1d65e7fb26989c0c1396 100644 (file)
@@ -1,12 +1,3 @@
 /ecpglib.def
 /blibecpgdll.def
 /exports.list
-/path.c
-/pgstrcasecmp.c
-/snprintf.c
-/strerror.c
-/strlcpy.c
-/strnlen.c
-/thread.c
-/win32setlocale.c
-/isinf.c
index b381623f18e014a541639020fff5778ce4cdab0c..3b0f39c6713d11e4effe654738a43e0ba48b0348 100644 (file)
@@ -22,20 +22,10 @@ override CPPFLAGS := -I../include -I$(top_srcdir)/src/interfaces/ecpg/include \
        -I$(libpq_srcdir) -I$(top_builddir)/src/port -DFRONTEND $(CPPFLAGS)
 override CFLAGS += $(PTHREAD_CFLAGS)
 
-# Need to recompile any libpgport object files
-LIBS := $(filter-out -lpgport, $(LIBS))
+OBJS= execute.o typename.o descriptor.o sqlda.o data.o error.o prepare.o \
+       memory.o connect.o misc.o $(WIN32RES)
 
-OBJS= execute.o typename.o descriptor.o sqlda.o data.o error.o prepare.o memory.o \
-       connect.o misc.o path.o pgstrcasecmp.o snprintf.o strerror.o \
-       $(filter strlcpy.o strnlen.o win32setlocale.o isinf.o, $(LIBOBJS)) \
-       $(WIN32RES)
-
-# thread.c is needed only for non-WIN32 implementation of path.c
-ifneq ($(PORTNAME), win32)
-OBJS += thread.o
-endif
-
-SHLIB_LINK_INTERNAL = -L../pgtypeslib -lpgtypes $(libpq)
+SHLIB_LINK_INTERNAL = -L../pgtypeslib -lpgtypes $(libpq_pgport_shlib)
 SHLIB_LINK = $(filter -lintl -lm, $(LIBS)) $(PTHREAD_LIBS)
 SHLIB_PREREQS = submake-libpq submake-pgtypeslib
 
@@ -52,16 +42,8 @@ submake-pgtypeslib:
 # Shared library stuff
 include $(top_srcdir)/src/Makefile.shlib
 
-# We use some port modules verbatim, but since we need to
-# compile with appropriate options to build a shared lib, we can't
-# necessarily use the same object files as the backend uses. Instead,
-# symlink the source files in here and build our own object file.
-
-path.c pgstrcasecmp.c snprintf.c strerror.c strlcpy.c strnlen.c thread.c win32setlocale.c isinf.c: % : $(top_srcdir)/src/port/%
-       rm -f $@ && $(LN_S) $< .
-
+# Make dependency on pg_config_paths.h visible.
 misc.o: misc.c $(top_builddir)/src/port/pg_config_paths.h
-path.o: path.c $(top_builddir)/src/port/pg_config_paths.h
 
 $(top_builddir)/src/port/pg_config_paths.h:
        $(MAKE) -C $(top_builddir)/src/port pg_config_paths.h
@@ -74,6 +56,5 @@ uninstall: uninstall-lib
 
 clean distclean: clean-lib
        rm -f $(OBJS)
-       rm -f path.c pgstrcasecmp.c snprintf.c strerror.c strlcpy.c strnlen.c thread.c win32setlocale.c isinf.c
 
 maintainer-clean: distclean maintainer-clean-lib
index 333b2817f899d0590a463fc2b8d0f09057b5094e..91402ad88b3e0aa9a790e00ffccbe0b316319def 100644 (file)
@@ -1,10 +1,3 @@
 /pgtypeslib.def
 /blibpgtypesdll.def
 /exports.list
-/pgstrcasecmp.c
-/rint.c
-/snprintf.c
-/strerror.c
-/strlcpy.c
-/string.c
-/strnlen.c
index 874c1a9fad43e4cf1267aa777ff8c7fc9b25180f..c1b41636ac9b2c7523e6f04e9d3482c5db7346cc 100644 (file)
@@ -22,17 +22,12 @@ override CPPFLAGS := -I../include -I$(top_srcdir)/src/interfaces/ecpg/include \
        -DFRONTEND $(CPPFLAGS)
 override CFLAGS += $(PTHREAD_CFLAGS)
 
-# Need to recompile any libpgport object files
-LIBS := $(filter-out -lpgport, $(LIBS))
-
+SHLIB_LINK_INTERNAL = -lpgcommon_shlib -lpgport_shlib
 SHLIB_LINK += $(filter -lintl -lm, $(LIBS))
 
 SHLIB_EXPORTS = exports.txt
 
 OBJS= numeric.o datetime.o common.o dt_common.o timestamp.o interval.o \
-       pgstrcasecmp.o snprintf.o strerror.o \
-       $(filter rint.o strlcpy.o strnlen.o, $(LIBOBJS)) \
-       string.o \
        $(WIN32RES)
 
 all: all-lib
@@ -40,17 +35,6 @@ all: all-lib
 # Shared library stuff
 include $(top_srcdir)/src/Makefile.shlib
 
-# We use some port modules verbatim, but since we need to
-# compile with appropriate options to build a shared lib, we can't
-# necessarily use the same object files as the backend uses. Instead,
-# symlink the source files in here and build our own object file.
-
-pgstrcasecmp.c rint.c snprintf.c strerror.c strlcpy.c strnlen.c: % : $(top_srcdir)/src/port/%
-       rm -f $@ && $(LN_S) $< .
-
-string.c: % : $(top_srcdir)/src/common/%
-       rm -f $@ && $(LN_S) $< .
-
 install: all installdirs install-lib
 
 installdirs: installdirs-lib
@@ -58,6 +42,6 @@ installdirs: installdirs-lib
 uninstall: uninstall-lib
 
 clean distclean: clean-lib
-       rm -f $(OBJS) pgstrcasecmp.c rint.c snprintf.c strerror.c strlcpy.c strnlen.c string.c
+       rm -f $(OBJS)
 
 maintainer-clean: distclean maintainer-clean-lib
index 8885e91e53868b70e3cd10641a07dd173c0a873e..9be338dec89b468e2db15dcd0bcbc34ea5b2cc90 100644 (file)
@@ -1,14 +1,5 @@
 /exports.list
 /libpq.rc
 # .c files that are symlinked in from elsewhere
-/ip.c
-/md5.c
-/base64.c
-/link-canary.c
-/scram-common.c
-/sha2.c
-/sha2_openssl.c
-/saslprep.c
-/unicode_norm.c
 /encnames.c
 /wchar.c
index 769c58b38615b3408992dd7554f9eb5880307ca5..9ac06874b8d7ade0dc3b84d375ebb2e8817693e9 100644 (file)
@@ -32,13 +32,9 @@ OBJS=        fe-auth.o fe-auth-scram.o fe-connect.o fe-exec.o fe-misc.o fe-print.o fe-l
 
 # src/backend/utils/mb
 OBJS += encnames.o wchar.o
-# src/common
-OBJS += base64.o ip.o link-canary.o md5.o scram-common.o saslprep.o unicode_norm.o
 
 ifeq ($(with_openssl),yes)
-OBJS += fe-secure-openssl.o fe-secure-common.o sha2_openssl.o
-else
-OBJS += sha2.o
+OBJS += fe-secure-openssl.o fe-secure-common.o
 endif
 
 ifeq ($(PORTNAME), cygwin)
@@ -59,12 +55,14 @@ endif
 
 # Add libraries that libpq depends (or might depend) on into the
 # shared library link.  (The order in which you list them here doesn't
-# matter.)  Note that we filter out -lpgport from LIBS and instead
-# insert -lpgport_shlib, to get port files that are built correctly.
+# matter.)  Note that we filter out -lpgcommon and -lpgport from LIBS and
+# instead link with -lpgcommon_shlib and -lpgport_shlib, to get object files
+# that are built correctly for use in a shlib.
+SHLIB_LINK_INTERNAL = -lpgcommon_shlib -lpgport_shlib
 ifneq ($(PORTNAME), win32)
-SHLIB_LINK += -lpgport_shlib $(filter -lcrypt -ldes -lcom_err -lcrypto -lk5crypto -lkrb5 -lgssapi_krb5 -lgss -lgssapi -lssl -lsocket -lnsl -lresolv -lintl -lm, $(LIBS)) $(LDAP_LIBS_FE) $(PTHREAD_LIBS)
+SHLIB_LINK += $(filter -lcrypt -ldes -lcom_err -lcrypto -lk5crypto -lkrb5 -lgssapi_krb5 -lgss -lgssapi -lssl -lsocket -lnsl -lresolv -lintl -lm, $(LIBS)) $(LDAP_LIBS_FE) $(PTHREAD_LIBS)
 else
-SHLIB_LINK += -lpgport_shlib $(filter -lcrypt -ldes -lcom_err -lcrypto -lk5crypto -lkrb5 -lgssapi32 -lssl -lsocket -lnsl -lresolv -lintl -lm $(PTHREAD_LIBS), $(LIBS)) $(LDAP_LIBS_FE)
+SHLIB_LINK += $(filter -lcrypt -ldes -lcom_err -lcrypto -lk5crypto -lkrb5 -lgssapi32 -lssl -lsocket -lnsl -lresolv -lintl -lm $(PTHREAD_LIBS), $(LIBS)) $(LDAP_LIBS_FE)
 endif
 ifeq ($(PORTNAME), win32)
 SHLIB_LINK += -lshell32 -lws2_32 -lsecur32 $(filter -leay32 -lssleay32 -lcomerr32 -lkrb5_32, $(LIBS))
@@ -87,9 +85,6 @@ backend_src = $(top_srcdir)/src/backend
 # Instead, symlink the source files in here and build our own object files.
 # When you add a file here, remember to add it in the "clean" target below.
 
-ip.c md5.c base64.c link-canary.c scram-common.c sha2.c sha2_openssl.c saslprep.c unicode_norm.c: % : $(top_srcdir)/src/common/%
-       rm -f $@ && $(LN_S) $< .
-
 encnames.c wchar.c: % : $(backend_src)/utils/mb/%
        rm -f $@ && $(LN_S) $< .
 
@@ -136,8 +131,7 @@ clean distclean: clean-lib
        rm -f $(OBJS) pthread.h libpq.rc
 # Might be left over from a Win32 client-only build
        rm -f pg_config_paths.h
-# Remove files we (may have) symlinked in from src/common and other places
-       rm -f ip.c md5.c base64.c link-canary.c scram-common.c sha2.c sha2_openssl.c saslprep.c unicode_norm.c
+# Remove files we (may have) symlinked in from other places
        rm -f encnames.c wchar.c
 
 maintainer-clean: distclean maintainer-clean-lib
index ec62a31d29f27aa3c90602ac41ee540a8c3429ff..585c53757bab6309f15ae2e524b938635c04ea94 100644 (file)
@@ -14,7 +14,7 @@
 #
 #      libpgport_shlib.a - contains object files with FRONTEND defined,
 #              built suitably for use in shared libraries; for use
-#              by libpq and other frontend libraries
+#              by frontend libraries
 #
 #      libpgport_srv.a - contains object files without FRONTEND defined,
 #              for use only by the backend
@@ -53,15 +53,16 @@ OBJS_SRV = $(OBJS:%.o=%_srv.o)
 all: libpgport.a libpgport_shlib.a libpgport_srv.a
 
 # libpgport is needed by some contrib
-# currently we don't install libpgport_shlib.a, maybe we should?
 install: all installdirs
        $(INSTALL_STLIB) libpgport.a '$(DESTDIR)$(libdir)/libpgport.a'
+       $(INSTALL_STLIB) libpgport_shlib.a '$(DESTDIR)$(libdir)/libpgport_shlib.a'
 
 installdirs:
        $(MKDIR_P) '$(DESTDIR)$(libdir)'
 
 uninstall:
        rm -f '$(DESTDIR)$(libdir)/libpgport.a'
+       rm -f '$(DESTDIR)$(libdir)/libpgport_shlib.a'
 
 libpgport.a: $(OBJS)
        rm -f $@