oksh-noxz

[fork] Portable OpenBSD ksh, based on the Public Domain Korn Shell (pdksh).
git clone https://noxz.tech/git/oksh-noxz.git
oksh-noxz

commit: 952f2c0902741143b3424b41e97563fd47c2cf99
parent: 62f501f0b29cd88ed4fd4ed6d252dcd62a42b954
author: Brian Callahan <bcallah@openbsd.org>
date:   Sat, 20 Jan 2018 00:54:06 -0500
Add --enable-static, --enable-ksh, and --enable-sh configure options.
Each has a corresponding --disable flag.
MCVS/Entries82+++++++--------
Mconfigure110+++++++++++++++++---
2 files changed, 138 insertions(+), 54 deletions(-)
diff --git a/CVS/Entries b/CVS/Entries
@@ -1,46 +1,46 @@
 /config.h/1.19/Tue Jan 16 02:21:56 2018//
 /history.c/1.80/Tue Jan 16 02:21:56 2018//
-/CONTRIBUTORS/1.10/Wed Jan 17 03:52:32 2018//
-/LEGAL/1.2/Wed Jan 17 03:52:32 2018//
-/Makefile/1.38/Wed Jan 17 03:56:16 2018//
-/NOTES/1.16/Wed Jan 17 03:52:32 2018//
-/PROJECTS/1.9/Wed Jan 17 03:52:32 2018//
-/README/1.16/Wed Jan 17 03:56:16 2018//
-/alloc.c/1.19/Wed Jan 17 03:56:16 2018//
-/c_ksh.c/1.58/Wed Jan 17 03:56:16 2018//
-/c_sh.c/1.62/Wed Jan 17 03:52:32 2018//
-/c_test.c/1.24/Wed Jan 17 03:52:32 2018//
-/c_test.h/1.4/Wed Jan 17 03:52:32 2018//
-/c_ulimit.c/1.26/Wed Jan 17 03:56:16 2018//
-/edit.c/1.63/Wed Jan 17 03:56:16 2018//
-/edit.h/1.11/Wed Jan 17 03:52:32 2018//
 /emacs.c/1.84/Result of merge//
-/eval.c/1.59/Wed Jan 17 03:56:16 2018//
-/exec.c/1.72/Wed Jan 17 03:56:16 2018//
-/expand.h/1.15/Wed Jan 17 03:52:32 2018//
-/expr.c/1.32/Wed Jan 17 03:52:32 2018//
-/io.c/1.36/Wed Jan 17 03:56:16 2018//
-/jobs.c/1.59/Wed Jan 17 03:56:16 2018//
-/ksh.1/1.197/Wed Jan 17 03:52:32 2018//
-/lex.c/1.78/Wed Jan 17 03:52:32 2018//
-/lex.h/1.21/Wed Jan 17 03:52:32 2018//
-/mail.c/1.22/Wed Jan 17 03:52:32 2018//
 /main.c/1.89/Result of merge//
-/misc.c/1.68/Wed Jan 17 03:56:16 2018//
-/path.c/1.22/Wed Jan 17 03:52:32 2018//
-/sh.1/1.146/Wed Jan 17 03:52:32 2018//
-/sh.h/1.71/Wed Jan 17 03:56:16 2018//
-/shf.c/1.32/Wed Jan 17 03:56:16 2018//
-/shf.h/1.8/Wed Jan 17 03:52:32 2018//
-/syn.c/1.38/Wed Jan 17 03:52:32 2018//
-/table.c/1.25/Wed Jan 17 03:56:16 2018//
-/table.h/1.13/Wed Jan 17 03:52:32 2018//
-/trap.c/1.31/Wed Jan 17 03:56:16 2018//
-/tree.c/1.31/Wed Jan 17 03:56:16 2018//
-/tree.h/1.12/Wed Jan 17 03:52:32 2018//
-/tty.c/1.16/Wed Jan 17 03:52:32 2018//
-/tty.h/1.6/Wed Jan 17 03:52:32 2018//
-/var.c/1.65/Wed Jan 17 03:56:16 2018//
-/version.c/1.12/Wed Jan 17 03:52:32 2018//
-/vi.c/1.55/Wed Jan 17 03:56:16 2018//
+/CONTRIBUTORS/1.10/Sat Jan 20 04:43:43 2018//
+/LEGAL/1.2/Sat Jan 20 04:43:43 2018//
+/Makefile/1.38/Sat Jan 20 05:05:02 2018//
+/NOTES/1.16/Sat Jan 20 04:43:43 2018//
+/PROJECTS/1.9/Sat Jan 20 04:43:43 2018//
+/README/1.16/Sat Jan 20 05:05:02 2018//
+/alloc.c/1.19/Sat Jan 20 04:43:43 2018//
+/c_ksh.c/1.58/Sat Jan 20 04:43:43 2018//
+/c_sh.c/1.62/Sat Jan 20 04:43:43 2018//
+/c_test.c/1.24/Sat Jan 20 04:43:43 2018//
+/c_test.h/1.4/Sat Jan 20 04:43:43 2018//
+/c_ulimit.c/1.26/Sat Jan 20 04:43:43 2018//
+/edit.c/1.63/Sat Jan 20 04:43:43 2018//
+/edit.h/1.11/Sat Jan 20 04:43:43 2018//
+/eval.c/1.59/Sat Jan 20 04:43:43 2018//
+/exec.c/1.72/Sat Jan 20 04:43:43 2018//
+/expand.h/1.15/Sat Jan 20 04:43:43 2018//
+/expr.c/1.32/Sat Jan 20 04:43:43 2018//
+/io.c/1.36/Sat Jan 20 04:43:43 2018//
+/jobs.c/1.59/Sat Jan 20 04:43:43 2018//
+/ksh.1/1.197/Sat Jan 20 04:43:43 2018//
+/lex.c/1.78/Sat Jan 20 04:43:43 2018//
+/lex.h/1.21/Sat Jan 20 04:43:43 2018//
+/mail.c/1.22/Sat Jan 20 04:43:43 2018//
+/misc.c/1.68/Sat Jan 20 04:43:43 2018//
+/path.c/1.22/Sat Jan 20 04:43:43 2018//
+/sh.1/1.146/Sat Jan 20 04:43:43 2018//
+/sh.h/1.71/Sat Jan 20 04:43:43 2018//
+/shf.c/1.32/Sat Jan 20 04:43:43 2018//
+/shf.h/1.8/Sat Jan 20 04:43:43 2018//
+/syn.c/1.38/Sat Jan 20 04:43:43 2018//
+/table.c/1.25/Sat Jan 20 04:43:43 2018//
+/table.h/1.13/Sat Jan 20 04:43:43 2018//
+/trap.c/1.31/Sat Jan 20 04:43:43 2018//
+/tree.c/1.31/Sat Jan 20 04:43:43 2018//
+/tree.h/1.12/Sat Jan 20 04:43:43 2018//
+/tty.c/1.16/Sat Jan 20 04:43:43 2018//
+/tty.h/1.6/Sat Jan 20 04:43:43 2018//
+/var.c/1.65/Sat Jan 20 04:43:43 2018//
+/version.c/1.12/Sat Jan 20 04:43:43 2018//
+/vi.c/1.55/Sat Jan 20 04:43:43 2018//
 D
diff --git a/configure b/configure
@@ -10,9 +10,16 @@ int main(void){return 0;}
 EOF
     $CC -o conftest conftest.c > /dev/null 2>&1
     if [ $? -eq 0 ] ; then
-      rm -f conftest conftest.c
-      cc="$CC"
-      return 0
+      ./conftest
+      if [ $? -eq 0 ] ; then
+	rm -f conftest conftest.c
+	cc="$CC"
+	return 0
+      else
+	echo "could not build working executables"
+	echo "Please ensure your C compiler is a native compiler"
+	exit 1
+      fi
     else
       rm -f conftest conftest.c
     fi
@@ -26,9 +33,16 @@ EOF
     $compiler -o conftest conftest.c > /dev/null 2>&1
 
     if [ $? -eq 0 ] ; then
-      rm -f conftest conftest.c
-      cc="$compiler"
-      return 0
+      ./conftest
+      if [ $? -eq 0 ] ; then
+	rm -f conftest conftest.c
+	cc="$compiler"
+	return 0
+      else
+	echo "could not build working executables"
+	echo "Please ensure your C compiler is a native compiler"
+	exit 1
+      fi
     else
       rm -f conftest conftest.c
     fi
@@ -284,15 +298,20 @@ EOF
   fi
 }
 
+# Option variables
 if [ ! -z "$PREFIX" ] ; then
-prefix="$PREFIX"
+  prefix="$PREFIX"
 else
-prefix="/usr/local"
+  prefix="/usr/local"
 fi
 
 mandir="$prefix/man"
 
-# Options.
+instprog="oksh"
+instsh=0
+static=0
+
+# Options
 for opt
 do
   case "$opt" in
@@ -302,6 +321,27 @@ do
     --mandir=*)
 	mandir=`echo $opt | cut -d '=' -f 2`
 	;;
+    --disable-ksh|--enable-ksh)
+	if [ "x$opt" = "x--enable-ksh" ] ; then
+	  instprog="ksh"
+	else
+	  instprog="oksh"
+	fi
+	;;
+    --disable-sh|--enable-sh)
+	if [ "x$opt" = "x--enable-sh" ] ; then
+	  instsh=1
+	else
+	  instsh=0
+	fi
+	;;
+    --disable-static|--enable-static)
+	if [ "x$opt" = "x--enable-static" ] ; then
+	  static=1
+	else
+	  static=0
+	fi
+	;;
     --help|-h)
 	echo "Usage: configure [options]"
 	echo ""
@@ -312,6 +352,12 @@ do
 	echo "Top level install directory is PREFIX [$prefix]"
 	printf "  --mandir=MANDIR            "
 	echo "Manual pages are installed to MANDIR [$mandir]"
+	printf "  --enable-ksh               "
+	echo "Install executable as ksh [default=no]"
+	printf "  --enable-sh                "
+	echo "Install additional sh executable [default=no]"
+	printf "  --enable-static            "
+	echo "Statically link executables [default=no]"
 	exit 1
 	;;
     *)
@@ -320,9 +366,19 @@ do
 done
 
 if [ ! -z "$CFLAGS" ] ; then
-cflags="$CFLAGS -DEMACS -DVI"
+  cflags="$CFLAGS -DEMACS -DVI"
+else
+  cflags="-DEMACS -DVI"
+fi
+
+if [ ! -z "$LDFLAGS" ] ; then
+  ldflags="$LDFLAGS "
 else
-cflags="-DEMACS -DVI"
+  ldflags=""
+fi
+
+if [ $static -ne 0 ] ; then
+  ldflags="${ldflags}-static"
 fi
 
 printf "checking for C compiler... "
@@ -502,9 +558,18 @@ cat << EOF > Makefile
 
 CC =		$cc
 CFLAGS =	$cflags
+EOF
+
+if [ ! -z "$ldflags" ] ; then
+cat << EOF >> Makefile
+LDFLAGS =	$ldflags
+EOF
+fi
+
+cat << EOF >> Makefile
 PREFIX =	$prefix
 MANDIR =	$mandir
-PROG =		oksh
+PROG =		$instprog
 
 OBJS =	alloc.o c_ksh.o c_sh.o c_test.o c_ulimit.o edit.o emacs.o eval.o \\
 	exec.o expr.o history.o io.o jobs.o lex.o mail.o main.o misc.o \\
@@ -523,7 +588,26 @@ all: \${PROG}
 install:
 	install -c -s -m 755 \${PROG} \${PREFIX}/bin
 	install -c -m 644 oksh.1 \${MANDIR}/man1/\${PROG}.1
-	echo \${ETS}
+EOF
+
+if [ $instsh -ne 0 ] ; then
+cat << EOF >> Makefile
+	install -c -s -m 755 \${PROG} \${PREFIX}/bin/sh
+	install -c -m 644 sh.1 \${MANDIR}/man1
+EOF
+fi
+
+cat << EOF >> Makefile
+	echo "Please add $prefix/bin/$instprog to /etc/shells"
+EOF
+
+if [ $instsh -ne 0 ] ; then
+cat << EOF >> Makefile
+	echo "Please add $prefix/bin/sh to /etc/shells"
+EOF
+fi
+
+cat << EOF >> Makefile
 
 test:
 	echo "No tests"