2001-04-09 Andrew MacLeod <amacleod@redhat.com>
[official-gcc.git] / gcc / gccbug.in
blob42b52aec6b1679e175756061ae2219287099374b
1 #!/bin/sh
2 # Submit a problem report to a GNATS site.
3 # Copyright (C) 1993, 2000, 2001 Free Software Foundation, Inc.
4 # Contributed by Brendan Kehoe (brendan@cygnus.com), based on a
5 # version written by Heinz G. Seidl (hgs@cygnus.com).
7 # This file is part of GNU GNATS.
9 # GNU GNATS is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 2, or (at your option)
12 # any later version.
14 # GNU GNATS is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with GNU GNATS; see the file COPYING. If not, write to
21 # the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
23 # The version of this send-pr.
24 VERSION=3.113
26 # The submitter-id for your site.
27 SUBMITTER=net
29 # The default mail address for PR submissions.
30 GNATS_ADDR=gcc-gnats@gcc.gnu.org
32 # The default release for this host.
33 DEFAULT_RELEASE="@gcc_version_full@"
35 # The default organization.
36 DEFAULT_ORGANIZATION=
38 # What mailer to use. This must come after the config file, since it is
39 # host-dependent.
40 # Copied from cvsbug
41 if [ -f /usr/sbin/sendmail ]; then
42 MAIL_AGENT="/usr/sbin/sendmail -oi -t"
43 else
44 MAIL_AGENT="/usr/lib/sendmail -oi -t"
46 MAILER=`echo $MAIL_AGENT | sed -e 's, .*,,'`
47 if [ ! -f "$MAILER" ] ; then
48 echo "$COMMAND: Cannot file mail program \"$MAILER\"."
49 echo "$COMMAND: Please fix the MAIL_AGENT entry in the $COMMAND file."
50 exit 1
54 # How to read the passwd database.
55 PASSWD="cat /etc/passwd"
57 ECHON=bsd
59 if [ $ECHON = bsd ] ; then
60 ECHON1="echo -n"
61 ECHON2=
62 elif [ $ECHON = sysv ] ; then
63 ECHON1=echo
64 ECHON2='\c'
65 else
66 ECHON1=echo
67 ECHON2=
70 #\f
72 if [ -z "$TMPDIR" ]; then
73 TMPDIR=/tmp
74 else
75 if [ "`echo $TMPDIR | grep '/$'`" != "" ]; then
76 TMPDIR="`echo $TMPDIR | sed -e 's,/$,,'`"
80 if [ @have_mktemp_command@ = yes ]; then
81 TEMP0=`mktemp $TMPDIR/poXXXXXX` || exit 1
82 TEMP=`mktemp $TMPDIR/pXXXXXX` || exit 1
83 BAD=`mktemp $TMPDIR/pbadXXXXXX` || exit 1
84 REF=`mktemp $TMPDIR/pfXXXXXX` || exit 1
85 else
86 TEMP0=$TMPDIR/po$$
87 TEMP=$TMPDIR/p$$
88 BAD=$TMPDIR/pbad$$
89 REF=$TMPDIR/pf$$
90 # set -C _may_ use O_EXCL, but it need not.
91 set -C
92 bad_temp=0
93 : > $TEMP0 || bad_temp=1
94 : > $TEMP || bad_temp=1
95 : > $BAD || bad_temp=1
96 : > $REF || bad_temp=1
97 if [ $bad_temp = 1 ]; then
98 rm -f $TEMP0 $TEMP $BAD $REF
99 exit 1;
101 set +C
103 REMOVE_TEMP="rm -f $TEMP0 $TEMP $BAD $REF"
105 # find a user name
106 if [ "$LOGNAME" = "" ]; then
107 if [ "$USER" != "" ]; then
108 LOGNAME="$USER"
109 else
110 LOGNAME="UNKNOWN"
114 FROM="$LOGNAME"
115 REPLY_TO="${REPLY_TO:-${REPLYTO:-$LOGNAME}}"
117 # Find out the name of the originator of this PR.
118 if [ -n "$NAME" ]; then
119 ORIGINATOR="$NAME"
120 elif [ -f $HOME/.fullname ]; then
121 ORIGINATOR="`sed -e '1q' $HOME/.fullname`"
122 else
123 # Must use temp file due to incompatibilities in quoting behavior
124 # and to protect shell metacharacters in the expansion of $LOGNAME
125 $PASSWD | grep "^$LOGNAME:" | awk -F: '{print $5}' | sed -e 's/,.*//' > $TEMP0
126 ORIGINATOR="`cat $TEMP0`"
127 rm -f $TEMP0
130 if [ -n "$ORGANIZATION" ]; then
131 if [ -f "$ORGANIZATION" ]; then
132 ORGANIZATION="`cat $ORGANIZATION`"
134 else
135 if [ -n "$DEFAULT_ORGANIZATION" ]; then
136 ORGANIZATION="$DEFAULT_ORGANIZATION"
137 elif [ -f $HOME/.organization ]; then
138 ORGANIZATION="`cat $HOME/.organization`"
142 # If they don't have a preferred editor set, then use
143 if [ -z "$VISUAL" ]; then
144 if [ -z "$EDITOR" ]; then
145 EDIT=vi
146 else
147 EDIT="$EDITOR"
149 else
150 EDIT="$VISUAL"
153 # Find out some information.
154 SYSTEM=`( [ -f /bin/uname ] && /bin/uname -a ) || \
155 ( [ -f /usr/bin/uname ] && /usr/bin/uname -a ) || echo ""`
156 ARCH=`[ -f /bin/arch ] && /bin/arch`
157 MACHINE=`[ -f /bin/machine ] && /bin/machine`
159 COMMAND=`echo $0 | sed -e 's,.*/,,'`
160 USAGE="Usage: $COMMAND [-PVL] [-t address] [-f filename] [-s severity]
161 [-c address] [--request-id] [--version]"
162 REMOVE=
163 BATCH=
165 SEVERITY_C=
167 while [ $# -gt 0 ]; do
168 case "$1" in
169 -r) ;; # Ignore for backward compat.
170 -t | --to) if [ $# -eq 1 ]; then echo "$USAGE"; $REMOVE_TEMP; exit 1; fi
171 shift ; GNATS_ADDR="$1"
172 EXPLICIT_GNATS_ADDR=true
174 -f | --file) if [ $# -eq 1 ]; then echo "$USAGE"; $REMOVE_TEMP; exit 1; fi
175 shift ; IN_FILE="$1"
176 if [ "$IN_FILE" != "-" -a ! -r "$IN_FILE" ]; then
177 echo "$COMMAND: cannot read $IN_FILE"
178 $REMOVE_TEMP
179 exit 1
182 -b | --batch) BATCH=true ;;
183 -c | --cc) if [ $# -eq 1 ]; then echo "$USAGE"; $REMOVE_TEMP; exit 1; fi
184 shift ; CC="$1"
186 -s | --severity) if [ $# -eq 1 ]; then echo "$USAGE"; $REMOVE_TEMP; exit 1; fi
187 shift ; SEVERITY_C="$1"
189 -p | -P | --print) PRINT=true ;;
190 -L | --list) FORMAT=norm ;;
191 -l | -CL | --lisp) FORMAT=lisp ;;
192 --request-id) REQUEST_ID=true ;;
193 -h | --help) echo "$USAGE"; $REMOVE_TEMP; exit 0 ;;
194 -V | --version) echo "$VERSION"; $REMOVE_TEMP; exit 0 ;;
195 -*) echo "$USAGE" ; $REMOVE_TEMP; exit 1 ;;
196 *) echo "$USAGE" ; $REMOVE_TEMP; exit 1
197 esac
198 shift
199 done
201 # spam does not need to be listed here
202 CATEGORIES="c++ c debug fortran java libf2c libgcj libobjc libstdc++ middle-end objc optimization other preprocessor target web"
204 case "$FORMAT" in
205 lisp) echo "$CATEGORIES" | \
206 awk 'BEGIN {printf "( "} {printf "(\"%s\") ",$0} END {printf ")\n"}'
207 $REMOVE_TEMP
208 exit 0
210 norm) l=`echo "$CATEGORIES" | \
211 awk 'BEGIN {max = 0; } { if (length($0) > max) { max = length($0); } }
212 END {print max + 1;}'`
213 c=`expr 70 / $l`
214 if [ $c -eq 0 ]; then c=1; fi
215 echo "$CATEGORIES" | \
216 awk 'BEGIN {print "Known categories:"; i = 0 }
217 { printf ("%-'$l'.'$l's", $0); if ((++i % '$c') == 0) { print "" } }
218 END { print ""; }'
219 $REMOVE_TEMP
220 exit 0
222 esac
224 ORIGINATOR_C='<name of the PR author (one line)>'
225 ORGANIZATION_C='<organization of PR author (multiple lines)>'
226 SYNOPSIS_C='<synopsis of the problem (one line)>'
227 if [ -z "$SEVERITY_C" ]; then
228 SEVERITY_C='<[ non-critical | serious | critical ] (one line)>'
230 PRIORITY_C='<[ low | medium ] (one line)>'
231 CATEGORY_C='<choose from the top of this file (one line)>'
232 RELEASE_C='<release number or tag (one line)>'
233 ENVIRONMENT_C='<machine, os, target, libraries (multiple lines)>'
234 DESCRIPTION_C='<precise description of the problem (multiple lines)>'
235 HOW_TO_REPEAT_C='<When reporting a compiler error, preprocessor output must be included>'
236 FIX_C='<how to correct or work around the problem, if known (multiple lines)>'
238 # Catch some signals. ($xs kludge needed by Sun /bin/sh)
239 xs=0
240 trap '$REMOVE_TEMP; exit $xs' 0
241 trap 'echo "$COMMAND: Aborting ..."; $REMOVE_TEMP; xs=1; exit' 1 3 13 15
243 # If they told us to use a specific file, then do so.
244 if [ -n "$IN_FILE" ]; then
245 if [ "$IN_FILE" = "-" ]; then
246 # The PR is coming from the standard input.
247 if [ -n "$EXPLICIT_GNATS_ADDR" ]; then
248 sed -e "s;^[Tt][Oo]:.*;To: $GNATS_ADDR;" > $TEMP
249 else
250 cat > $TEMP
252 else
253 # Use the file they named.
254 if [ -n "$EXPLICIT_GNATS_ADDR" ]; then
255 sed -e "s;^[Tt][Oo]:.*;To: $GNATS_ADDR;" $IN_FILE > $TEMP
256 else
257 cat $IN_FILE > $TEMP
260 else
262 if [ -n "$PR_FORM" -a -z "$PRINT_INTERN" ]; then
263 # If their PR_FORM points to a bogus entry, then bail.
264 if [ ! -f "$PR_FORM" -o ! -r "$PR_FORM" -o ! -s "$PR_FORM" ]; then
265 echo "$COMMAND: can't seem to read your template file (\`$PR_FORM'), ignoring PR_FORM"
266 sleep 1
267 PRINT_INTERN=bad_prform
271 if [ -n "$PR_FORM" -a -z "$PRINT_INTERN" ]; then
272 cp $PR_FORM $TEMP ||
273 ( echo "$COMMAND: could not copy $PR_FORM" ; xs=1; exit )
274 else
275 for file in $TEMP $REF ; do
276 cat > $file << '__EOF__'
277 SEND-PR: -*- send-pr -*-
278 SEND-PR: Lines starting with `SEND-PR' will be removed automatically, as
279 SEND-PR: will all comments (text enclosed in `<' and `>').
280 SEND-PR:
281 SEND-PR: Please consult the GCC manual if you are not sure how to
282 SEND-PR: fill out a problem report.
283 SEND-PR: Note that the Synopsis field is mandatory. The Subject (for
284 SEND-PR: the mail) will be made the same as Synopsis unless explicitly
285 SEND-PR: changed.
286 SEND-PR:
287 SEND-PR: Choose from the following categories:
288 SEND-PR:
289 __EOF__
291 # Format the categories so they fit onto lines.
292 l=`echo "$CATEGORIES" | \
293 awk 'BEGIN {max = 0; } { if (length($0) > max) { max = length($0); } }
294 END {print max + 1;}'`
295 c=`expr 61 / $l`
296 if [ $c -eq 0 ]; then c=1; fi
297 echo "$CATEGORIES" | \
298 awk 'BEGIN {printf "SEND-PR: "; i = 0 }
299 { printf ("%-'$l'.'$l's", $0);
300 if ((++i % '$c') == 0) { printf "\nSEND-PR: " } }
301 END { printf "\nSEND-PR:\n"; }' >> $file
303 cat >> $file << __EOF__
304 To: $GNATS_ADDR
305 Subject:
306 From: $FROM
307 Reply-To: $REPLYTO
308 Cc: $CC
309 X-send-pr-version: $VERSION
310 X-GNATS-Notify:
313 >Submitter-Id: $SUBMITTER
314 >Originator: $ORIGINATOR
315 >Organization: ${ORGANIZATION-$ORGANIZATION_C}
316 >Confidential: no
317 SEND-PR: Leave "Confidential" as "no"; all GCC PRs are public.
318 >Synopsis: $SYNOPSIS_C
319 >Severity: $SEVERITY_C
320 SEND-PR: critical GCC is completely not operational; no work-around known.
321 SEND-PR: serious GCC is not working properly; a work-around is possible.
322 SEND-PR: non-critical Report indicates minor problem.
323 >Priority: $PRIORITY_C
324 SEND-PR: medium The problem should be solved in the next release.
325 SEND-PR: low The problem should be solve in a future release.
326 >Category: $CATEGORY_C
327 >Class: <[ doc-bug | accepts-illegal | rejects-legal | wrong-code | ice-on-legal-code| ice-on-illegal-code | pessimizes-code | sw-bug | change-request | support ] (one line)>
328 SEND-PR: doc-bug The doumentation is incorrect.
329 SEND-PR: accepts-illegal GCC fails to reject erroneous code.
330 SEND-PR: rejects-legal GCC gives an error message for correct code.
331 SEND-PR: wrong-code The machine code generated by gcc is incorrect.
332 SEND-PR: ice-on-legal-code GCC gives an Internal Compiler Error (ICE)
333 SEND-PR: for correct code
334 SEND-PR: ice-on-illegal-code GCC gives an ICE instead of reporting an error
335 SEND-PR: pessimizes-code GCC misses an important optimization opportunity
336 SEND-PR: sw-bug Software bug of some other class than above
337 SEND-PR: change-request A feature in GCC is missing.
338 SEND-PR: support I need help with gcc.
339 >Release: ${DEFAULT_RELEASE-$RELEASE_C}
340 >Environment:
341 `[ -n "$SYSTEM" ] && echo System: $SYSTEM`
342 `[ -n "$ARCH" ] && echo Architecture: $ARCH`
343 `[ -n "$MACHINE" ] && echo Machine: $MACHINE`
344 $ENVIRONMENT_C
345 host: @host@
346 build: @build@
347 target: @target@
348 configured with: @gcc_config_arguments@
349 >Description:
350 $DESCRIPTION_C
351 >How-To-Repeat:
352 $HOW_TO_REPEAT_C
353 >Fix:
354 $FIX_C
355 __EOF__
356 done
359 if [ "$PRINT" = true -o "$PRINT_INTERN" = true ]; then
360 cat $TEMP
361 xs=0; exit
364 chmod u+w $TEMP
365 if [ -z "$REQUEST_ID" ]; then
366 eval $EDIT $TEMP
367 else
368 ed -s $TEMP << '__EOF__'
369 /^Subject/s/^Subject:.*/Subject: request for a customer id/
370 /^>Category/s/^>Category:.*/>Category: send-pr/
373 __EOF__
376 if cmp -s $REF $TEMP ; then
377 echo "$COMMAND: problem report not filled out, therefore not sent"
378 xs=1; exit
383 # Check the enumeration fields
385 # This is a "sed-subroutine" with one keyword parameter
386 # (with workaround for Sun sed bug)
388 SED_CMD='
389 /$PATTERN/{
390 s|||
391 s|<.*>||
392 s|^[ ]*||
393 s|[ ]*$||
399 while [ -z "$REQUEST_ID" ]; do
400 CNT=0
402 # 1) Confidential
404 PATTERN=">Confidential:"
405 CONFIDENTIAL=`eval sed -n -e "\"$SED_CMD\"" $TEMP`
406 case "$CONFIDENTIAL" in
407 no) CNT=`expr $CNT + 1` ;;
408 *) echo "$COMMAND: \`$CONFIDENTIAL' is not a valid value for \`Confidential'." ;;
409 esac
411 # 2) Severity
413 PATTERN=">Severity:"
414 SEVERITY=`eval sed -n -e "\"$SED_CMD\"" $TEMP`
415 case "$SEVERITY" in
416 ""|non-critical|serious|critical) CNT=`expr $CNT + 1` ;;
417 *) echo "$COMMAND: \`$SEVERITY' is not a valid value for \`Severity'."
418 esac
420 # 3) Priority
422 PATTERN=">Priority:"
423 PRIORITY=`eval sed -n -e "\"$SED_CMD\"" $TEMP`
424 case "$PRIORITY" in
425 ""|low|medium) CNT=`expr $CNT + 1` ;;
426 high) echo "$COMMAND: \`Priority: high' is reserved for GCC maintainers." ;;
427 *) echo "$COMMAND: \`$PRIORITY' is not a valid value for \`Priority'."
428 esac
430 # 4) Category
432 PATTERN=">Category:"
433 CATEGORY=`eval sed -n -e "\"$SED_CMD\"" $TEMP`
434 FOUND=
435 for C in $CATEGORIES
437 if [ "$C" = "$CATEGORY" ]; then FOUND=true ; break ; fi
438 done
439 if [ -n "$FOUND" ]; then
440 CNT=`expr $CNT + 1`
441 else
442 if [ -z "$CATEGORY" ]; then
443 echo "$COMMAND: you must include a Category: field in your report."
444 else
445 echo "$COMMAND: \`$CATEGORY' is not a known category."
449 # 5) Class
451 PATTERN=">Class:"
452 CLASS=`eval sed -n -e "\"$SED_CMD\"" $TEMP`
453 case "$CLASS" in
454 ""|doc-bug|accepts-illegal|rejects-legal|wrong-code|ice-on-legal-code|ice-on-illegal-code|pessimizes-code|sw-bug|change-request|support) CNT=`expr $CNT + 1` ;;
455 *) echo "$COMMAND: \`$CLASS' is not a valid value for \`Class'."
456 esac
458 # 6) Check that synopsis is not empty
460 if grep "^>Synopsis:[ ]*${SYNOPSIS_C}\$" $TEMP > /dev/null
461 then
462 echo "$COMMAND: Synopsis must not be empty."
463 else
464 CNT=`expr $CNT + 1`
467 [ $CNT -lt 6 -a -z "$BATCH" ] &&
468 echo "Errors were found with the problem report."
470 while true; do
471 if [ -z "$BATCH" ]; then
472 $ECHON1 "a)bort, e)dit or s)end? $ECHON2"
473 read input
474 else
475 if [ $CNT -eq 6 ]; then
476 input=s
477 else
478 input=a
481 case "$input" in
483 if [ -z "$BATCH" ]; then
484 echo "$COMMAND: the problem report remains in $BAD and is not sent."
485 REMOVE_TEMP="rm -f $TEMP0 $TEMP $REF"
486 mv $TEMP $BAD
487 else
488 echo "$COMMAND: the problem report is not sent."
490 xs=1; exit
493 eval $EDIT $TEMP
494 continue 2
497 break 2
499 esac
500 done
501 done
504 # Make sure the mail has got a Subject. If not, use the same as
505 # in Synopsis.
508 if grep '^Subject:[ ]*$' $TEMP > /dev/null
509 then
510 SYNOPSIS=`grep '^>Synopsis:' $TEMP | sed -e 's/^>Synopsis:[ ]*//'`
511 ed -s $TEMP << __EOF__
512 /^Subject:/s/:.*\$/: $SYNOPSIS/
515 __EOF__
519 # Remove comments and send the problem report
520 # (we have to use patterns, where the comment contains regex chars)
522 # /^>Originator:/s;$ORIGINATOR;;
523 sed -e "
524 /^SEND-PR:/d
525 /^>Organization:/,/^>[A-Za-z-]*:/s;$ORGANIZATION_C;;
526 /^>Confidential:/s;<.*>;;
527 /^>Synopsis:/s;$SYNOPSIS_C;;
528 /^>Severity:/s;<.*>;;
529 /^>Priority:/s;<.*>;;
530 /^>Category:/s;$CATEGORY_C;;
531 /^>Class:/s;<.*>;;
532 /^>Release:/,/^>[A-Za-z-]*:/s;$RELEASE_C;;
533 /^>Environment:/,/^>[A-Za-z-]*:/s;$ENVIRONMENT_C;;
534 /^>Description:/,/^>[A-Za-z-]*:/s;$DESCRIPTION_C;;
535 /^>How-To-Repeat:/,/^>[A-Za-z-]*:/s;$HOW_TO_REPEAT_C;;
536 /^>Fix:/,/^>[A-Za-z-]*:/s;$FIX_C;;
537 " $TEMP > $REF
539 if $MAIL_AGENT < $REF; then
540 echo "$COMMAND: problem report sent"
541 xs=0; exit
542 else
543 echo "$COMMAND: mysterious mail failure."
544 if [ -z "$BATCH" ]; then
545 echo "$COMMAND: the problem report remains in $BAD and is not sent."
546 REMOVE_TEMP="rm -f $TEMP0 $TEMP $REF"
547 mv $REF $BAD
548 else
549 echo "$COMMAND: the problem report is not sent."
551 xs=1; exit