]> granicus.if.org Git - postgresql/blobdiff - src/Makefile.shlib
Review program help output for wording and formatting
[postgresql] / src / Makefile.shlib
index 61984935612dd1e05f710e67acfafcbe7d015046..86db52fe5e1f5b0c36ea91eff2e30a5a5a387f1e 100644 (file)
@@ -6,7 +6,7 @@
 # Copyright (c) 1998, Regents of the University of California
 #
 # IDENTIFICATION
-#    $PostgreSQL: pgsql/src/Makefile.shlib,v 1.124 2010/07/05 18:54:37 tgl Exp $
+#    src/Makefile.shlib
 #
 #-------------------------------------------------------------------------
 
@@ -22,6 +22,7 @@
 # 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, in the format "function_name  number"
 #
 # 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.)
@@ -78,25 +73,19 @@ LINK.static = $(AR) $(AROPT)
 
 
 
-# Automatically append LDFLAGS and LDFLAGS_SL to SHLIB_LINK
-SHLIB_LINK += $(LDFLAGS) $(LDFLAGS_SL)
-
 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)
+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
@@ -122,6 +111,7 @@ ifeq ($(PORTNAME), aix)
     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
 
@@ -132,13 +122,13 @@ ifeq ($(PORTNAME), darwin)
     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)
@@ -159,19 +149,6 @@ ifeq ($(PORTNAME), openbsd)
   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
@@ -233,16 +210,6 @@ ifeq ($(PORTNAME), hpux)
   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
@@ -270,14 +237,6 @@ ifeq ($(PORTNAME), solaris)
   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
@@ -290,14 +249,6 @@ ifeq ($(PORTNAME), sco)
   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
@@ -311,6 +262,7 @@ ifeq ($(PORTNAME), unixware)
 endif
 
 ifeq ($(PORTNAME), cygwin)
+  LINK.shared          = $(CC) -shared
   ifdef SO_MAJOR_VERSION
     shlib              = cyg$(NAME)$(DLSUFFIX)
   endif
@@ -336,6 +288,7 @@ all-lib: all-shared-lib
 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)
@@ -343,19 +296,19 @@ 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) -o $@ $(OBJS) $(SHLIB_LINK)
+$(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))
@@ -385,11 +338,12 @@ endif
 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) -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)
 
@@ -397,29 +351,67 @@ endif # PORTNAME == aix
 
 else # PORTNAME == cygwin || PORTNAME == win32
 
-# Cygwin or Win32 case
+ifeq ($(PORTNAME), cygwin)
 
-# 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))
-DLL_DEFFILE = lib$(NAME)dll.def
-exports_file = $(DLL_DEFFILE)
+# Cygwin case
+
+$(shlib): $(OBJS) | $(SHLIB_PREREQS)
+       $(CC) $(CFLAGS)  -shared -o $@  $(OBJS) $(LDFLAGS) $(LDFLAGS_SL) $(SHLIB_LINK) $(LIBS) $(LDAP_LIBS_BE)
+
+$(stlib): $(OBJS) | $(SHLIB_PREREQS)
+       rm -f $@
+       $(LINK.static) $@ $^
+       $(RANLIB) $@
 
-$(exports_file): $(OBJS)
-       $(DLLTOOL) --export-all $(DLLTOOL_DEFFLAGS) --output-def $@ $^
 else
-DLL_DEFFILE = lib$(NAME)dll.def
-endif
 
-$(shlib): $(OBJS) $(DLL_DEFFILE)
-       $(DLLWRAP) -o $@ --dllname $(shlib) $(DLLWRAP_FLAGS) --def $(DLL_DEFFILE) $(OBJS) $(SHLIB_LINK)
+# Win32 case
+
+# 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) $(DLL_DEFFILE)
-       $(DLLTOOL) --dllname $(shlib) $(DLLTOOL_LIBFLAGS) --def $(DLL_DEFFILE) --output-lib $@
+$(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
+
+$(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
@@ -434,19 +426,19 @@ distprep: lib$(NAME)dll.def lib$(NAME)ddll.def blib$(NAME)dll.def
 UC_NAME = $(shell echo $(NAME) | tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')
 
 lib$(NAME)dll.def: $(SHLIB_EXPORTS)
-       echo '; DEF file for MS VC++' >$@
-       echo 'LIBRARY LIB$(UC_NAME)' >>$@
+       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/' $< >>$@
 
 lib$(NAME)ddll.def: $(SHLIB_EXPORTS)
-       echo '; DEF file for MS VC++' >$@
-       echo 'LIBRARY LIB$(UC_NAME)D' >>$@
+       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/' $< >>$@
 
 blib$(NAME)dll.def: $(SHLIB_EXPORTS)
-       echo '; DEF file for Borland C++ Builder' >$@
+       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/' $< >>$@
@@ -464,8 +456,12 @@ 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)
@@ -473,7 +469,6 @@ 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
@@ -495,22 +490,17 @@ endif
 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
-       $(MKDIR_P) '$(DESTDIR)$(libdir)'
+       $(MKDIR_P) '$(DESTDIR)$(libdir)' '$(DESTDIR)$(pkgconfigdir)' $(if $(findstring $(PORTNAME),win32 cygwin),'$(DESTDIR)$(bindir)')
 else
        $(MKDIR_P) '$(DESTDIR)$(pkglibdir)'
 endif
@@ -524,11 +514,10 @@ 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
@@ -540,7 +529,7 @@ 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: