]> granicus.if.org Git - postgresql/blobdiff - src/Makefile.shlib
Update copyright for 2019
[postgresql] / src / Makefile.shlib
index 74d48c56f2c2d582d1b7bad4d9dd73c6996a6084..373d73caefca34305ddc3ec363ea04c946e10cd3 100644 (file)
 #
 # NAME                  Name of library to build (no suffix nor "lib" prefix)
 # 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_LINK            Stuff to append to library's link command
+#                       (typically, -L and -l switches for external libraries)
+# SHLIB_LINK_INTERNAL   -L and -l switches for Postgres-supplied libraries
 # 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"
 #
+# Don't use SHLIB_LINK for references to files in the build tree, or the
+# wrong things will happen --- use SHLIB_LINK_INTERNAL for those!
+#
 # When building a shared library, the following version information
 # must also be set.  It should be omitted when building a dynamically
 # loadable module.
 #
 # Got that?  Look at src/interfaces/libpq/Makefile for an example.
 #
-# While the linker allows creation of most shared libraries,
-# -Bsymbolic requires resolution of all symbols, making the
-# compiler a better choice for shared library creation on ELF platforms.
-# With the linker, -Bsymbolic requires the crt1.o startup object file.
-# bjm 2001-02-10
 
 
 COMPILER = $(CC) $(CFLAGS)
 LINK.static = $(AR) $(AROPT)
 
+LDFLAGS_INTERNAL += $(SHLIB_LINK_INTERNAL)
+
 
 
 ifdef SO_MAJOR_VERSION
@@ -143,6 +144,11 @@ ifeq ($(PORTNAME), openbsd)
     ifdef soname
       LINK.shared      += -Wl,-x,-soname,$(soname)
     endif
+    BUILD.exports      = ( echo '{ global:'; $(AWK) '/^[^\#]/ {printf "%s;\n",$$1}' $<; echo ' local: *; };' ) >$@
+    exports_file       = $(SHLIB_EXPORTS:%.txt=%.list)
+    ifneq (,$(exports_file))
+      LINK.shared      += -Wl,--version-script=$(exports_file)
+    endif
     SHLIB_LINK         += -lc
   else
     LINK.shared                = $(LD) -x -Bshareable -Bforcearchive
@@ -158,6 +164,11 @@ ifeq ($(PORTNAME), freebsd)
     ifdef soname
       LINK.shared      += -Wl,-x,-soname,$(soname)
     endif
+    BUILD.exports      = ( echo '{ global:'; $(AWK) '/^[^\#]/ {printf "%s;\n",$$1}' $<; echo ' local: *; };' ) >$@
+    exports_file       = $(SHLIB_EXPORTS:%.txt=%.list)
+    ifneq (,$(exports_file))
+      LINK.shared      += -Wl,--version-script=$(exports_file)
+    endif
   else
     ifdef SO_MAJOR_VERSION
       shlib            = lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
@@ -172,6 +183,11 @@ ifeq ($(PORTNAME), netbsd)
     ifdef soname
       LINK.shared      += -Wl,-x,-soname,$(soname)
     endif
+    BUILD.exports      = ( echo '{ global:'; $(AWK) '/^[^\#]/ {printf "%s;\n",$$1}' $<; echo ' local: *; };' ) >$@
+    exports_file       = $(SHLIB_EXPORTS:%.txt=%.list)
+    ifneq (,$(exports_file))
+      LINK.shared      += -Wl,--version-script=$(exports_file)
+    endif
   else
     LINK.shared                = $(LD) -x -Bshareable -Bforcearchive
   endif
@@ -182,12 +198,12 @@ ifeq ($(PORTNAME), hpux)
     shlib                      = lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
   endif
   ifeq ($(with_gnu_ld), yes)
-    LINK.shared                = $(CC) -shared
+    LINK.shared                = $(CC) -shared -Wl,-Bsymbolic
     ifdef soname
       LINK.shared      += -Wl,-h -Wl,$(soname)
     endif
   else
-    LINK.shared                = $(LD) -b
+    LINK.shared                = $(LD) -b -Bsymbolic
     ifdef soname
       LINK.shared      += +h $(soname)
     endif
@@ -224,9 +240,9 @@ endif
 
 ifeq ($(PORTNAME), solaris)
   ifeq ($(GCC), yes)
-    LINK.shared                = $(COMPILER) -shared
+    LINK.shared                = $(COMPILER) -shared -Wl,-Bsymbolic
   else
-    LINK.shared                = $(COMPILER) -G
+    LINK.shared                = $(COMPILER) -G -Bsymbolic
   endif
   ifdef soname
     ifeq ($(with_gnu_ld), yes)
@@ -271,11 +287,17 @@ all-static-lib: $(stlib)
 
 all-shared-lib: $(shlib)
 
+# In this rule, "touch $@" works around a problem on some platforms wherein
+# ranlib updates the library file's mod time with a value calculated to
+# seconds precision.  If the filesystem has sub-second timestamps, this can
+# cause the library file to appear older than its input files, triggering
+# parallel-make problems.
 ifndef haslibarule
 $(stlib): $(OBJS) | $(SHLIB_PREREQS)
        rm -f $@
        $(LINK.static) $@ $^
        $(RANLIB) $@
+       touch $@
 endif #haslibarule
 
 
@@ -337,12 +359,11 @@ ifeq ($(PORTNAME), cygwin)
 # Cygwin case
 
 $(shlib): $(OBJS) | $(SHLIB_PREREQS)
-       $(CC) $(CFLAGS)  -shared -o $@  $(OBJS) $(LDFLAGS) $(LDFLAGS_SL) $(SHLIB_LINK) $(LIBS) $(LDAP_LIBS_BE)
+       $(CC) $(CFLAGS)  -shared -o $@ -Wl,--out-implib=$(stlib) $(OBJS) $(LDFLAGS) $(LDFLAGS_SL) $(SHLIB_LINK) $(LIBS) $(LDAP_LIBS_BE)
 
-$(stlib): $(OBJS) | $(SHLIB_PREREQS)
-       rm -f $@
-       $(LINK.static) $@ $^
-       $(RANLIB) $@
+# see notes in src/backend/parser/Makefile  about use of this type of rule
+$(stlib): $(shlib)
+       touch $@
 
 else
 
@@ -435,7 +456,7 @@ install-lib-static: $(stlib) installdirs-lib
        $(INSTALL_STLIB) $< '$(DESTDIR)$(libdir)/$(stlib)'
 ifeq ($(PORTNAME), darwin)
        cd '$(DESTDIR)$(libdir)' && \
-       ranlib $(stlib)
+       $(RANLIB) $(stlib)
 endif
 
 install-lib-shared: $(shlib) installdirs-lib