1 #-------------------------------------------------------------------------
4 # Makefile for src/common
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.
10 # This makefile generates three outputs:
12 # libpgcommon.a - contains object files with FRONTEND defined,
13 # for use by client applications
15 # libpgcommon_shlib.a - contains object files with FRONTEND defined,
16 # built suitably for use in shared libraries; for use
17 # by frontend libraries
19 # libpgcommon_srv.a - contains object files without FRONTEND defined,
20 # for use only by the backend
25 #-------------------------------------------------------------------------
29 include $(top_builddir
)/src
/Makefile.global
31 # don't include subdirectory-path-dependent -I and -L switches
32 STD_CPPFLAGS
:= $(filter-out -I
$(top_srcdir
)/src
/include -I
$(top_builddir
)/src
/include,$(CPPFLAGS
))
33 STD_LDFLAGS
:= $(filter-out -L
$(top_builddir
)/src
/common
-L
$(top_builddir
)/src
/port
,$(LDFLAGS
))
34 override CPPFLAGS
+= -DVAL_CC
="\"$(CC)\""
35 override CPPFLAGS
+= -DVAL_CPPFLAGS
="\"$(STD_CPPFLAGS)\""
36 override CPPFLAGS
+= -DVAL_CFLAGS
="\"$(CFLAGS)\""
37 override CPPFLAGS
+= -DVAL_CFLAGS_SL
="\"$(CFLAGS_SL)\""
38 override CPPFLAGS
+= -DVAL_LDFLAGS
="\"$(STD_LDFLAGS)\""
39 override CPPFLAGS
+= -DVAL_LDFLAGS_EX
="\"$(LDFLAGS_EX)\""
40 override CPPFLAGS
+= -DVAL_LDFLAGS_SL
="\"$(LDFLAGS_SL)\""
41 override CPPFLAGS
+= -DVAL_LIBS
="\"$(LIBS)\""
43 override CPPFLAGS
:= -DFRONTEND
-I.
-I
$(top_srcdir
)/src
/common
$(CPPFLAGS
)
44 LIBS
+= $(PTHREAD_LIBS
)
88 ifeq ($(with_ssl
),openssl
)
90 cryptohash_openssl.o \
101 # A few files are currently only built for frontend, not server.
102 # logging.c is excluded from OBJS_FRONTEND_SHLIB (shared library) as
103 # a matter of policy, because it is not appropriate for general purpose
104 # libraries such as libpq to report errors directly. fe_memutils.c is
105 # excluded because libpq must not exit() on allocation failure.
107 # The excluded files for _shlib builds are pulled into their own static
108 # library, for the benefit of test programs that need not follow the
110 OBJS_FRONTEND_SHLIB
= \
114 OBJS_EXCLUDED_SHLIB
= \
118 $(OBJS_FRONTEND_SHLIB
) \
119 $(OBJS_EXCLUDED_SHLIB
)
121 # foo.o, foo_shlib.o, and foo_srv.o are all built from foo.c
122 OBJS_SHLIB
= $(OBJS_FRONTEND_SHLIB
:%.o
=%_shlib.o
)
123 OBJS_SRV
= $(OBJS_COMMON
:%.o
=%_srv.o
)
125 # where to find gen_keywordlist.pl and subsidiary files
126 TOOLSDIR
= $(top_srcdir
)/src
/tools
127 GEN_KEYWORDLIST
= $(PERL
) -I
$(TOOLSDIR
) $(TOOLSDIR
)/gen_keywordlist.pl
128 GEN_KEYWORDLIST_DEPS
= $(TOOLSDIR
)/gen_keywordlist.pl
$(TOOLSDIR
)/PerfectHash.pm
130 all: libpgcommon.a libpgcommon_shlib.a libpgcommon_srv.a libpgcommon_excluded_shlib.a
132 # libpgcommon is needed by some contrib
133 install: all installdirs
134 $(INSTALL_STLIB
) libpgcommon.a
'$(DESTDIR)$(libdir)/libpgcommon.a'
135 $(INSTALL_STLIB
) libpgcommon_shlib.a
'$(DESTDIR)$(libdir)/libpgcommon_shlib.a'
138 $(MKDIR_P
) '$(DESTDIR)$(libdir)'
141 rm -f
'$(DESTDIR)$(libdir)/libpgcommon.a'
142 rm -f
'$(DESTDIR)$(libdir)/libpgcommon_shlib.a'
144 libpgcommon.a
: $(OBJS_FRONTEND
)
149 # Files in libpgcommon.a should use/export the "xxx_private" versions
150 # of pg_char_to_encoding() and friends.
152 $(OBJS_FRONTEND
): CPPFLAGS
+= -DUSE_PRIVATE_ENCODING_FUNCS
156 # Shared library versions of object files
159 libpgcommon_shlib.a
: $(OBJS_SHLIB
)
163 # The JSON API normally exits on out-of-memory; disable that behavior for shared
164 # library builds. This requires libpq's pqexpbuffer.h.
165 jsonapi_shlib.o
: override CPPFLAGS
+= -DJSONAPI_USE_PQEXPBUFFER
166 jsonapi_shlib.o
: override CPPFLAGS
+= -I
$(libpq_srcdir
)
168 # Because this uses its own compilation rule, it doesn't use the
169 # dependency tracking logic from Makefile.global. To make sure that
170 # dependency tracking works anyway for the *_shlib.o files, depend on
171 # their *.o siblings as well, which do have proper dependencies. It's
172 # a hack that might fail someday if there is a *_shlib.o without a
173 # corresponding *.o, but there seems little reason for that.
175 $(CC
) $(CFLAGS
) $(CFLAGS_SL
) $(CPPFLAGS
) -c
$< -o
$@
177 libpgcommon_excluded_shlib.a
: $(OBJS_EXCLUDED_SHLIB
)
182 # Server versions of object files
185 libpgcommon_srv.a
: $(OBJS_SRV
)
189 # Because this uses its own compilation rule, it doesn't use the
190 # dependency tracking logic from Makefile.global. To make sure that
191 # dependency tracking works anyway for the *_srv.o files, depend on
192 # their *.o siblings as well, which do have proper dependencies. It's
193 # a hack that might fail someday if there is a *_srv.o without a
194 # corresponding *.o, but it works for now.
196 $(CC
) $(CFLAGS
) $(subst -DFRONTEND
,, $(CPPFLAGS
)) -c
$< -o
$@
198 # generate SQL keyword lookup table to be included into keywords*.o.
199 kwlist_d.h
: $(top_srcdir
)/src
/include/parser
/kwlist.h
$(GEN_KEYWORDLIST_DEPS
)
200 $(GEN_KEYWORDLIST
) --extern
$<
202 # Dependencies of keywords*.o need to be managed explicitly to make sure
203 # that you don't get broken parsing code, even in a non-enable-depend build.
204 keywords.o keywords_shlib.o keywords_srv.o
: kwlist_d.h
206 # The code imported from Ryu gets a pass on declaration-after-statement,
207 # in order to keep it more closely aligned with its upstream.
208 RYU_FILES
= d2s.o f2s.o
209 RYU_OBJS
= $(RYU_FILES
) $(RYU_FILES
:%.o
=%_shlib.o
) $(RYU_FILES
:%.o
=%_srv.o
)
211 $(RYU_OBJS
): CFLAGS
+= $(PERMIT_DECLARATION_AFTER_STATEMENT
)
214 rm -f libpgcommon.a libpgcommon_shlib.a libpgcommon_srv.a libpgcommon_excluded_shlib.a
215 rm -f
$(OBJS_FRONTEND
) $(OBJS_SHLIB
) $(OBJS_SRV
)