33# Makefile
44# Makefile for src/common
55#
6- # This makefile generates two outputs:
6+ # These files are used by the Postgres backend, and also by frontend
7+ # programs. These files provide common functionality that isn't directly
8+ # concerned with portability and thus doesn't belong in src/port.
9+ #
10+ # This makefile generates three outputs:
711#
812# libpgcommon.a - contains object files with FRONTEND defined,
913# for use by client applications
1014#
11- # libpgcommon_srv.a - contains object files without FRONTEND defined,
12- # for use only by the backend binaries
15+ # libpgcommon_shlib.a - contains object files with FRONTEND defined,
16+ # built suitably for use in shared libraries; for use
17+ # by frontend libraries
1318#
14- # You can also symlink/copy individual source files from this directory,
15- # to compile with different options. (libpq does that, because it needs
16- # to use -fPIC on some platforms.)
19+ # libpgcommon_srv.a - contains object files without FRONTEND defined,
20+ # for use only by the backend
1721#
1822# IDENTIFICATION
1923# src/common/Makefile
5256OBJS_COMMON += sha2.o
5357endif
5458
59+ # A few files are currently only built for frontend, not server
5560OBJS_FRONTEND = $(OBJS_COMMON ) fe_memutils.o file_utils.o restricted_token.o
5661
62+ # foo.o, foo_shlib.o, and foo_srv.o are all built from foo.c
63+ OBJS_SHLIB = $(OBJS_FRONTEND:%.o=%_shlib.o )
5764OBJS_SRV = $(OBJS_COMMON:%.o=%_srv.o )
5865
59- all : libpgcommon.a libpgcommon_srv.a
66+ all : libpgcommon.a libpgcommon_shlib.a libpgcommon_srv.a
6067
6168# libpgcommon is needed by some contrib
6269install : all installdirs
6370 $(INSTALL_STLIB ) libpgcommon.a ' $(DESTDIR)$(libdir)/libpgcommon.a'
71+ $(INSTALL_STLIB ) libpgcommon_shlib.a ' $(DESTDIR)$(libdir)/libpgcommon_shlib.a'
6472
6573installdirs :
6674 $(MKDIR_P ) ' $(DESTDIR)$(libdir)'
6775
6876uninstall :
6977 rm -f ' $(DESTDIR)$(libdir)/libpgcommon.a'
78+ rm -f ' $(DESTDIR)$(libdir)/libpgcommon_shlib.a'
7079
7180libpgcommon.a : $(OBJS_FRONTEND )
7281 rm -f $@
7382 $(AR ) $(AROPT ) $@ $^
7483
84+ #
85+ # Shared library versions of object files
86+ #
87+
88+ libpgcommon_shlib.a : $(OBJS_SHLIB )
89+ rm -f $@
90+ $(AR ) $(AROPT ) $@ $^
91+
92+ # Because this uses its own compilation rule, it doesn't use the
93+ # dependency tracking logic from Makefile.global. To make sure that
94+ # dependency tracking works anyway for the *_shlib.o files, depend on
95+ # their *.o siblings as well, which do have proper dependencies. It's
96+ # a hack that might fail someday if there is a *_shlib.o without a
97+ # corresponding *.o, but there seems little reason for that.
98+ % _shlib.o : % .c % .o
99+ $(CC ) $(CFLAGS ) $(CFLAGS_SL ) $(CPPFLAGS ) -c $< -o $@
100+
75101#
76102# Server versions of object files
77103#
@@ -87,16 +113,18 @@ libpgcommon_srv.a: $(OBJS_SRV)
87113# a hack that might fail someday if there is a *_srv.o without a
88114# corresponding *.o, but it works for now.
89115% _srv.o : % .c % .o
90- $(CC ) $(CFLAGS ) $(subst -DFRONTEND ,, $(CPPFLAGS ) ) -c $< -o $@
116+ $(CC ) $(CFLAGS ) $(subst -DFRONTEND,, $(CPPFLAGS ) ) -c $< -o $@
91117
92118# Dependencies of keywords.o need to be managed explicitly to make sure
93119# that you don't get broken parsing code, even in a non-enable-depend build.
94- # Note that gram.h isn't required for the frontend version of keywords.o.
120+ # Note that gram.h isn't required for the frontend versions of keywords.o.
95121$(top_builddir ) /src/include/parser/gram.h : $(top_srcdir ) /src/backend/parser/gram.y
96122 $(MAKE ) -C $(top_builddir ) /src/backend $(top_builddir ) /src/include/parser/gram.h
97123
98124keywords.o : $(top_srcdir ) /src/include/parser/kwlist.h
125+ keywords_shlib.o : $(top_srcdir ) /src/include/parser/kwlist.h
99126keywords_srv.o : $(top_builddir ) /src/include/parser/gram.h $(top_srcdir ) /src/include/parser/kwlist.h
100127
101128clean distclean maintainer-clean :
102- rm -f libpgcommon.a libpgcommon_srv.a $(OBJS_FRONTEND ) $(OBJS_SRV )
129+ rm -f libpgcommon.a libpgcommon_shlib.a libpgcommon_srv.a
130+ rm -f $(OBJS_FRONTEND ) $(OBJS_SHLIB ) $(OBJS_SRV )
0 commit comments