]> granicus.if.org Git - postgresql/blobdiff - src/Makefile.shlib
Update copyright for 2019
[postgresql] / src / Makefile.shlib
index c293a34d1aa8403f776eefddc14b57d65a180824..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
@@ -100,6 +101,7 @@ endif
 # Try to keep the sections in some kind of order, folks...
 
 override CFLAGS += $(CFLAGS_SL)
+override CXXFLAGS += $(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)
@@ -142,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
@@ -157,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)
@@ -171,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
@@ -181,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
@@ -223,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)
@@ -270,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
 
 
@@ -314,13 +337,9 @@ else # PORTNAME == aix
 
 # AIX 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) ;
+# See notes in src/backend/parser/Makefile about the following two rules
+$(stlib): $(shlib)
+       touch $@
 
 $(shlib): $(OBJS) | $(SHLIB_PREREQS)
        rm -f $(stlib)
@@ -340,24 +359,19 @@ 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
 
 # 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) ;
+# See notes in src/backend/parser/Makefile about the following two rules
+$(stlib): $(shlib)
+       touch $@
 
 # 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
@@ -377,7 +391,7 @@ $(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
 endif # PORTNAME == cygwin || PORTNAME == win32
 
 
@@ -405,30 +419,22 @@ endif # PORTNAME == cygwin || PORTNAME == win32
 # tarballs.
 
 ifneq (,$(SHLIB_EXPORTS))
-distprep: lib$(NAME)dll.def lib$(NAME)ddll.def blib$(NAME)dll.def
+distprep: lib$(NAME)dll.def lib$(NAME)ddll.def
 
 UC_NAME = $(shell echo $(NAME) | tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')
 
 lib$(NAME)dll.def: $(SHLIB_EXPORTS)
-       echo '; DEF file for win32.mak release build and for Makefile.shlib (MinGW)' >$@
+       echo '; DEF file 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 win32.mak debug build' >$@
+       echo '; DEF file for Makefile.shlib (MinGW)' >$@
        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 bcc32.mak (Borland C++ Builder)' >$@
-       echo 'LIBRARY BLIB$(UC_NAME)' >>$@
-       echo 'EXPORTS' >>$@
-       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/ *$$//' >>$@
 endif # SHLIB_EXPORTS
 
 
@@ -450,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
@@ -517,5 +523,5 @@ clean-lib:
 
 ifneq (,$(SHLIB_EXPORTS))
 maintainer-clean-lib:
-       rm -f lib$(NAME)dll.def lib$(NAME)ddll.def blib$(NAME)dll.def
+       rm -f lib$(NAME)dll.def lib$(NAME)ddll.def
 endif