]> granicus.if.org Git - postgresql/blobdiff - src/Makefile.shlib
Review program help output for wording and formatting
[postgresql] / src / Makefile.shlib
index 37a99dbf9518228f199680fad13fb9006e78e0ef..86db52fe5e1f5b0c36ea91eff2e30a5a5a387f1e 100644 (file)
@@ -6,7 +6,7 @@
 # Copyright (c) 1998, Regents of the University of California
 #
 # IDENTIFICATION
-#    $PostgreSQL: pgsql/src/Makefile.shlib,v 1.119 2008/12/11 07:34:07 petere Exp $
+#    src/Makefile.shlib
 #
 #-------------------------------------------------------------------------
 
@@ -22,8 +22,9 @@
 # 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.)
@@ -78,33 +73,24 @@ LINK.static = $(AR) $(AROPT)
 
 
 
-# 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)
+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
@@ -125,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
 
@@ -135,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)
@@ -162,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
@@ -208,17 +182,17 @@ ifeq ($(PORTNAME), hpux)
     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
@@ -227,25 +201,15 @@ ifeq ($(PORTNAME), hpux)
     # 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
@@ -273,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
@@ -293,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
@@ -314,6 +262,7 @@ ifeq ($(PORTNAME), unixware)
 endif
 
 ifeq ($(PORTNAME), cygwin)
+  LINK.shared          = $(CC) -shared
   ifdef SO_MAJOR_VERSION
     shlib              = cyg$(NAME)$(DLSUFFIX)
   endif
@@ -327,10 +276,6 @@ ifeq ($(PORTNAME), win32)
   haslibarule   = yes
 endif
 
-ifeq ($(enable_rpath), yes)
-SHLIB_LINK += $(rpath)
-endif
-
 
 
 ##
@@ -343,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)
@@ -350,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) $(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))
@@ -392,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) $(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)
 
@@ -404,28 +351,67 @@ endif # PORTNAME == aix
 
 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
+
+# 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) ;
 
-$(shlib): $(OBJS) $(DLL_DEFFILE)
-       $(DLLWRAP) $(LDFLAGS_SL) -o $@ --dllname $(shlib) $(DLLWRAP_FLAGS) --def $(DLL_DEFFILE) $(OBJS) $(SHLIB_LINK)
+# 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
@@ -435,30 +421,30 @@ endif # enable_shared
 # 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
 
 
@@ -470,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)
@@ -479,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
@@ -501,24 +490,19 @@ 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
-       $(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
 
 
@@ -530,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
@@ -546,9 +529,9 @@ 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