Report version of gcc in use.
[kopensolaris-gnu/glibc.git] / glibcbug.in
1 #! /bin/sh
2 #
3 # glibcbug - create a bug report and mail it to the bug address.
4 #
5 # configuration section:
6 #       these variables are filled in by configure
7 #
8 VERSION="@VERSION@"
9 BUGGLIBC="bugs@gnu.org"
10 ADDONS="@subdirs@"
11 HOST="@host@"
12 CC='@CC@'
13 CFLAGS="@CFLAGS@"
14 VERSIONING="@VERSIONING@"
15 BUILD_STATIC="@static@"
16 BUILD_SHARED="@shared@"
17 BUILD_PIC_DEFAULT="@pic_default@"
18 BUILD_PROFILE="@profile@"
19 BUILD_OMITFP="@omitfp@"
20 BUILD_BOUNDED="@bounded@"
21 BUILD_STATIC_NSS="@static_nss@"
22 STDIO="@stdio@"
23
24 PATH=/bin:/usr/bin:/usr/local/bin:$PATH
25 export PATH
26
27 TEMP=`mktemp -q /tmp/glibcbugXXXXXX 2>/dev/null`
28 if test $? -ne 0; then
29   TEMP=/tmp/glibcbug.$$
30   echo > $TEMP
31   chmod 600 $TEMP
32 fi
33 TEMPx=`mktemp -q /tmp/glibcbugXXXXXX 2>/dev/null`
34 if test $? -ne 0; then
35   TEMPx=/tmp/glibcbug.$$.x
36   echo > $TEMPx
37   chmod 600 $TEMPx
38 fi
39
40 BUGADDR=${1-$BUGGLIBC}
41 ENVIRONMENT=`uname -a`
42
43 : ${EDITOR=emacs}
44
45 : ${USER=${LOGNAME-`whoami`}}
46
47 trap 'rm -f $TEMP $TEMPx; exit 1' 1 2 3 13 15
48 trap 'rm -f $TEMP $TEMPx' 0
49
50
51 # How to read the passwd database.
52 PASSWD="cat /etc/passwd"
53
54 if [ -f /usr/lib/sendmail ] ; then
55         MAIL_AGENT="/usr/lib/sendmail -oi -t"
56 elif [ -f /usr/sbin/sendmail ] ; then
57         MAIL_AGENT="/usr/sbin/sendmail -oi -t"
58 else
59         MAIL_AGENT=rmail
60 fi
61
62 # Figure out how to echo a string without a trailing newline
63 N=`echo 'hi there\c'`
64 case "$N" in
65 *c)     ECHON1='echo -n' ECHON2= ;;
66 *)      ECHON1=echo ECHON2='\c' ;;
67 esac
68
69 # Find out the name of the originator of this PR.
70 if [ -n "$NAME" ]; then
71   ORIGINATOR="$NAME"
72 elif [ -f $HOME/.fullname ]; then
73   ORIGINATOR="`sed -e '1q' $HOME/.fullname`"
74 else
75   # Must use temp file due to incompatibilities in quoting behavior
76   # and to protect shell metacharacters in the expansion of $LOGNAME
77   $PASSWD | grep "^$LOGNAME:" | awk -F: '{print $5}' | sed -e 's/,.*//' > $TEMP
78   ORIGINATOR="`cat $TEMP`"
79 fi
80
81 if [ -n "$ORGANIZATION" ]; then
82   if [ -f "$ORGANIZATION" ]; then
83     ORGANIZATION="`cat $ORGANIZATION`"
84   fi
85 else
86   if [ -f $HOME/.organization ]; then
87     ORGANIZATION="`cat $HOME/.organization`"
88   elif [ -f $HOME/.signature ]; then
89     ORGANIZATION=`sed -e "s/^/  /" $HOME/.signature; echo ">"`
90   fi
91 fi
92
93 # If they don't have a preferred editor set, then use
94 if [ -z "$VISUAL" ]; then
95   if [ -z "$EDITOR" ]; then
96     EDIT=vi
97   else
98     EDIT="$EDITOR"
99   fi
100 else
101   EDIT="$VISUAL"
102 fi
103
104 # Find out some information.
105 SYSTEM=`( [ -f /bin/uname ] && /bin/uname -a ) || \
106         ( [ -f /usr/bin/uname ] && /usr/bin/uname -a ) || echo ""`
107 ARCH=`[ -f /bin/arch ] && /bin/arch`
108 MACHINE=`[ -f /bin/machine ] && /bin/machine`
109 CCVERSION=`$CC -v 2>&1 | sed -n 's/gcc version //p'`
110
111 ORGANIZATION_C='<organization of PR author (multiple lines)>'
112 SYNOPSIS_C='<synopsis of the problem (one line)>'
113 SEVERITY_C='<[ non-critical | serious | critical ] (one line)>'
114 PRIORITY_C='<[ low | medium | high ] (one line)>'
115 CLASS_C='<[ sw-bug | doc-bug | change-request | support ] (one line)>'
116 RELEASE_C='<release number or tag (one line)>'
117 ENVIRONMENT_C='<machine, os, target, libraries (multiple lines)>'
118 DESCRIPTION_C='<precise description of the problem (multiple lines)>'
119 HOW_TO_REPEAT_C='<code/input/activities to reproduce the problem (multiple lines)>'
120 FIX_C='<how to correct or work around the problem, if known (multiple lines)>'
121
122
123 cat > $TEMP <<EOF
124 SEND-PR: -*- send-pr -*-
125 SEND-PR: Lines starting with \`SEND-PR' will be removed automatically, as
126 SEND-PR: will all comments (text enclosed in \`<' and \`>').
127 SEND-PR:
128 From: ${USER}
129 To: ${BUGADDR}
130 Subject: [50 character or so descriptive subject here (for reference)]
131
132 >Submitter-Id:  net
133 >Originator:    ${ORIGINATOR}
134 >Organization:
135 ${ORGANIZATION- $ORGANIZATION_C}
136 >Confidential:  no
137 >Synopsis:      $SYNOPSIS_C
138 >Severity:      $SEVERITY_C
139 >Priority:      $PRIORITY_C
140 >Category:      libc
141 >Class:         $CLASS_C
142 >Release:       libc-${VERSION}
143 >Environment:
144         $ENVIRONMENT_C
145 `[ -n "$HOST" ] && echo Host type: $HOST`
146 `[ -n "$SYSTEM" ] && echo System: $SYSTEM`
147 `[ -n "$ARCH" ] && echo Architecture: $ARCH`
148 `[ -n "$MACHINE" ] && echo Machine: $MACHINE`
149 `[ -n "$ADDONS" ] && echo Addons: $ADDONS`
150 `[ -n "$CFLAGS" ] && echo Build CFLAGS: $CFLAGS`
151 `[ -n "$CC" ] && echo Build CC: $CC`
152 `[ -n "$CCVERSION" ] && echo Compiler version: $CCVERSION`
153 `[ -n "$VERSIONING" ] && echo Symbol versioning: $VERSIONING`
154 `[ -n "$BUILD_STATIC" ] && echo Build static: $BUILD_STATIC`
155 `[ -n "$BUILD_SHARED" ] && echo Build shared: $BUILD_SHARED`
156 `[ -n "$BUILD_PIC_DEFAULT" ] && echo Build pic-default: $BUILD_PIC_DEFAULT`
157 `[ -n "$BUILD_PROFILE" ] && echo Build profile: $BUILD_PROFILE`
158 `[ -n "$BUILD_OMITFP" ] && echo Build omitfp: $BUILD_OMITFP`
159 `[ -n "$BUILD_BOUNDED" ] && echo Build bounded: $BUILD_BOUNDED`
160 `[ -n "$BUILD_STATIC_NSS" ] && echo Build static-nss: $BUILD_STATIC_NSS`
161 `[ -n "$STDIO" ] && echo Stdio: $STDIO`
162
163 >Description:
164         $DESCRIPTION_C
165 >How-To-Repeat:
166         $HOW_TO_REPEAT_C
167 >Fix:
168         $FIX_C
169 EOF
170
171 chmod u+w $TEMP
172 cp $TEMP $TEMPx
173
174 eval $EDIT $TEMP
175
176 if cmp -s $TEMP $TEMPx; then
177         echo "File not changed, no bug report submitted."
178         exit 1
179 fi
180
181 #\f
182 #       Check the enumeration fields
183
184 # This is a "sed-subroutine" with one keyword parameter
185 # (with workaround for Sun sed bug)
186 #
187 SED_CMD='
188 /$PATTERN/{
189 s|||
190 s|<.*>||
191 s|^[    ]*||
192 s|[     ]*$||
193 p
194 q
195 }'
196
197
198 while :; do
199   CNT=0
200
201   #
202   # 1) Severity
203   #
204   PATTERN=">Severity:"
205   SEVERITY=`eval sed -n -e "\"$SED_CMD\"" $TEMP`
206   case "$SEVERITY" in
207     ""|non-critical|serious|critical) CNT=`expr $CNT + 1` ;;
208     *)  echo "$COMMAND: \`$SEVERITY' is not a valid value for \`Severity'."
209   esac
210   #
211   # 2) Priority
212   #
213   PATTERN=">Priority:"
214   PRIORITY=`eval sed -n -e "\"$SED_CMD\"" $TEMP`
215   case "$PRIORITY" in
216     ""|low|medium|high) CNT=`expr $CNT + 1` ;;
217     *)  echo "$COMMAND: \`$PRIORITY' is not a valid value for \`Priority'."
218   esac
219   #
220   # 3) Class
221   #
222   PATTERN=">Class:"
223   CLASS=`eval sed -n -e "\"$SED_CMD\"" $TEMP`
224   case "$CLASS" in
225     ""|sw-bug|doc-bug|change-request|support) CNT=`expr $CNT + 1` ;;
226     *)  echo "$COMMAND: \`$CLASS' is not a valid value for \`Class'."
227   esac
228
229   [ $CNT -lt 3 ] &&
230     echo "Errors were found with the problem report."
231
232   while :; do
233     $ECHON1 "a)bort, e)dit or s)end? $ECHON2"
234     read input
235     case "$input" in
236       a*)
237         echo "$COMMAND: problem report saved in $HOME/dead.glibcbug."
238         cat $TEMP >> $HOME/dead.glibcbug
239         xs=1; exit
240         ;;
241       e*)
242         eval $EDIT $TEMP
243         continue 2
244         ;;
245       s*)
246         break 2
247         ;;
248     esac
249   done
250 done
251 #
252 #       Remove comments and send the problem report
253 #       (we have to use patterns, where the comment contains regex chars)
254 #
255 # /^>Originator:/s;$ORIGINATOR;;
256 sed  -e "
257 /^SEND-PR:/d
258 /^>Organization:/,/^>[A-Za-z-]*:/s;$ORGANIZATION_C;;
259 /^>Confidential:/s;<.*>;;
260 /^>Synopsis:/s;$SYNOPSIS_C;;
261 /^>Severity:/s;<.*>;;
262 /^>Priority:/s;<.*>;;
263 /^>Class:/s;<.*>;;
264 /^>Release:/,/^>[A-Za-z-]*:/s;$RELEASE_C;;
265 /^>Environment:/,/^>[A-Za-z-]*:/s;$ENVIRONMENT_C;;
266 /^>Description:/,/^>[A-Za-z-]*:/s;$DESCRIPTION_C;;
267 /^>How-To-Repeat:/,/^>[A-Za-z-]*:/s;$HOW_TO_REPEAT_C;;
268 /^>Fix:/,/^>[A-Za-z-]*:/s;$FIX_C;;
269 " $TEMP > $TEMPx
270
271 if $MAIL_AGENT < $TEMPx; then
272   echo "$COMMAND: problem report sent"
273   xs=0; exit
274 else
275   echo "$COMMAND: mysterious mail failure, report not sent."
276   echo "$COMMAND: problem report saved in $HOME/dead.glibcbug."
277   cat $TEMP >> $HOME/dead.glibcbug
278 fi
279
280 exit 0