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