Attempt to unify hpux-shared rules. More adjustments might be required
[openssl.git] / Makefile.shared
index f163bae..f817d12 100644 (file)
@@ -7,21 +7,34 @@
 
 # CC contains the current compiler.  This one MUST be defined
 CC=cc
-# LDFLAGS contains flags to be used when the temporary object file is
-# created.  SHARED_LDFLAGS contains flags to be used when the shared
-# library is created.
+# LDFLAGS contains flags to be used when temporary object files (when building
+# shared libraries) are created, or when an application is linked.
+# SHARED_LDFLAGS contains flags to be used when the shared library is created.
 LDFLAGS=
 SHARED_LDFLAGS=
 
-# LIBNAME contains just the name of thhe library, without prefix ("lib"
+# LIBNAME contains just the name of the library, without prefix ("lib"
 # on Unix, "cyg" for certain forms under Cygwin...) or suffix (.a, .so,
-# .dll, ...).  This one MUST have a value when using this makefile.
+# .dll, ...).  This one MUST have a value when using this makefile to
+# build shared libraries.
 # For example, to build libfoo.so, you need to do the following:
 #LIBNAME=foo
 LIBNAME=
 
+# APPNAME contains just the name of the application, without suffix (""
+# on Unix, ".exe" on Windows, ...).  This one MUST have a value when using
+# this makefile to build applications.
+# For example, to build foo, you need to do the following:
+#APPNAME=foo
+APPNAME=
+
+# OBJECTS contains all the object files to link together into the application.
+# This must contain at least one object file.
+#OBJECTS=foo.o
+OBJECTS=
+
 # LIBEXTRAS contains extra modules to link together with the library.
-# For example, if a seond library, say libbar.a needs to be linked into
+# For example, if a second library, say libbar.a needs to be linked into
 # libfoo.so, you need to do the following:
 #LIBEXTRAS=libbar.a
 # Note that this MUST be used when using the link_o targets, to hold the
@@ -64,421 +77,511 @@ CALC_VERSIONS=    \
        if [ -n "$(LIBVERSION)$(LIBCOMPATVERSIONS)" ]; then \
                prev=""; \
                for v in `echo "$(LIBVERSION) $(LIBCOMPATVERSIONS)" | cut -d';' -f1`; do \
-                       SHLIB_SOVER_NODOT=$$v \
+                       SHLIB_SOVER_NODOT=$$v; \
                        SHLIB_SOVER=.$$v; \
                        if [ -n "$$prev" ]; then \
-                               SHLIB_COMPAT=$$SHLIB_COMPAT .$$prev; \
+                               SHLIB_COMPAT="$$SHLIB_COMPAT .$$prev"; \
                        fi; \
                        prev=$$v; \
                done; \
        fi
 
+LINK_APP=      \
+  ( $(DEBUG);   \
+    LIBPATH=`for x in $$LIBDEPS; do if echo $$x | grep '^ *-L' > /dev/null 2>&1; then echo $$x | sed -e 's/^ *-L//'; fi; done | uniq`; \
+    LIBPATH=`echo $$LIBPATH | sed -e 's/ /:/g'`; \
+    LD_LIBRARY_PATH=$$LIBPATH:$$LD_LIBRARY_PATH \
+    $$LDCMD $(LDFLAGS) $$LDFLAGS -o $$APPNAME $(OBJECTS) $$LIBDEPS )
+
 LINK_SO=       \
-  ( $(DEBUG); \
+  ( $(DEBUG);   \
     nm -Pg $$SHOBJECTS | grep ' [BDT] ' | cut -f1 -d' ' > lib$(LIBNAME).exp; \
+    LIBPATH=`for x in $$LIBDEPS; do if echo $$x | grep '^ *-L' > /dev/null 2>&1; then echo $$x | sed -e 's/^ *-L//'; fi; done | uniq`; \
+    LIBPATH=`echo $$LIBPATH | sed -e 's/ /:/g'`; \
+    LD_LIBRARY_PATH=$$LIBPATH:$$LD_LIBRARY_PATH \
     $$SHAREDCMD $(SHARED_LDFLAGS) $$SHAREDFLAGS -o $$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX \
        $$ALLSYMSFLAGS $$SHOBJECTS $$NOALLSYMSFLAGS $$LIBDEPS ) && \
   $(SYMLINK_SO); ( $(DEBUG); rm -f lib$(LIBNAME).exp )
 SYMLINK_SO=    \
-       prev=$$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX; \
-       if [ -n "$$SHLIB_COMPAT"]; then \
-               for x in $$SHLIB_COMPAT; do \
-                       ( $(DEBUG); rm -f $$SHLIB$$x$$SHLIB_SUFFIX; \
-                         ln -s $$prev $$SHLIB$$x$$SHLIB_SUFFIX ); \
-                       prev=$$SHLIB$$x$$SHLIB_SUFFIX; \
-               done; \
-       fi; \
-       if [ -n "$$SHLIB_SOVER" ]; then \
-               ( $(DEBUG); rm -f $$SHLIB$$SHLIB_SUFFIX; \
-                 ln -s $$prev $$SHLIB$$SHLIB_SUFFIX ); \
+       if [ -n "$$INHIBIT_SYMLINKS" ]; then :; else \
+               prev=$$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX; \
+               if [ -n "$$SHLIB_COMPAT" ]; then \
+                       for x in $$SHLIB_COMPAT; do \
+                               ( $(DEBUG); rm -f $$SHLIB$$x$$SHLIB_SUFFIX; \
+                                 ln -s $$prev $$SHLIB$$x$$SHLIB_SUFFIX ); \
+                               prev=$$SHLIB$$x$$SHLIB_SUFFIX; \
+                       done; \
+               fi; \
+               if [ -n "$$SHLIB_SOVER" ]; then \
+                       ( $(DEBUG); rm -f $$SHLIB$$SHLIB_SUFFIX; \
+                         ln -s $$prev $$SHLIB$$SHLIB_SUFFIX ); \
+               fi; \
        fi
 
 LINK_SO_A=     SHOBJECTS="lib$(LIBNAME).a $(LIBEXTRAS)"; $(LINK_SO)
 LINK_SO_O=     SHOBJECTS="$(LIBEXTRAS)"; $(LINK_SO)
 LINK_SO_A_VIA_O=       \
-  SHOBJECTS=lib$(LIBNAME).o ALL=$$ALLSYMSFLAGS ALLSYMSFLAGS= NOALLSYMSFLAGS=; \
+  SHOBJECTS=lib$(LIBNAME).o; \
+  ALL=$$ALLSYMSFLAGS; ALLSYMSFLAGS=; NOALLSYMSFLAGS=; \
   ( $(DEBUG); \
     ld $(LDFLAGS) -r -o lib$(LIBNAME).o $$ALL lib$(LIBNAME).a $(LIBEXTRAS) ); \
   $(LINK_SO) && rm -f $(LIBNAME).o
 LINK_SO_A_UNPACKED=    \
   UNPACKDIR=link_tmp.$$$$; rm -rf $$UNPACKDIR; mkdir $$UNPACKDIR; \
-  (cd $$UNPACKDIR; ar x ../lib$(LIBNAME).a) && cp $(LIBEXTRAS) $$UNPACKDIR && \
+  (cd $$UNPACKDIR; ar x ../lib$(LIBNAME).a) && \
+  ([ -z "$(LIBEXTRAS)" ] || cp $(LIBEXTRAS) $$UNPACKDIR) && \
   SHOBJECTS=$$UNPACKDIR/*.o; \
   $(LINK_SO) && rm -rf $$UNPACKDIR
 
-DETECT_GNU_LD=${CC} -v 2>&1 | grep '^gcc' >/dev/null 2>&1 && \
-       my_ld=`gcc -print-prog-name=ld 2>&1` && \
-       [ -n "$$my_ld" ] && \
-       $$my_ld -v 2>&1 | grep 'GNU ld' >/dev/null 2>&1
+DETECT_GNU_LD=(${CC} -Wl,-V /dev/null 2>&1 | grep '^GNU ld' )>/dev/null
+
+DO_GNU_SO=$(CALC_VERSIONS); \
+       SHLIB=lib$(LIBNAME).so; \
+       SHLIB_SUFFIX=; \
+       LIBDEPS="$(LIBDEPS) -lc"; \
+       ALLSYMSFLAGS='-Wl,--whole-archive'; \
+       NOALLSYMSFLAGS='-Wl,--no-whole-archive'; \
+       SHAREDFLAGS="-shared -Wl,-Bsymbolic -Wl,-soname=$$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX -Wl,-rpath,$(LIBRPATH)"; \
+       SHAREDCMD='$(CC)'
+DO_GNU_APP=LDCMD=$(CC);\
+       LDFLAGS="-Wl,-rpath,$(LIBRPATH)"; \
+       LIBDEPS="$(LIBDEPS) -lc"; \
+       APPNAME=$(APPNAME)
+
+#This is rather special.  It's a special target with which one can link
+#applications without bothering with any features that have anything to
+#do with shared libraries, for example when linking against static
+#libraries.  It's mostly here to avoid a lot of conditionals everywhere
+#else...
+link_app.:
+       LDCMD=$(CC); \
+       LDFLAGS=""; \
+       LIBDEPS="$(LIBDEPS)"; \
+       APPNAME="$(APPNAME)"; \
+       $(LINK_APP)
 
 link_o.gnu:
-       @ $(CALC_VERSIONS); \
-       SHLIB=lib$(LIBNAME).so \
-       SHLIB_SUFFIX= \
-       LIBDEPS="$(LIBDEPS)" \
-       NOALLSYMSFLAGS='-Wl,--no-whole-archive' \
-       SHAREDFLAGS="-shared -Wl,-Bsymbolic -Wl,-soname=$$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX" \
-       SHAREDCMD='$(CC)'; \
-       $(LINK_SO_O)
+       @ $(DO_GNU_SO); $(LINK_SO_O)
 link_a.gnu:
-       @ $(CALC_VERSIONS); \
-       SHLIB=lib$(LIBNAME).so \
-       SHLIB_SUFFIX= \
-       LIBDEPS="$(LIBDEPS)" \
-       ALLSYMSFLAGS='-Wl,--whole-archive' \
-       NOALLSYMSFLAGS='-Wl,--no-whole-archive' \
-       SHAREDFLAGS="-shared -Wl,-Bsymbolic -Wl,-soname=$$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX" \
-       SHAREDCMD='$(CC)'; \
-       $(LINK_SO_A)
+       @ $(DO_GNU_SO); $(LINK_SO_A)
+link_app.gnu:
+       @ $(DO_GNU_APP); $(LINK_APP)
 
 # For Darwin AKA Mac OS/X (dyld)
 link_o.darwin:
        @ $(CALC_VERSIONS); \
-       SHLIB=lib$(LIBNAME) \
-       SHLIB_SUFFIX=.dylib \
-       LIBDEPS="$(LIBDEPS)" \
-       ALLSYMSFLAGS='-all_load' \
-       NOALLSYMSFLAGS='' \
-       SHAREDFLAGS="-dynamiclib" \
+       SHLIB=lib$(LIBNAME); \
+       SHLIB_SUFFIX=.dylib; \
+       LIBDEPS="$(LIBDEPS) -lc"; \
+       ALLSYMSFLAGS='-all_load'; \
+       NOALLSYMSFLAGS=''; \
+       SHAREDFLAGS="-dynamiclib"; \
        SHAREDCMD='$(CC)'; \
        if [ -n "$(LIBVERSION)" ]; then \
-               SHAREDFLAGS="$SHAREDFLAGS -current_version $(LIBVERSION)"; \
+               SHAREDFLAGS="$$SHAREDFLAGS -current_version $(LIBVERSION)"; \
        fi; \
        if [ -n "$$SHLIB_SOVER_NODOT" ]; then \
-               SHAREDFLAGS="$SHAREDFLAGS -compatibility_version $$SHLIB_SOVER_NODOT"; \
+               SHAREDFLAGS="$$SHAREDFLAGS -compatibility_version $$SHLIB_SOVER_NODOT"; \
        fi; \
        $(LINK_SO_O)
 link_a.darwin:
        @ $(CALC_VERSIONS); \
-       SHLIB=lib$(LIBNAME) \
-       SHLIB_SUFFIX=.dylib \
-       LIBDEPS="$(LIBDEPS)" \
-       ALLSYMSFLAGS='-all_load' \
-       NOALLSYMSFLAGS='' \
-       SHAREDFLAGS="-dynamiclib" \
+       SHLIB=lib$(LIBNAME); \
+       SHLIB_SUFFIX=.dylib; \
+       LIBDEPS="$(LIBDEPS) -lc"; \
+       ALLSYMSFLAGS='-all_load'; \
+       NOALLSYMSFLAGS=''; \
+       SHAREDFLAGS="-dynamiclib"; \
        SHAREDCMD='$(CC)'; \
        if [ -n "$(LIBVERSION)" ]; then \
-               SHAREDFLAGS="$SHAREDFLAGS -current_version $(LIBVERSION)"; \
+               SHAREDFLAGS="$$SHAREDFLAGS -current_version $(LIBVERSION)"; \
        fi; \
        if [ -n "$$SHLIB_SOVER_NODOT" ]; then \
-               SHAREDFLAGS="$SHAREDFLAGS -compatibility_version $$SHLIB_SOVER_NODOT"; \
+               SHAREDFLAGS="$$SHAREDFLAGS -compatibility_version $$SHLIB_SOVER_NODOT"; \
        fi; \
        $(LINK_SO_A)
+link_app.darwin:
+       LDCMD=$(CC);\
+       LDFLAGS=""; \
+       LIBDEPS="$(LIBDEPS) -lc"; \
+       APPNAME="$(APPNAME)"; \
+       $(LINK_APP)
 
 link_o.cygwin:
-       @ SHLIB=cyg$(LIBNAME).dll \
-       SHLIB_SUFFIX= \
-       LIBDEPS="$(LIBDEPS)" \
-       SHLIB_SOVER= \
-       ALLSYMSFLAGS='-Wl,--whole-archive' \
-       NOALLSYMSFLAGS='-Wl,--no-whole-archive' \
-       SHAREDFLAGS="-shared -Wl,-Bsymbolic -Wl,--out-implib,lib$(LIBNAME).dll.a" \
+       @ $(CALC_VERSIONS); \
+       INHIBIT_SYMLINKS=yes; \
+       SHLIB=cyg$(LIBNAME); \
+       SHLIB_SUFFIX=.dll; \
+       LIBDEPS="$(LIBDEPS) -lc"; \
+       SHLIB_SOVER=-$(LIBVERSION); \
+       ALLSYMSFLAGS='-Wl,--whole-archive'; \
+       NOALLSYMSFLAGS='-Wl,--no-whole-archive'; \
+       SHAREDFLAGS="-shared -Wl,-Bsymbolic -Wl,--out-implib,lib$(LIBNAME).dll.a"; \
        SHAREDCMD='${CC}'; \
        $(LINK_SO_O)
 link_a.cygwin:
-       @ SHLIB=cyg$(LIBNAME).dll \
-       SHLIB_SUFFIX= \
-       LIBDEPS="$(LIBDEPS)" \
-       SHLIB_SOVER= \
-       ALLSYMSFLAGS='-Wl,--whole-archive' \
-       NOALLSYMSFLAGS='-Wl,--no-whole-archive' \
-       SHAREDFLAGS="-shared -Wl,-Bsymbolic -Wl,--out-implib,lib$(LIBNAME).dll.a" \
+       @ $(CALC_VERSIONS); \
+       INHIBIT_SYMLINKS=yes; \
+       SHLIB=cyg$(LIBNAME); \
+       SHLIB_SUFFIX=.dll; \
+       LIBDEPS="$(LIBDEPS) -lc"; \
+       SHLIB_SOVER=; \
+       ALLSYMSFLAGS='-Wl,--whole-archive'; \
+       NOALLSYMSFLAGS='-Wl,--no-whole-archive'; \
+       SHAREDFLAGS="-shared -Wl,-Bsymbolic -Wl,--out-implib,lib$(LIBNAME).dll.a"; \
        SHAREDCMD='${CC}'; \
        $(LINK_SO_A)
+link_app.cygwin:
+       LDCMD=$(CC);\
+       LDFLAGS=""; \
+       LIBDEPS="$(LIBDEPS) -lc"; \
+       APPNAME="$(APPNAME).exe"
+       $(LINK_APP)
 
 link_o.alpha-osf1:
        @ if ${DETECT_GNU_LD}; then \
-               $(MAKE) -f $(SHARED_MAKEFILE) CC="$(CC)" LDFLAGS="$(LDFLAGS) \
-                       SHARED_LDFLAGS="$(SHARED_LDFLAGS)" \
-                       LIBNAME="$(LIBNAME)" LIBEXTRAS="$(LIBEXTRAS)" \
-                       LIBVERSION=$(LIBVERSION) \
-                       LIBCOMPATVERSIONS="$(LIBCOMPATVERSIONS)" \
-                       LIBDEPS="$(LIBDEPS)" link_o.gnu; \
+               $(DO_GNU_SO); \
        else \
-               SHLIB=lib$(LIBNAME).so \
-               SHLIB_SUFFIX= \
-               LIBDEPS="$(LIBDEPS)" \
+               SHLIB=lib$(LIBNAME).so; \
+               SHLIB_SUFFIX=; \
+               LIBDEPS="$(LIBDEPS) -lc"; \
                SHLIB_HIST=`echo "$(LIBCOMPATVERSIONS)" | cut -d';' -f2 | sed -e 's/ */:/'`; \
                if [ -n "$$SHLIB_HIST" ]; then \
                        SHLIB_HIST="$${SHLIB_HIST}:$(LIBVERSION)"; \
                else \
                        SHLIB_HIST="$(LIBVERSION)"; \
-               fi
-               SHLIB_SOVER= \
-               ALLSYMSFLAGS='-all' \
-               NOALLSYMSFLAGS='-none' \
-               SHAREDFLAGS="-shared" \
+               fi; \
+               SHLIB_SOVER=; \
+               ALLSYMSFLAGS='-all'; \
+               NOALLSYMSFLAGS='-none'; \
+               SHAREDFLAGS="-shared"; \
                SHAREDCMD='$(CC)'; \
                if [ -n "$$SHLIB_HIST" ]; then \
-                       SHAREDFLAGS="$SHAREDFLAGS -set_version \"$$SHLIB_HIST\""; \
+                       SHAREDFLAGS="$$SHAREDFLAGS -set_version \"$$SHLIB_HIST\""; \
                fi; \
-               $(LINK_SO_O); \
-       fi
+       fi; \
+       $(LINK_SO_O)
 link_a.alpha-osf1:
        @ if ${DETECT_GNU_LD}; then \
-               $(MAKE) -f $(SHARED_MAKEFILE) CC="$(CC)" LDFLAGS="$(LDFLAGS) \
-                       SHARED_LDFLAGS="$(SHARED_LDFLAGS)" \
-                       LIBNAME="$(LIBNAME)" LIBEXTRAS="$(LIBEXTRAS)" \
-                       LIBVERSION=$(LIBVERSION) \
-                       LIBCOMPATVERSIONS="$(LIBCOMPATVERSIONS)" \
-                       LIBDEPS="$(LIBDEPS)" link_o.gnu; \
+               $(DO_GNU_SO); \
        else \
-               SHLIB=lib$(LIBNAME).so \
-               SHLIB_SUFFIX= \
-               LIBDEPS="$(LIBDEPS)" \
+               SHLIB=lib$(LIBNAME).so; \
+               SHLIB_SUFFIX=; \
+               LIBDEPS="$(LIBDEPS) -lc"; \
                SHLIB_HIST=`echo "$(LIBCOMPATVERSIONS)" | cut -d';' -f2 | sed -e 's/ */:/'`; \
                if [ -n "$$SHLIB_HIST" ]; then \
                        SHLIB_HIST="$${SHLIB_HIST}:$(LIBVERSION)"; \
                else \
                        SHLIB_HIST="$(LIBVERSION)"; \
-               fi
-               SHLIB_SOVER= \
-               ALLSYMSFLAGS='-all' \
-               NOALLSYMSFLAGS='-none' \
-               SHAREDFLAGS="-shared" \
+               fi; \
+               SHLIB_SOVER=; \
+               ALLSYMSFLAGS='-all'; \
+               NOALLSYMSFLAGS='-none'; \
+               SHAREDFLAGS="-shared"; \
                SHAREDCMD='$(CC)'; \
                if [ -n "$$SHLIB_HIST" ]; then \
-                       SHAREDFLAGS="$SHAREDFLAGS -set_version \"$$SHLIB_HIST\""; \
+                       SHAREDFLAGS="$$SHAREDFLAGS -set_version \"$$SHLIB_HIST\""; \
                fi; \
-               $(LINK_SO_A); \
-       fi
+       fi; \
+       $(LINK_SO_A)
+link_app.alpha-osf1:
+       @ if ${DETECT_GNU_LD}; then \
+               $(DO_GNU_APP); \
+       else \
+               LDCMD=$(CC);\
+               LDFLAGS=""; \
+               LIBDEPS="$(LIBDEPS) -lc"; \
+               APPNAME="$(APPNAME)"
+       fi; \
+       $(LINK_APP)
 
 # The difference between alpha-osf1-shared and tru64-shared is the `-msym'
 # option passed to the linker.
 link_o.tru64:
        @ if ${DETECT_GNU_LD}; then \
-               $(MAKE) -f $(SHARED_MAKEFILE) CC="$(CC)" LDFLAGS="$(LDFLAGS) \
-                       SHARED_LDFLAGS="$(SHARED_LDFLAGS)" \
-                       LIBNAME="$(LIBNAME)" LIBEXTRAS="$(LIBEXTRAS)" \
-                       LIBVERSION=$(LIBVERSION) \
-                       LIBCOMPATVERSIONS="$(LIBCOMPATVERSIONS)" \
-                       LIBDEPS="$(LIBDEPS)" link_o.gnu; \
+               $(DO_GNU_SO); \
        else \
-               SHLIB=lib$(LIBNAME).so \
-               SHLIB_SUFFIX= \
-               LIBDEPS="$(LIBDEPS)" \
+               SHLIB=lib$(LIBNAME).so; \
+               SHLIB_SUFFIX=; \
+               LIBDEPS="$(LIBDEPS) -lc"; \
                SHLIB_HIST=`echo "$(LIBCOMPATVERSIONS)" | cut -d';' -f2 | sed -e 's/ */:/'`; \
                if [ -n "$$SHLIB_HIST" ]; then \
                        SHLIB_HIST="$${SHLIB_HIST}:$(LIBVERSION)"; \
                else \
                        SHLIB_HIST="$(LIBVERSION)"; \
-               fi
-               SHLIB_SOVER= \
-               ALLSYMSFLAGS='-all' \
-               NOALLSYMSFLAGS='-none' \
-               SHAREDFLAGS="-shared -msym" \
+               fi; \
+               SHLIB_SOVER=; \
+               ALLSYMSFLAGS='-all'; \
+               NOALLSYMSFLAGS='-none'; \
+               SHAREDFLAGS="-shared -msym -rpath $(LIBRPATH)"; \
                SHAREDCMD='$(CC)'; \
                if [ -n "$$SHLIB_HIST" ]; then \
-                       SHAREDFLAGS="$SHAREDFLAGS -set_version \"$$SHLIB_HIST\""; \
+                       SHAREDFLAGS="$$SHAREDFLAGS -set_version \"$$SHLIB_HIST\""; \
                fi; \
-               $(LINK_SO_O); \
-       fi
+       fi; \
+       $(LINK_SO_O)
 link_a.tru64:
        @ if ${DETECT_GNU_LD}; then \
-               $(MAKE) -f $(SHARED_MAKEFILE) CC="$(CC)" LDFLAGS="$(LDFLAGS) \
-                       SHARED_LDFLAGS="$(SHARED_LDFLAGS)" \
-                       LIBNAME="$(LIBNAME)" LIBEXTRAS="$(LIBEXTRAS)" \
-                       LIBVERSION=$(LIBVERSION) \
-                       LIBCOMPATVERSIONS="$(LIBCOMPATVERSIONS)" \
-                       LIBDEPS="$(LIBDEPS)" link_o.gnu; \
+               $(DO_GNU_SO); \
        else \
-               SHLIB=lib$(LIBNAME).so \
-               SHLIB_SUFFIX= \
-               LIBDEPS="$(LIBDEPS)" \
+               SHLIB=lib$(LIBNAME).so; \
+               SHLIB_SUFFIX=; \
+               LIBDEPS="$(LIBDEPS) -lc"; \
                SHLIB_HIST=`echo "$(LIBCOMPATVERSIONS)" | cut -d';' -f2 | sed -e 's/ */:/'`; \
                if [ -n "$$SHLIB_HIST" ]; then \
                        SHLIB_HIST="$${SHLIB_HIST}:$(LIBVERSION)"; \
                else \
                        SHLIB_HIST="$(LIBVERSION)"; \
-               fi
-               SHLIB_SOVER= \
-               ALLSYMSFLAGS='-all' \
-               NOALLSYMSFLAGS='-none' \
-               SHAREDFLAGS="-shared -msym" \
+               fi; \
+               SHLIB_SOVER=; \
+               ALLSYMSFLAGS='-all'; \
+               NOALLSYMSFLAGS='-none'; \
+               SHAREDFLAGS="-shared -msym -rpath $(LIBRPATH)"; \
                SHAREDCMD='$(CC)'; \
                if [ -n "$$SHLIB_HIST" ]; then \
-                       SHAREDFLAGS="$SHAREDFLAGS -set_version \"$$SHLIB_HIST\""; \
+                       SHAREDFLAGS="$$SHAREDFLAGS -set_version \"$$SHLIB_HIST\""; \
                fi; \
-               $(LINK_SO_A); \
-       fi
+       fi; \
+       $(LINK_SO_A)
+link_app.tru64:
+       @ if ${DETECT_GNU_LD}; then \
+               $(DO_GNU_APP); \
+       else \
+               LDCMD=$(CC);\
+               LDFLAGS="-rpath $(LIBRPATH)"; \
+               LIBDEPS="$(LIBDEPS) -lc"; \
+               APPNAME="$(APPNAME)"; \
+       fi; \
+       $(LINK_APP)
 
 # The difference between tru64-shared and tru64-shared-rpath is the
 # -rpath ${LIBRPATH} passed to the linker.
 link_o.tru64-rpath:
        @ if ${DETECT_GNU_LD}; then \
-               $(MAKE) -f $(SHARED_MAKEFILE) CC="$(CC)" LDFLAGS="$(LDFLAGS) \
-                       SHARED_LDFLAGS="$(SHARED_LDFLAGS)" \
-                       LIBNAME="$(LIBNAME)" LIBEXTRAS="$(LIBEXTRAS)" \
-                       LIBVERSION=$(LIBVERSION) \
-                       LIBCOMPATVERSIONS="$(LIBCOMPATVERSIONS)" \
-                       LIBDEPS="$(LIBDEPS)" link_o.gnu; \
+               $(DO_GNU_SO); \
        else \
-               SHLIB=lib$(LIBNAME).so \
-               SHLIB_SUFFIX= \
-               LIBDEPS="$(LIBDEPS)" \
+               SHLIB=lib$(LIBNAME).so; \
+               SHLIB_SUFFIX=; \
+               LIBDEPS="$(LIBDEPS) -lc"; \
                SHLIB_HIST=`echo "$(LIBCOMPATVERSIONS)" | cut -d';' -f2 | sed -e 's/ */:/'`; \
                if [ -n "$$SHLIB_HIST" ]; then \
                        SHLIB_HIST="$${SHLIB_HIST}:$(LIBVERSION)"; \
                else \
                        SHLIB_HIST="$(LIBVERSION)"; \
-               fi
-               SHLIB_SOVER= \
-               ALLSYMSFLAGS='-all' \
-               NOALLSYMSFLAGS='-none' \
-               SHAREDFLAGS="-shared -msym -rpath $(LIBRPATH)" \
+               fi; \
+               SHLIB_SOVER=; \
+               ALLSYMSFLAGS='-all'; \
+               NOALLSYMSFLAGS='-none'; \
+               SHAREDFLAGS="-shared -msym -rpath $(LIBRPATH)"; \
                SHAREDCMD='$(CC)'; \
                if [ -n "$$SHLIB_HIST" ]; then \
-                       SHAREDFLAGS="$SHAREDFLAGS -set_version \"$$SHLIB_HIST\""; \
+                       SHAREDFLAGS="$$SHAREDFLAGS -set_version \"$$SHLIB_HIST\""; \
                fi; \
-               $(LINK_SO_O); \
-       fi
+       fi; \
+       $(LINK_SO_O)
 link_a.tru64-rpath:
        @ if ${DETECT_GNU_LD}; then \
-               $(MAKE) -f $(SHARED_MAKEFILE) CC="$(CC)" LDFLAGS="$(LDFLAGS) \
-                       SHARED_LDFLAGS="$(SHARED_LDFLAGS)" \
-                       LIBNAME="$(LIBNAME)" LIBEXTRAS="$(LIBEXTRAS)" \
-                       LIBVERSION=$(LIBVERSION) \
-                       LIBCOMPATVERSIONS="$(LIBCOMPATVERSIONS)" \
-                       LIBDEPS="$(LIBDEPS)" link_o.gnu; \
+               $(DO_GNU_SO); \
        else \
-               SHLIB=lib$(LIBNAME).so \
-               SHLIB_SUFFIX= \
-               LIBDEPS="$(LIBDEPS)" \
+               SHLIB=lib$(LIBNAME).so; \
+               SHLIB_SUFFIX=; \
+               LIBDEPS="$(LIBDEPS) -lc"; \
                SHLIB_HIST=`echo "$(LIBCOMPATVERSIONS)" | cut -d';' -f2 | sed -e 's/ */:/'`; \
                if [ -n "$$SHLIB_HIST" ]; then \
                        SHLIB_HIST="$${SHLIB_HIST}:$(LIBVERSION)"; \
                else \
                        SHLIB_HIST="$(LIBVERSION)"; \
-               fi
-               SHLIB_SOVER= \
-               ALLSYMSFLAGS='-all' \
-               NOALLSYMSFLAGS='-none' \
-               SHAREDFLAGS="-shared -msym -rpath $(LIBRPATH)" \
+               fi; \
+               SHLIB_SOVER=; \
+               ALLSYMSFLAGS='-all'; \
+               NOALLSYMSFLAGS='-none'; \
+               SHAREDFLAGS="-shared -msym -rpath $(LIBRPATH)"; \
                SHAREDCMD='$(CC)'; \
                if [ -n "$$SHLIB_HIST" ]; then \
-                       SHAREDFLAGS="$SHAREDFLAGS -set_version \"$$SHLIB_HIST\""; \
+                       SHAREDFLAGS="$$SHAREDFLAGS -set_version \"$$SHLIB_HIST\""; \
                fi; \
-               $(LINK_SO_A); \
-       fi
+       fi; \
+       $(LINK_SO_A)
+link_app.tru64-rpath:
+       @ if ${DETECT_GNU_LD}; then \
+               $(DO_GNU_APP); \
+       else \
+               LDCMD=$(CC);\
+               LDFLAGS="-rpath $(LIBRPATH)"; \
+               LIBDEPS="$(LIBDEPS) -lc"; \
+               APPNAME="$(APPNAME)"; \
+       fi; \
+       $(LINK_APP)
 
 link_o.solaris:
        @ if ${DETECT_GNU_LD}; then \
-               $(MAKE) -f $(SHARED_MAKEFILE) CC="$(CC)" LDFLAGS="$(LDFLAGS) \
-                       SHARED_LDFLAGS="$(SHARED_LDFLAGS)" \
-                       LIBNAME="$(LIBNAME)" LIBEXTRAS="$(LIBEXTRAS)" \
-                       LIBVERSION="$(LIBVERSION)" \
-                       LIBCOMPATVERSIONS="$(LIBCOMPATVERSIONS)" \
-                       LIBDEPS="$(LIBDEPS)" link_o.gnu; \
+               $(DO_GNU_SO); \
        else \
                $(CALC_VERSIONS); \
-               SHLIB=lib$(LIBNAME).so \
-               SHLIB_SUFFIX= \
-               LIBDEPS="$(LIBDEPS)" \
-               ALLSYMSFLAGS='-z allextract' \
-               NOALLSYMSFLAGS='' \
-               SHAREDFLAGS='-G -h $$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX' \
+               MINUSZ='-z '; \
+               (${CC} -v 2>&1 | grep gcc) > /dev/null && MINUSZ='-Wl,-z,'; \
+               SHLIB=lib$(LIBNAME).so; \
+               SHLIB_SUFFIX=; \
+               LIBDEPS="$(LIBDEPS) -lc"; \
+               ALLSYMSFLAGS="$${MINUSZ}allextract"; \
+               NOALLSYMSFLAGS="$${MINUSZ}defaultextract"; \
+               SHAREDFLAGS="-G -dy -z text -h $$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX -R $(LIBRPATH)"; \
                SHAREDCMD='$(CC)'; \
-               $(LINK_SO_O); \
-       fi
+       fi; \
+       $(LINK_SO_O)
 link_a.solaris:
        @ if ${DETECT_GNU_LD}; then \
-               $(MAKE) -f $(SHARED_MAKEFILE) CC="$(CC)" LDFLAGS="$(LDFLAGS) \
-                       SHARED_LDFLAGS="$(SHARED_LDFLAGS)" \
-                       LIBNAME="$(LIBNAME)" LIBEXTRAS="$(LIBEXTRAS)" \
-                       LIBVERSION="$(LIBVERSION)" \
-                       LIBCOMPATVERSIONS="$(LIBCOMPATVERSIONS)" \
-                       LIBDEPS="$(LIBDEPS)" link_o.gnu; \
+               $(DO_GNU_SO); \
        else \
                $(CALC_VERSIONS); \
-               SHLIB=lib$(LIBNAME).so \
-               SHLIB_SUFFIX= \
-               LIBDEPS="$(LIBDEPS)" \
-               ALLSYMSFLAGS='-z allextract' \
-               NOALLSYMSFLAGS='' \
-               SHAREDFLAGS='-G -h $$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX' \
+               MINUSZ='-z '; \
+               (${CC} -v 2>&1 | grep gcc) > /dev/null && MINUSZ='-Wl,-z,'; \
+               SHLIB=lib$(LIBNAME).so; \
+               SHLIB_SUFFIX=;\
+               LIBDEPS="$(LIBDEPS) -lc"; \
+               ALLSYMSFLAGS="$${MINUSZ}allextract"; \
+               NOALLSYMSFLAGS="$${MINUSZ}defaultextract"; \
+               SHAREDFLAGS="-G -dy -z text -h $$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX -R $(LIBRPATH)"; \
                SHAREDCMD='$(CC)'; \
-               $(LINK_SO_A); \
-       fi
+       fi; \
+       $(LINK_SO_A)
+link_app.solaris:
+       @ if ${DETECT_GNU_LD}; then \
+               $(DO_GNU_APP); \
+       else \
+               LDCMD=$(CC);\
+               LDFLAGS="-R $(LIBRPATH)"; \
+               LIBDEPS="$(LIBDEPS) -lc"; \
+               APPNAME="$(APPNAME)"; \
+       fi; \
+       $(LINK_APP)
 
 # OpenServer 5 native compilers used
-# UnixWare 7 and OpenUNIX 8 native compilers used
 link_o.svr3:
        @ if ${DETECT_GNU_LD}; then \
-               $(MAKE) -f $(SHARED_MAKEFILE) CC="$(CC)" LDFLAGS="$(LDFLAGS) \
-                       SHARED_LDFLAGS="$(SHARED_LDFLAGS)" \
-                       LIBNAME="$(LIBNAME)" LIBEXTRAS="$(LIBEXTRAS)" \
-                       LIBVERSION=$(LIBVERSION) \
-                       LIBCOMPATVERSIONS="$(LIBCOMPATVERSIONS)" \
-                       LIBDEPS="$(LIBDEPS)" link_o.gnu; \
+               $(DO_GNU_SO); \
        else \
                $(CALC_VERSIONS); \
-               SHLIB=lib$(LIBNAME).so \
-               SHLIB_SUFFIX= \
-               LIBDEPS="$(LIBDEPS)" \
-               ALLSYMSFLAGS='-z allextract' \
-               NOALLSYMSFLAGS='' \
-               SHAREDFLAGS='-G -h $$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX' \
+               SHLIB=lib$(LIBNAME).so; \
+               SHLIB_SUFFIX=; \
+               LIBDEPS="$(LIBDEPS) -lc"; \
+               ALLSYMSFLAGS=''; \
+               NOALLSYMSFLAGS=''; \
+               SHAREDFLAGS="-G -h $$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX"; \
                SHAREDCMD='$(CC)'; \
-               $(LINK_SO_O); \
-       fi
+       fi; \
+       $(LINK_SO_O)
 link_a.svr3:
        @ if ${DETECT_GNU_LD}; then \
-               $(MAKE) -f $(SHARED_MAKEFILE) CC="$(CC)" LDFLAGS="$(LDFLAGS) \
-                       SHARED_LDFLAGS="$(SHARED_LDFLAGS)" \
-                       LIBNAME="$(LIBNAME)" LIBEXTRAS="$(LIBEXTRAS)" \
-                       LIBVERSION=$(LIBVERSION) \
-                       LIBCOMPATVERSIONS="$(LIBCOMPATVERSIONS)" \
-                       LIBDEPS="$(LIBDEPS)" link_o.gnu; \
+               $(DO_GNU_SO); \
        else \
                $(CALC_VERSIONS); \
-               SHLIB=lib$(LIBNAME).so \
-               SHLIB_SUFFIX= \
-               LIBDEPS="$(LIBDEPS)" \
-               ALLSYMSFLAGS='-z allextract' \
-               NOALLSYMSFLAGS='' \
-               SHAREDFLAGS='-G -h $$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX' \
+               SHLIB=lib$(LIBNAME).so; \
+               SHLIB_SUFFIX=; \
+               LIBDEPS="$(LIBDEPS) -lc"; \
+               ALLSYMSFLAGS=''; \
+               NOALLSYMSFLAGS=''; \
+               SHAREDFLAGS="-G -h $$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX"; \
                SHAREDCMD='$(CC)'; \
-               $(LINK_SO_A_UNPACKED); \
-       fi
+       fi; \
+       $(LINK_SO_A_UNPACKED)
+link_app.svr3:
+       @ if ${DETECT_GNU_LD}; then \
+               $(DO_GNU_APP); \
+       else \
+               LDCMD=$(CC);\
+               LDFLAGS=""; \
+               LIBDEPS="$(LIBDEPS) -lc"; \
+               APPNAME="$(APPNAME)"; \
+       fi; \
+       $(LINK_APP)
+
+# UnixWare 7 and OpenUNIX 8 native compilers used
+link_o.svr5:
+       @ if ${DETECT_GNU_LD}; then \
+               $(DO_GNU_SO); \
+       else \
+               $(CALC_VERSIONS); \
+               SHARE_FLAG='-G'; \
+               (${CC} -v 2>&1 | grep gcc) > /dev/null && SHARE_FLAG='-shared'; \
+               SHLIB=lib$(LIBNAME).so; \
+               SHLIB_SUFFIX=; \
+               LIBDEPS="$(LIBDEPS) -lc"; \
+               ALLSYMSFLAGS=''; \
+               NOALLSYMSFLAGS=''; \
+               SHAREDFLAGS="$${SHARE_FLAG} -h $$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX"; \
+               SHAREDCMD='$(CC)'; \
+       fi; \
+       $(LINK_SO_O)
+link_a.svr5:
+       @ if ${DETECT_GNU_LD}; then \
+               $(DO_GNU_SO); \
+       else \
+               $(CALC_VERSIONS); \
+               SHARE_FLAG='-G'; \
+               (${CC} -v 2>&1 | grep gcc) > /dev/null && SHARE_FLAG='-shared'; \
+               SHLIB=lib$(LIBNAME).so; \
+               SHLIB_SUFFIX=; \
+               LIBDEPS="$(LIBDEPS) -lc"; \
+               ALLSYMSFLAGS=''; \
+               NOALLSYMSFLAGS=''; \
+               SHAREDFLAGS="$${SHARE_FLAG} -h $$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX"; \
+               SHAREDCMD='$(CC)'; \
+       fi; \
+       $(LINK_SO_A_UNPACKED)
+link_app.svr5:
+       @ if ${DETECT_GNU_LD}; then \
+               $(DO_GNU_APP); \
+       else \
+               LDCMD=$(CC);\
+               LDFLAGS=""; \
+               LIBDEPS="$(LIBDEPS) -lc"; \
+               APPNAME="$(APPNAME)"; \
+       fi; \
+       $(LINK_APP)
 
 link_o.irix:
        @ if ${DETECT_GNU_LD}; then \
-               $(MAKE) -f $(SHARED_MAKEFILE) CC="$(CC)" LDFLAGS="$(LDFLAGS) \
-                       SHARED_LDFLAGS="$(SHARED_LDFLAGS)" \
-                       LIBNAME="$(LIBNAME)" LIBEXTRAS="$(LIBEXTRAS)" \
-                       LIBVERSION=$(LIBVERSION) \
-                       LIBCOMPATVERSIONS="$(LIBCOMPATVERSIONS)" \
-                       LIBDEPS="$(LIBDEPS)" link_o.gnu; \
+               $(DO_GNU_SO); \
        else \
                $(CALC_VERSIONS); \
-               SHLIB=lib$(LIBNAME).so \
-               SHLIB_SUFFIX= \
-               LIBDEPS="$(LIBDEPS)" \
-               ALLSYMSFLAGS='-all' \
-               NOALLSYMSFLAGS='' \
-               SHAREDFLAGS='-shared -Wl,-soname,$$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX' \
+               SHLIB=lib$(LIBNAME).so; \
+               SHLIB_SUFFIX=; \
+               LIBDEPS="$(LIBDEPS) -lc"; \
+               MINUSWL=""; \
+               ($(CC) -v 2>&1 | grep gcc) > /dev/null && MINUSWL="-Wl,"; \
+               ALLSYMSFLAGS="$${MINUSWL}-all"; \
+               NOALLSYMSFLAGS="$${MINUSWL}-notall"; \
+               SHAREDFLAGS="-shared -Wl,-soname,$$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX -Wl,-rpath,$(LIBRPATH)"; \
                SHAREDCMD='$(CC)'; \
-               $(LINK_SO_O); \
-       fi
+       fi; \
+       $(LINK_SO_O)
 link_a.irix:
        @ if ${DETECT_GNU_LD}; then \
-               $(MAKE) -f $(SHARED_MAKEFILE) CC="$(CC)" LDFLAGS="$(LDFLAGS) \
-                       SHARED_LDFLAGS="$(SHARED_LDFLAGS)" \
-                       LIBNAME="$(LIBNAME)" LIBEXTRAS="$(LIBEXTRAS)" \
-                       LIBVERSION=$(LIBVERSION) \
-                       LIBCOMPATVERSIONS="$(LIBCOMPATVERSIONS)" \
-                       LIBDEPS="$(LIBDEPS)" link_o.gnu; \
+               $(DO_GNU_SO); \
        else \
                $(CALC_VERSIONS); \
-               SHLIB=lib$(LIBNAME).so \
-               SHLIB_SUFFIX= \
-               LIBDEPS="$(LIBDEPS)" \
-               ALLSYMSFLAGS='-all' \
-               NOALLSYMSFLAGS='' \
-               SHAREDFLAGS='-shared -Wl,-soname,$$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX' \
+               SHLIB=lib$(LIBNAME).so; \
+               SHLIB_SUFFIX=; \
+               LIBDEPS="$(LIBDEPS) -lc"; \
+               MINUSWL=""; \
+               ($(CC) -v 2>&1 | grep gcc) > /dev/null && MINUSWL="-Wl,"; \
+               ALLSYMSFLAGS="$${MINUSWL}-all"; \
+               NOALLSYMSFLAGS="$${MINUSWL}-notall"; \
+               SHAREDFLAGS="-shared -Wl,-soname,$$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX -Wl,-rpath,$(LIBRPATH)"; \
                SHAREDCMD='$(CC)'; \
-               $(LINK_SO_A); \
-       fi
+       fi; \
+       $(LINK_SO_A)
+link_app.irix:
+       @ if ${DETECT_GNU_LD}; then \
+               $(DO_GNU_APP); \
+       else \
+               LDCMD=$(CC);\
+               LDFLAGS="-Wl,-rpath,$(LIBRPATH)"; \
+               LIBDEPS="$(LIBDEPS) -lc"; \
+               APPNAME="$(APPNAME)"; \
+       fi; \
+       $(LINK_APP)
 
 # HP-UX includes the full pathname of libs we depend on, so we would get
 # ./libcrypto (with ./ as path information) compiled into libssl, hence
@@ -492,24 +595,32 @@ link_a.irix:
 #
 link_o.hpux32:
        @ $(CALC_VERSIONS); \
-       SHLIB=lib$(LIBNAME).sl \
-       SHLIB_SUFFIX= \
-       LIBDEPS="$(LIBDEPS) -lc" \
-       ALLSYMSFLAGS='-Fl' \
-       NOALLSYMSFLAGS='' \
-       SHAREDFLAGS='+vnocompatwarnings -b -z +s +h $$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX' \
-       SHAREDCMD='/usr/ccs/bin/ld'; \
+       SHLIB=lib$(LIBNAME).sl; \
+       SHLIB_SUFFIX=; \
+       LIBDEPS="$(LIBDEPS)"; \
+       ALLSYMSFLAGS='-Wl,-Fl'; \
+       NOALLSYMSFLAGS=''; \
+       expr $(PLATFORM) : '.*64' > /dev/null && ALLSYMFLAGS='-Wl,+forceload'; \
+       SHAREDFLAGS="-Wl,+vnocompatwarnings,-z,+s,+h,$$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX,+b,$(LIBRPATH)"; \
+       SHAREDCMD=$(CC); \
        $(LINK_SO_O) && chmod a=rx $$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX
 link_a.hpux32:
        @ $(CALC_VERSIONS); \
-       SHLIB=lib$(LIBNAME).sl \
-       SHLIB_SUFFIX= \
-       LIBDEPS="$(LIBDEPS) -lc" \
-       ALLSYMSFLAGS='-Fl' \
-       NOALLSYMSFLAGS='' \
-       SHAREDFLAGS='+vnocompatwarnings -b -z +s +h $$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX' \
-       SHAREDCMD='/usr/ccs/bin/ld'; \
+       SHLIB=lib$(LIBNAME).sl; \
+       SHLIB_SUFFIX=; \
+       LIBDEPS="$(LIBDEPS)"; \
+       ALLSYMSFLAGS='-Wl,-Fl'; \
+       NOALLSYMSFLAGS=''; \
+       expr $(PLATFORM) : '.*64' > /dev/null && ALLSYMFLAGS='-Wl,+forceload'; \
+       SHAREDFLAGS="-Wl,+vnocompatwarnings,-z,+s,+h,$$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX,+b,$(LIBRPATH)"; \
+       SHAREDCMD='$(CC)'; \
        $(LINK_SO_A) && chmod a=rx $$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX
+link_app.hpux32:
+       LDCMD=$(CC);\
+       LDFLAGS="-Wl,+b,$(LIBRPATH)"; \
+       LIBDEPS="$(LIBDEPS)"; \
+       APPNAME="$(APPNAME)"; \
+       $(LINK_APP)
 
 # HP-UX includes the full pathname of libs we depend on, so we would get
 # ./libcrypto (with ./ as path information) compiled into libssl, hence
@@ -521,124 +632,157 @@ link_a.hpux32:
 #
 link_o.hpux64:
        @ $(CALC_VERSIONS); \
-       SHLIB=lib$(LIBNAME).sl \
-       SHLIB_SUFFIX= \
-       LIBDEPS="$(LIBDEPS) -lc" \
-       ALLSYMSFLAGS='+forceload' \
-       NOALLSYMSFLAGS='' \
-       SHAREDFLAGS='-b -z +h $$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX' \
+       SHLIB=lib$(LIBNAME).sl; \
+       SHLIB_SUFFIX=; \
+       LIBDEPS="$(LIBDEPS) -lc"; \
+       ALLSYMSFLAGS='+forceload'; \
+       NOALLSYMSFLAGS=''; \
+       SHAREDFLAGS="-b -z +h $$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX +b $(LIBRPATH)"; \
        SHAREDCMD='/usr/ccs/bin/ld'; \
        $(LINK_SO_O) && chmod a=rx $$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX
 link_a.hpux64:
        @ $(CALC_VERSIONS); \
-       SHLIB=lib$(LIBNAME).sl \
-       SHLIB_SUFFIX= \
-       LIBDEPS="$(LIBDEPS) -lc" \
-       ALLSYMSFLAGS='+forceload' \
-       NOALLSYMSFLAGS='' \
-       SHAREDFLAGS='-b -z +h $$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX' \
+       SHLIB=lib$(LIBNAME).sl; \
+       SHLIB_SUFFIX=; \
+       LIBDEPS="$(LIBDEPS) -lc"; \
+       ALLSYMSFLAGS='+forceload'; \
+       NOALLSYMSFLAGS=''; \
+       SHAREDFLAGS="-b -z +h $$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX +b $(LIBRPATH)"; \
        SHAREDCMD='/usr/ccs/bin/ld'; \
        $(LINK_SO_A) && chmod a=rx $$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX
+link_app.hpux64:
+       LDCMD=$(CC);\
+       LDFLAGS="-Wl,+b,$(LIBRPATH)"; \
+       LIBDEPS="$(LIBDEPS) -lc"; \
+       APPNAME="$(APPNAME)"
+       $(LINK_APP)
 
 link_o.aix:
        @ $(CALC_VERSIONS); \
-       SHLIB=lib$(LIBNAME).so \
-       SHLIB_SUFFIX= \
-       LIBDEPS="$(LIBDEPS)" \
-       ALLSYMSFLAGS='-bnogc' \
-       NOALLSYMSFLAGS='' \
-       SHAREDFLAGS='-G -bE:lib$(LIBNAME).exp -bM:SRE' \
+       SHLIB=lib$(LIBNAME).so; \
+       SHLIB_SUFFIX=; \
+       LIBDEPS="$(LIBDEPS) -lc"; \
+       ALLSYMSFLAGS='-bnogc'; \
+       NOALLSYMSFLAGS=''; \
+       SHAREDFLAGS='-G -bE:lib$(LIBNAME).exp -bM:SRE -blibpath:$(LIBRPATH)'; \
        SHAREDCMD='$(CC)'; \
        $(LINK_SO_O)
 link_a.aix:
        @ $(CALC_VERSIONS); \
-       SHLIB=lib$(LIBNAME).so \
-       SHLIB_SUFFIX= \
-       LIBDEPS="$(LIBDEPS)" \
-       ALLSYMSFLAGS='-bnogc' \
-       NOALLSYMSFLAGS='' \
-       SHAREDFLAGS='-G -bE:lib$(LIBNAME).exp -bM:SRE' \
+       SHLIB=lib$(LIBNAME).so; \
+       SHLIB_SUFFIX=; \
+       LIBDEPS="$(LIBDEPS) -lc"; \
+       ALLSYMSFLAGS='-bnogc'; \
+       NOALLSYMSFLAGS=''; \
+       SHAREDFLAGS='-G -bE:lib$(LIBNAME).exp -bM:SRE -blibpath:$(LIBRPATH)'; \
        SHAREDCMD='$(CC)'; \
        $(LINK_SO_A_VIA_O)
+link_app.aix:
+       LDCMD=$(CC);\
+       LDFLAGS="-blibpath:$(LIBRPATH)"; \
+       LIBDEPS="$(LIBDEPS) -lc"; \
+       APPNAME="$(APPNAME)"
+       $(LINK_APP)
 
 link_o.reliantunix:
        @ $(CALC_VERSIONS); \
-       SHLIB=lib$(LIBNAME).so \
-       SHLIB_SUFFIX= \
-       LIBDEPS="$(LIBDEPS)" \
-       ALLSYMSFLAGS= \
-       NOALLSYMSFLAGS='' \
-       SHAREDFLAGS='-G' \
+       SHLIB=lib$(LIBNAME).so; \
+       SHLIB_SUFFIX=; \
+       LIBDEPS="$(LIBDEPS) -lc"; \
+       ALLSYMSFLAGS=; \
+       NOALLSYMSFLAGS=''; \
+       SHAREDFLAGS='-G'; \
        SHAREDCMD='$(CC)'; \
        $(LINK_SO_O)
 link_a.reliantunix:
        @ $(CALC_VERSIONS); \
-       SHLIB=lib$(LIBNAME).so \
-       SHLIB_SUFFIX= \
-       LIBDEPS="$(LIBDEPS)" \
-       ALLSYMSFLAGS= \
-       NOALLSYMSFLAGS='' \
-       SHAREDFLAGS='-G' \
+       SHLIB=lib$(LIBNAME).so; \
+       SHLIB_SUFFIX=; \
+       LIBDEPS="$(LIBDEPS) -lc"; \
+       ALLSYMSFLAGS=; \
+       NOALLSYMSFLAGS=''; \
+       SHAREDFLAGS='-G'; \
        SHAREDCMD='$(CC)'; \
        $(LINK_SO_A_UNPACKED)
+link_app.reliantunix:
+       LDCMD=$(CC);\
+       LDFLAGS=""; \
+       LIBDEPS="$(LIBDEPS) -lc"; \
+       APPNAME="$(APPNAME)"
+       $(LINK_APP)
 
 # Targets to build symbolic links when needed
-symlink.gnu symlink.solaris symlink.svr3 symlink.irix \
+symlink.gnu symlink.solaris symlink.svr3 symlink.svr5 symlink.irix \
 symlink.aix symlink.reliantunix:
        @ $(CALC_VERSIONS); \
-       SHLIB=lib$(LIBNAME).so \
+       SHLIB=lib$(LIBNAME).so; \
        $(SYMLINK_SO)
 symlink.darwin:
        @ $(CALC_VERSIONS); \
-       SHLIB=lib$(LIBNAME) \
-       SHLIB_SUFFIX=.dylib \
+       SHLIB=lib$(LIBNAME); \
+       SHLIB_SUFFIX=.dylib; \
        $(SYMLINK_SO)
-symlink.cygwin symlib.alpha-osf1 symlink.tru64 symlink.tru64-rpath:
 symlink.hpux32 symlink.hpux64:
        @ $(CALC_VERSIONS); \
-       SHLIB=lib$(LIBNAME).sl \
+       SHLIB=lib$(LIBNAME).sl; \
        $(SYMLINK_SO)
+# The following lines means those specific architectures do no symlinks
+symlink.cygwin symlib.alpha-osf1 symlink.tru64 symlink.tru64-rpath:
 
 # Compatibility targets
 link_o.bsd-gcc-shared link_o.linux-shared link_o.gnu-shared: link_o.gnu
 link_a.bsd-gcc-shared link_a.linux-shared link_a.gnu-shared: link_a.gnu
+link_app.bsd-gcc-shared link_app.linux-shared link_app.gnu-shared: link_app.gnu
 symlink.bsd-gcc-shared symlink.linux-shared symlink.gnu-shared: symlink.gnu
 link_o.darwin-shared: link_o.darwin
 link_a.darwin-shared: link_a.darwin
+link_app.darwin-shared: link_app.darwin
 symlink.darwin-shared: symlink.darwin
 link_o.cygwin-shared: link_o.cygwin
 link_a.cygwin-shared: link_a.cygwin
+link_app.cygwin-shared: link_app.cygwin
 symlink.cygwin-shared: symlink.cygwin
 link_o.alpha-osf1-shared: link_o.alpha-osf1
 link_a.alpha-osf1-shared: link_a.alpha-osf1
+link_app.alpha-osf1-shared: link_app.alpha-osf1
 symlink.alpha-osf1-shared: symlink.alpha-osf1
 link_o.tru64-shared: link_o.tru64
 link_a.tru64-shared: link_a.tru64
+link_app.tru64-shared: link_app.tru64
 symlink.tru64-shared: symlink.tru64
 link_o.tru64-shared-rpath: link_o.tru64-rpath
 link_a.tru64-shared-rpath: link_a.tru64-rpath
+link_app.tru64-shared-rpath: link_app.tru64-rpath
 symlink.tru64-shared-rpath: symlink.tru64-rpath
 link_o.solaris-shared: link_o.solaris
 link_a.solaris-shared: link_a.solaris
+link_app.solaris-shared: link_app.solaris
 symlink.solaris-shared: symlink.solaris
 link_o.svr3-shared: link_o.svr3
 link_a.svr3-shared: link_a.svr3
+link_app.svr3-shared: link_app.svr3
 symlink.svr3-shared: symlink.svr3
-link_o.svr5-shared: link_o.svr3
-link_a.svr5-shared: link_a.svr3
-symlink.svr5-shared: symlink.svr3
+link_o.svr5-shared: link_o.svr5
+link_a.svr5-shared: link_a.svr5
+link_app.svr5-shared: link_app.svr5
+symlink.svr5-shared: symlink.svr5
 link_o.irix-shared: link_o.irix
 link_a.irix-shared: link_a.irix
+link_app.irix-shared: link_app.irix
 symlink.irix-shared: symlink.irix
 link_o.hpux-shared: link_o.hpux32
 link_a.hpux-shared: link_a.hpux32
+link_app.hpux-shared: link_app.hpux32
 symlink.hpux-shared: symlink.hpux32
 link_o.hpux64-shared: link_o.hpux64
 link_a.hpux64-shared: link_a.hpux64
+link_app.hpux64-shared: link_app.hpux64
 symlink.hpux64-shared: symlink.hpux64
 link_o.aix-shared: link_o.aix
 link_a.aix-shared: link_a.aix
+link_app.aix-shared: link_app.aix
 symlink.aix-shared: symlink.aix
 link_o.reliantunix-shared: link_o.reliantunix
 link_a.reliantunix-shared: link_a.reliantunix
+link_app.reliantunix-shared: link_app.reliantunix
 symlink.reliantunix-shared: symlink.reliantunix