aboutsummaryrefslogtreecommitdiff
path: root/gcc/cobol/gcobc
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/cobol/gcobc')
-rwxr-xr-xgcc/cobol/gcobc176
1 files changed, 122 insertions, 54 deletions
diff --git a/gcc/cobol/gcobc b/gcc/cobol/gcobc
index 93e1bd302..fa9f609 100755
--- a/gcc/cobol/gcobc
+++ b/gcc/cobol/gcobc
@@ -35,6 +35,10 @@
## output set the mode variable. Everything else is appended to the
## opts variable.
##
+## - -fPIC is added to the command line if $mode is "-shared". That
+## option applies only to "certain machines", per the gcc info
+## manual. For this script to be portable across machines, -fPIC
+## would have to be set more judiciously.
if [ "$COBCPY" ]
then
@@ -73,7 +77,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 +107,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
@@ -112,11 +119,12 @@ $0 recognizes the following GnuCOBOL cobc compilation options:
--fixed
-F, --free
-fimplicit-init
- -h, --help
- -save-temps=
- -save-temps
- -std=mvs
- -std=mf
+ -h, --help
+ -save-temps=
+ -save-temps
+ -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,11 +135,14 @@ To override, set the gcobol environment variable.
EOF
}
+dialect="mf 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).
+# Iterate over the command-line tokens. We can't use getopts here
+# because it's not designed for single-dash words (e.g. -shared).
#
-
for opt in "$@"
do
if [ "$skip_arg" ]
@@ -142,41 +153,57 @@ do
if [ "$pending_arg" ]
then
- opts="$opts $pending_arg $opt"
+ case $pending_arg in
+ -o) output_name="$opt" # capture named output file
+ ;;
+ esac
+
+ 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"
;;
--conf=*) warn "$opt"
- ;;
- -C) error "$opt $incomparable"
- ;;
- -d | --debug) opts="$opts -fcobol-exceptions=EC-ALL"
- warn "$opt implies -fstack-check:"
- ;;
- # -D
- -E) opts="$opts $opt -fsyntax-only"
+ ;;
+ -C) error "$opt $incomparable"
+ ;;
+ -d | -debug | --debug) opts="$opts -fcobol-exceptions=EC-ALL"
+ warn "$opt implies -fstack-check:"
+ ;;
+ # define for preprocessor, note: -D* is directly passed
+ -D)
+ pending_arg=$opt
;;
- -echo) echo="echo"
+ -E) opts="$opts $opt -fsyntax-only"
+ ;;
+ -echo) echo="echo"
;;
-fec=* | -fno-ec=*)
opt="$(echo "$opt" | sed -E 's/-f(no-)?ec=/-f\1cobol-exceptions=EC-/g')"
- opts="$opts $opt"
- ;;
- -ext)
- pending_arg=$opt
- ;;
- -ext=*) opts="$opts $(echo "$opt" | sed 's/-ext=/-copyext ./')"
- ;;
-
+ opts="$opts $opt"
+ ;;
+ -ext)
+ pending_arg="$opt "
+ ;;
+ -ext=*) opts="$opts $(echo "$opt" | sed 's/-ext=/-copyext ./')"
+ ;;
# A.3 Compiler options
-fsign=*) warn "$opt" ;;
-ffold-copy=*) warn "$opt" ;;
@@ -354,19 +381,18 @@ 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,
# (with changing right-column to 250/255, which isn't supported in gcobol, yet)
- opts="$opts -ffixed-form"
- ;;
-
- -F | -free | --free | -fformat=free | -fformat=* )
- # note: "all other formats" are only _more similar_ to free than fixed
- opts="$opts -ffree-form"
- ;;
+ opts="$opts -ffixed-form"
+ ;;
+ -F | -free | --free | -fformat=free | -fformat=*)
+ # note: "all other formats" are only _more similar_ to free than fixed
+ opts="$opts -ffree-form"
+ ;;
-h | --help) opts="$opts --help"
;;
@@ -392,7 +418,13 @@ do
;;
# -main
# -nomain
- # -o
+
+ -o) pending_arg=$opt
+ ;;
+ -o*) output_name=$opt ## non-empty means do not infer
+ opts="$opts $opt"
+ ;;
+
# -O0, -Ox
-O | -O2 | -Os) warn "$opt"
;;
@@ -402,24 +434,37 @@ do
export GCOBOL_TEMPDIR="$opt"
;;
-save-temps) export GCOBOL_TEMPDIR="${PWD:-$(pwd)}"
- ;;
- # -shared is identical
+ ;;
+ # -shared is identical
- -std=mvs) opts="$opts -dialect ibm"
+ -std=mvs | -std=mvs-strict | -std=ibm | -std=ibm-strict) dialect=ibm
;;
- -std=mf) opts="$opts -dialect mf"
+ -std=mf | -std=mf-strict) dialect=mf
+ ;;
+ # GnuCOBOL's default and GCC's dialect for GnuCOBOL
+ -std=default) dialect=gnu
+ ;;
+ # GCC COBOL targets COBOL2024 "mostly backward to COBOL85"
+ -std=cobol*) dialect=""
+ ;;
+ -std=*)
+ dialect=""
+ warn "$opt (unkown dialect)"
;;
- -t | -T | -tlines=* | -P | -P=* | -X | --Xref)
- warn "$opt (no listing)"
+ -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"
;;
- -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"
;;
@@ -432,7 +477,25 @@ do
-x) mode=
;;
- *) opts="$opts $opt" # pass through
+ -) output_name=a.out # nonnull to prevent overriding gcc default
+ opts="$opts /dev/stdin"
+ ;;
+
+ # First file name argument is default output filename.
+ *) if [ -z "$output_name" -a -e "$opt" ]
+ then
+ output_name=$(basename "${opt%.*}")
+ case $mode in
+ -c) output_name="$output_name".o
+ ;;
+ -shared)
+ output_name="$output_name".so
+ opts="$opts -fPIC"
+ ;;
+ esac
+ opts="$opts -o $output_name"
+ fi
+ opts="$opts $opt" # pass through
;;
esac
done
@@ -451,6 +514,11 @@ fi
# To override the default gcobol, set the "gcobol" environment variable.
gcobol="${gcobol:-${0%/*}/gcobol}"
+if [ "$dialect" ]
+then
+ dialect=$(echo $dialect | sed -E 's/[[:alnum:]]+/-dialect &/g')
+fi
+
if [ "$echo" ]
then
echo $gcobol $mode $opts
@@ -462,4 +530,4 @@ then
set -x
fi
-exec $gcobol $mode $opts
+exec $gcobol $mode $dialect $opts