Skip to content

Commit 253d590

Browse files
committed
ksh93: remove a bunch of hacks.
Build as Cygwin. Add check function. the sigchld tests take A LONG TIME. Several tests fail, but those can be investigated later.
1 parent 32b9502 commit 253d590

File tree

4 files changed

+137
-225
lines changed

4 files changed

+137
-225
lines changed

Diff for: ksh93/PKGBUILD

+76-225
Original file line numberDiff line numberDiff line change
@@ -6,253 +6,104 @@ pkgdesc="The Original ATT Korn Shell, Now Maintained By The Community."
66
arch=('i686' 'x86_64')
77
url="https://www.github.com/ksh93/ksh"
88
license=('spdx:EPL-2.0')
9-
makedepends=('gcc' 'binutils' 'bison' 'libintl' 'ncurses-devel' 'texinfo')
10-
11-
# There exists already a package that provides ksh.exe, mksh, so I will set this to be a conflict.
12-
# Unless there can be a convincing reason to let both packages be installed.
9+
makedepends=('gcc' 'bison' 'libiconv-devel' 'gettext-devel' 'ncurses-devel' 'texinfo')
10+
depends=('libiconv')
1311
conflicts=('mksh')
12+
backup=('etc/ksh.kshrc')
1413

1514
source=("${pkgname}-${pkgver}.zip"::https://github.com/ksh93/ksh/archive/refs/tags/v1.0.10.zip
16-
'ksh.kshrc'
17-
'ksh-unc-paths.patch')
15+
'ksh.kshrc'
16+
'ksh-defpath-usr-bin.patch'
17+
'ksh-mamake.patch'
18+
'ksh-shtests-mkdir-m.patch'
19+
'ksh-unc-paths.patch')
1820

1921
sha256sums=('ab412118ce9527c6d805335080593fa874a0b859e9229c172f3fcf55d26f92e9'
20-
'SKIP'
21-
'4838b950e32fc61dbfbb5e446570f4f7503f302a26305dff1f9b0769585a94bc')
22-
23-
# Special file suggested by another user on the github
24-
print_gnulinux_builtin_header() {
25-
26-
# Make sure to use \\ instead of \ for continuations
27-
cat <<ENDOFTEXT
28-
29-
#ifndef _GNULINUX_KSH_CMDLIST_H
30-
#define _GNULINUX_KSH_CMDLIST_H
31-
32-
#ifdef __cplusplus
33-
extern "C" {
34-
#endif
35-
36-
/*
37-
* List builtins for Linux.
38-
* The list here is partially autogenerated and partially hand-picked
39-
* based on compatibility with the native GNU coreutils versions of
40-
* these tools
41-
*/
42-
43-
/* GNU coreutils compatible commands.
44-
* Be careful, some are in /bin while others are in /usr/bin
45-
*/
46-
#define ASTCMDLIST(f) \
47-
{ "/usr/ast/bin/" #f, NV_BLTIN|NV_BLTINOPT|NV_NOFREE, bltin(f) },
48-
#define BINCMDLIST(f) \
49-
{ "/bin/" #f, NV_BLTIN|NV_BLTINOPT|NV_NOFREE, bltin(f) }, \
50-
{ "/usr/bin/" #f, NV_BLTIN|NV_BLTINOPT|NV_NOFREE, bltin(f) },
51-
/* undo ast_map.h #defines to avoid collision */
52-
#undef basename
53-
#undef chmod
54-
#undef chown
55-
#undef dirname
56-
#undef mkdir
57-
#undef mkfifo
58-
#undef mktemp
59-
#undef readlink
60-
#undef realpath
61-
#undef rmdir
62-
63-
64-
/* Generated data, do not edit. */
65-
BINCMDLIST(basename)
66-
BINCMDLIST(cksum)
67-
BINCMDLIST(comm)
68-
BINCMDLIST(cut)
69-
BINCMDLIST(dirname)
70-
BINCMDLIST(expr)
71-
BINCMDLIST(fold)
72-
BINCMDLIST(join)
73-
BINCMDLIST(logname)
74-
BINCMDLIST(mkdir)
75-
BINCMDLIST(mkfifo)
76-
BINCMDLIST(mktemp)
77-
BINCMDLIST(paste)
78-
BINCMDLIST(pathchk)
79-
BINCMDLIST(rev)
80-
BINCMDLIST(rmdir)
81-
BINCMDLIST(sleep)
82-
BINCMDLIST(sync)
83-
BINCMDLIST(tee)
84-
BINCMDLIST(tty)
85-
BINCMDLIST(uniq)
86-
BINCMDLIST(wc)
87-
88-
/* Mandatory for ksh93 test suite and AST scripts */
89-
BINCMDLIST(getconf)
90-
91-
ASTCMDLIST(basename)
92-
ASTCMDLIST(cat)
93-
ASTCMDLIST(chgrp)
94-
ASTCMDLIST(chmod)
95-
ASTCMDLIST(chown)
96-
ASTCMDLIST(cksum)
97-
ASTCMDLIST(cmp)
98-
ASTCMDLIST(comm)
99-
ASTCMDLIST(cp)
100-
ASTCMDLIST(cut)
101-
ASTCMDLIST(date)
102-
ASTCMDLIST(dirname)
103-
//BINCMDLIST(egrep)
104-
//ASTCMDLIST(egrep)
105-
ASTCMDLIST(expr)
106-
ASTCMDLIST(fds)
107-
//BINCMDLIST(fgrep)
108-
//ASTCMDLIST(fgrep)
109-
ASTCMDLIST(fmt)
110-
ASTCMDLIST(fold)
111-
//BINCMDLIST(grep)
112-
//ASTCMDLIST(grep)
113-
ASTCMDLIST(head)
114-
ASTCMDLIST(id)
115-
//BINCMDLIST(iconv)
116-
//ASTCMDLIST(iconv)
117-
ASTCMDLIST(join)
118-
ASTCMDLIST(ln)
119-
ASTCMDLIST(logname)
120-
//ASTCMDLIST(ls)
121-
ASTCMDLIST(md5sum)
122-
BINCMDLIST(md5sum)
123-
ASTCMDLIST(mkdir)
124-
ASTCMDLIST(mkfifo)
125-
ASTCMDLIST(mktemp)
126-
ASTCMDLIST(mv)
127-
ASTCMDLIST(paste)
128-
ASTCMDLIST(pathchk)
129-
ASTCMDLIST(pids)
130-
//BINCMDLIST(od)
131-
//ASTCMDLIST(od)
132-
//BINCMDLIST(readlink)
133-
//ASTCMDLIST(readlink)
134-
//BINCMDLIST(realpath)
135-
//ASTCMDLIST(realpath)
136-
ASTCMDLIST(rev)
137-
ASTCMDLIST(rm)
138-
ASTCMDLIST(rmdir)
139-
ASTCMDLIST(stty)
140-
//ASTCMDLIST(sha1sum)
141-
//BINCMDLIST(sha1sum)
142-
//ASTCMDLIST(sha256sum)
143-
//BINCMDLIST(sha256sum)
144-
//ASTCMDLIST(sha384sum)
145-
//BINCMDLIST(sha384sum)
146-
//ASTCMDLIST(sha512sum)
147-
//BINCMDLIST(sha512sum)
148-
ASTCMDLIST(sum)
149-
ASTCMDLIST(sync)
150-
ASTCMDLIST(tail)
151-
ASTCMDLIST(tee)
152-
//BINCMDLIST(tr)
153-
//ASTCMDLIST(tr)
154-
ASTCMDLIST(tty)
155-
ASTCMDLIST(uname)
156-
ASTCMDLIST(uniq)
157-
//ASTCMDLIST(vmstate)
158-
ASTCMDLIST(wc)
159-
// ASTCMDLIST(xgrep)
160-
//BINCMDLIST(xargs)
161-
//ASTCMDLIST(xargs)
162-
163-
#ifdef __cplusplus
164-
}
165-
#endif
166-
167-
#endif /* !_GNULINUX_KSH_CMDLIST_H */
168-
ENDOFTEXT
169-
}
22+
'ed57db19753904b3969884f5768fa84d158f5ba65ba0766c095961cce0c8e267'
23+
'ca07713ffe1b4e2bafde1b3a5aa7ad112445f49f105388c5bb117d486953c3c7'
24+
'49ff8cdfe5509846807db764f16ab321f431148c1d56f97c4843251a8f8bc109'
25+
'c7d1489142cbce27122fb11e506cf4b56459fc6803ec384bae52eaea8a012118'
26+
'4838b950e32fc61dbfbb5e446570f4f7503f302a26305dff1f9b0769585a94bc')
17027

17128
prepare() {
17229
cd "${srcdir}/ksh-${pkgver}"
17330
patch -p1 -i ../ksh-unc-paths.patch
174-
export gnu_linux_builtin_header="${PWD}/tmp_gnulinux_builtin_header.h"
175-
print_gnulinux_builtin_header >"${gnu_linux_builtin_header}"
31+
patch -p1 -i ../ksh-defpath-usr-bin.patch
32+
patch -p1 -i ../ksh-mamake.patch
33+
patch -p1 -i ../ksh-shtests-mkdir-m.patch
17634
}
17735

178-
# Things might get a bit messary, prepare yourselves.
179-
# I really should use gisburn's kshrc default config.
18036
build() {
181-
cd "${srcdir}/ksh-${pkgver}"
182-
183-
export BAST_FLAGS="-DSHOPT_CMDLIB_BLTIN=0 -DSH_CMDLIB_DIR=\\\"/usr/ast/bin\\\" -DSHOPT_CMDLIB_HDR=\\\"${gnu_linux_builtin_header}\\\" -DSHOPT_SYSRC"
184-
185-
# For now, it literally fails if cc1.exe is not explicitly on the PATH.
186-
local GCC_DIR="$(gcc -print-search-dirs | sed -ne '/^install: /s///p')"
187-
export PATH="$PATH:$GCC_DIR"
188-
189-
190-
# Additional weird workaround.
191-
export CFLAGS="-I${GCC_DIR}/include -L${GCC_DIR} -L/usr/lib"
192-
export CCFLAGS="${CFLAGS} -I${scrdir}/ksh-${pkgver} -fno-use-linker-plugin ${BAST_FLAGS} -std=gnu17"
193-
export LIBRARY_PATH="${GCC_DIR}"
194-
195-
# What the build system does by default is
196-
# entirely a shell script system. It sets 'chmod +x' to the script
197-
# but that does nothing with windows. Need to append
198-
# shebang at the start.
199-
sed -i '1s/^/#!\/usr\/bin\/bash\n/' src/cmd/INIT/mamprobe.sh
200-
sed -i '6s/^/#undef _lib_iconv_open\n/' src/lib/libast/features/iconv # Without this, fails with libiconv installed.
201-
202-
# My previous attempt at patching the mamake.exe replacement failed. Reason being, is that
203-
# this build process is highly biased towards unix way of thinking, which doesn't work well with
204-
# windows. It might kinda work on cygwin, but that fails with msys2. The only successful way so far
205-
# it's been to build it, is to build it twice. Failure is expected.
206-
207-
# First round. Note that '|| true' has to be there, it WILL bail the build process when the expected fork() issue
208-
# happens, so this tells bash to keep going anyways in spite of non zero return code.
209-
printf "If it reports back fork() error, this is to be expected.\n"
210-
printf "It will simply run the build command again to finish the job.\n"
211-
/usr/bin/bash bin/package make PACKAGEROOT="$PWD" CC="/usr/bin/gcc" SHELL="/usr/bin/bash" || true
212-
213-
sleep 2
214-
215-
/usr/bin/bash bin/package make PACKAGEROOT="$PWD" CC="/usr/bin/gcc" SHELL="/usr/bin/bash" || true
37+
cd "${srcdir}/ksh-${pkgver}"
21638

39+
CFLAGS+=" -fno-strict-aliasing -std=gnu17"
40+
export CCFLAGS="${CFLAGS}"
41+
42+
# What the build system does by default is
43+
# entirely a shell script system. It sets 'chmod +x' to the script
44+
# but that does nothing with windows. Need to append
45+
# shebang at the start.
46+
sed -i '1s/^/#!\/usr\/bin\/bash\n/' src/cmd/INIT/mamprobe.sh
47+
48+
case "$CARCH" in
49+
i?86)
50+
export HOSTTYPE=cygwin.i386
51+
;;
52+
x86_64)
53+
export HOSTTYPE=cygwin.i386-64
54+
;;
55+
*)
56+
echo "Unhandled architecture ${CARCH}" >&2
57+
false
58+
;;
59+
esac
60+
61+
# the brain-dead build system insists on setting CYGWIN=ntsec, even though
62+
# the CYGWIN variable does nothing on MSYS2, and the ntsec option is obsolete
63+
# and no longer does anything on Cygwin anyway
64+
export CYGWIN=ntsec
65+
bash bin/package make PACKAGEROOT="$PWD" CC="cc" SHELL="/usr/bin/bash" HOSTTYPE="${HOSTTYPE}"
66+
}
21767

68+
check() {
69+
cd "${srcdir}/ksh-${pkgver}"
70+
bash bin/shtests --compile PACKAGEROOT="$PWD" CC="cc" HOSTTYPE="${HOSTTYPE}" || true
21871
}
21972

22073
package() {
221-
cd "${srcdir}"
222-
install -dm0755 "${pkgdir}/etc/skel"
223-
install -dm0755 "${pkgdir}/usr/share/ksh"
224-
install -dm0755 "${pkgdir}/usr/share/doc/ksh"
225-
install -dm0755 "${pkgdir}/usr/share/licenses/ksh"
226-
227-
# Install the core components of ksh93
228-
cd "${srcdir}/ksh-${pkgver}"
229-
/usr/bin/bash bin/package install CC="/usr/bin/gcc" SHELL="/usr/bin/bash" "${pkgdir}/usr" PACKAGEROOT="$PWD"
74+
cd "${srcdir}"
75+
install -dm0755 "${pkgdir}/etc/skel"
76+
install -dm0755 "${pkgdir}/usr/share/ksh"
77+
install -dm0755 "${pkgdir}/usr/share/doc/ksh"
78+
install -dm0755 "${pkgdir}/usr/share/licenses/ksh"
23079

231-
# install ksh sample rc file
232-
install -Dm644 "${srcdir}/ksh.kshrc" "${pkgdir}/etc/ksh.kshrc"
80+
# Install the core components of ksh93
81+
cd "${srcdir}/ksh-${pkgver}"
82+
bash bin/package install CC="cc" SHELL="/usr/bin/bash" "${pkgdir}/usr" PACKAGEROOT="$PWD" HOSTTYPE="${HOSTTYPE}"
23383

234-
# Install copyright and license files
235-
install -Dm0644 LICENSE.md "${pkgdir}/usr/share/licenses/ksh/LICENSE.md"
236-
install -Dm0644 COPYRIGHT "${pkgdir}/usr/share/licenses/ksh/COPYRIGHT"
84+
# install ksh sample rc file
85+
install -Dm644 "${srcdir}/ksh.kshrc" "${pkgdir}/etc/ksh.kshrc"
23786

238-
local _docs
239-
for _docs in 'builtins.mm' 'COMPATIBILITY' 'DESIGN' 'OBSOLETE' 'PROMO.mm' 'README' 'README-AUDIT.md' \
240-
'RELEASE' 'RELEASE88' 'RELEASE93' 'sh.memo' 'TYPES'; do
241-
install -Dm0644 "src/cmd/ksh93/${_docs}" "${pkgdir}/usr/share/doc/ksh/${_docs}"
242-
done
87+
# Install copyright and license files
88+
install -Dm0644 LICENSE.md "${pkgdir}/usr/share/licenses/ksh/LICENSE.md"
89+
install -Dm0644 COPYRIGHT "${pkgdir}/usr/share/licenses/ksh/COPYRIGHT"
24390

244-
# Because ksh.exe, like mksh, provided by this package and often people want to specify ksh93,
245-
# I will make a copy of of the ksh executable naming it ksh93.exe.
246-
cp "${pkgdir}/usr/bin/ksh.exe" "${pkgdir}/usr/bin/ksh93.exe"
247-
248-
# Lastly, move ksh-specific /usr/share/fun to /usr/share/ksh/functions
249-
mv "${pkgdir}/usr/share/fun" "${pkgdir}/usr/share/ksh/functions"
91+
local _docs
92+
for _docs in 'builtins.mm' 'COMPATIBILITY' 'DESIGN' 'OBSOLETE' 'PROMO.mm' \
93+
'README' 'README-AUDIT.md' 'RELEASE' 'RELEASE88' 'RELEASE93' 'sh.memo' \
94+
'TYPES'; do
95+
install -Dm0644 "src/cmd/ksh93/${_docs}" "${pkgdir}/usr/share/doc/ksh/${_docs}"
96+
done
25097

251-
# It was requested to add as well the tests subdir
252-
for I in src/cmd/ksh93/tests/*; do
253-
install -Dm0644 "$I" "${pkgdir}/usr/share/ksh/tests/$(basename $I)"
254-
done
98+
# Because ksh.exe, like mksh, provided by this package and often people want to specify ksh93,
99+
# I will make a copy of of the ksh executable naming it ksh93.exe.
100+
cp "${pkgdir}/usr/bin/ksh.exe" "${pkgdir}/usr/bin/ksh93.exe"
255101

256-
102+
# Lastly, move ksh-specific /usr/share/fun to /usr/share/ksh/functions
103+
mv "${pkgdir}/usr/share/fun" "${pkgdir}/usr/share/ksh/functions"
257104

105+
# It was requested to add as well the tests subdir
106+
for I in src/cmd/ksh93/tests/*; do
107+
install -Dm0644 "$I" "${pkgdir}/usr/share/ksh/tests/$(basename $I)"
108+
done
258109
}

Diff for: ksh93/ksh-defpath-usr-bin.patch

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--- ksh-1.0.10/bin/package.orig 2025-03-13 11:30:37.844745700 -0700
2+
+++ ksh-1.0.10/bin/package 2025-03-13 11:33:55.678158000 -0700
3+
@@ -1,3 +1,4 @@
4+
+#!/bin/sh
5+
########################################################################
6+
# #
7+
# This software is part of the ast package #
8+
@@ -1792,6 +1793,12 @@
9+
esac
10+
fi
11+
12+
+if test /bin -ef /usr/bin; then
13+
+ # /bin and /usr/bin are the same - but MSYS2 gcc dies badly if invoked
14+
+ # as /bin/cc, so make sure /usr/bin is first
15+
+ DEFPATH="/usr/bin:$DEFPATH"
16+
+fi
17+
+
18+
export DEFPATH # for iffe, etc.
19+
20+
PATH=$(sanitize_PATH "/opt/ast/bin:$DEFPATH:$PATH")

Diff for: ksh93/ksh-mamake.patch

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Patch to avoid ETXBUSY when trying to replace mamake.exe
2+
--- a/bin/package Thu Aug 01 18:54:10 2024
3+
+++ b/bin/package Mon Mar 10 20:42:45 2025
4+
@@ -2464,7 +2464,7 @@
5+
# To allow relinking the binary against libast later, add a _bootstrap suffix and create
6+
# a symlink to it. The symlink can be removed/renamed instead of the _bootstrap binary.
7+
$exec $CC -O $CCFLAGS $LDFLAGS -o "$INSTALLROOT/bin/${i}_bootstrap" "$INITROOT/$i.c" || return
8+
- $exec ln -sf "${i}_bootstrap" "$INSTALLROOT/bin/$i" || return
9+
+ MSYS="$MSYS winsymlinks:native" $exec ln -sf "${i}_bootstrap" "$INSTALLROOT/bin/$i" || return
10+
;;
11+
*) $exec $CC -O $CCFLAGS $LDFLAGS -o "$INSTALLROOT/bin/$i" "$INITROOT/$i.c" || return
12+
;;

Diff for: ksh93/ksh-shtests-mkdir-m.patch

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
--- ksh-1.0.10/src/cmd/ksh93/tests/shtests.orig 2025-03-13 11:48:28.444460100 -0700
2+
+++ ksh-1.0.10/src/cmd/ksh93/tests/shtests 2025-03-13 11:48:30.253240200 -0700
3+
@@ -284,7 +284,7 @@
4+
5+
tmp=$(
6+
d=${TMPDIR:-/tmp}/ksh93.shtests.$$.${RANDOM:-0}
7+
- mkdir -m700 -- "$d" && CDPATH= cd -P -- "$d" && pwd
8+
+ mkdir -- "$d" && CDPATH= cd -P -- "$d" && pwd
9+
) || {
10+
echo 'mkdir failed' >&2
11+
exit 1
12+
@@ -372,7 +372,7 @@
13+
for lang in $locales
14+
do o=$u
15+
tmp_s=$tmp/$u.$lang
16+
- mkdir -m700 "$tmp_s" || exit
17+
+ mkdir "$tmp_s" || exit
18+
cd "$tmp_s" || exit
19+
if [[ $lang == C ]]
20+
then lang=
21+
@@ -415,7 +415,7 @@
22+
o="$u(shcomp)"
23+
echo test $o begins ${time:+"at $(date +%Y-%m-%d+%H:%M:%S)"}
24+
tmp_s=$tmp/$u.shcomp
25+
- mkdir -m700 "$tmp_s" || exit
26+
+ mkdir "$tmp_s" || exit
27+
# Must define aliases from _common in script itself so they are expanded at compile time.
28+
# Replace the first few lines with those to avoid affecting $LINENO; they are comments anyway.
29+
num_alias=$(grep -c '^alias [[:alnum:]_]\{2,\}=' _common)

0 commit comments

Comments
 (0)