Debian Codegraph @

gcc/cobol/gcobc

raw
1 #! /bin/sh -e
2
3 #
4 # COPYRIGHT
5 # The gcobc program is in public domain.
6 # If it breaks then you get to keep both pieces.
7 #
8 # This file emulates the GnuCOBOL cobc compiler to a limited degree.
9 # For options that can be "mapped" (see migration-guide.1), it accepts
10 # cobc options, changing them to the gcobol equivalents. Options not
11 # recognized by the script are passed verbatim to gcobol, which will
12 # reject them unless of course they are gcobol options.
13 #
14 # User-defined variables, and their defaults:
15 #
16 # Variable Default Effect
17 # echo none If defined, echo the gcobol command
18 # gcobcx none Produce verbose messages
19 # gcobol ./gcobol Name of the gcobol binary
20 # GCOBCUDF PREFIX/share/cobol/udf/ Location of UDFs to be prepended to input
21 #
22 # By default, this script includes all files in $GCOBCUDF. To defeat
23 # that behavior, use GCOBCUDF=none.
24 #
25 # A list of supported options is produced with "gcobc -HELP".
26 #
27 ## Maintainer note. In modifying this file, the following may make
28 ## your life easier:
29 ##
30 ## - To force the script to exit, either set exit_status to 1, or call
31 ## the error function.
32 ## - As handled options are added, add them to the HELP here-doc.
33 ## - The compiler can produce only one kind of output. In this
34 ## script, that's known by $mode. Options that affect the type of
35 ## output set the mode variable. Everything else is appended to the
36 ## opts variable.
37 ##
38 ## - -fPIC is added to the command line if $mode is "-shared". That
39 ## option applies only to "certain machines", per the gcc info
40 ## manual. For this script to be portable across machines, -fPIC
41 ## would have to be set more judiciously.
42
43 if [ "$COBCPY" ]
44 then
45 copydir="-I$COBCPY"
46 fi
47
48 if [ "$COB_COPY_DIR" ]
49 then
50 copydir="-I$COB_COPY_DIR"
51 fi
52
53 # TODO: this file likely needs to query gcobol for its shared path instead
54 udf_default="${0%/*}/../share/gcobol/udf"
55 if [ ! -d "$udfdir" ]
56 then
57 # the one above is the installed one from the packages this one was previously used
58 udf_default="${0%/*}/../share/cobol/udf"
59 fi
60 udfdir="${GCOBCUDF:-$udf_default}"
61
62 if [ -d "$udfdir" ]
63 then
64 for F in "$udfdir"/*
65 do
66 if [ -f "$F" ]
67 then
68 includes="$includes -include $F "
69 fi
70 done
71 else
72 if [ "${GCOBCUDF:-none}" != "none" ]
73 then
74 echo warning: no such directory: "'$GCOBCUDF'"
75 fi
76 fi
77
78 exit_status=0
79 skip_arg=
80 opts="$copydir $includes"
81 mode=-shared
82
83 incomparable="has no comparable gcobol option"
84
85 if [ "${gcobcx:-0}" -gt 1 ]
86 then
87 set -x
88 fi
89
90 error() {
91 echo "error: $1" >&2
92 exit_status=1
93 }
94 warn() {
95 echo "warning: $1 ignored" >&2
96 }
97 ignore_arg() {
98 warn "$1"
99 skip_arg="$1"
100 }
101 no_warn() { :; } # silence is golden
102
103 help() {
104 cat<<EOF
105 $0 recognizes the following GnuCOBOL cobc output mode options:
106 -b, -c, -m, -S, -x
107 $0 recognizes the following GnuCOBOL cobc compilation options:
108 -C
109 -d, --debug
110 -D
111 -A
112 -Q
113 -E
114 -g
115 --coverage
116 -ext
117 -fec=exception-name, -fno-ec=exception-name
118 -fformat
119 --fixed
120 -F, --free
121 -fimplicit-init
122 -h, --help
123 -save-temps=
124 -save-temps
125 -std=mvs -std=mvs-strict
126 -std=mf -std=mf-strict
127 -std=cobol85 -std=cobol2002 -std=cobol2014
128 Options that are the same in gcobol and cobc are passed through verbatim.
129 Options that have no analog in gcobol produce a warning message.
130 To produce this message, use -HELP.
131 To see the constructed cobc command-line, use -echo.
132 To override the default cobc, set the "cobc" environment variable.
133 By default, gcobc invokes the gcobol the same directory the gcobc resides.
134 To override, set the gcobol environment variable.
135 EOF
136 }
137
138 dialect="mf gnu"
139 out_set=""
140 first=""
141
142 #
143 # Iterate over the command-line tokens. We can't use getopts here
144 # because it's not designed for single-dash words (e.g. -shared).
145 #
146 for opt in "$@"
147 do
148 if [ "$skip_arg" ]
149 then
150 skip_arg=
151 continue
152 fi
153
154 if [ "$pending_arg" ]
155 then
156 case $pending_arg in
157 -o) output_name="$opt" # capture named output file
158 ;;
159 esac
160
161 opts="$opts $pending_arg$opt"
162 pending_arg=
163 continue
164 fi
165
166 case $opt in
167
168 # pass next parameter to GCC
169 -A)
170 pending_arg=" "
171 ;;
172
173 # pass next parameter to linker
174 -Q)
175 pending_arg=-Wl,
176 ;;
177
178 -b) mode="-shared"
179 ;;
180 -c) mode="-c"
181 ;;
182 --conf=*) warn "$opt"
183 ;;
184 -C) error "$opt $incomparable"
185 ;;
186 -d | -debug | --debug) opts="$opts -fcobol-exceptions=EC-ALL"
187 warn "$opt implies -fstack-check:"
188 ;;
189 # define for preprocessor, note: -D* is directly passed
190 -D)
191 pending_arg=$opt
192 ;;
193 -E) opts="$opts $opt -fsyntax-only"
194 ;;
195 -echo) echo="echo"
196 ;;
197
198 -fec=* | -fno-ec=*)
199 opt="$(echo "$opt" | sed -E 's/-f(no-)?ec=/-f\1cobol-exceptions=EC-/g')"
200 opts="$opts $opt"
201 ;;
202 -ext)
203 pending_arg="$opt "
204 ;;
205 -ext=*) opts="$opts $(echo "$opt" | sed 's/-ext=/-copyext ./')"
206 ;;
207 # A.3 Compiler options
208 -fsign=*) warn "$opt" ;;
209 -ffold-copy=*) warn "$opt" ;;
210 -ffold-call=*) warn "$opt" ;;
211 -fmax-errors=*) warn "$opt" ;;
212 -fintrinsics=*) warn "$opt" ;;
213 -fdump=*) warn "$opt" ;;
214 -fcallfh=*) warn "$opt" ;;
215 -fsqlschema=*) warn "$opt" ;;
216 -fsql) warn "$opt" ;;
217 -fno-recursive-check) no_warn "$opt" ;;
218 -fstack-extended) warn "$opt" ;;
219 -fno-remove-unreachable) no_warn "$opt" ;;
220 -finline-intrinsic) warn "$opt" ;;
221 -ftrace) warn "$opt" ;;
222 -ftraceall) warn "$opt" ;;
223 -fsymtab) warn "$opt" ;;
224 # -fsyntax-only is identical
225 -fdebugging-line) warn "$opt" ;;
226 -fsource-location) warn "$opt" ;;
227 -fstack-check) warn "$opt" ;;
228 -fsection-exit-check) warn "$opt" ;;
229 -fimplicit-goback-check) warn "$opt" ;;
230 -fwrite-after) warn "$opt" ;;
231 -fmfcomment) warn "$opt" ;;
232 -facucomment) warn "$opt" ;;
233 -fno-trunc) no_warn "$opt" ;;
234 -fsingle-quote) warn "$opt" ;;
235 -foptional-file) warn "$opt" ;;
236 -fstatic-call | -fno-static-call)
237 opts="$opts $opt"
238 static_used="x"
239 ;;
240 -fno-gen-c-decl-static-call) no_warn "$opt" ;;
241 -fmf-files) warn "$opt" ;;
242 -ffile-format=*) warn "$opt" ;;
243 -fno-theaders) no_warn "$opt" ;;
244 -fno-tsource) no_warn "$opt" ;;
245 -fno-tmessages) no_warn "$opt" ;;
246 -ftsymbols) warn "$opt" ;;
247 -fdatamap) warn "$opt" ;;
248 -fno-diagnostics-show-option) no_warn "$opt" ;;
249 -fibmcomp) warn "$opt" ;;
250 -fno-ibmcomp) no_warn "$opt" ;;
251
252 # A.4 Compiler dialect configuration options
253 -fname=*) warn "$opt" ;;
254 -freserved-words=*) warn "$opt" ;;
255 -ftab-width=*) warn "$opt" ;;
256 -ftext-column=*) warn "$opt" ;;
257 -fpic-length=*) warn "$opt" ;;
258 -fword-length=*) warn "$opt" ;;
259 -fliteral-length=*) warn "$opt" ;;
260 -fnumeric-literal-length=*) warn "$opt" ;;
261 -fdefaultbyte=*) warn "$opt" ;;
262 -falign-record=*) warn "$opt" ;;
263 -fkeycompress=*) warn "$opt" ;;
264 -falign-opt) warn "$opt" ;;
265 -fbinary-size=*) warn "$opt" ;;
266 -fbinary-byteorder=*) warn "$opt" ;;
267 -fassign-clause=*) warn "$opt" ;;
268 -fscreen-section-rules=*) warn "$opt" ;;
269 -fdpc-in-data=*) warn "$opt" ;;
270 -ffilename-mapping) warn "$opt" ;;
271 -fpretty-display) warn "$opt" ;;
272 -fbinary-truncate | -fno-binary-truncate) warn "$opt" ;;
273 -fcomplex-odo) warn "$opt" ;;
274 -fodoslide) warn "$opt" ;;
275 -findirect-redefines) warn "$opt" ;;
276 -flarger-redefines-ok) warn "$opt" ;;
277 -frelax-syntax-checks) warn "$opt" ;;
278 -fref-mod-zero-length) warn "$opt" ;;
279 -frelax-level-hierarchy) warn "$opt" ;;
280 -flocal-implies-recursive) warn "$opt" ;;
281 -fsticky-linkage) warn "$opt" ;;
282 -fmove-ibm) warn "$opt" ;;
283 -fperform-osvs) warn "$opt" ;;
284 -farithmetic-osvs) warn "$opt" ;;
285 -fconstant-folding) warn "$opt" ;;
286 -fhostsign) warn "$opt" ;;
287 -fprogram-name-redefinition) warn "$opt" ;;
288 -faccept-update) warn "$opt" ;;
289 -faccept-auto) warn "$opt" ;;
290 -fconsole-is-crt) warn "$opt" ;;
291 -fno-echo-means-secure) no_warn "$opt" ;;
292 -fline-col-zero-default) warn "$opt" ;;
293 -freport-column-plus) warn "$opt" ;;
294 -fdisplay-special-fig-consts) warn "$opt" ;;
295 -fbinary-comp-1) warn "$opt" ;;
296 -fnumeric-pointer) warn "$opt" ;;
297 -fmove-non-numeric-lit-to-numeric-is-zero) warn "$opt" ;;
298 -fimplicit-assign-dynamic-var) warn "$opt" ;;
299 -fcomment-paragraphs=*) warn "$opt" ;;
300 -fmemory-size-clause=*) warn "$opt" ;;
301 -fmultiple-file-tape-clause=*) warn "$opt" ;;
302 -flabel-records-clause=*) warn "$opt" ;;
303 -fvalue-of-clause=*) warn "$opt" ;;
304 -fdata-records-clause=*) warn "$opt" ;;
305 -ftop-level-occurs-clause=*) warn "$opt" ;;
306 -fsame-as-clause=*) warn "$opt" ;;
307 -ftype-to-clause=*) warn "$opt" ;;
308 -fusage-type=*) warn "$opt" ;;
309 -fsynchronized-clause=*) warn "$opt" ;;
310 -fsync-left-right=*) warn "$opt" ;;
311 -fspecial-names-clause=*) warn "$opt" ;;
312 -fgoto-statement-without-name=*) warn "$opt" ;;
313 -fstop-literal-statement=*) warn "$opt" ;;
314 -fstop-identifier-statement=*) warn "$opt" ;;
315 -fdebugging-mode=*) warn "$opt" ;;
316 -fuse-for-debugging=*) warn "$opt" ;;
317 -fpadding-character-clause=*) warn "$opt" ;;
318 -fnext-sentence-phrase=*) warn "$opt" ;;
319 -flisting-statements=*) warn "$opt" ;;
320 -ftitle-statement=*) warn "$opt" ;;
321 -fentry-statement=*) warn "$opt" ;;
322 -fmove-noninteger-to-alphanumeric=*) warn "$opt" ;;
323 -foccurs-max-length-without-subscript) warn "$opt" ;;
324 -flength-in-data-division) warn "$opt" ;;
325 -fmove-figurative-constant-to-numeric=*) warn "$opt" ;;
326 -fmove-figurative-space-to-numeric=*) warn "$opt" ;;
327 -fmove-figurative-quote-to-numeric=*) warn "$opt" ;;
328 -fodo-without-to=*) warn "$opt" ;;
329 -fodo-last-varlen=*) warn "$opt" ;;
330 -fsection-segments=*) warn "$opt" ;;
331 -falter-statement=*) warn "$opt" ;;
332 -fcall-overflow=*) warn "$opt" ;;
333 -fnumeric-boolean=*) warn "$opt" ;;
334 -fhexadecimal-boolean=*) warn "$opt" ;;
335 -fnational-literals=*) warn "$opt" ;;
336 -fhexadecimal-national-literals=*) warn "$opt" ;;
337 -fnational-character-literals=*) warn "$opt" ;;
338 -fhp-octal-literals=*) warn "$opt" ;;
339 -facu-literals=*) warn "$opt" ;;
340 -fword-continuation=*) warn "$opt" ;;
341 -fnot-exception-before-exception=*) warn "$opt" ;;
342 -faccept-display-extensions=*) warn "$opt" ;;
343 -frenames-uncommon-levels=*) warn "$opt" ;;
344 -fsymbolic-constant=*) warn "$opt" ;;
345 -fconstant-78=*) warn "$opt" ;;
346 -fconstant-01=*) warn "$opt" ;;
347 -fperform-varying-without-by=*) warn "$opt" ;;
348 -freference-out-of-declaratives=*) warn "$opt" ;;
349 -freference-bounds-check=*) warn "$opt" ;;
350 -fprogram-prototypes=*) warn "$opt" ;;
351 -fcall-convention-mnemonic=*) warn "$opt" ;;
352 -fcall-convention-linkage=*) warn "$opt" ;;
353 -fnumeric-value-for-edited-item=*) warn "$opt" ;;
354 -fincorrect-conf-sec-order=*) warn "$opt" ;;
355 -fdefine-constant-directive=*) warn "$opt" ;;
356 -ffree-redefines-position=*) warn "$opt" ;;
357 -frecords-mismatch-record-clause=*) warn "$opt" ;;
358 -frecord-delimiter=*) warn "$opt" ;;
359 -fsequential-delimiters=*) warn "$opt" ;;
360 -frecord-delim-with-fixed-recs=*) warn "$opt" ;;
361 -frecord-sequential-advancing=*) warn "$opt" ;;
362 -fmissing-statement=*) warn "$opt" ;;
363 -fzero-length-literals=*) warn "$opt" ;;
364 -fxml-generate-extra-phrases=*) warn "$opt" ;;
365 -fcontinue-after=*) warn "$opt" ;;
366 -fgoto-entry=*) warn "$opt" ;;
367 -fdepending-on-not-fixed=*) warn "$opt" ;;
368 -fbinary-sync-clause=*) warn "$opt" ;;
369 -fnonnumeric-with-numeric-group-usage=*) warn "$opt" ;;
370 -fassign-variable=*) warn "$opt" ;;
371 -fassign-using-variable=*) warn "$opt" ;;
372 -fassign-ext-dyn=*) warn "$opt" ;;
373 -fassign-disk-from=*) warn "$opt" ;;
374 -fvsam-status=*) warn "$opt" ;;
375 -fself-call-recursive=*) warn "$opt" ;;
376
377 # TODO: create a temporary COBOL file with COBOL-WORDS directives
378 # and force-include it
379 -fnot-reserved=*) warn "$opt" ;;
380 -freserved=*) warn "$opt" ;;
381 -fnot-register=*) warn "$opt" ;;
382 -fregister=*) warn "$opt" ;;
383
384 -fformat=auto) ;; # gcobol and gnucobol default
385
386 -fixed | --fixed | -fformat=fixed | -fformat=variable | -fformat=xcard)
387 # note: variable + xcard are only _more similar_ to fixed than free,
388 # (with changing right-column to 250/255, which isn't supported in gcobol, yet)
389 opts="$opts -ffixed-form"
390 ;;
391
392 -F | -free | --free | -fformat=free | -fformat=*)
393 # note: "all other formats" are only _more similar_ to free than fixed
394 opts="$opts -ffree-form"
395 ;;
396 -h | --help) opts="$opts --help"
397 ;;
398
399 -HELP) help && exit
400 ;;
401 -i | --info) warn "$opt"
402 ;;
403
404 # -I
405 -fimplicit-init) warn "$opt"
406 ;;
407 -j | -job) warn "$opt"
408 ;;
409 -K) ignore_arg "$opt"
410 ;;
411 -K*) warn "$opt"
412 ;;
413 # -l
414 # -L
415 --list*) warn "$opt"
416 ;;
417 -m) mode="-shared"
418 ;;
419 # -main
420 # -nomain
421
422 -o) pending_arg=$opt
423 ;;
424 -o*) output_name=$opt ## non-empty means do not infer
425 opts="$opts $opt"
426 ;;
427
428 # -O0, -Ox
429 -O | -O2 | -Os) warn "$opt"
430 ;;
431 -S) mode="$opt"
432 ;;
433 -save-temps=*) opt="$(echo "$opt" | sed -E 's/^.+=//')"
434 export GCOBOL_TEMPDIR="$opt"
435 ;;
436 -save-temps) export GCOBOL_TEMPDIR="${PWD:-$(pwd)}"
437 ;;
438 # -shared is identical
439
440 -std=mvs | -std=mvs-strict | -std=ibm | -std=ibm-strict) dialect=ibm
441 ;;
442 -std=mf | -std=mf-strict) dialect=mf
443 ;;
444 # GnuCOBOL's default and GCC's dialect for GnuCOBOL
445 -std=default) dialect=gnu
446 ;;
447 # GCC COBOL targets COBOL2024 "mostly backward to COBOL85"
448 -std=cobol*) dialect=""
449 ;;
450 -std=*)
451 dialect=""
452 warn "$opt (unkown dialect)"
453 ;;
454 -P | -P=* | -X | --Xref)
455 warn "$opt (no listing)"
456 ;;
457 -t | -T)
458 # note: -P has an _optional_ arg, so we leave it above
459 ignore_arg "$opt (no listing)"
460 ;;
461 -q | --brief) warn "$opt"
462 ;;
463 -v | --verbose) opts="$opts -V"
464 ;;
465 # note: we want -dumpversion to be passed to gcc
466 -V | --version | -version) opts="$opts --version"
467 ;;
468 # pass through, strangely -Wall is not supported
469 -w | -W | -Wextra) opts="$opts $opt"
470 ;;
471 -Wno-*) no_warn "$opt"
472 ;;
473
474 -W*) ignore_arg "$opt"
475 ;;
476
477 -x) mode=
478 ;;
479
480 -) output_name=a.out # nonnull to prevent overriding gcc default
481 opts="$opts /dev/stdin"
482 ;;
483
484 # First file name argument is default output filename.
485 *) if [ -z "$output_name" -a -e "$opt" ]
486 then
487 output_name=$(basename "${opt%.*}")
488 case $mode in
489 -c) output_name="$output_name".o
490 ;;
491 -shared)
492 output_name="$output_name".so
493 opts="$opts -fPIC"
494 ;;
495 esac
496 opts="$opts -o $output_name"
497 fi
498 opts="$opts $opt" # pass through
499 ;;
500 esac
501 done
502
503 # cobc default:
504 if [ "$static_used" = "" ]
505 then
506 opts="$opts -fno-static-call";
507 fi
508
509 if [ "$exit_status" -gt 0 ]
510 then
511 exit $exit_status
512 fi
513
514 # To override the default gcobol, set the "gcobol" environment variable.
515 gcobol="${gcobol:-${0%/*}/gcobol}"
516
517 if [ "$dialect" ]
518 then
519 dialect=$(echo $dialect | sed -E 's/[[:alnum:]]+/-dialect &/g')
520 fi
521
522 if [ "$echo" ]
523 then
524 echo $gcobol $mode $opts
525 exit
526 fi
527
528 if [ "$gcobcx" ]
529 then
530 set -x
531 fi
532
533 exec $gcobol $mode $dialect $opts