apenwarr-redo/redoconf/link-shlib.od
Avery Pennarun 88250334da redoconf: move -Wl,-rpath flags to shlib.rc and add -Wl,-z,origin.
It was kind of ugly to have this kind of special flag directly in
link.od; now we detect whether it's available.  This also gives a
project the ability to override the flag in some other way if they
want.

As a result, rc/shlib.rc needs to be included in all.rc.od if you want
to create or link against shared libraries.

While we're here, also add -Wl,-z,origin on platforms where it works.
This is apparently needed for FreeBSD 8.0 at least, and probably other
platforms.

Reported-by: Wayne Scott <wsc9tt@gmail.com>
2019-03-01 13:55:22 -05:00

61 lines
1.2 KiB
Text

. ./redoconf.rc
rc_include _all.rc
# Tricky quoting: see _compile.od for details.
if [ "$HAVE_SHLIB" = UNIX ]; then
cat >$3 <<-EOF
#!/bin/sh -e
LINK=$(shquote "$LINK")
LDFLAGS=$(shquote "$LDFLAGS")
OPTFLAGS=$(shquote "$OPTFLAGS")
LIBS=$(shquote "$LIBS")
o="\$1"
ob="\${o#*/}"
shift
IFS="$NL"
set -f
\$LINK -shared -o "\$o" \\
-Wl,-soname,"\$ob" \\
\$LDFLAGS \$OPTFLAGS \\
"\$@" \\
\$LIBS
EOF
elif [ "$HAVE_SHLIB" = MACOS ]; then
cat >$3 <<-EOF
#!/bin/sh -e
LINK=$(shquote "$LINK")
LDFLAGS=$(shquote "$LDFLAGS")
OPTFLAGS=$(shquote "$OPTFLAGS")
LIBS=$(shquote "$LIBS")
LIBDIR=$(shquote "$LIBDIR")
o="\$1"
ob="\${o#*/}"
shift
IFS="$NL"
set -f
\$LINK -dynamiclib -o "\$o" \\
-install_name "\$ob" \\
\$LDFLAGS \$OPTFLAGS \\
"\$@" \\
\$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.
cat >$3 <<-EOF
#!/bin/sh -e
o="\$1"
shift
rm -f "\$o"
ar q "\$o" "\$@"
EOF
fi
chmod a+x "$3"
redo-stamp <$3