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: d4810a4c2a8163a5ae2e2339e40c93064b2a4f79
parent: d401cd57fbd7e82c8728d7117607fd0d3154a703
author: Brian Callahan <bcallah@openbsd.org>
date:   Sat, 31 Oct 2020 18:25:07 -0400
If the user didn't specify CFLAGS on the command line, check to see
if the compiler can use -g -O2 as default flags (similar to GNU
default flags) and use those if the compiler can.

Should figure out good default flags for other compilers too. But
-g -O2 will cover all the gcc and clang permutations, which is the
vast majority of compiles.

This is a noop if the user did specify CFLAGS on the command line.
Mconfigure32+++++++++++++++++---
1 file changed, 28 insertions(+), 4 deletions(-)
diff --git a/configure b/configure
@@ -265,6 +265,20 @@ EOF
   fi
 }
 
+defaultcflagscheck() {
+  cat << EOF > conftest.c
+int main(void){return 0;}
+EOF
+  $cc $cflags -g -O2 -o conftest.o -c 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
+}
+
 issetugidcheck() {
   cat << EOF > conftest.c
 #include <unistd.h>
@@ -631,12 +645,11 @@ wflagcheck() {
 int main(void){return 0;}
 EOF
   $cc $cflags -w -o conftest.o -c 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
+    rm -f conftest conftest.o conftest.c
     return 1
   else
-    rm -f conftest conftest.err conftest.o conftest.c
+    rm -f conftest conftest.o conftest.c
     return 0
   fi
 }
@@ -852,9 +865,20 @@ else
   echo "yes"
 fi
 
+if [ "x$cflags" = "x-DEMACS -DVI" ] ; then
+  printf "checking if the compiler understands -g -O2... "
+  defaultcflagscheck
+  if [ $? -eq 0 ] ; then
+    echo "no"
+  else
+    cflags="-g -O2 $cflags"
+    echo "yes"
+  fi
+fi
+
 printf "checking for -w compiler flag... "
 wflagcheck
-if [ $? -ne 0 ] ; then
+if [ $? -eq 0 ] ; then
   echo "no"
 else
   cflags="$cflags -w"