Skip to content

Commit

Permalink
Add dylib support for Dragonfly BSD, Haiku, QNX (also man for QNX)
Browse files Browse the repository at this point in the history
These systems can compile dynamic libraries with existing code;
they just needed to be whitelisted in dylink.sh. The package script
did need to learn about Haiku's LIBRARY_PATH variable to make a
preinstalled dynamically linked ksh work via 'bin/package use'.

This was tested on DragonFly 6.2.2, Haiku beta 4, and QNX 6.5.0.

src/cmd/INIT/dylink.sh:
- Whitelist host types: dragonflybsd.* haiku.* qnx.*

bin/package:
- Add support for Haiku's LIBRARY_PATH variable.
- cp(1) on QNX 6.5.0 does not support the POSIX -P option, which
  copies a symlink without dereferencing it. However, -R is
  supported and implies -P. So, when installing dynamic libraries
  and symlinks, use 'cp -R' instead.

src/cmd/ksh93/fun/man:
- Add support for less(1) without -R option (use the more dangerous
  -r instead). This makes pager() work with 'less' on QNX 6.5.0.
- Add support for integrating the QNX 6.5.0 'use' command which
  extracts documentation directly from binaries (QNX does not come
  with a man command).
- Tweaks.

src/cmd/ksh93/include/terminal.h:
- Fix macro redefine warning on Haiku.
  • Loading branch information
McDutchie committed Jun 29, 2024
1 parent 7b611ad commit 19668e3
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 14 deletions.
18 changes: 14 additions & 4 deletions bin/package
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ command=${0##*/}
case $(getopts '[-][123:xyz]' opt --xyz 2>/dev/null; echo 0$opt) in
0123) USAGE=$'
[-?
@(#)$Id: '$command$' (ksh 93u+m) 2024-04-02 $
@(#)$Id: '$command$' (ksh 93u+m) 2024-06-29 $
]
[-author?Glenn Fowler <gsf@research.att.com>]
[-author?Contributors to https://github.com/ksh93/ksh]
Expand Down Expand Up @@ -548,7 +548,7 @@ SEE ALSO
pkgadd(1), pkgmk(1), rpm(1), sh(1), tar(1), optget(3)

IMPLEMENTATION
version package (ksh 93u+m) 2024-04-02
version package (ksh 93u+m) 2024-06-29
author Glenn Fowler <gsf@research.att.com>
author Contributors to https://github.com/ksh93/ksh
copyright (c) 1994-2012 AT&T Intellectual Property
Expand Down Expand Up @@ -2142,6 +2142,16 @@ case $x in
$show _RLD_ROOT=$_RLD_ROOT
$show export _RLD_ROOT
export _RLD_ROOT
# Haiku
case $LIBRARY_PATH: in
$INSTALLROOT/dyn/lib:*)
;;
*) LIBRARY_PATH=$INSTALLROOT/dyn/lib${LIBRARY_PATH:+:$LIBRARY_PATH}
$show LIBRARY_PATH=$LIBRARY_PATH
$show export LIBRARY_PATH
export LIBRARY_PATH
;;
esac

# now set up PATH
#
Expand Down Expand Up @@ -2704,8 +2714,8 @@ do_install() # dir [ command ... ]
if test -e "$libdir/$f"
then rm -f "$libdir/$f" || exit
fi
# to copy symlinks with BSD cp, we need to specify -R as well as -P, contra POSIX
trace cp -PR "$f" "$libdir"/
# cp -P is not yet universally supported, but cp -R also preserves symlinks
trace cp -R "$f" "$libdir"/
done
# install developer stuff
test -d "$includedir/ast" && trace rm -rf -- "$includedir/ast"
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/INIT/dylink.sh
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ esac

# Check for supported system.
case $HOSTTYPE in
android.* | darwin.* | freebsd* | linux.* | netbsd.* | openbsd.* | sol* )
android.* | darwin.* | dragonflybsd.* | freebsd* | haiku.* | linux.* | netbsd.* | openbsd.* | qnx.* | sol* )
# supported
;;
cygwin.*)
Expand Down
60 changes: 51 additions & 9 deletions src/cmd/ksh93/fun/man
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,18 @@ namespace man
typeset pager=${MANPAGER:-${PAGER-}}
((!stdout_on_terminal)) && pager=cat
case $pager in
'') pager='less -R' ;;
'') pager="less $lessopt" ;;
less | */less | less[[:blank:]]* | */less[[:blank:]]*)
pager+=' -R' ;;
pager+=" -$lessopt" ;;
esac
$pager
command -- $pager
}

# Shorthand for invoking the OS man(1) command on the default system PATH.

os_man()
{
command -p man ${.sh.manopts-} "$@"
}

# Try if a system manual page in a section exists. Unfortunately, we
Expand All @@ -131,7 +138,7 @@ namespace man

try_os_man()
{
[[ $2 != */* && $(command man ${.sh.manopts-} -s "$1" "$2" 2>/dev/null) == *$'\n'*$'\n'*$'\n'* ]]
[[ $2 != */* && $(os_man -s "$1" "$2" 2>/dev/null) == *$'\n'*$'\n'*$'\n'* ]]
}

# The main function puts it all together. When given a single argument,
Expand All @@ -144,18 +151,18 @@ namespace man

main()
{
if (($# != 1)); then
command man ${.sh.manopts-} "$@"
if (($# != 1)) || [[ $1 == -* ]]; then
os_man "$@"
elif builtin_has_selfdoc "$1"; then
show_selfdoc "$1" | pager
elif try_os_man 1 "$1"; then
command man ${.sh.manopts-} -s 1 "$1"
os_man -s 1 "$1"
elif try_os_man 8 "$1"; then
command man ${.sh.manopts-} -s 8 "$1"
os_man -s 8 "$1"
elif extcmd_has_selfdoc "$1"; then
show_selfdoc "$1" | pager
else
command man ${.sh.manopts-} "$1"
os_man "$1"
fi
}
}
Expand Down Expand Up @@ -194,3 +201,38 @@ if ((.sh.version < 20211227)); then
print "WARNING: this man wrapper function requires ksh 93u+m 2021-12-27 or later" >&2
sleep 1
fi

# Check if 'less' has an -R option. Some versions have only -r.
# In the man namespace functions above, ${.man.lessopt} is simply $lessopt.
if echo test | less -R >/dev/null 2>&1; then
.man.lessopt=-R
else
.man.lessopt=-r
fi

# Check for QNX, which uses 'use' instead of 'man'.
# Override .man.main function with QNX version.
# Instead of .sh.manotps, 'use' options may be set in .sh.useopts.

if command -pv use >/dev/null && [[ $(command -p uname -s) == QNX ]]
then namespace man
{
unset -f os_man try_os_man
os_use()
{
command -p use ${.sh.useopts-} "$@"
}
main()
{
if (($# != 1)) || [[ $1 == -* ]]; then
os_use "$@"
elif builtin_has_selfdoc "$1" || extcmd_has_selfdoc "$1"; then
show_selfdoc "$1" | pager
elif os_use "$1" >/dev/null 2>&1; then
os_use "$1" | pager
else
os_use "$1" # show error without pager
fi
}
}
fi
3 changes: 3 additions & 0 deletions src/cmd/ksh93/include/terminal.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ extern int sh_ioctl(int,int,void*,int);
extern int sh_tcgetattr(int,struct termios*);
extern int sh_tcsetattr(int,int,struct termios*);

#undef ioctl
#undef tcgetattr
#undef tcsetattr
#define ioctl(a,b,c) sh_ioctl(a,b,c,sizeof(c))
#define tcgetattr(a,b) sh_tcgetattr(a,b)
#define tcsetattr(a,b,c) sh_tcsetattr(a,b,c)
Expand Down

0 comments on commit 19668e3

Please sign in to comment.