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
38OBJS = $(LIBOBJS) $(PG_CRC32C_OBJS) chklocale.o erand48.o inet_net_ntop.o \
39	noblock.o path.o pg_bitutils.o pgcheckdir.o pgmkdirp.o pgsleep.o \
40	pg_strong_random.o pgstrcasecmp.o pgstrsignal.o pqsignal.o \
41	qsort.o qsort_arg.o quotes.o snprintf.o sprompt.o strerror.o \
42	tar.o thread.o
43
44# libpgport.a, libpgport_shlib.a, and libpgport_srv.a contain the same files
45# foo.o, foo_shlib.o, and foo_srv.o are all built from foo.c
46OBJS_SHLIB = $(OBJS:%.o=%_shlib.o)
47OBJS_SRV = $(OBJS:%.o=%_srv.o)
48
49all: libpgport.a libpgport_shlib.a libpgport_srv.a
50
51# libpgport is needed by some contrib
52install: all installdirs
53	$(INSTALL_STLIB) libpgport.a '$(DESTDIR)$(libdir)/libpgport.a'
54	$(INSTALL_STLIB) libpgport_shlib.a '$(DESTDIR)$(libdir)/libpgport_shlib.a'
55
56installdirs:
57	$(MKDIR_P) '$(DESTDIR)$(libdir)'
58
59uninstall:
60	rm -f '$(DESTDIR)$(libdir)/libpgport.a'
61	rm -f '$(DESTDIR)$(libdir)/libpgport_shlib.a'
62
63libpgport.a: $(OBJS)
64	rm -f $@
65	$(AR) $(AROPT) $@ $^
66
67# thread.o and thread_shlib.o need PTHREAD_CFLAGS (but thread_srv.o does not)
68thread.o: CFLAGS+=$(PTHREAD_CFLAGS)
69thread_shlib.o: CFLAGS+=$(PTHREAD_CFLAGS)
70
71# all versions of pg_crc32c_sse42.o need CFLAGS_SSE42
72pg_crc32c_sse42.o: CFLAGS+=$(CFLAGS_SSE42)
73pg_crc32c_sse42_shlib.o: CFLAGS+=$(CFLAGS_SSE42)
74pg_crc32c_sse42_srv.o: CFLAGS+=$(CFLAGS_SSE42)
75
76# all versions of pg_crc32c_armv8.o need CFLAGS_ARMV8_CRC32C
77pg_crc32c_armv8.o: CFLAGS+=$(CFLAGS_ARMV8_CRC32C)
78pg_crc32c_armv8_shlib.o: CFLAGS+=$(CFLAGS_ARMV8_CRC32C)
79pg_crc32c_armv8_srv.o: CFLAGS+=$(CFLAGS_ARMV8_CRC32C)
80
81#
82# Shared library versions of object files
83#
84
85libpgport_shlib.a: $(OBJS_SHLIB)
86	rm -f $@
87	$(AR) $(AROPT) $@ $^
88
89# Because this uses its own compilation rule, it doesn't use the
90# dependency tracking logic from Makefile.global.  To make sure that
91# dependency tracking works anyway for the *_shlib.o files, depend on
92# their *.o siblings as well, which do have proper dependencies.  It's
93# a hack that might fail someday if there is a *_shlib.o without a
94# corresponding *.o, but there seems little reason for that.
95%_shlib.o: %.c %.o
96	$(CC) $(CFLAGS) $(CFLAGS_SL) $(CPPFLAGS) -c $< -o $@
97
98#
99# Server versions of object files
100#
101
102libpgport_srv.a: $(OBJS_SRV)
103	rm -f $@
104	$(AR) $(AROPT) $@ $^
105
106# Because this uses its own compilation rule, it doesn't use the
107# dependency tracking logic from Makefile.global.  To make sure that
108# dependency tracking works anyway for the *_srv.o files, depend on
109# their *.o siblings as well, which do have proper dependencies.  It's
110# a hack that might fail someday if there is a *_srv.o without a
111# corresponding *.o, but it works for now (and those would probably go
112# into src/backend/port/ anyway).
113%_srv.o: %.c %.o
114	$(CC) $(CFLAGS) $(subst -DFRONTEND,, $(CPPFLAGS)) -c $< -o $@
115
116# Dependency is to ensure that path changes propagate
117
118path.o: path.c pg_config_paths.h
119
120path_shlib.o: path.c pg_config_paths.h
121
122path_srv.o: path.c pg_config_paths.h
123
124# We create a separate file rather than put these in pg_config.h
125# because many of these values come from makefiles and are not
126# available to configure.
127pg_config_paths.h: $(top_builddir)/src/Makefile.global
128	echo "#define PGBINDIR \"$(bindir)\"" >$@
129	echo "#define PGSHAREDIR \"$(datadir)\"" >>$@
130	echo "#define SYSCONFDIR \"$(sysconfdir)\"" >>$@
131	echo "#define INCLUDEDIR \"$(includedir)\"" >>$@
132	echo "#define PKGINCLUDEDIR \"$(pkgincludedir)\"" >>$@
133	echo "#define INCLUDEDIRSERVER \"$(includedir_server)\"" >>$@
134	echo "#define LIBDIR \"$(libdir)\"" >>$@
135	echo "#define PKGLIBDIR \"$(pkglibdir)\"" >>$@
136	echo "#define LOCALEDIR \"$(localedir)\"" >>$@
137	echo "#define DOCDIR \"$(docdir)\"" >>$@
138	echo "#define HTMLDIR \"$(htmldir)\"" >>$@
139	echo "#define MANDIR \"$(mandir)\"" >>$@
140
141clean distclean maintainer-clean:
142	rm -f libpgport.a libpgport_shlib.a libpgport_srv.a
143	rm -f $(OBJS) $(OBJS_SHLIB) $(OBJS_SRV) pg_config_paths.h
144