# Copyright (c) 1998, Regents of the University of California
#
# IDENTIFICATION
-# $PostgreSQL: pgsql/src/Makefile.shlib,v 1.114 2008/04/07 14:15:58 petere Exp $
+# src/Makefile.shlib
#
#-------------------------------------------------------------------------
# OBJS List of object files to include in library
# SHLIB_LINK If shared library relies on other libraries,
# additional stuff to put in its link command
+# SHLIB_PREREQS Order-only prerequisites for library build target
# SHLIB_EXPORTS (optional) Name of file containing list of symbols to
-# export
+# export, in the format "function_name number"
#
# When building a shared library, the following version information
# must also be set. It should be omitted when building a dynamically
# SO_MINOR_VERSION Minor version number to use for shared library
# (If you want a patchlevel, include it in SO_MINOR_VERSION, e.g., "6.2".)
#
-# Optional flags when building DLL's (only applicable to win32 and cygwin
-# platforms).
-# DLLTOOL_DEFFLAGS Additional flags when creating the dll .def file
-# DLLTOOL_LIBFLAGS Additional flags when creating the lib<module>.a file
-# DLLWRAP_FLAGS Additional flags to dllwrap
-#
# The module Makefile must also include
# $(top_builddir)/src/Makefile.global before including this file.
# (Makefile.global sets PORTNAME and other needed symbols.)
-# Insert -L from LDFLAGS after any -L already present in SHLIB_LINK
-SHLIB_LINK := $(filter -L%, $(SHLIB_LINK)) $(filter -L%, $(LDFLAGS)) $(filter-out -L%, $(SHLIB_LINK))
-
-# Need a -L-free version of LDFLAGS to use in combination with SHLIB_LINK
-LDFLAGS_NO_L = $(filter-out -L%, $(LDFLAGS))
-
ifdef SO_MAJOR_VERSION
# Default library naming convention used by the majority of platforms
-ifeq ($(enable_shared), yes)
shlib = lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
shlib_major = lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
shlib_bare = lib$(NAME)$(DLSUFFIX)
-endif
# Testing the soname variable is a reliable way to determine whether a
# linkable library is being built.
soname = $(shlib_major)
-stlib = lib$(NAME).a
+pkgconfigdir = $(libdir)/pkgconfig
else
# Naming convention for dynamically loadable modules
-ifeq ($(enable_shared), yes)
shlib = $(NAME)$(DLSUFFIX)
endif
-endif
+stlib = lib$(NAME).a
ifndef soname
# additional flags for backend modules
-SHLIB_LINK := $(BE_DLLLIBS) $(SHLIB_LINK)
+SHLIB_LINK += $(BE_DLLLIBS)
endif
# For each platform we support shared libraries on, set shlib to the
# Try to keep the sections in some kind of order, folks...
override CFLAGS += $(CFLAGS_SL)
+ifdef SO_MAJOR_VERSION
+# libraries ought to use this to refer to versioned gettext domain names
+override CPPFLAGS += -DSO_MAJOR_VERSION=$(SO_MAJOR_VERSION)
+endif
ifeq ($(PORTNAME), aix)
ifdef SO_MAJOR_VERSION
shlib = lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
endif
haslibarule = yes
+ # $(exports_file) is also usable as an import file
exports_file = lib$(NAME).exp
endif
ifneq ($(SO_MAJOR_VERSION), 0)
version_link = -compatibility_version $(SO_MAJOR_VERSION) -current_version $(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
endif
- LINK.shared = $(COMPILER) -dynamiclib -install_name $(libdir)/lib$(NAME).$(SO_MAJOR_VERSION)$(DLSUFFIX) $(version_link) $(exported_symbols_list) -multiply_defined suppress
+ LINK.shared = $(COMPILER) -dynamiclib -install_name '$(libdir)/lib$(NAME).$(SO_MAJOR_VERSION)$(DLSUFFIX)' $(version_link) $(exported_symbols_list) -multiply_defined suppress
shlib = lib$(NAME).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)$(DLSUFFIX)
shlib_major = lib$(NAME).$(SO_MAJOR_VERSION)$(DLSUFFIX)
else
# loadable module
DLSUFFIX = .so
- LINK.shared = $(COMPILER) -bundle -multiply_defined suppress
+ LINK.shared = $(COMPILER) -bundle -multiply_defined suppress -Wl,-undefined,dynamic_lookup
endif
BUILD.exports = $(AWK) '/^[^\#]/ {printf "_%s\n",$$1}' $< >$@
exports_file = $(SHLIB_EXPORTS:%.txt=%.list)
endif
endif
-ifeq ($(PORTNAME), bsdi)
- ifeq ($(DLSUFFIX), .so)
- LINK.shared = $(COMPILER) -shared
- ifdef soname
- LINK.shared += -Wl,-x,-soname,$(soname)
- endif
- SHLIB_LINK += -lc
- endif
- ifeq ($(DLSUFFIX), .o)
- LINK.shared = shlicc -O $(LDREL)
- endif
-endif
-
ifeq ($(PORTNAME), freebsd)
ifdef ELF_SYSTEM
ifdef SO_MAJOR_VERSION
shlib = lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
endif
ifeq ($(with_gnu_ld), yes)
- LINK.shared = $(CC) $(LDFLAGS_NO_L) -shared
+ LINK.shared = $(CC) -shared
ifdef soname
LINK.shared += -Wl,-h -Wl,$(soname)
endif
else
- # can't use the CC-syntax rpath pattern here
- rpath =
LINK.shared = $(LD) -b
ifdef soname
LINK.shared += +h $(soname)
endif
+ # can't use the CC-syntax rpath pattern here, so instead:
+ rpath =
ifeq ($(enable_rpath), yes)
LINK.shared += +b '$(rpathdir)'
endif
# ld can find the same libraries gcc does. Make sure it goes after any
# -L switches provided explicitly.
ifeq ($(GCC), yes)
- SHLIB_LINK := $(filter -L%, $(SHLIB_LINK)) -L/usr/local/lib $(filter-out -L%, $(SHLIB_LINK))
+ SHLIB_LINK += -L/usr/local/lib
endif
endif
- # do this last so above filtering doesn't pull out -L switches in LDFLAGS
+ # And we need to link with libgcc, too
ifeq ($(GCC), yes)
SHLIB_LINK += `$(CC) $(LDFLAGS) -print-libgcc-file-name`
endif
endif
-ifeq ($(PORTNAME), irix)
- ifdef SO_MAJOR_VERSION
- shlib = lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
- endif
- LINK.shared = $(COMPILER) -shared
- ifdef soname
- LINK.shared += -Wl,-set_version,sgi$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
- endif
-endif
-
ifeq ($(PORTNAME), linux)
LINK.shared = $(COMPILER) -shared
ifdef soname
ifeq ($(PORTNAME), solaris)
ifeq ($(GCC), yes)
- LINK.shared = $(COMPILER) -shared # $(COMPILER) needed for -m64
+ LINK.shared = $(COMPILER) -shared
else
-# CFLAGS added for X86_64
- LINK.shared = $(CC) -G $(CFLAGS)
+ LINK.shared = $(COMPILER) -G
endif
ifdef soname
ifeq ($(with_gnu_ld), yes)
endif
endif
-ifeq ($(PORTNAME), sunos4)
- LINK.shared = $(LD) -assert pure-text -Bdynamic
-endif
-
-ifeq ($(PORTNAME), osf)
- LINK.shared = $(LD) -shared -expect_unresolved '*'
-endif
-
ifeq ($(PORTNAME), sco)
ifeq ($(GCC), yes)
LINK.shared = $(CC) -shared
endif
endif
-ifeq ($(PORTNAME), svr4)
- LINK.shared = $(LD) -G
-endif
-
-ifeq ($(PORTNAME), univel)
- LINK.shared = $(LD) -G -z text
-endif
-
ifeq ($(PORTNAME), unixware)
ifeq ($(GCC), yes)
LINK.shared = $(CC) -shared
endif
ifeq ($(PORTNAME), cygwin)
- shlib = cyg$(NAME)$(DLSUFFIX)
+ LINK.shared = $(CC) -shared
+ ifdef SO_MAJOR_VERSION
+ shlib = cyg$(NAME)$(DLSUFFIX)
+ endif
haslibarule = yes
endif
ifeq ($(PORTNAME), win32)
- shlib = lib$(NAME)$(DLSUFFIX)
+ ifdef SO_MAJOR_VERSION
+ shlib = lib$(NAME)$(DLSUFFIX)
+ endif
haslibarule = yes
endif
-ifeq ($(enable_rpath), yes)
-SHLIB_LINK += $(rpath)
-endif
-
##
ifdef soname
# no static library when building a dynamically loadable module
all-lib: all-static-lib
+all-lib: lib$(NAME).pc
endif
all-static-lib: $(stlib)
all-shared-lib: $(shlib)
ifndef haslibarule
-$(stlib): $(OBJS)
+$(stlib): $(OBJS) | $(SHLIB_PREREQS)
+ rm -f $@
$(LINK.static) $@ $^
$(RANLIB) $@
endif #haslibarule
-ifeq ($(enable_shared), yes)
ifeq (,$(filter cygwin win32,$(PORTNAME)))
ifneq ($(PORTNAME), aix)
# Normal case
-$(shlib): $(OBJS)
- $(LINK.shared) $(LDFLAGS_SL) $(OBJS) $(SHLIB_LINK) -o $@
+$(shlib): $(OBJS) | $(SHLIB_PREREQS)
+ $(LINK.shared) -o $@ $(OBJS) $(LDFLAGS) $(LDFLAGS_SL) $(SHLIB_LINK)
ifdef shlib_major
# If we're using major and minor versions, then make a symlink to major-version-only.
ifneq ($(shlib), $(shlib_major))
else # PORTNAME == aix
# AIX case
-$(shlib) $(stlib): $(OBJS)
+$(shlib) $(stlib): $(OBJS) | $(SHLIB_PREREQS)
+ rm -f $(stlib)
$(LINK.static) $(stlib) $^
$(RANLIB) $(stlib)
- $(MKLDEXPORT) $(stlib) >$(exports_file)
- $(COMPILER) $(LDFLAGS_NO_L) $(LDFLAGS_SL) -o $(shlib) $(stlib) -Wl,-bE:$(exports_file) $(SHLIB_LINK)
+ $(MKLDEXPORT) $(stlib) $(shlib) >$(exports_file)
+ $(COMPILER) -o $(shlib) $(stlib) -Wl,-bE:$(exports_file) $(LDFLAGS) $(LDFLAGS_SL) $(SHLIB_LINK)
rm -f $(stlib)
$(AR) $(AROPT) $(stlib) $(shlib)
else # PORTNAME == cygwin || PORTNAME == win32
-# Cygwin or Win32 case
+ifeq ($(PORTNAME), cygwin)
-DLL_DEFFILE = lib$(NAME)dll.def
+# Cygwin case
-# If SHLIB_EXPORTS is set, the rules below will build a .def file from
-# that. Else we build a temporary one here.
-ifeq (,$(SHLIB_EXPORTS))
-exports_file = $(DLL_DEFFILE)
+$(shlib): $(OBJS) | $(SHLIB_PREREQS)
+ $(CC) $(CFLAGS) -shared -o $@ $(OBJS) $(LDFLAGS) $(LDFLAGS_SL) $(SHLIB_LINK) $(LIBS) $(LDAP_LIBS_BE)
-$(exports_file): $(OBJS)
- $(DLLTOOL) --export-all $(DLLTOOL_DEFFLAGS) --output-def $@ $^
-endif
+$(stlib): $(OBJS) | $(SHLIB_PREREQS)
+ rm -f $@
+ $(LINK.static) $@ $^
+ $(RANLIB) $@
+
+else
+
+# Win32 case
-$(shlib): $(OBJS) $(DLL_DEFFILE)
- $(DLLWRAP) $(LDFLAGS_SL) -o $@ --dllname $(shlib) $(DLLWRAP_FLAGS) --def $(DLL_DEFFILE) $(OBJS) $(SHLIB_LINK)
+# There is no correct way to write a rule that generates two files.
+# Rules with two targets don't have that meaning, they are merely
+# shorthand for two otherwise separate rules. To be safe for parallel
+# make, we must chain the dependencies like this. The semicolon is
+# important, otherwise make will choose some built-in rule.
+
+$(stlib): $(shlib) ;
+
+# XXX A backend that loads a module linked with libgcc_s_dw2-1.dll will exit
+# uncleanly, hence -static-libgcc. (Last verified with MinGW-w64 compilers
+# from i686-4.9.1-release-win32-dwarf-rt_v3-rev1.) Shared libgcc has better
+# support for C++/Java exceptions; while core PostgreSQL does not use them, it
+# would be nice to support shared libgcc for the benefit of extensions.
+#
+# If SHLIB_EXPORTS is set, the rules below will build a .def file from that.
+# Else we just use --export-all-symbols.
+ifeq (,$(SHLIB_EXPORTS))
+$(shlib): $(OBJS) | $(SHLIB_PREREQS)
+ $(CC) $(CFLAGS) -shared -static-libgcc -o $@ $(OBJS) $(LDFLAGS) $(LDFLAGS_SL) $(SHLIB_LINK) $(LIBS) -Wl,--export-all-symbols -Wl,--out-implib=$(stlib)
+else
+DLL_DEFFILE = lib$(NAME)dll.def
-$(stlib): $(shlib) $(DLL_DEFFILE)
- $(DLLTOOL) --dllname $(shlib) $(DLLTOOL_LIBFLAGS) --def $(DLL_DEFFILE) --output-lib $@
+$(shlib): $(OBJS) $(DLL_DEFFILE) | $(SHLIB_PREREQS)
+ $(CC) $(CFLAGS) -shared -static-libgcc -o $@ $(OBJS) $(DLL_DEFFILE) $(LDFLAGS) $(LDFLAGS_SL) $(SHLIB_LINK) $(LIBS) -Wl,--out-implib=$(stlib)
+endif
+endif # PORTNAME == cgywin
endif # PORTNAME == cygwin || PORTNAME == win32
-endif # enable_shared
+
+%.pc: $(MAKEFILE_LIST)
+ echo 'Name: lib$(NAME)' >$@
+ echo 'Description: PostgreSQL lib$(NAME) library' >>$@
+ echo 'Url: http://www.postgresql.org/' >>$@
+ echo 'Version: $(VERSION)' >>$@
+ echo 'Requires: ' >>$@
+ echo 'Requires.private: $(PKG_CONFIG_REQUIRES_PRIVATE)' >>$@
+ echo 'Cflags: -I$(includedir)' >>$@
+ echo 'Libs: -L$(libdir) -l$(NAME)' >>$@
+# Record -L flags that the user might have passed in to the PostgreSQL
+# build to locate third-party libraries (e.g., ldap, ssl). Filter out
+# those that point inside the build or source tree. Use sort to
+# remove duplicates. Also record the -l flags necessary for static
+# linking, but not those already covered by Requires.private.
+ echo 'Libs.private: $(sort $(filter-out -L.% -L$(top_srcdir)/%,$(filter -L%,$(LDFLAGS) $(SHLIB_LINK)))) $(filter-out $(PKG_CONFIG_REQUIRES_PRIVATE:lib%=-l%),$(filter -l%,$(SHLIB_LINK)))' >>$@
# We need several not-quite-identical variants of .DEF files to build
# tarballs.
ifneq (,$(SHLIB_EXPORTS))
-distprep: $(srcdir)/lib$(NAME)dll.def $(srcdir)/lib$(NAME)ddll.def $(srcdir)/blib$(NAME)dll.def
+distprep: lib$(NAME)dll.def lib$(NAME)ddll.def blib$(NAME)dll.def
UC_NAME = $(shell echo $(NAME) | tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')
-$(srcdir)/lib$(NAME)dll.def: $(SHLIB_EXPORTS)
- echo '; DEF file for MS VC++' >$@
- echo 'LIBRARY LIB$(UC_NAME)' >>$@
+lib$(NAME)dll.def: $(SHLIB_EXPORTS)
+ echo '; DEF file for win32.mak release build and for Makefile.shlib (MinGW)' >$@
+ echo 'LIBRARY LIB$(UC_NAME).dll' >>$@
echo 'EXPORTS' >>$@
- sed -e '/^#/d' -e 's/^\(.* \)\([0-9][0-9]*\)/ \1@ \2/' $< >>$@
+ sed -e '/^#/d' -e 's/^\(.*[ ]\)\([0-9][0-9]*\)/ \1@ \2/' $< >>$@
-$(srcdir)/lib$(NAME)ddll.def: $(SHLIB_EXPORTS)
- echo '; DEF file for MS VC++' >$@
- echo 'LIBRARY LIB$(UC_NAME)D' >>$@
+lib$(NAME)ddll.def: $(SHLIB_EXPORTS)
+ echo '; DEF file for win32.mak debug build' >$@
+ echo 'LIBRARY LIB$(UC_NAME)D.dll' >>$@
echo 'EXPORTS' >>$@
- sed -e '/^#/d' -e 's/^\(.* \)\([0-9][0-9]*\)/ \1@ \2/' $< >>$@
+ sed -e '/^#/d' -e 's/^\(.*[ ]\)\([0-9][0-9]*\)/ \1@ \2/' $< >>$@
-$(srcdir)/blib$(NAME)dll.def: $(SHLIB_EXPORTS)
- echo '; DEF file for Borland C++ Builder' >$@
+blib$(NAME)dll.def: $(SHLIB_EXPORTS)
+ echo '; DEF file for bcc32.mak (Borland C++ Builder)' >$@
echo 'LIBRARY BLIB$(UC_NAME)' >>$@
echo 'EXPORTS' >>$@
- sed -e '/^#/d' -e 's/^\(.* \)\([0-9][0-9]*\)/ _\1@ \2/' $< >>$@
+ sed -e '/^#/d' -e 's/^\(.*[ ]\)\([0-9][0-9]*\)/ _\1@ \2/' $< >>$@
echo >>$@
echo '; Aliases for MS compatible names' >> $@
- sed -e '/^#/d' -e 's/^\(.* \)\([0-9][0-9]*\)/ \1= _\1/' $< | sed 's/ *$$//' >>$@
+ sed -e '/^#/d' -e 's/^\(.*[ ]\)\([0-9][0-9]*\)/ \1= _\1/' $< | sed 's/ *$$//' >>$@
endif # SHLIB_EXPORTS
install-lib: install-lib-shared
ifdef soname
install-lib: install-lib-static
+install-lib: install-lib-pc
endif
+install-lib-pc: lib$(NAME).pc installdirs-lib
+ $(INSTALL_DATA) $< '$(DESTDIR)$(pkgconfigdir)/lib$(NAME).pc'
+
install-lib-static: $(stlib) installdirs-lib
$(INSTALL_STLIB) $< '$(DESTDIR)$(libdir)/$(stlib)'
ifeq ($(PORTNAME), darwin)
ranlib $(stlib)
endif
-ifeq ($(enable_shared), yes)
install-lib-shared: $(shlib) installdirs-lib
ifdef soname
# we don't install $(shlib) on AIX
+# (see http://archives.postgresql.org/message-id/52EF20B2E3209443BC37736D00C3C1380A6E79FE@EXADV1.host.magwien.gv.at)
ifneq ($(PORTNAME), aix)
$(INSTALL_SHLIB) $< '$(DESTDIR)$(libdir)/$(shlib)'
ifneq ($(PORTNAME), cygwin)
endif # not win32
endif # not cygwin
endif # not aix
+ifneq (,$(findstring $(PORTNAME),win32 cygwin))
+ $(INSTALL_SHLIB) $< '$(DESTDIR)$(bindir)/$(shlib)'
+endif
else # no soname
$(INSTALL_SHLIB) $< '$(DESTDIR)$(pkglibdir)/$(shlib)'
endif
-else # not enable_shared
-ifndef soname
-install-lib-shared:
- @echo "*****"; \
- echo "* Module $(NAME) was not installed due to lack of shared library support."; \
- echo "*****"
-endif
-endif # enable_shared
installdirs-lib:
ifdef soname
- $(mkinstalldirs) '$(DESTDIR)$(libdir)'
+ $(MKDIR_P) '$(DESTDIR)$(libdir)' '$(DESTDIR)$(pkgconfigdir)' $(if $(findstring $(PORTNAME),win32 cygwin),'$(DESTDIR)$(bindir)')
else
- $(mkinstalldirs) '$(DESTDIR)$(pkglibdir)'
+ $(MKDIR_P) '$(DESTDIR)$(pkglibdir)'
endif
uninstall-lib:
ifdef soname
rm -f '$(DESTDIR)$(libdir)/$(stlib)'
-ifeq ($(enable_shared), yes)
rm -f '$(DESTDIR)$(libdir)/$(shlib_bare)' \
'$(DESTDIR)$(libdir)/$(shlib_major)' \
- '$(DESTDIR)$(libdir)/$(shlib)'
-endif # enable_shared
+ '$(DESTDIR)$(libdir)/$(shlib)' $(if $(findstring $(PORTNAME),win32 cygwin),'$(DESTDIR)$(bindir)/$(shlib)') \
+ '$(DESTDIR)$(pkgconfigdir)/lib$(NAME).pc'
else # no soname
rm -f '$(DESTDIR)$(pkglibdir)/$(shlib)'
endif # no soname
.PHONY: clean-lib
clean-lib:
- rm -f $(shlib) $(shlib_bare) $(shlib_major) $(stlib) $(exports_file)
+ rm -f $(shlib) $(shlib_bare) $(shlib_major) $(stlib) $(exports_file) lib$(NAME).pc
ifneq (,$(SHLIB_EXPORTS))
maintainer-clean-lib:
- rm -f $(srcdir)/lib$(NAME)dll.def $(srcdir)/lib$(NAME)ddll.def $(srcdir)/blib$(NAME)dll.def
+ rm -f lib$(NAME)dll.def lib$(NAME)ddll.def blib$(NAME)dll.def
endif