bin/errs12: Update.
[nethome.git] / bin / errs12
1 #! /bin/bash
2 # $Id$
3
4 #renice +19 -p $$; ionice -c3 -p $$
5 renice +10 -p $$; ionice -c3 -p $$
6
7 # Do not use for ctags - it would override $PATH:
8 # PS1=x; . ~/.bashrc
9 function ctags {(unset ctags; PS1=x; . ~/.bashrc; ctags; );}
10
11 customss="--enable-static --disable-shared"
12 customm="-m64"
13 target=
14 targets=
15 configure="./configure"
16 # >=4.7 has small macros section.
17 if gcc --version|perl -ne 'exit(!(/(\d+)\.(\d+)/&&($1>4||($1==4&&$2>=7))));';then
18   debug="-g3"
19 else
20   debug="-g2"
21 fi
22 permissive=""
23 asan=""
24 #asan="-fsanitize=address -static-libasan"
25 mcheck=""
26 #mcheck="-lmcheck"
27 fast=false
28 readline=""
29 disablebinutils="--disable-binutils --disable-gas --disable-gold --disable-gprof --disable-ld"
30 python=""
31
32 while true
33 do
34         if [ "$1" = "--origss" ];then
35                 customss=
36                 shift
37                 continue
38         fi
39         if [ "$1" = "--fast" ];then
40                 fast=true
41                 shift
42                 continue
43         fi
44         if [ "$1" = "--shared" ];then
45                 customss="--disable-static --enable-shared"
46                 shift
47                 continue
48         fi
49
50         if [ "$1" = "-m" ];then
51                 customm=
52                 shift
53                 continue
54         fi
55         if [ "$1" = "-m32" ];then
56                 customm=-m32
57                 case `uname -m` in
58                   i?86|x86_64|ia64) target=i386-unknown-linux-gnu ;;
59                   ppc*)             target=powerpc64-unknown-linux-gnu ;;
60                   s390*)            target=s390-unknown-linux-gnu ;;
61                 esac
62                 shift
63                 continue
64         fi
65
66         if [ "${1#*/configure}" != "$1" ];then
67                 configure="$1"
68                 shift
69                 continue
70         fi
71
72         if [ "$1" = "-s" ];then
73                 # -O0 is important to override GCC -O2.
74                 debug="-O0 -s"
75                 shift
76                 continue
77         fi
78
79         if [ "$1" = "-fpermissive" ];then
80                 permissive="-fpermissive"
81                 shift
82                 continue
83         fi
84
85         if [ "$1" = "--asan" ];then
86                 asan="-fsanitize=address -static-libasan"
87                 shift
88                 continue
89         fi
90
91         if [ "$1" = "--noasan" ];then
92                 asan=""
93                 shift
94                 continue
95         fi
96
97         if [ "$1" = "--nomcheck" ];then
98                 mcheck=""
99                 shift
100                 continue
101         fi
102
103         if [ "$1" = "--binutils" ];then
104                 disablebinutils="--enable-gold"
105                 shift
106                 continue
107         fi
108
109         break
110 done
111
112 rm -f errs1.ok
113 (
114         set -ex
115         find -name config.cache|xargs rm -f
116
117         # sourceware.org?
118         if test -f `dirname $configure`/bfd/elf64-x86-64.c \
119              -o -f `dirname $configure`/gcc/reload.c;then
120                 maintainer=""
121         else
122                 :
123 #               maintainer="--enable-maintainer-mode"
124         fi
125         if test -f `dirname $configure`/bfd/elf64-x86-64.c;then
126                 test -f g77 || (test -f /usr/bin/gfortran && ln -s /usr/bin/gfortran g77)
127         fi
128         if ! $fast;then
129                 targets="$targets --enable-64-bit-bfd"
130         fi
131         if ! $fast && test -f `dirname $configure`/bfd/elf64-x86-64.c -a '(' -d CVS -o -d .git ')';then
132                 targets="$targets --enable-targets=all"
133         fi
134         if test ! -e readline/readline/display.c;then # $fast ||
135                 targets="$targets --with-system-readline"
136         fi
137
138         if test -f `dirname $configure`/gcc/reload.c;then
139                 werror="--disable-werror"
140                 customm=""
141                 # --disable-static would fail on finding built libstdc++ due to -static-libstdc++.
142                 # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49829
143                 #customss=""
144                 customss="--disable-static --enable-shared"
145         else
146                 werror=""
147         fi
148
149         if test -d readline/doc && ! test -e readline/readline.c;then
150                 # Fedora gdb.spec prep.
151                 readline="--with-system-readline"
152         fi
153
154         if test -z "$python";then
155                 if [ -x /usr/bin/python3 ];then
156                         python="--with-python=/usr/bin/python3"
157                 fi
158         fi
159
160         test -z "$CC" && CC=gcc
161         : >errs1.c
162         # -Wp,-D_FORTIFY_SOURCE=2: /usr/include/features.h:329:3: error: #warning _FORTIFY_SOURCE requested but disabled [-Werror=cpp]
163         # -ftrack-macro-expansion=0:
164         # hash.c:535:5: error: statement is indented as if it were guarded by... [-Werror=misleading-indentation]
165         # hash.c:535:5: note: ...this ‘if’ clause, but it is not
166         for flags in                                                                                                                                    \
167                 "$debug -pipe -Wall -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -fno-diagnostics-show-caret -Wno-error=cast-function-type -Wno-error=stringop-truncation -Wno-error=format-truncation $asan"        \
168                 "$debug -pipe -Wall -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -fno-diagnostics-show-caret $asan"  \
169                 "$debug -pipe -Wall -fexceptions -fstack-protector --param=ssp-buffer-size=4 -fno-diagnostics-show-caret $asan" \
170                 "$debug -pipe -Wall -fexceptions -fstack-protector --param=ssp-buffer-size=4 -fno-diagnostics-show-caret"       \
171                 "$debug -pipe -Wall -fexceptions -fstack-protector --param=ssp-buffer-size=4"                                                           \
172                 "$debug -pipe -Wall -fexceptions"                                                                                                       \
173                 ""                                                                                                                                      \
174                 ;do
175                 if [ -z "$flags" ];then
176                         rm -f errs1.c
177                         echo >&2 "flags error"
178                         exit 1
179                 fi
180                 # Use -Werror:
181                 # cc1: warnings being treated as errors
182                 # archive.c:1: error: -fstack-protector not supported for this target
183                 "$CC" $flags -Werror -c errs1.c -o /dev/null && break
184         done
185         if test -n "$customm" && "$CC" $customm -c errs1.c -o /dev/null;then
186                 flags="$customm $flags"
187         fi
188         echo 'int main (void) { return 0; }' >errs1.c
189         for ldflags in \
190                 "-fuse-ld=gold -Wl,--gdb-index -ltcmalloc" \
191                 "-fuse-ld=gold -Wl,--gdb-index" \
192                 "-ltcmalloc" \
193                 "" \
194         ;do
195                 "$CC" $flags $ldflags errs1.c -o /dev/null && break
196         done
197         rm -f errs1.c
198         if ! echo "$flags"|grep -q 'fsanitize=address';then
199                 asan=""
200         fi
201         flags="$flags -D_GLIBCXX_DEBUG"
202         export CFLAGS="$flags"
203         export CXXFLAGS="$flags $permissive"
204         export GCJFLAGS="$flags"
205         export CFLAGS_FOR_TARGET="$flags"
206         export CXXFLAGS_FOR_TARGET="$flags $permissive"
207         export LDFLAGS="$ldflags $mcheck $asan"
208
209         time nice "$configure" $target $targets $customss $readline $disablebinutils $python --enable-debug --disable-sim $maintainer $werror --with-separate-debug-dir=/usr/lib/debug --without-guile "$@"
210 # --enable-gold --enable-plugins
211
212         (ctags; test -d gdb && (cd gdb; ctags; cd testsuite; ctags; cd ../gdbserver; ctags)) &
213
214         errs2
215
216         touch errs1.ok
217         ) 2>&1|tee errs1
218 test -f errs1.ok
219 rc=$?
220 rm -f errs1.ok
221 exit $rc