diff --git a/docs/cookbook/c/all.rc.od b/docs/cookbook/c/all.rc.od index 22b35b0..f206e7f 100644 --- a/docs/cookbook/c/all.rc.od +++ b/docs/cookbook/c/all.rc.od @@ -2,6 +2,7 @@ rc_include \ rc/CC.required.rc \ rc/CXX.rc \ + rc/shlib.rc \ rc/libqt4.rc \ rc/libgtk2.rc \ rc/Wextra.rc \ diff --git a/redoconf/link-shlib.od b/redoconf/link-shlib.od index aa632f0..239762c 100644 --- a/redoconf/link-shlib.od +++ b/redoconf/link-shlib.od @@ -1,5 +1,5 @@ . ./redoconf.rc -rc_include _all.rc rc/shlib.rc +rc_include _all.rc # Tricky quoting: see _compile.od for details. if [ "$HAVE_SHLIB" = UNIX ]; then @@ -40,6 +40,12 @@ elif [ "$HAVE_SHLIB" = MACOS ]; then \$LIBS EOF else + if [ -z "$HAVE_SHLIB" ]; then + echo "link-shlib.od: fatal:" \ + "must include rc/shlib.rc to use shared libraries." >&2 + exit 90 + fi + # If no shared library support and we try to build one, # compensate by building a static library instead in the # same place. diff --git a/redoconf/link.od b/redoconf/link.od index e416539..41912ea 100644 --- a/redoconf/link.od +++ b/redoconf/link.od @@ -13,7 +13,6 @@ cat >$3 <<-EOF IFS="$NL" set -f \$LINK -o "\$o" \\ - -Wl,-rpath,'\$ORIGIN' \\ \$LDFLAGS \$OPTFLAGS \\ "\$@" \\ \$LIBS diff --git a/redoconf/rc/shlib.rc.od b/redoconf/rc/shlib.rc.od index 20211b4..6944118 100644 --- a/redoconf/rc/shlib.rc.od +++ b/redoconf/rc/shlib.rc.od @@ -27,17 +27,29 @@ try_macos_style() { if [ -n "$STATIC" ]; then echo "--enable-static specified; not building shared libraries." >&2 - rc_replaceln HAVE_SHLIB "" + rc_replaceln HAVE_SHLIB "STATIC" elif [ -n "$NOSHARED" ]; then echo "--disable-shared specified; not building shared libraries." >&2 - rc_replaceln HAVE_SHLIB "" + rc_replaceln HAVE_SHLIB "STATIC" elif try_unix_style; then rc_replaceln HAVE_SHLIB UNIX elif try_macos_style; then rc_replaceln HAVE_SHLIB MACOS else echo "Not building shared libraries on this platform." >&2 - rc_undo - rc_replaceln HAVE_SHLIB "" + rc_replaceln HAVE_SHLIB "STATIC" fi + +if [ "$HAVE_SHLIB" != "STATIC" ]; then + x='-Wl,-z,origin' + if (appendln LDFLAGS "$x" && rc_compile cc link); then + rc_appendln LDFLAGS "$x" + fi + + x='-Wl,-rpath,$ORIGIN' + if (appendln LDFLAGS "$x" && rc_compile cc link); then + rc_appendln LDFLAGS "$x" + fi +fi + rc_save