2002-07-18 04:13:59 +00:00
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
2004-10-04 13:43:59 +00:00
|
|
|
# Makefile
|
2018-09-27 11:23:43 -04:00
|
|
|
# Makefile for src/port
|
2002-07-18 04:13:59 +00:00
|
|
|
#
|
2018-09-27 11:23:43 -04: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 13:43:59 +00:00
|
|
|
#
|
2018-09-27 11:23:43 -04:00
|
|
|
# This makefile generates three outputs:
|
2004-10-04 13:43:59 +00:00
|
|
|
#
|
|
|
|
# libpgport.a - contains object files with FRONTEND defined,
|
2018-09-27 11:23:43 -04:00
|
|
|
# for use by client applications
|
|
|
|
#
|
|
|
|
# libpgport_shlib.a - contains object files with FRONTEND defined,
|
|
|
|
# built suitably for use in shared libraries; for use
|
2018-09-28 14:28:19 -04:00
|
|
|
# by frontend libraries
|
2004-10-04 13:43:59 +00:00
|
|
|
#
|
|
|
|
# libpgport_srv.a - contains object files without FRONTEND defined,
|
2018-09-27 11:23:43 -04:00
|
|
|
# for use only by the backend
|
2004-10-04 13:43:59 +00:00
|
|
|
#
|
2010-12-10 19:42:44 -05: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-28 22:25:49 +00:00
|
|
|
# OBJS adds additional object files that are always compiled.
|
|
|
|
#
|
2002-07-18 04:13:59 +00:00
|
|
|
# IDENTIFICATION
|
2010-09-20 22:08:53 +02:00
|
|
|
# src/port/Makefile
|
2002-07-18 04:13:59 +00:00
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
|
|
|
|
subdir = src/port
|
|
|
|
top_builddir = ../..
|
|
|
|
include $(top_builddir)/src/Makefile.global
|
|
|
|
|
2004-10-04 13:43:59 +00:00
|
|
|
override CPPFLAGS := -I$(top_builddir)/src/port -DFRONTEND $(CPPFLAGS)
|
2004-05-30 14:07:47 +00:00
|
|
|
LIBS += $(PTHREAD_LIBS)
|
2004-05-22 02:15:08 +00:00
|
|
|
|
2019-11-05 14:41:07 -08:00
|
|
|
OBJS = \
|
|
|
|
$(LIBOBJS) \
|
|
|
|
$(PG_CRC32C_OBJS) \
|
2021-03-23 00:11:20 +01:00
|
|
|
bsearch_arg.o \
|
2019-11-05 14:41:07 -08:00
|
|
|
chklocale.o \
|
|
|
|
inet_net_ntop.o \
|
|
|
|
noblock.o \
|
|
|
|
path.o \
|
|
|
|
pg_bitutils.o \
|
Provide thread-safe pg_localeconv_r().
This involves four different implementation strategies:
1. For Windows, we now require _configthreadlocale() to be available
and work (commit f1da075d9a0), and the documentation says that the
object returned by localeconv() is in thread-local memory.
2. For glibc, we translate to nl_langinfo_l() calls, because it
offers the same information that way as an extension, and that API is
thread-safe.
3. For macOS/*BSD, use localeconv_l(), which is thread-safe.
4. For everything else, use uselocale() to set the locale for the
thread, and use a big ugly lock to defend against the returned object
being concurrently clobbered. In practice this currently means only
Solaris.
The new call is used in pg_locale.c, replacing calls to setlocale() and
localeconv().
Author: Thomas Munro <thomas.munro@gmail.com>
Reviewed-by: Heikki Linnakangas <hlinnaka@iki.fi>
Reviewed-by: Peter Eisentraut <peter@eisentraut.org>
Discussion: https://postgr.es/m/CA%2BhUKGJqVe0%2BPv9dvC9dSums_PXxGo9SWcxYAMBguWJUGbWz-A%40mail.gmail.com
2025-03-27 07:52:22 +01:00
|
|
|
pg_localeconv_r.o \
|
2025-04-07 22:51:49 +02:00
|
|
|
pg_numa.o \
|
2025-03-28 14:49:35 -05:00
|
|
|
pg_popcount_aarch64.o \
|
Use __attribute__((target(...))) for AVX-512 support.
Presently, we check for compiler support for the required
intrinsics both with and without extra compiler flags (e.g.,
-mxsave), and then depending on the results of those checks, we
pick which files to compile with which flags. This is tedious and
complicated, and it results in unsustainable coding patterns such
as separate files for each portion of code may need to be built
with different compiler flags.
This commit introduces support for __attribute__((target(...))) and
uses it for the AVX-512 code. This simplifies both the
configure-time checks and the build scripts, and it allows us to
place the functions that use the intrinsics in files that we
otherwise do not want to build with special CPU instructions. We
are careful to avoid using __attribute__((target(...))) on
compilers that do not understand it, but we still perform the
configure-time checks in case the compiler allows using the
intrinsics without it (e.g., MSVC).
A similar change could likely be made for some of the CRC-32C code,
but that is left as a future exercise.
Suggested-by: Andres Freund
Reviewed-by: Raghuveer Devulapalli, Andres Freund
Discussion: https://postgr.es/m/20240731205254.vfpap7uxwmebqeaf%40awork3.anarazel.de
2024-11-07 13:58:43 -06:00
|
|
|
pg_popcount_avx512.o \
|
2019-11-05 14:41:07 -08:00
|
|
|
pg_strong_random.o \
|
|
|
|
pgcheckdir.o \
|
|
|
|
pgmkdirp.o \
|
|
|
|
pgsleep.o \
|
|
|
|
pgstrcasecmp.o \
|
|
|
|
pgstrsignal.o \
|
|
|
|
pqsignal.o \
|
|
|
|
qsort.o \
|
|
|
|
qsort_arg.o \
|
|
|
|
quotes.o \
|
|
|
|
snprintf.o \
|
|
|
|
strerror.o \
|
2024-09-02 08:16:25 +02:00
|
|
|
tar.o
|
2010-12-10 19:42:44 -05:00
|
|
|
|
2018-09-27 11:23:43 -04: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-28 22:25:49 +00:00
|
|
|
OBJS_SRV = $(OBJS:%.o=%_srv.o)
|
2004-10-04 13:43:59 +00:00
|
|
|
|
2018-09-27 11:23:43 -04:00
|
|
|
all: libpgport.a libpgport_shlib.a libpgport_srv.a
|
2002-07-18 04:13:59 +00:00
|
|
|
|
2004-08-20 20:13:10 +00:00
|
|
|
# libpgport is needed by some contrib
|
2005-12-09 21:19:36 +00:00
|
|
|
install: all installdirs
|
|
|
|
$(INSTALL_STLIB) libpgport.a '$(DESTDIR)$(libdir)/libpgport.a'
|
2018-09-28 14:28:19 -04:00
|
|
|
$(INSTALL_STLIB) libpgport_shlib.a '$(DESTDIR)$(libdir)/libpgport_shlib.a'
|
2005-12-09 21:19:36 +00:00
|
|
|
|
|
|
|
installdirs:
|
2009-08-26 22:24:44 +00:00
|
|
|
$(MKDIR_P) '$(DESTDIR)$(libdir)'
|
2004-08-20 20:13:10 +00:00
|
|
|
|
|
|
|
uninstall:
|
2005-12-09 21:19:36 +00:00
|
|
|
rm -f '$(DESTDIR)$(libdir)/libpgport.a'
|
2018-09-28 14:28:19 -04:00
|
|
|
rm -f '$(DESTDIR)$(libdir)/libpgport_shlib.a'
|
2004-08-20 20:13:10 +00:00
|
|
|
|
2007-09-28 22:25:49 +00:00
|
|
|
libpgport.a: $(OBJS)
|
2015-03-01 13:05:23 -05:00
|
|
|
rm -f $@
|
2003-10-24 20:31:43 +00:00
|
|
|
$(AR) $(AROPT) $@ $^
|
2002-07-27 20:10:05 +00:00
|
|
|
|
2022-12-01 18:46:55 -08:00
|
|
|
# all versions of pg_crc32c_armv8.o need CFLAGS_CRC
|
|
|
|
pg_crc32c_armv8.o: CFLAGS+=$(CFLAGS_CRC)
|
|
|
|
pg_crc32c_armv8_shlib.o: CFLAGS+=$(CFLAGS_CRC)
|
|
|
|
pg_crc32c_armv8_srv.o: CFLAGS+=$(CFLAGS_CRC)
|
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 12:22:45 +03:00
|
|
|
|
2018-09-27 11:23:43 -04: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 13:43:59 +00:00
|
|
|
#
|
|
|
|
# Server versions of object files
|
|
|
|
#
|
|
|
|
|
2007-09-28 22:25:49 +00:00
|
|
|
libpgport_srv.a: $(OBJS_SRV)
|
2015-03-01 13:05:23 -05:00
|
|
|
rm -f $@
|
2004-10-04 13:43:59 +00:00
|
|
|
$(AR) $(AROPT) $@ $^
|
|
|
|
|
2012-05-08 20:08:53 +03: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 13:43:59 +00:00
|
|
|
$(CC) $(CFLAGS) $(subst -DFRONTEND,, $(CPPFLAGS)) -c $< -o $@
|
|
|
|
|
2004-05-21 20:56:50 +00:00
|
|
|
# Dependency is to ensure that path changes propagate
|
2007-09-28 22:25:49 +00:00
|
|
|
|
|
|
|
path.o: path.c pg_config_paths.h
|
|
|
|
|
2018-09-27 11:23:43 -04:00
|
|
|
path_shlib.o: path.c pg_config_paths.h
|
|
|
|
|
2007-09-28 22:25:49 +00:00
|
|
|
path_srv.o: path.c pg_config_paths.h
|
|
|
|
|
2006-06-26 18:40:50 +00: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 20:56:50 +00: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 06:56:39 +00:00
|
|
|
echo "#define INCLUDEDIRSERVER \"$(includedir_server)\"" >>$@
|
|
|
|
echo "#define LIBDIR \"$(libdir)\"" >>$@
|
2004-05-21 20:56:50 +00:00
|
|
|
echo "#define PKGLIBDIR \"$(pkglibdir)\"" >>$@
|
2004-05-25 01:00:30 +00:00
|
|
|
echo "#define LOCALEDIR \"$(localedir)\"" >>$@
|
2005-09-27 17:39:35 +00:00
|
|
|
echo "#define DOCDIR \"$(docdir)\"" >>$@
|
2008-02-18 14:51:48 +00:00
|
|
|
echo "#define HTMLDIR \"$(htmldir)\"" >>$@
|
2005-09-27 17:39:35 +00:00
|
|
|
echo "#define MANDIR \"$(mandir)\"" >>$@
|
2004-05-21 20:56:50 +00:00
|
|
|
|
Remove distprep
A PostgreSQL release tarball contains a number of prebuilt files, in
particular files produced by bison, flex, perl, and well as html and
man documentation. We have done this consistent with established
practice at the time to not require these tools for building from a
tarball. Some of these tools were hard to get, or get the right
version of, from time to time, and shipping the prebuilt output was a
convenience to users.
Now this has at least two problems:
One, we have to make the build system(s) work in two modes: Building
from a git checkout and building from a tarball. This is pretty
complicated, but it works so far for autoconf/make. It does not
currently work for meson; you can currently only build with meson from
a git checkout. Making meson builds work from a tarball seems very
difficult or impossible. One particular problem is that since meson
requires a separate build directory, we cannot make the build update
files like gram.h in the source tree. So if you were to build from a
tarball and update gram.y, you will have a gram.h in the source tree
and one in the build tree, but the way things work is that the
compiler will always use the one in the source tree. So you cannot,
for example, make any gram.y changes when building from a tarball.
This seems impossible to fix in a non-horrible way.
Second, there is increased interest nowadays in precisely tracking the
origin of software. We can reasonably track contributions into the
git tree, and users can reasonably track the path from a tarball to
packages and downloads and installs. But what happens between the git
tree and the tarball is obscure and in some cases non-reproducible.
The solution for both of these issues is to get rid of the step that
adds prebuilt files to the tarball. The tarball now only contains
what is in the git tree (*). Getting the additional build
dependencies is no longer a problem nowadays, and the complications to
keep these dual build modes working are significant. And of course we
want to get the meson build system working universally.
This commit removes the make distprep target altogether. The make
dist target continues to do its job, it just doesn't call distprep
anymore.
(*) - The tarball also contains the INSTALL file that is built at make
dist time, but not by distprep. This is unchanged for now.
The make maintainer-clean target, whose job it is to remove the
prebuilt files in addition to what make distclean does, is now just an
alias to make distprep. (In practice, it is probably obsolete given
that git clean is available.)
The following programs are now hard build requirements in configure
(they were already required by meson.build):
- bison
- flex
- perl
Reviewed-by: Michael Paquier <michael@paquier.xyz>
Reviewed-by: Andres Freund <andres@anarazel.de>
Discussion: https://www.postgresql.org/message-id/flat/e07408d9-e5f2-d9fd-5672-f53354e9305e@eisentraut.org
2023-11-06 14:51:52 +01:00
|
|
|
clean distclean:
|
2018-09-27 11:23:43 -04:00
|
|
|
rm -f libpgport.a libpgport_shlib.a libpgport_srv.a
|
|
|
|
rm -f $(OBJS) $(OBJS_SHLIB) $(OBJS_SRV) pg_config_paths.h
|