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: 6d93631928bc2939043fcac603967acea604d915
parent: 5bbd418ff3631968dd78c2aede811f96e15a4cbf
author: Brian Callahan <bcallah@openbsd.org>
date:   Thu, 9 Jul 2020 14:02:07 -0400
Add --enable-lto for those who want link-time optimization.
Mconfigure40+++++++++++++++++++-
1 file changed, 39 insertions(+), 1 deletion(-)
diff --git a/configure b/configure
@@ -188,6 +188,20 @@ EOF
   fi
 }
 
+ltoflagcheck() {
+  cat << EOF > conftest.c
+int main(void){return 0;}
+EOF
+  $cc $cflags -flto $ldflags -o conftest conftest.c > /dev/null 2>&1
+  if [ $? -eq 0 ] ; then
+    rm -f conftest conftest.o conftest.c
+    return 1
+  else
+    rm -f conftest conftest.o conftest.c
+    return 0
+  fi
+}
+
 ncursescheck() {
   cat << EOF > conftest.c
 #include <term.h>
@@ -502,7 +516,7 @@ wflagcheck() {
   cat << EOF > conftest.c
 int main(void){return 0;}
 EOF
-  $cc -w -o conftest conftest.c > /dev/null 2> conftest.err
+  $cc $cflags -w $ldflags -o conftest conftest.c > /dev/null 2>&1
   grep ':' conftest.err > /dev/null 2>&1
   if [ $? -eq 0 ] ; then
     rm -f conftest conftest.err conftest.o conftest.c
@@ -530,6 +544,7 @@ libs=""
 curses=1
 instsh=0
 static=0
+lto=0
 
 # Options
 for opt
@@ -580,6 +595,13 @@ do
 	  static=0
 	fi
 	;;
+    --disable-lto|--enable-lto)
+	if [ "x$opt" = "x--enable-lto" ] ; then
+	  lto=1
+	else
+	  lto=0
+	fi
+	;;
     --help|-h)
 	echo "Usage: configure [options]"
 	echo ""
@@ -596,6 +618,8 @@ do
 	echo "Use curses library for screen clear [default=yes]"
 	printf "  --enable-ksh            "
 	echo "Install executable as ksh [default=no]"
+	printf "  --enable-lto            "
+	echo "Enable link-time optimization [default=no]"
 	printf "  --enable-sh             "
 	echo "Install additional sh executable [default=no]"
 	printf "  --enable-static         "
@@ -677,6 +701,20 @@ case "x$os" in
     ;;
 esac
 
+printf "checking for -flto compiler flag... "
+if [ $lto -eq 0 ] ; then
+  echo "not enabled"
+else
+  ltoflagcheck
+  if [ $lto -eq 0 ] ; then
+    echo "no"
+  else
+    cflags="$cflags -flto"
+    ldflags="$ldflags -flto -Wl,-O3"
+    echo "yes"
+  fi
+fi
+
 cat << EOF > pconfig.h
 /* This file automatically generated by configure.  */