1 #-------------------------------------------------------------------------
3 # Makefile for src/interfaces/libpq library
5 # Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
6 # Portions Copyright (c) 1994, Regents of the University of California
8 # $PostgreSQL: pgsql/src/interfaces/libpq/Makefile,v 1.155 2007/07/10 13:14:21 mha Exp $
10 #-------------------------------------------------------------------------
12 subdir = src/interfaces/libpq
13 top_builddir = ../../..
14 include $(top_builddir)/src/Makefile.global
17 # shared library parameters
23 override CPPFLAGS := -DFRONTEND -I$(srcdir) $(CPPFLAGS) -I$(top_builddir)/src/port
24 ifneq ($(PORTNAME), win32)
25 override CFLAGS += $(PTHREAD_CFLAGS)
28 # Need to recompile any libpgport object files because we need these
29 # object files to use the same compile flags as libpq. If we used
30 # the object files from libpgport, this would not be true on all
32 LIBS := $(LIBS:-lpgport=)
34 OBJS= fe-auth.o fe-connect.o fe-exec.o fe-misc.o fe-print.o fe-lobj.o \
35 fe-protocol2.o fe-protocol3.o pqexpbuffer.o pqsignal.o fe-secure.o \
36 md5.o ip.o wchar.o encnames.o noblock.o pgstrcasecmp.o thread.o \
37 $(filter crypt.o getaddrinfo.o inet_aton.o open.o snprintf.o strerror.o strlcpy.o, $(LIBOBJS))
39 ifeq ($(PORTNAME), cygwin)
40 override shlib = cyg$(NAME)$(DLSUFFIX)
43 ifeq ($(PORTNAME), win32)
44 OBJS += win32.o libpqrc.o
45 DLL_DEFFILE=libpqdll.def
48 windres -i libpq.rc -o libpqrc.o
50 ifeq ($(enable_thread_safety), yes)
51 OBJS += pthread-win32.o
56 # Add libraries that libpq depends (or might depend) on into the
57 # shared library link. (The order in which you list them here doesn't
59 ifneq ($(PORTNAME), win32)
60 SHLIB_LINK += $(filter -lcrypt -ldes -lcom_err -lcrypto -lk5crypto -lkrb5 -lgssapi_krb5 -lssl -lsocket -lnsl -lresolv -lintl, $(LIBS)) $(LDAP_LIBS_FE) $(PTHREAD_LIBS)
62 SHLIB_LINK += $(filter -lcrypt -ldes -lcom_err -lcrypto -lk5crypto -lkrb5 -lgssapi32 -lssl -lsocket -lnsl -lresolv -lintl $(PTHREAD_LIBS), $(LIBS)) $(LDAP_LIBS_FE)
64 ifeq ($(PORTNAME), win32)
65 SHLIB_LINK += -lshfolder -lwsock32 -lws2_32 $(filter -leay32 -lssleay32 -lcomerr32 -lkrb5_32, $(LIBS))
69 all: def-files $(srcdir)/libpq.rc all-lib
71 # Shared library stuff
72 include $(top_srcdir)/src/Makefile.shlib
73 backend_src = $(top_srcdir)/src/backend
76 # We use several backend modules verbatim, but since we need to
77 # compile with appropriate options to build a shared lib, we can't
78 # necessarily use the same object files as the backend uses. Instead,
79 # symlink the source files in here and build our own object file.
80 # For port modules, this only happens if configure decides the module
81 # is needed (see filter hack in OBJS, above).
83 crypt.c getaddrinfo.c inet_aton.c noblock.c open.c pgstrcasecmp.c snprintf.c strerror.c strlcpy.c thread.c: % : $(top_srcdir)/src/port/%
84 rm -f $@ && $(LN_S) $< .
86 md5.c ip.c: % : $(backend_src)/libpq/%
87 rm -f $@ && $(LN_S) $< .
89 encnames.c wchar.c : % : $(backend_src)/utils/mb/%
90 rm -f $@ && $(LN_S) $< .
93 # We need several not-quite-identical variants of .DEF files to build libpq
94 # DLLs for Windows. These are made from the single source file exports.txt.
95 # Since we can't assume that Windows boxes will have sed, the .DEF files are
96 # always built and included in distribution tarballs.
98 distprep: def-files $(srcdir)/libpq.rc
102 def-files: $(srcdir)/libpqdll.def $(srcdir)/libpqddll.def $(srcdir)/blibpqdll.def
104 $(srcdir)/libpqdll.def: exports.txt
105 echo '; DEF file for MS VC++' > $@
106 echo 'LIBRARY LIBPQ' >> $@
108 sed -e '/^#/d' -e 's/^\(.* \)\([0-9][0-9]*\)/ \1@ \2/' < $< >> $@
110 $(srcdir)/libpqddll.def: exports.txt
111 echo '; DEF file for MS VC++' > $@
112 echo 'LIBRARY LIBPQD' >> $@
114 sed -e '/^#/d' -e 's/^\(.* \)\([0-9][0-9]*\)/ \1@ \2/' < $< >> $@
116 $(srcdir)/blibpqdll.def: exports.txt
117 echo '; DEF file for Borland C++ Builder' > $@
118 echo 'LIBRARY BLIBPQ' >> $@
120 sed -e '/^#/d' -e 's/^\(.* \)\([0-9][0-9]*\)/ _\1@ \2/' < $< >> $@
122 echo '; Aliases for MS compatible names' >> $@
123 sed -e '/^#/d' -e 's/^\(.* \)\([0-9][0-9]*\)/ \1= _\1/' < $< | sed 's/ *$$//' >> $@
125 # Where possible, restrict the symbols exported by the library to just the
126 # official list, so as to avoid unintentional ABI changes. On recent Darwin
127 # this also quiets multiply-defined-symbol warnings in programs that use
128 # libpgport along with libpq.
130 ifeq ($(PORTNAME), darwin)
131 $(shlib): exports.list
133 exports.list: exports.txt
134 $(AWK) '/^[^#]/ {printf "_%s\n",$$1}' $< >$@
136 exported_symbols_list = -exported_symbols_list exports.list
139 ifeq ($(PORTNAME), linux)
140 $(shlib): exports.list
142 exports.list: exports.txt
144 $(AWK) '/^[^#]/ {printf "%s;\n",$$1}' $< >>$@
145 echo ' local: *; };' >>$@
147 exported_symbols_list = -Wl,--version-script=exports.list
150 # depend on Makefile.global to force rebuild on re-run of configure
151 $(srcdir)/libpq.rc: libpq.rc.in $(top_builddir)/src/Makefile.global
152 sed -e 's/\(VERSION.*\),0 *$$/\1,'`date '+%y%j' | sed 's/^0*//'`'/' < $< > $@
154 fe-connect.o: fe-connect.c $(top_builddir)/src/port/pg_config_paths.h
156 $(top_builddir)/src/port/pg_config_paths.h:
157 $(MAKE) -C $(top_builddir)/src/port pg_config_paths.h
159 install: all installdirs install-lib
160 $(INSTALL_DATA) $(srcdir)/libpq-fe.h '$(DESTDIR)$(includedir)'
161 $(INSTALL_DATA) $(srcdir)/libpq-int.h '$(DESTDIR)$(includedir_internal)'
162 $(INSTALL_DATA) $(srcdir)/pqexpbuffer.h '$(DESTDIR)$(includedir_internal)'
163 $(INSTALL_DATA) $(srcdir)/pg_service.conf.sample '$(DESTDIR)$(datadir)/pg_service.conf.sample'
166 $(mkinstalldirs) '$(DESTDIR)$(libdir)' '$(DESTDIR)$(includedir)' '$(DESTDIR)$(includedir_internal)'
168 uninstall: uninstall-lib
169 rm -f '$(DESTDIR)$(includedir)/libpq-fe.h' '$(DESTDIR)$(includedir_internal)/libpq-int.h' '$(DESTDIR)$(includedir_internal)/pqexpbuffer.h' '$(DESTDIR)$(datadir)/pg_service.conf.sample'
171 clean distclean: clean-lib
172 rm -f $(OBJS) pg_config_paths.h crypt.c getaddrinfo.c inet_aton.c noblock.c open.c pgstrcasecmp.c snprintf.c strerror.c strlcpy.c thread.c md5.c ip.c encnames.c wchar.c pthread.h exports.list
173 # Might be left over from a Win32 client-only build
174 rm -f pg_config_paths.h
176 maintainer-clean: distclean
177 rm -f $(srcdir)/libpqdll.def $(srcdir)/libpqddll.def $(srcdir)/blibpqdll.def $(srcdir)/libpq.rc