1#-------------------------------------------------------------------------
2#
3# Makefile
4#    Makefile for src/common
5#
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:
11#
12#	libpgcommon.a - contains object files with FRONTEND defined,
13#		for use by client applications
14#
15#	libpgcommon_shlib.a - contains object files with FRONTEND defined,
16#		built suitably for use in shared libraries; for use
17#		by frontend libraries
18#
19#	libpgcommon_srv.a - contains object files without FRONTEND defined,
20#		for use only by the backend
21#
22# IDENTIFICATION
23#    src/common/Makefile
24#
25#-------------------------------------------------------------------------
26
27subdir = src/common
28top_builddir = ../..
29include $(top_builddir)/src/Makefile.global
30
31# don't include subdirectory-path-dependent -I and -L switches
32STD_CPPFLAGS := $(filter-out -I$(top_srcdir)/src/include -I$(top_builddir)/src/include,$(CPPFLAGS))
33STD_LDFLAGS := $(filter-out -L$(top_builddir)/src/common -L$(top_builddir)/src/port,$(LDFLAGS))
34override CPPFLAGS += -DVAL_CC="\"$(CC)\""
35override CPPFLAGS += -DVAL_CPPFLAGS="\"$(STD_CPPFLAGS)\""
36override CPPFLAGS += -DVAL_CFLAGS="\"$(CFLAGS)\""
37override CPPFLAGS += -DVAL_CFLAGS_SL="\"$(CFLAGS_SL)\""
38override CPPFLAGS += -DVAL_LDFLAGS="\"$(STD_LDFLAGS)\""
39override CPPFLAGS += -DVAL_LDFLAGS_EX="\"$(LDFLAGS_EX)\""
40override CPPFLAGS += -DVAL_LDFLAGS_SL="\"$(LDFLAGS_SL)\""
41override CPPFLAGS += -DVAL_LIBS="\"$(LIBS)\""
42
43override CPPFLAGS := -DFRONTEND -I. -I$(top_srcdir)/src/common $(CPPFLAGS)
44LIBS += $(PTHREAD_LIBS)
45
46# If you add objects here, see also src/tools/msvc/Mkvcbuild.pm
47
48OBJS_COMMON = \
49	archive.o \
50	base64.o \
51	checksum_helper.o \
52	config_info.o \
53	controldata_utils.o \
54	d2s.o \
55	encnames.o \
56	exec.o \
57	f2s.o \
58	file_perm.o \
59	hashfn.o \
60	ip.o \
61	jsonapi.o \
62	keywords.o \
63	kwlookup.o \
64	link-canary.o \
65	md5.o \
66	pg_lzcompress.o \
67	pgfnames.o \
68	psprintf.o \
69	relpath.o \
70	rmtree.o \
71	saslprep.o \
72	scram-common.o \
73	string.o \
74	stringinfo.o \
75	unicode_norm.o \
76	username.o \
77	wait_error.o \
78	wchar.o
79
80ifeq ($(with_openssl),yes)
81OBJS_COMMON += \
82	protocol_openssl.o \
83	sha2_openssl.o
84else
85OBJS_COMMON += sha2.o
86endif
87
88# A few files are currently only built for frontend, not server
89# (Mkvcbuild.pm has a copy of this list, too)
90OBJS_FRONTEND = \
91	$(OBJS_COMMON) \
92	fe_memutils.o \
93	file_utils.o \
94	logging.o \
95	restricted_token.o
96
97# foo.o, foo_shlib.o, and foo_srv.o are all built from foo.c
98OBJS_SHLIB = $(OBJS_FRONTEND:%.o=%_shlib.o)
99OBJS_SRV = $(OBJS_COMMON:%.o=%_srv.o)
100
101# where to find gen_keywordlist.pl and subsidiary files
102TOOLSDIR = $(top_srcdir)/src/tools
103GEN_KEYWORDLIST = $(PERL) -I $(TOOLSDIR) $(TOOLSDIR)/gen_keywordlist.pl
104GEN_KEYWORDLIST_DEPS = $(TOOLSDIR)/gen_keywordlist.pl $(TOOLSDIR)/PerfectHash.pm
105
106all: libpgcommon.a libpgcommon_shlib.a libpgcommon_srv.a
107
108distprep: kwlist_d.h
109
110# libpgcommon is needed by some contrib
111install: all installdirs
112	$(INSTALL_STLIB) libpgcommon.a '$(DESTDIR)$(libdir)/libpgcommon.a'
113	$(INSTALL_STLIB) libpgcommon_shlib.a '$(DESTDIR)$(libdir)/libpgcommon_shlib.a'
114
115installdirs:
116	$(MKDIR_P) '$(DESTDIR)$(libdir)'
117
118uninstall:
119	rm -f '$(DESTDIR)$(libdir)/libpgcommon.a'
120	rm -f '$(DESTDIR)$(libdir)/libpgcommon_shlib.a'
121
122libpgcommon.a: $(OBJS_FRONTEND)
123	rm -f $@
124	$(AR) $(AROPT) $@ $^
125
126#
127# Shared library versions of object files
128#
129
130libpgcommon_shlib.a: $(OBJS_SHLIB)
131	rm -f $@
132	$(AR) $(AROPT) $@ $^
133
134# Because this uses its own compilation rule, it doesn't use the
135# dependency tracking logic from Makefile.global.  To make sure that
136# dependency tracking works anyway for the *_shlib.o files, depend on
137# their *.o siblings as well, which do have proper dependencies.  It's
138# a hack that might fail someday if there is a *_shlib.o without a
139# corresponding *.o, but there seems little reason for that.
140%_shlib.o: %.c %.o
141	$(CC) $(CFLAGS) $(CFLAGS_SL) $(CPPFLAGS) -c $< -o $@
142
143#
144# Server versions of object files
145#
146
147libpgcommon_srv.a: $(OBJS_SRV)
148	rm -f $@
149	$(AR) $(AROPT) $@ $^
150
151# Because this uses its own compilation rule, it doesn't use the
152# dependency tracking logic from Makefile.global.  To make sure that
153# dependency tracking works anyway for the *_srv.o files, depend on
154# their *.o siblings as well, which do have proper dependencies.  It's
155# a hack that might fail someday if there is a *_srv.o without a
156# corresponding *.o, but it works for now.
157%_srv.o: %.c %.o
158	$(CC) $(CFLAGS) $(subst -DFRONTEND,, $(CPPFLAGS)) -c $< -o $@
159
160# generate SQL keyword lookup table to be included into keywords*.o.
161kwlist_d.h: $(top_srcdir)/src/include/parser/kwlist.h $(GEN_KEYWORDLIST_DEPS)
162	$(GEN_KEYWORDLIST) --extern $<
163
164# Dependencies of keywords*.o need to be managed explicitly to make sure
165# that you don't get broken parsing code, even in a non-enable-depend build.
166keywords.o keywords_shlib.o keywords_srv.o: kwlist_d.h
167
168# The code imported from Ryu gets a pass on declaration-after-statement,
169# in order to keep it more closely aligned with its upstream.
170RYU_FILES = d2s.o f2s.o
171RYU_OBJS = $(RYU_FILES) $(RYU_FILES:%.o=%_shlib.o) $(RYU_FILES:%.o=%_srv.o)
172
173$(RYU_OBJS): CFLAGS += $(PERMIT_DECLARATION_AFTER_STATEMENT)
174
175# kwlist_d.h is in the distribution tarball, so it is not cleaned here.
176clean distclean:
177	rm -f libpgcommon.a libpgcommon_shlib.a libpgcommon_srv.a
178	rm -f $(OBJS_FRONTEND) $(OBJS_SHLIB) $(OBJS_SRV)
179
180maintainer-clean: distclean
181	rm -f kwlist_d.h
182