1#-------------------------------------------------------------------------
2#
3# Makefile
4#    Makefile for src/port
5#
6# These files are used by the Postgres backend, and also by frontend
7# programs.  Primarily, they are meant to provide portability on systems
8# with broken/missing library files.
9#
10# This makefile generates three outputs:
11#
12#	libpgport.a - contains object files with FRONTEND defined,
13#		for use by client applications
14#
15#	libpgport_shlib.a - contains object files with FRONTEND defined,
16#		built suitably for use in shared libraries; for use
17#		by frontend libraries
18#
19#	libpgport_srv.a - contains object files without FRONTEND defined,
20#		for use only by the backend
21#
22# LIBOBJS is set by configure (via Makefile.global) to be the list of object
23# files that are conditionally needed as determined by configure's probing.
24# OBJS adds additional object files that are always compiled.
25#
26# IDENTIFICATION
27#    src/port/Makefile
28#
29#-------------------------------------------------------------------------
30
31subdir = src/port
32top_builddir = ../..
33include $(top_builddir)/src/Makefile.global
34
35override CPPFLAGS := -I$(top_builddir)/src/port -DFRONTEND $(CPPFLAGS)
36LIBS += $(PTHREAD_LIBS)
37
38# If you add objects here, see also src/tools/msvc/Mkvcbuild.pm
39
40OBJS = \
41	$(LIBOBJS) \
42	$(PG_CRC32C_OBJS) \
43	bsearch_arg.o \
44	chklocale.o \
45	erand48.o \
46	inet_net_ntop.o \
47	noblock.o \
48	path.o \
49	pg_bitutils.o \
50	pg_strong_random.o \
51	pgcheckdir.o \
52	pgmkdirp.o \
53	pgsleep.o \
54	pgstrcasecmp.o \
55	pgstrsignal.o \
56	pqsignal.o \
57	qsort.o \
58	qsort_arg.o \
59	quotes.o \
60	snprintf.o \
61	strerror.o \
62	tar.o \
63	thread.o
64
65# libpgport.a, libpgport_shlib.a, and libpgport_srv.a contain the same files
66# foo.o, foo_shlib.o, and foo_srv.o are all built from foo.c
67OBJS_SHLIB = $(OBJS:%.o=%_shlib.o)
68OBJS_SRV = $(OBJS:%.o=%_srv.o)
69
70all: libpgport.a libpgport_shlib.a libpgport_srv.a
71
72# libpgport is needed by some contrib
73install: all installdirs
74	$(INSTALL_STLIB) libpgport.a '$(DESTDIR)$(libdir)/libpgport.a'
75	$(INSTALL_STLIB) libpgport_shlib.a '$(DESTDIR)$(libdir)/libpgport_shlib.a'
76
77installdirs:
78	$(MKDIR_P) '$(DESTDIR)$(libdir)'
79
80uninstall:
81	rm -f '$(DESTDIR)$(libdir)/libpgport.a'
82	rm -f '$(DESTDIR)$(libdir)/libpgport_shlib.a'
83
84libpgport.a: $(OBJS)
85	rm -f $@
86	$(AR) $(AROPT) $@ $^
87
88# thread.o and thread_shlib.o need PTHREAD_CFLAGS (but thread_srv.o does not)
89thread.o: CFLAGS+=$(PTHREAD_CFLAGS)
90thread_shlib.o: CFLAGS+=$(PTHREAD_CFLAGS)
91
92# all versions of pg_crc32c_sse42.o need CFLAGS_SSE42
93pg_crc32c_sse42.o: CFLAGS+=$(CFLAGS_SSE42)
94pg_crc32c_sse42_shlib.o: CFLAGS+=$(CFLAGS_SSE42)
95pg_crc32c_sse42_srv.o: CFLAGS+=$(CFLAGS_SSE42)
96
97# all versions of pg_crc32c_armv8.o need CFLAGS_ARMV8_CRC32C
98pg_crc32c_armv8.o: CFLAGS+=$(CFLAGS_ARMV8_CRC32C)
99pg_crc32c_armv8_shlib.o: CFLAGS+=$(CFLAGS_ARMV8_CRC32C)
100pg_crc32c_armv8_srv.o: CFLAGS+=$(CFLAGS_ARMV8_CRC32C)
101
102#
103# Shared library versions of object files
104#
105
106libpgport_shlib.a: $(OBJS_SHLIB)
107	rm -f $@
108	$(AR) $(AROPT) $@ $^
109
110# Because this uses its own compilation rule, it doesn't use the
111# dependency tracking logic from Makefile.global.  To make sure that
112# dependency tracking works anyway for the *_shlib.o files, depend on
113# their *.o siblings as well, which do have proper dependencies.  It's
114# a hack that might fail someday if there is a *_shlib.o without a
115# corresponding *.o, but there seems little reason for that.
116%_shlib.o: %.c %.o
117	$(CC) $(CFLAGS) $(CFLAGS_SL) $(CPPFLAGS) -c $< -o $@
118
119#
120# Server versions of object files
121#
122
123libpgport_srv.a: $(OBJS_SRV)
124	rm -f $@
125	$(AR) $(AROPT) $@ $^
126
127# Because this uses its own compilation rule, it doesn't use the
128# dependency tracking logic from Makefile.global.  To make sure that
129# dependency tracking works anyway for the *_srv.o files, depend on
130# their *.o siblings as well, which do have proper dependencies.  It's
131# a hack that might fail someday if there is a *_srv.o without a
132# corresponding *.o, but it works for now (and those would probably go
133# into src/backend/port/ anyway).
134%_srv.o: %.c %.o
135	$(CC) $(CFLAGS) $(subst -DFRONTEND,, $(CPPFLAGS)) -c $< -o $@
136
137# Dependency is to ensure that path changes propagate
138
139path.o: path.c pg_config_paths.h
140
141path_shlib.o: path.c pg_config_paths.h
142
143path_srv.o: path.c pg_config_paths.h
144
145# We create a separate file rather than put these in pg_config.h
146# because many of these values come from makefiles and are not
147# available to configure.
148pg_config_paths.h: $(top_builddir)/src/Makefile.global
149	echo "#define PGBINDIR \"$(bindir)\"" >$@
150	echo "#define PGSHAREDIR \"$(datadir)\"" >>$@
151	echo "#define SYSCONFDIR \"$(sysconfdir)\"" >>$@
152	echo "#define INCLUDEDIR \"$(includedir)\"" >>$@
153	echo "#define PKGINCLUDEDIR \"$(pkgincludedir)\"" >>$@
154	echo "#define INCLUDEDIRSERVER \"$(includedir_server)\"" >>$@
155	echo "#define LIBDIR \"$(libdir)\"" >>$@
156	echo "#define PKGLIBDIR \"$(pkglibdir)\"" >>$@
157	echo "#define LOCALEDIR \"$(localedir)\"" >>$@
158	echo "#define DOCDIR \"$(docdir)\"" >>$@
159	echo "#define HTMLDIR \"$(htmldir)\"" >>$@
160	echo "#define MANDIR \"$(mandir)\"" >>$@
161
162clean distclean maintainer-clean:
163	rm -f libpgport.a libpgport_shlib.a libpgport_srv.a
164	rm -f $(OBJS) $(OBJS_SHLIB) $(OBJS_SRV) pg_config_paths.h
165