| 1 |
#------------------------------------------------------------------------- |
| 2 |
# |
| 3 |
# Makefile for src/interfaces/libpq library |
| 4 |
# |
| 5 |
# Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group |
| 6 |
# Portions Copyright (c) 1994, Regents of the University of California |
| 7 |
# |
| 8 |
# src/interfaces/libpq/Makefile |
| 9 |
# |
| 10 |
#------------------------------------------------------------------------- |
| 11 |
|
| 12 |
EXTRA_INSTALL=src/test/modules/injection_points |
| 13 |
|
| 14 |
subdir = src/interfaces/libpq |
| 15 |
top_builddir = ../../.. |
| 16 |
include $(top_builddir)/src/Makefile.global |
| 17 |
|
| 18 |
export with_ssl with_gssapi with_krb_srvnam |
| 19 |
|
| 20 |
PGFILEDESC = "PostgreSQL Access Library" |
| 21 |
|
| 22 |
# shared library parameters |
| 23 |
NAME= pq |
| 24 |
SO_MAJOR_VERSION= 5 |
| 25 |
SO_MINOR_VERSION= $(MAJORVERSION) |
| 26 |
|
| 27 |
override CPPFLAGS := -I$(srcdir) -I$(top_builddir)/src/port -I$(top_srcdir)/src/port $(CPPFLAGS) |
| 28 |
ifneq ($(PORTNAME), win32) |
| 29 |
override CFLAGS += $(PTHREAD_CFLAGS) |
| 30 |
endif |
| 31 |
|
| 32 |
OBJS = \ |
| 33 |
$(WIN32RES) \ |
| 34 |
fe-auth-scram.o \ |
| 35 |
fe-cancel.o \ |
| 36 |
fe-connect.o \ |
| 37 |
fe-exec.o \ |
| 38 |
fe-lobj.o \ |
| 39 |
fe-misc.o \ |
| 40 |
fe-print.o \ |
| 41 |
fe-protocol3.o \ |
| 42 |
fe-secure.o \ |
| 43 |
fe-trace.o \ |
| 44 |
legacy-pqsignal.o \ |
| 45 |
libpq-events.o \ |
| 46 |
pqexpbuffer.o \ |
| 47 |
fe-auth.o |
| 48 |
|
| 49 |
# File shared across all SSL implementations supported. |
| 50 |
ifneq ($(with_ssl),no) |
| 51 |
OBJS += \ |
| 52 |
fe-secure-common.o |
| 53 |
endif |
| 54 |
|
| 55 |
ifeq ($(with_ssl),openssl) |
| 56 |
OBJS += \ |
| 57 |
fe-secure-openssl.o |
| 58 |
endif |
| 59 |
|
| 60 |
ifeq ($(with_gssapi),yes) |
| 61 |
OBJS += \ |
| 62 |
fe-gssapi-common.o \ |
| 63 |
fe-secure-gssapi.o |
| 64 |
endif |
| 65 |
|
| 66 |
# The OAuth implementation differs depending on the type of library being built. |
| 67 |
OBJS_STATIC = fe-auth-oauth.o |
| 68 |
|
| 69 |
fe-auth-oauth_shlib.o: override CPPFLAGS_SHLIB += -DUSE_DYNAMIC_OAUTH |
| 70 |
OBJS_SHLIB = fe-auth-oauth_shlib.o |
| 71 |
|
| 72 |
ifeq ($(PORTNAME), cygwin) |
| 73 |
override shlib = cyg$(NAME)$(DLSUFFIX) |
| 74 |
endif |
| 75 |
|
| 76 |
ifeq ($(PORTNAME), win32) |
| 77 |
OBJS += \ |
| 78 |
pthread-win32.o \ |
| 79 |
win32.o |
| 80 |
endif |
| 81 |
|
| 82 |
|
| 83 |
# Add libraries that libpq depends (or might depend) on into the |
| 84 |
# shared library link. (The order in which you list them here doesn't |
| 85 |
# matter.) Note that we filter out -lpgcommon and -lpgport from LIBS and |
| 86 |
# instead link with -lpgcommon_shlib and -lpgport_shlib, to get object files |
| 87 |
# that are built correctly for use in a shlib. |
| 88 |
SHLIB_LINK_INTERNAL = -lpgcommon_shlib -lpgport_shlib |
| 89 |
ifneq ($(PORTNAME), win32) |
| 90 |
SHLIB_LINK += $(filter -lcrypt -ldes -lcom_err -lcrypto -lk5crypto -lkrb5 -lgssapi_krb5 -lgss -lgssapi -lssl -lsocket -lnsl -lresolv -lintl -ldl -lm, $(LIBS)) $(LDAP_LIBS_FE) $(PTHREAD_LIBS) |
| 91 |
else |
| 92 |
SHLIB_LINK += $(filter -lcrypt -ldes -lcom_err -lcrypto -lk5crypto -lkrb5 -lgssapi32 -lssl -lsocket -lnsl -lresolv -lintl -lm $(PTHREAD_LIBS), $(LIBS)) $(LDAP_LIBS_FE) |
| 93 |
endif |
| 94 |
ifeq ($(PORTNAME), win32) |
| 95 |
SHLIB_LINK += -lshell32 -lws2_32 -lsecur32 $(filter -lcomerr32 -lkrb5_32, $(LIBS)) |
| 96 |
endif |
| 97 |
SHLIB_PREREQS = submake-libpgport |
| 98 |
|
| 99 |
SHLIB_EXPORTS = exports.txt |
| 100 |
|
| 101 |
# Appends to a comma-separated list. |
| 102 |
comma := , |
| 103 |
define add_to_list |
| 104 |
$(eval $1 := $(if $($1),$($1)$(comma) $2,$2)) |
| 105 |
endef |
| 106 |
|
| 107 |
ifeq ($(with_ssl),openssl) |
| 108 |
$(call add_to_list,PKG_CONFIG_REQUIRES_PRIVATE,libssl) |
| 109 |
$(call add_to_list,PKG_CONFIG_REQUIRES_PRIVATE,libcrypto) |
| 110 |
endif |
| 111 |
|
| 112 |
ifeq ($(with_libcurl),yes) |
| 113 |
# libpq.so doesn't link against libcurl, but libpq.a needs libpq-oauth, and |
| 114 |
# libpq-oauth needs libcurl. Put both into *.private. |
| 115 |
$(call add_to_list,PKG_CONFIG_REQUIRES_PRIVATE,libcurl) |
| 116 |
%.pc: override SHLIB_LINK_INTERNAL += -lpq-oauth |
| 117 |
endif |
| 118 |
|
| 119 |
all: all-lib libpq-refs-stamp |
| 120 |
|
| 121 |
# Shared library stuff |
| 122 |
include $(top_srcdir)/src/Makefile.shlib |
| 123 |
backend_src = $(top_srcdir)/src/backend |
| 124 |
|
| 125 |
# Add shlib-/stlib-specific objects. |
| 126 |
$(shlib): override OBJS += $(OBJS_SHLIB) |
| 127 |
$(shlib): $(OBJS_SHLIB) |
| 128 |
|
| 129 |
$(stlib): override OBJS += $(OBJS_STATIC) |
| 130 |
$(stlib): $(OBJS_STATIC) |
| 131 |
|
| 132 |
# Check for functions that libpq must not call, currently just exit(). |
| 133 |
# (Ideally we'd reject abort() too, but there are various scenarios where |
| 134 |
# build toolchains insert abort() calls, e.g. to implement assert().) |
| 135 |
# If nm doesn't exist or doesn't work on shlibs, this test will do nothing, |
| 136 |
# which is fine. The exclusion of __cxa_atexit is necessary on OpenBSD, |
| 137 |
# which seems to insert references to that even in pure C code. Excluding |
| 138 |
# __tsan_func_exit is necessary when using ThreadSanitizer data race detector |
| 139 |
# which use this function for instrumentation of function exit. |
| 140 |
# Skip the test when profiling, as gcc may insert exit() calls for that. |
| 141 |
# Also skip the test on platforms where libpq infrastructure may be provided |
| 142 |
# by statically-linked libraries, as we can't expect them to honor this |
| 143 |
# coding rule. |
| 144 |
libpq-refs-stamp: $(shlib) |
| 145 |
ifneq ($(enable_coverage), yes) |
| 146 |
ifeq (,$(filter solaris,$(PORTNAME))) |
| 147 |
@if nm -A -u $< 2>/dev/null | grep -v -e __cxa_atexit -e __tsan_func_exit | grep exit; then \ |
| 148 |
echo 'libpq must not be calling any function which invokes exit'; exit 1; \ |
| 149 |
fi |
| 150 |
endif |
| 151 |
endif |
| 152 |
touch $@ |
| 153 |
|
| 154 |
# Make dependencies on pg_config_paths.h visible in all builds. |
| 155 |
fe-connect.o: fe-connect.c $(top_builddir)/src/port/pg_config_paths.h |
| 156 |
fe-misc.o: fe-misc.c $(top_builddir)/src/port/pg_config_paths.h |
| 157 |
|
| 158 |
$(top_builddir)/src/port/pg_config_paths.h: |
| 159 |
$(MAKE) -C $(top_builddir)/src/port pg_config_paths.h |
| 160 |
|
| 161 |
# Use src/common/Makefile's trick for tracking dependencies of shlib-specific |
| 162 |
# objects. |
| 163 |
%_shlib.o: %.c %.o |
| 164 |
$(CC) $(CFLAGS) $(CFLAGS_SL) $(CPPFLAGS) $(CPPFLAGS_SHLIB) -c $< -o $@ |
| 165 |
|
| 166 |
install: all installdirs install-lib |
| 167 |
$(INSTALL_DATA) $(srcdir)/libpq-fe.h '$(DESTDIR)$(includedir)' |
| 168 |
$(INSTALL_DATA) $(srcdir)/libpq-events.h '$(DESTDIR)$(includedir)' |
| 169 |
$(INSTALL_DATA) $(srcdir)/libpq-int.h '$(DESTDIR)$(includedir_internal)' |
| 170 |
$(INSTALL_DATA) $(srcdir)/fe-auth-sasl.h '$(DESTDIR)$(includedir_internal)' |
| 171 |
$(INSTALL_DATA) $(srcdir)/pqexpbuffer.h '$(DESTDIR)$(includedir_internal)' |
| 172 |
$(INSTALL_DATA) $(srcdir)/pg_service.conf.sample '$(DESTDIR)$(datadir)/pg_service.conf.sample' |
| 173 |
|
| 174 |
test-build: |
| 175 |
$(MAKE) -C test all |
| 176 |
|
| 177 |
check installcheck: export PATH := $(CURDIR)/test:$(PATH) |
| 178 |
|
| 179 |
check: test-build all |
| 180 |
$(prove_check) |
| 181 |
|
| 182 |
installcheck: test-build all |
| 183 |
$(prove_installcheck) |
| 184 |
|
| 185 |
installdirs: installdirs-lib |
| 186 |
$(MKDIR_P) '$(DESTDIR)$(includedir)' '$(DESTDIR)$(includedir_internal)' '$(DESTDIR)$(datadir)' |
| 187 |
|
| 188 |
uninstall: uninstall-lib |
| 189 |
rm -f '$(DESTDIR)$(includedir)/libpq-fe.h' |
| 190 |
rm -f '$(DESTDIR)$(includedir)/libpq-events.h' |
| 191 |
rm -f '$(DESTDIR)$(includedir_internal)/libpq-int.h' |
| 192 |
rm -f '$(DESTDIR)$(includedir_internal)/fe-auth-sasl.h' |
| 193 |
rm -f '$(DESTDIR)$(includedir_internal)/pqexpbuffer.h' |
| 194 |
rm -f '$(DESTDIR)$(datadir)/pg_service.conf.sample' |
| 195 |
|
| 196 |
clean distclean: clean-lib |
| 197 |
$(MAKE) -C test $@ |
| 198 |
rm -rf tmp_check |
| 199 |
rm -f $(OBJS) $(OBJS_SHLIB) $(OBJS_STATIC) pthread.h libpq-refs-stamp |
| 200 |
# Might be left over from a Win32 client-only build |
| 201 |
rm -f pg_config_paths.h |