Note: the check_GNU_style.sh script raises several errors - but it would raise them on the complete script, so I've opted to stay with its style.

Side-note: Using this updated wrapper allows to runt the NIST test runner from a configured GnuCOBOL source tree using make  COBC=/usr/local/gcobol-dbg/bin/gcobc COBOL_FLAGS="-fixed -g -Q -rpath -Q /usr/local/gcobol-dbg/lib64"

(the -fixed is necessary as current gcobol does not deduce the fixed-format in NIST correctly)

Kind regards,
Simon


From 187bffd7ac3fb6097d99fe54e28853bd7aeda637 Mon Sep 17 00:00:00 2001

From: Simon Sobisch <simonsobi...@gnu.org>
Date: Sat, 5 Apr 2025 00:25:36 +0200
Subject: [PATCH] cobol: gcobc wrapper fixes and additions

* defaults to dialect GNU (gnucobol)
* more ibm and strict dialects supported
* Implemented -A, -Q, -E
* support known alias "-debug" for "--debug"
* fix -P, -T and -W consuming source files
* deduce output file name, as done by cobc
---
 gcc/cobol/gcobc | 101 ++++++++++++++++++++++++++++++++++++++++--------
 1 file changed, 84 insertions(+), 17 deletions(-)

diff --git a/gcc/cobol/gcobc b/gcc/cobol/gcobc
index 93e1bd302a6..f503e53a336 100755
--- a/gcc/cobol/gcobc
+++ b/gcc/cobol/gcobc
@@ -73,7 +73,7 @@ fi

 exit_status=0
 skip_arg=
-opts="$copydir ${dialect:--dialect mf} $includes"
+opts="$copydir $includes"
 mode=-shared

 incomparable="has no comparable gcobol option"
@@ -103,6 +103,9 @@ $0 recognizes the following GnuCOBOL cobc output mode options:
 $0 recognizes the following GnuCOBOL cobc compilation options:
         -C
         -d, --debug
+        -D
+        -A
+        -Q
         -E
         -g
         --coverage
@@ -115,8 +118,9 @@ $0 recognizes the following GnuCOBOL cobc compilation options:
         -h, --help
         -save-temps=
         -save-temps
-        -std=mvs
-        -std=mf
+        -std=mvs -std=mvs-strict
+        -std=mf  -std=mf-strict
+        -std=cobol85 -std=cobol2002 -std=cobol2014
 Options that are the same in gcobol and cobc are passed through verbatim.
 Options that have no analog in gcobol produce a warning message.
 To produce this message, use -HELP.
@@ -127,6 +131,10 @@ To override, set the gcobol environment variable.
 EOF
 }

+dialect="gnu"
+out_set=""
+first=""
+
 #
 # Simply iterate over the command-line tokens.  We can't use getopts
 # here because it's not designed for single-dash words (e.g. -shared).
@@ -142,14 +150,23 @@ do

     if [ "$pending_arg" ]
     then
-        opts="$opts $pending_arg $opt"
+        opts="$opts $pending_arg$opt"
         pending_arg=
         continue
     fi

     case $opt in
-        -A | -Q) warn "$opt"
-                 ;;
+
+        # pass next parameter to GCC
+        -A)
+            pending_arg=" "
+            ;;
+
+        # pass next parameter to linker
+        -Q)
+            pending_arg=-Wl,
+            ;;
+
         -b) mode="-shared"
             ;;
         -c) mode="-c"
@@ -158,10 +175,13 @@ do
                   ;;
         -C) error "$opt $incomparable"
             ;;
-        -d | --debug) opts="$opts -fcobol-exceptions=EC-ALL"
+        -d | -debug | --debug) opts="$opts -fcobol-exceptions=EC-ALL"
                       warn "$opt implies -fstack-check:"
                       ;;
-        # -D
+        # define for preprocessor, note: -D* is directly passed
+        -D)
+            pending_arg=$opt
+            ;;
         -E) opts="$opts $opt -fsyntax-only"
             ;;
         -echo) echo="echo"
@@ -172,7 +192,7 @@ do
             opts="$opts $opt"
             ;;
         -ext)
-            pending_arg=$opt
+            pending_arg="$opt "
             ;;
         -ext=*) opts="$opts $(echo "$opt" | sed 's/-ext=/-copyext ./')"
                 ;;
@@ -354,7 +374,7 @@ do
         -fnot-register=*) warn "$opt" ;;
         -fregister=*) warn "$opt" ;;

-        -fformat=auto ) ;; # gcobol and gnucobol default
+        -fformat=auto) ;; # gcobol and gnucobol default

         -fixed | --fixed | -fformat=fixed | -fformat=variable | -fformat=xcard)                      # note: variable + xcard are only _more similar_ to fixed than free,
@@ -362,7 +382,7 @@ do
                     opts="$opts -ffixed-form"
                     ;;

-        -F | -free | --free | -fformat=free | -fformat=* )
+        -F | -free | --free | -fformat=free | -fformat=*)
                     # note: "all other formats" are only _more similar_ to free than fixed
                     opts="$opts -ffree-form"
                     ;;
@@ -405,20 +425,32 @@ do
                       ;;
         # -shared is identical

-        -std=mvs) opts="$opts -dialect ibm"
+        -std=mvs | -std=mvs-strict | -std=ibm | -std=ibm-strict) dialect=ibm
+                  ;;
+        -std=mf | -std=mf-strict)  dialect=mf
+                  ;;
+        -std=default)  dialect=gnu  # that's GnuCOBOL's default and GCC's dialect for GnuCOBOL
                   ;;
-        -std=mf)  opts="$opts -dialect mf"
+        -std=cobol*)    dialect=""   # GCC COBOL targets COBOL2024 "mostly backward to COBOL85"
                   ;;
-        -t | -T | -tlines=* | -P | -P=* | -X | --Xref)
+        -std=*)
+            dialect=""
+            warn "$opt (unkown dialect)"
+                  ;;
+        -P | -P=* | -X | --Xref)
             warn "$opt (no listing)"
             ;;
+        -t | -T)
+            # note: -P has an _optional_ arg, so we leave it above
+            ignore_arg "$opt (no listing)"
+            ;;
         -q | --brief) warn "$opt"
                       ;;
         -v | --verbose) opts="$opts -V"
                         ;;
         # note: we want -dumpversion to be passed to gcc
         -V | --version | -version) opts="$opts --version"
-                                        ;;
+            ;;

         # pass through, strangely -Wall is not supported
         -w | -W | -Wextra) opts="$opts $opt"
@@ -426,21 +458,56 @@ do
         -Wno-*) no_warn "$opt"
              ;;

-        -W*) ignore_arg "$opt"
+        -W*) warn "$opt"
              ;;

         -x) mode=
             ;;

+        *.cob | *.COB | *.cbl | *.CBL)
+           if [ "$first" = "" ]; then first="$opt"; fi
+           opts="$opts $opt" # pass through
+           ;;
+
+        # uncommon (and therefore needs to have explicit lang setting), just for NIST
+        *.SUB)
+           if [ "$first" = "" ]; then first="$opt"; fi
+           opts="$opts -x cobol $opt" # pass through after lang setting
+           ;;
+
+        -o)
+           out_set=x
+           pending_arg="$opt "
+           ;;
+
+
         *) opts="$opts $opt" # pass through
            ;;
     esac
 done

+
+if [ "$dialect" != "" ]
+then
+    opts="$opts -dialect $dialect"
+fi
+
+if [ "$out_set" = "" ] && [ "$first" != "" ]
+then
+    case "$mode" in
+    -S) ext=".s" ;;
+    -c) ext=".o" ;;
+    -shared) ext=".so" ;;
+    *)  ext="";
+    esac
+    opts="$opts -o $(echo "$first" | sed -E -e 's/\..*//' -e 's#.*/##g')$ext"
+fi
+
+
 # cobc default:
 if [ "$static_used" = "" ]
 then
-    opts="$opts -fno-static-call";
+    opts="-fno-static-call $opts"
 fi

 if [ "$exit_status" -gt 0 ]
--
2.43.0


Reply via email to