Skip to content

Add ksh93 [new package] #5243

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
124 changes: 124 additions & 0 deletions ksh93/PKGBUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
# This took a lot of trial and error. There possibly should be patches from the linked gisburn repo and the ones from debian and red hat.
#
pkgname=ksh93
pkgver=1.0.10
pkgrel=1
pkgdesc="The Original ATT Korn Shell, Now Maintained By The Community."
arch=('x86_64')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
arch=('x86_64')
arch=('i686' 'x86_64')

url="https://www.github.com/ksh93/ksh"
license=('spdx:EPL-2.0')

Copy link
Member

@jeremyd2019 jeremyd2019 Mar 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe add a backup for etc/ksh.kshrc ?

backup=('etc/ksh.kshrc')

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the leading slash supposed to not be there?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is not.

backup=('etc/fstab' 'etc/shells' 'etc/profile'
etc/bash.bashrc etc/skel/.bash{rc,_profile}
etc/nsswitch.conf)

# These makedeps were suggested by 'gisburn' in a ksh93 issue.
makedepends=(
'gcc'
'gdb'
'make'
'gettext'
'gettext-devel'
'flex'
'bison'
'unzip'
'pax'
'tar'
'libiconv-devel'
'ncurses-devel'
'gmp-devel'
'mpfr-devel'
'mpc-devel'
'isl-devel'
'procps-ng'
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no way all of these are actually needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know what I was doing honestly. I just saw someone else from the ksh93 repo say you should install that and just dropped it in.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
makedepends=(
'gcc'
'gdb'
'make'
'gettext'
'gettext-devel'
'flex'
'bison'
'unzip'
'pax'
'tar'
'libiconv-devel'
'ncurses-devel'
'gmp-devel'
'mpfr-devel'
'mpc-devel'
'isl-devel'
'procps-ng'
)
makedepends=(
'gcc'
'gettext-devel'
'libiconv-devel'
'ncurses-devel'
)

maybe adding back

	'flex'
	'bison'
	'gmp-devel'
	'mpfr-devel'
	'mpc-devel'
	'isl-devel'

if it's demonstrated they're actually used

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not going to include libiconv-devel because it completely fails if the GNU one is installed, I have to patch out looking for the system wide libiconv and use the bundled one instead.

# There exists already a package that provides ksh.exe, mksh, so I will set this to be a conflict.
# Unless there can be a convincing reason to let both packages be installed.
conflicts=('mksh')

source=("${pkgname}-${pkgver}.zip"::https://github.com/ksh93/ksh/archive/refs/tags/v1.0.10.zip
'ksh.kshrc')
sha256sums=('ab412118ce9527c6d805335080593fa874a0b859e9229c172f3fcf55d26f92e9'
'SKIP')

# This is necessary
export PATH="/bin:/usr/bin:$gccdir:$gccdir/include:/usr/include"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't do this globally... Several things have to source PKGBUILDs to try to extract variables from them, and they don't need their paths messed up. BTW, where is gccdir set where this could see it, and why on earth would you want include dirs in the PATH?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I must have removed that variable and forgot to delete references to it. It works without it, so I'll remove it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have had multiple failures including another one here because cc1.exe cannot be found. It only works if I explicitly put it in the PATH for some reason.


# Things might get a bit messary, prepare yourselves.
# I really should use gisburn's kshrc default config.
build() {
cd "${srcdir}/ksh-${pkgver}"

export CYGWIN_CHOST="${CHOST/-msys/-cygwin}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is used in other PKGBUILDs as an argument to configure. I don't see you using it anywhere here, and I doubt ksh93's build scripts expect it to be set. Maybe you could try local MSYSTEM=CYGWIN and see if anything useful changes?


# Do not, I repeat, DO NOT delete the src subdir.
# For now, multiple rounds must be done.

# Bit of a workaround with cc1.exe not found for some reason.
export gccdir="/usr/lib/gcc/x86_64-pc-msys/13.3.0"
export PATH="/bin:/usr/bin:$gccdir:$gccdir/include:/usr/include"

# Additional weird workaround.
export CFLAGS="-I/usr/lib/gcc/x86_64-pc-msys/13.3.0/include"
export CFLAGS="$CFLAGS -L/usr/lib/gcc/x86_64-pc-msys/13.3.0 -L/usr/lib"
export CCFLAGS="${CFLAGS} -fno-use-linker-plugin"
export LIBRARY_PATH="/usr/lib/gcc/x86_64-pc-msys/13.3.0"

export PATH="$PATH:$PWD/arch/msys.i386/lib/probe/C/make"

# What the inane build system does by default is
# entirely a shell script system. It sets 'chmod +x' to the script
# but that does nothing with windows. Need to append
# shebang at the start.
sed -i '1s/^/#!\/usr\/bin\/bash\n/' src/cmd/INIT/mamprobe.sh
sed -i '6s/^/#undef _lib_iconv_open\n/' src/lib/libast/features/iconv # Without this, fails with libiconv installed.

# It WILL fail during the first round. It MUST be ran twice.
printf "This WILL show an error at some point. This is to be expected.\n"
printf "The build command is ran twice because of fork() issue.\n"
printf "\n\nRound 1 begins now.\n\n"
sleep 2

CC="/usr/bin/gcc" /usr/bin/bash bin/package make PACKAGEROOT="$PWD" || true

printf "\n\nSecond and final round begins now.\n\n"
sleep 2
CC="/usr/bin/gcc" /usr/bin/bash bin/package make PACKAGEROOT="$PWD" || true

sleep 2
printf "\n\nFinished!\n\n"
sleep 2


}

package() {
cd "${srcdir}"
install -dm0755 "${pkgdir}/etc/skel"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

were you intending to put something in /etc/skel?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably shouldn't have had that line, I was copying from the arch linux one I found on aur.

install -dm0755 "${pkgdir}/usr/share/ksh"
install -dm0755 "${pkgdir}/usr/share/doc/ksh"
install -dm0755 "${pkgdir}/usr/share/licenses/ksh"

# Install the core components of ksh93
cd "${srcdir}/ksh-${pkgver}"
CC="/usr/bin/gcc" /usr/bin/bash bin/package install "${pkgdir}/usr" PACKAGEROOT="$PWD"

# install ksh sample rc file
install -Dm644 "${srcdir}/ksh.kshrc" "${pkgdir}/etc/ksh.kshrc"

# Install copyright and license files
install -Dm0644 LICENSE.md "${pkgdir}/usr/share/licenses/ksh/LICENSE.md"
install -Dm0644 COPYRIGHT "${pkgdir}/usr/share/licenses/ksh/COPYRIGHT"

local _docs
for _docs in 'builtins.mm' 'COMPATIBILITY' 'DESIGN' 'OBSOLETE' 'PROMO.mm' 'README' 'README-AUDIT.md' \
'RELEASE' 'RELEASE88' 'RELEASE93' 'sh.memo' 'TYPES'; do
install -Dm0644 "src/cmd/ksh93/${_docs}" "${pkgdir}/usr/share/doc/ksh/${_docs}"
done
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

formatting


# Because ksh.exe, like mksh, provided by this package and often people want to specify ksh93,
# I will make a copy of of the ksh executable naming it ksh93.exe.
cp "${pkgdir}/usr/bin/ksh.exe" "${pkgdir}/usr/bin/ksh93.exe"

# Lastly, move ksh-specific /usr/share/fun to /usr/share/ksh/functions
mv "${pkgdir}/usr/share/fun" "${pkgdir}/usr/share/ksh/functions"



}
8 changes: 8 additions & 0 deletions ksh93/ksh.kshrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# If you want to edit or add to this file,
# create $HOME/.kshrc and put it in there. Only this file and
# $HOME/.kshrc are sourced when interactive.

PS1=$'\E[1;91m$(/usr/bin/logname)@$(/usr/bin/hostname) \E[1;33m${PWD/~(Sl-r)$HOME/"~"}\E[0m$ '

# You can change to vi if you want to.
set -o emacs