Skip to content

Commit 67eea4b

Browse files
committed
Fix installing ksh with dynamic libs on recent macOS (re: 41dfd03)
Problem: after 'sudo bin/package install /usr/local', the dynamically linked /usr/local/bin/ksh binary will not find its dynamic libraries in /usr/local/lib. Same for shcomp. For macOS to find the dynamic libraries, we need dylink.sh to add an "install name" of, e.g., @rpath/libshell.3.0.dylib instead of simply libshell.3.0.dylib, and then at install time, we need to add the directory path of the library (e.g., /usr/local/lib) to the binary using install_name_tool(1).
1 parent 33967ac commit 67eea4b

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

bin/package

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# #
33
# This software is part of the ast package #
44
# Copyright (c) 1994-2012 AT&T Intellectual Property #
5-
# Copyright (c) 2020-2025 Contributors to ksh 93u+m #
5+
# Copyright (c) 2020-2026 Contributors to ksh 93u+m #
66
# and is licensed under the #
77
# Eclipse Public License, Version 2.0 #
88
# #
@@ -136,7 +136,7 @@ case $(getopts '[-][123:xyz]' opt --xyz 2>/dev/null; echo 0$opt) in
136136
[-author?Glenn Fowler <gsf@research.att.com>]
137137
[-author?Contributors to https://github.com/ksh93/ksh]
138138
[-copyright?(c) 1994-2012 AT&T Intellectual Property]
139-
[-copyright?(c) 2020-2025 Contributors to ksh 93u+m]
139+
[-copyright?(c) 2020-2026 Contributors to ksh 93u+m]
140140
[-license?https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html]
141141
[+NAME?'$command$' - build, test and install ksh 93u+m]
142142
[+DESCRIPTION?The \b'$command$'\b command is the main control script
@@ -568,7 +568,7 @@ IMPLEMENTATION
568568
author Glenn Fowler <gsf@research.att.com>
569569
author Contributors to https://github.com/ksh93/ksh
570570
copyright (c) 1994-2012 AT&T Intellectual Property
571-
copyright (c) 2020-2025 Contributors to ksh 93u+m
571+
copyright (c) 2020-2026 Contributors to ksh 93u+m
572572
license https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html'
573573
case $1 in
574574
html) echo "</pre></body></html>" ;;
@@ -2619,6 +2619,11 @@ do_install() # dir [ command ... ]
26192619
# install executable
26202620
if test -f "dyn/bin/$f"
26212621
then trace cp "dyn/bin/$f" "$bindir/" || exit
2622+
case $HOSTTYPE in
2623+
darwin.*)
2624+
trace install_name_tool -add_rpath "$libdir" "$bindir/$f" || exit
2625+
;;
2626+
esac
26222627
else trace cp "bin/$f" "$bindir/" || exit
26232628
fi
26242629
# install manual pages and autoloadable functions

src/cmd/INIT/dylink.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
########################################################################
22
# #
33
# This file is part of the ksh 93u+m package #
4-
# Copyright (c) 2021-2025 Contributors to ksh 93u+m #
4+
# Copyright (c) 2021-2026 Contributors to ksh 93u+m #
55
# and is licensed under the #
66
# Eclipse Public License, Version 2.0 #
77
# #
@@ -136,7 +136,7 @@ case ${exec_file} in
136136
case $HOSTTYPE in
137137
darwin.*)
138138
do_link "lib/$lib_file" -dynamiclib \
139-
-Wl,-dylib_install_name -Wl,"$lib_linkname" \
139+
-Wl,-dylib_install_name -Wl,"@rpath/$lib_linkname" \
140140
"$@" -L"$dest_dir/lib" $l_flags
141141
;;
142142
*) do_link "lib/$lib_file" -shared -Wl,-soname -Wl,"$lib_linkname" \

0 commit comments

Comments
 (0)