2002-07-18 06:13:59 +02:00
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
2004-10-04 15:43:59 +02:00
|
|
|
# Makefile
|
2018-09-27 17:23:43 +02:00
|
|
|
# Makefile for src/port
|
2002-07-18 06:13:59 +02:00
|
|
|
#
|
2018-09-27 17:23:43 +02:00
|
|
|
# These files are used by the Postgres backend, and also by frontend
|
|
|
|
# programs. Primarily, they are meant to provide portability on systems
|
|
|
|
# with broken/missing library files.
|
2004-10-04 15:43:59 +02:00
|
|
|
#
|
2018-09-27 17:23:43 +02:00
|
|
|
# This makefile generates three outputs:
|
2004-10-04 15:43:59 +02:00
|
|
|
#
|
|
|
|
# libpgport.a - contains object files with FRONTEND defined,
|
2018-09-27 17:23:43 +02:00
|
|
|
# for use by client applications
|
|
|
|
#
|
|
|
|
# libpgport_shlib.a - contains object files with FRONTEND defined,
|
|
|
|
# built suitably for use in shared libraries; for use
|
|
|
|
# by libpq and other frontend libraries
|
2004-10-04 15:43:59 +02:00
|
|
|
#
|
|
|
|
# libpgport_srv.a - contains object files without FRONTEND defined,
|
2018-09-27 17:23:43 +02:00
|
|
|
# for use only by the backend
|
2004-10-04 15:43:59 +02:00
|
|
|
#
|
2010-12-11 01:42:44 +01:00
|
|
|
# LIBOBJS is set by configure (via Makefile.global) to be the list of object
|
|
|
|
# files that are conditionally needed as determined by configure's probing.
|
2007-09-29 00:25:49 +02:00
|
|
|
# OBJS adds additional object files that are always compiled.
|
|
|
|
#
|
2002-07-18 06:13:59 +02:00
|
|
|
# IDENTIFICATION
|
2010-09-20 22:08:53 +02:00
|
|
|
# src/port/Makefile
|
2002-07-18 06:13:59 +02:00
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
|
|
|
|
subdir = src/port
|
|
|
|
top_builddir = ../..
|
|
|
|
include $(top_builddir)/src/Makefile.global
|
|
|
|
|
2004-10-04 15:43:59 +02:00
|
|
|
override CPPFLAGS := -I$(top_builddir)/src/port -DFRONTEND $(CPPFLAGS)
|
2004-05-30 16:07:47 +02:00
|
|
|
LIBS += $(PTHREAD_LIBS)
|
2004-05-22 04:15:08 +02:00
|
|
|
|
Use Intel SSE 4.2 CRC instructions where available.
Modern x86 and x86-64 processors with SSE 4.2 support have special
instructions, crc32b and crc32q, for calculating CRC-32C. They greatly
speed up CRC calculation.
Whether the instructions can be used or not depends on the compiler and the
target architecture. If generation of SSE 4.2 instructions is allowed for
the target (-msse4.2 flag on gcc and clang), use them. If they are not
allowed by default, but the compiler supports the -msse4.2 flag to enable
them, compile just the CRC-32C function with -msse4.2 flag, and check at
runtime whether the processor we're running on supports it. If it doesn't,
fall back to the slicing-by-8 algorithm. (With the common defaults on
current operating systems, the runtime-check variant is what you get in
practice.)
Abhijit Menon-Sen, heavily modified by me, reviewed by Andres Freund.
2015-04-14 16:05:03 +02:00
|
|
|
OBJS = $(LIBOBJS) $(PG_CRC32C_OBJS) chklocale.o erand48.o inet_net_ntop.o \
|
2015-02-09 10:17:56 +01:00
|
|
|
noblock.o path.o pgcheckdir.o pgmkdirp.o pgsleep.o \
|
2016-10-18 15:28:23 +02:00
|
|
|
pgstrcasecmp.o pqsignal.o \
|
2018-09-26 19:13:57 +02:00
|
|
|
qsort.o qsort_arg.o quotes.o snprintf.o sprompt.o strerror.o \
|
|
|
|
tar.o thread.o
|
2010-12-11 01:42:44 +01:00
|
|
|
|
Replace PostmasterRandom() with a stronger source, second attempt.
This adds a new routine, pg_strong_random() for generating random bytes,
for use in both frontend and backend. At the moment, it's only used in
the backend, but the upcoming SCRAM authentication patches need strong
random numbers in libpq as well.
pg_strong_random() is based on, and replaces, the existing implementation
in pgcrypto. It can acquire strong random numbers from a number of sources,
depending on what's available:
- OpenSSL RAND_bytes(), if built with OpenSSL
- On Windows, the native cryptographic functions are used
- /dev/urandom
Unlike the current pgcrypto function, the source is chosen by configure.
That makes it easier to test different implementations, and ensures that
we don't accidentally fall back to a less secure implementation, if the
primary source fails. All of those methods are quite reliable, it would be
pretty surprising for them to fail, so we'd rather find out by failing
hard.
If no strong random source is available, we fall back to using erand48(),
seeded from current timestamp, like PostmasterRandom() was. That isn't
cryptographically secure, but allows us to still work on platforms that
don't have any of the above stronger sources. Because it's not very secure,
the built-in implementation is only used if explicitly requested with
--disable-strong-random.
This replaces the more complicated Fortuna algorithm we used to have in
pgcrypto, which is unfortunate, but all modern platforms have /dev/urandom,
so it doesn't seem worth the maintenance effort to keep that. pgcrypto
functions that require strong random numbers will be disabled with
--disable-strong-random.
Original patch by Magnus Hagander, tons of further work by Michael Paquier
and me.
Discussion: https://www.postgresql.org/message-id/CAB7nPqRy3krN8quR9XujMVVHYtXJ0_60nqgVc6oUk8ygyVkZsA@mail.gmail.com
Discussion: https://www.postgresql.org/message-id/CAB7nPqRWkNYRRPJA7-cF+LfroYV10pvjdz6GNvxk-Eee9FypKA@mail.gmail.com
2016-12-05 12:42:59 +01:00
|
|
|
ifeq ($(enable_strong_random), yes)
|
|
|
|
OBJS += pg_strong_random.o
|
|
|
|
endif
|
|
|
|
|
2018-09-27 17:23:43 +02:00
|
|
|
# libpgport.a, libpgport_shlib.a, and libpgport_srv.a contain the same files
|
|
|
|
# foo.o, foo_shlib.o, and foo_srv.o are all built from foo.c
|
|
|
|
OBJS_SHLIB = $(OBJS:%.o=%_shlib.o)
|
2007-09-29 00:25:49 +02:00
|
|
|
OBJS_SRV = $(OBJS:%.o=%_srv.o)
|
2004-10-04 15:43:59 +02:00
|
|
|
|
2018-09-27 17:23:43 +02:00
|
|
|
all: libpgport.a libpgport_shlib.a libpgport_srv.a
|
2002-07-18 06:13:59 +02:00
|
|
|
|
2004-08-20 22:13:10 +02:00
|
|
|
# libpgport is needed by some contrib
|
2018-09-27 17:23:43 +02:00
|
|
|
# currently we don't install libpgport_shlib.a, maybe we should?
|
2005-12-09 22:19:36 +01:00
|
|
|
install: all installdirs
|
|
|
|
$(INSTALL_STLIB) libpgport.a '$(DESTDIR)$(libdir)/libpgport.a'
|
|
|
|
|
|
|
|
installdirs:
|
2009-08-27 00:24:44 +02:00
|
|
|
$(MKDIR_P) '$(DESTDIR)$(libdir)'
|
2004-08-20 22:13:10 +02:00
|
|
|
|
|
|
|
uninstall:
|
2005-12-09 22:19:36 +01:00
|
|
|
rm -f '$(DESTDIR)$(libdir)/libpgport.a'
|
2004-08-20 22:13:10 +02:00
|
|
|
|
2007-09-29 00:25:49 +02:00
|
|
|
libpgport.a: $(OBJS)
|
2015-03-01 19:05:23 +01:00
|
|
|
rm -f $@
|
2003-10-24 22:31:43 +02:00
|
|
|
$(AR) $(AROPT) $@ $^
|
2002-07-27 22:10:05 +02:00
|
|
|
|
2018-09-27 17:23:43 +02:00
|
|
|
# thread.o and thread_shlib.o need PTHREAD_CFLAGS (but thread_srv.o does not)
|
2012-04-29 19:59:12 +02:00
|
|
|
thread.o: CFLAGS+=$(PTHREAD_CFLAGS)
|
2018-09-27 17:23:43 +02:00
|
|
|
thread_shlib.o: CFLAGS+=$(PTHREAD_CFLAGS)
|
2003-06-14 16:35:42 +02:00
|
|
|
|
2018-09-27 17:23:43 +02:00
|
|
|
# all versions of pg_crc32c_sse42.o need CFLAGS_SSE42
|
Use Intel SSE 4.2 CRC instructions where available.
Modern x86 and x86-64 processors with SSE 4.2 support have special
instructions, crc32b and crc32q, for calculating CRC-32C. They greatly
speed up CRC calculation.
Whether the instructions can be used or not depends on the compiler and the
target architecture. If generation of SSE 4.2 instructions is allowed for
the target (-msse4.2 flag on gcc and clang), use them. If they are not
allowed by default, but the compiler supports the -msse4.2 flag to enable
them, compile just the CRC-32C function with -msse4.2 flag, and check at
runtime whether the processor we're running on supports it. If it doesn't,
fall back to the slicing-by-8 algorithm. (With the common defaults on
current operating systems, the runtime-check variant is what you get in
practice.)
Abhijit Menon-Sen, heavily modified by me, reviewed by Andres Freund.
2015-04-14 16:05:03 +02:00
|
|
|
pg_crc32c_sse42.o: CFLAGS+=$(CFLAGS_SSE42)
|
2018-09-27 17:23:43 +02:00
|
|
|
pg_crc32c_sse42_shlib.o: CFLAGS+=$(CFLAGS_SSE42)
|
Use Intel SSE 4.2 CRC instructions where available.
Modern x86 and x86-64 processors with SSE 4.2 support have special
instructions, crc32b and crc32q, for calculating CRC-32C. They greatly
speed up CRC calculation.
Whether the instructions can be used or not depends on the compiler and the
target architecture. If generation of SSE 4.2 instructions is allowed for
the target (-msse4.2 flag on gcc and clang), use them. If they are not
allowed by default, but the compiler supports the -msse4.2 flag to enable
them, compile just the CRC-32C function with -msse4.2 flag, and check at
runtime whether the processor we're running on supports it. If it doesn't,
fall back to the slicing-by-8 algorithm. (With the common defaults on
current operating systems, the runtime-check variant is what you get in
practice.)
Abhijit Menon-Sen, heavily modified by me, reviewed by Andres Freund.
2015-04-14 16:05:03 +02:00
|
|
|
pg_crc32c_sse42_srv.o: CFLAGS+=$(CFLAGS_SSE42)
|
|
|
|
|
2018-09-27 17:23:43 +02:00
|
|
|
# all versions of pg_crc32c_armv8.o need CFLAGS_ARMV8_CRC32C
|
Use ARMv8 CRC instructions where available.
ARMv8 introduced special CPU instructions for calculating CRC-32C. Use
them, when available, for speed.
Like with the similar Intel CRC instructions, several factors affect
whether the instructions can be used. The compiler intrinsics for them must
be supported by the compiler, and the instructions must be supported by the
target architecture. If the compilation target architecture does not
support the instructions, but adding "-march=armv8-a+crc" makes them
available, then we compile the code with a runtime check to determine if
the host we're running on supports them or not.
For the runtime check, use glibc getauxval() function. Unfortunately,
that's not very portable, but I couldn't find any more portable way to do
it. If getauxval() is not available, the CRC instructions will still be
used if the target architecture supports them without any additional
compiler flags, but the runtime check will not be available.
Original patch by Yuqi Gu, heavily modified by me. Reviewed by Andres
Freund, Thomas Munro.
Discussion: https://www.postgresql.org/message-id/HE1PR0801MB1323D171938EABC04FFE7FA9E3110%40HE1PR0801MB1323.eurprd08.prod.outlook.com
2018-04-04 11:22:45 +02:00
|
|
|
pg_crc32c_armv8.o: CFLAGS+=$(CFLAGS_ARMV8_CRC32C)
|
2018-09-27 17:23:43 +02:00
|
|
|
pg_crc32c_armv8_shlib.o: CFLAGS+=$(CFLAGS_ARMV8_CRC32C)
|
Use ARMv8 CRC instructions where available.
ARMv8 introduced special CPU instructions for calculating CRC-32C. Use
them, when available, for speed.
Like with the similar Intel CRC instructions, several factors affect
whether the instructions can be used. The compiler intrinsics for them must
be supported by the compiler, and the instructions must be supported by the
target architecture. If the compilation target architecture does not
support the instructions, but adding "-march=armv8-a+crc" makes them
available, then we compile the code with a runtime check to determine if
the host we're running on supports them or not.
For the runtime check, use glibc getauxval() function. Unfortunately,
that's not very portable, but I couldn't find any more portable way to do
it. If getauxval() is not available, the CRC instructions will still be
used if the target architecture supports them without any additional
compiler flags, but the runtime check will not be available.
Original patch by Yuqi Gu, heavily modified by me. Reviewed by Andres
Freund, Thomas Munro.
Discussion: https://www.postgresql.org/message-id/HE1PR0801MB1323D171938EABC04FFE7FA9E3110%40HE1PR0801MB1323.eurprd08.prod.outlook.com
2018-04-04 11:22:45 +02:00
|
|
|
pg_crc32c_armv8_srv.o: CFLAGS+=$(CFLAGS_ARMV8_CRC32C)
|
|
|
|
|
2018-09-27 17:23:43 +02:00
|
|
|
#
|
|
|
|
# Shared library versions of object files
|
|
|
|
#
|
|
|
|
|
|
|
|
libpgport_shlib.a: $(OBJS_SHLIB)
|
|
|
|
rm -f $@
|
|
|
|
$(AR) $(AROPT) $@ $^
|
|
|
|
|
|
|
|
# Because this uses its own compilation rule, it doesn't use the
|
|
|
|
# dependency tracking logic from Makefile.global. To make sure that
|
|
|
|
# dependency tracking works anyway for the *_shlib.o files, depend on
|
|
|
|
# their *.o siblings as well, which do have proper dependencies. It's
|
|
|
|
# a hack that might fail someday if there is a *_shlib.o without a
|
|
|
|
# corresponding *.o, but there seems little reason for that.
|
|
|
|
%_shlib.o: %.c %.o
|
|
|
|
$(CC) $(CFLAGS) $(CFLAGS_SL) $(CPPFLAGS) -c $< -o $@
|
|
|
|
|
2004-10-04 15:43:59 +02:00
|
|
|
#
|
|
|
|
# Server versions of object files
|
|
|
|
#
|
|
|
|
|
2007-09-29 00:25:49 +02:00
|
|
|
libpgport_srv.a: $(OBJS_SRV)
|
2015-03-01 19:05:23 +01:00
|
|
|
rm -f $@
|
2004-10-04 15:43:59 +02:00
|
|
|
$(AR) $(AROPT) $@ $^
|
|
|
|
|
2012-05-08 19:08:53 +02:00
|
|
|
# Because this uses its own compilation rule, it doesn't use the
|
|
|
|
# dependency tracking logic from Makefile.global. To make sure that
|
|
|
|
# dependency tracking works anyway for the *_srv.o files, depend on
|
|
|
|
# their *.o siblings as well, which do have proper dependencies. It's
|
|
|
|
# a hack that might fail someday if there is a *_srv.o without a
|
|
|
|
# corresponding *.o, but it works for now (and those would probably go
|
|
|
|
# into src/backend/port/ anyway).
|
|
|
|
%_srv.o: %.c %.o
|
2004-10-04 15:43:59 +02:00
|
|
|
$(CC) $(CFLAGS) $(subst -DFRONTEND,, $(CPPFLAGS)) -c $< -o $@
|
|
|
|
|
2004-05-21 22:56:50 +02:00
|
|
|
# Dependency is to ensure that path changes propagate
|
2007-09-29 00:25:49 +02:00
|
|
|
|
|
|
|
path.o: path.c pg_config_paths.h
|
|
|
|
|
2018-09-27 17:23:43 +02:00
|
|
|
path_shlib.o: path.c pg_config_paths.h
|
|
|
|
|
2007-09-29 00:25:49 +02:00
|
|
|
path_srv.o: path.c pg_config_paths.h
|
|
|
|
|
2006-06-26 20:40:50 +02:00
|
|
|
# We create a separate file rather than put these in pg_config.h
|
|
|
|
# because many of these values come from makefiles and are not
|
|
|
|
# available to configure.
|
2004-05-21 22:56:50 +02:00
|
|
|
pg_config_paths.h: $(top_builddir)/src/Makefile.global
|
|
|
|
echo "#define PGBINDIR \"$(bindir)\"" >$@
|
|
|
|
echo "#define PGSHAREDIR \"$(datadir)\"" >>$@
|
|
|
|
echo "#define SYSCONFDIR \"$(sysconfdir)\"" >>$@
|
|
|
|
echo "#define INCLUDEDIR \"$(includedir)\"" >>$@
|
|
|
|
echo "#define PKGINCLUDEDIR \"$(pkgincludedir)\"" >>$@
|
2004-08-01 08:56:39 +02:00
|
|
|
echo "#define INCLUDEDIRSERVER \"$(includedir_server)\"" >>$@
|
|
|
|
echo "#define LIBDIR \"$(libdir)\"" >>$@
|
2004-05-21 22:56:50 +02:00
|
|
|
echo "#define PKGLIBDIR \"$(pkglibdir)\"" >>$@
|
2004-05-25 03:00:30 +02:00
|
|
|
echo "#define LOCALEDIR \"$(localedir)\"" >>$@
|
2005-09-27 19:39:35 +02:00
|
|
|
echo "#define DOCDIR \"$(docdir)\"" >>$@
|
2008-02-18 15:51:48 +01:00
|
|
|
echo "#define HTMLDIR \"$(htmldir)\"" >>$@
|
2005-09-27 19:39:35 +02:00
|
|
|
echo "#define MANDIR \"$(mandir)\"" >>$@
|
2004-05-21 22:56:50 +02:00
|
|
|
|
2002-07-27 22:10:05 +02:00
|
|
|
clean distclean maintainer-clean:
|
2018-09-27 17:23:43 +02:00
|
|
|
rm -f libpgport.a libpgport_shlib.a libpgport_srv.a
|
|
|
|
rm -f $(OBJS) $(OBJS_SHLIB) $(OBJS_SRV) pg_config_paths.h
|