rpmsafereduce: +$IGNORE_D,die->carp
[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 asan=""
23 #asan="-fsanitize=address -static-libasan"
24 mcheck=""
25 #mcheck="-lmcheck"
26 fast=false
27 readline=""
28 disablebinutils="--disable-binutils --disable-gas --disable-gold --disable-gprof --disable-ld"
29
30 while true
31 do
32         if [ "$1" = "--origss" ];then
33                 customss=
34                 shift
35                 continue
36         fi
37         if [ "$1" = "--fast" ];then
38                 fast=true
39                 shift
40                 continue
41         fi
42         if [ "$1" = "--shared" ];then
43                 customss="--disable-static --enable-shared"
44                 shift
45                 continue
46         fi
47
48         if [ "$1" = "-m" ];then
49                 customm=
50                 shift
51                 continue
52         fi
53         if [ "$1" = "-m32" ];then
54                 customm=-m32
55                 case `uname -m` in
56                   i?86|x86_64|ia64) target=i386-unknown-linux-gnu ;;
57                   ppc*)             target=powerpc64-unknown-linux-gnu ;;
58                   s390*)            target=s390-unknown-linux-gnu ;;
59                 esac
60                 shift
61                 continue
62         fi
63
64         if [ "${1#*/configure}" != "$1" ];then
65                 configure="$1"
66                 shift
67                 continue
68         fi
69
70         if [ "$1" = "-s" ];then
71                 # -O0 is important to override GCC -O2.
72                 debug="-O0 -s"
73                 shift
74                 continue
75         fi
76
77         if [ "$1" = "--asan" ];then
78                 asan="-fsanitize=address -static-libasan"
79                 shift
80                 continue
81         fi
82
83         if [ "$1" = "--noasan" ];then
84                 asan=""
85                 shift
86                 continue
87         fi
88
89         if [ "$1" = "--nomcheck" ];then
90                 mcheck=""
91                 shift
92                 continue
93         fi
94
95         if [ "$1" = "--binutils" ];then
96                 disablebinutils=""
97                 shift
98                 continue
99         fi
100
101         break
102 done
103
104 rm -f errs1.ok
105 (
106         set -ex
107         find -name config.cache|xargs rm -f
108
109         # sourceware.org?
110         if test -f `dirname $configure`/bfd/elf64-x86-64.c \
111              -o -f `dirname $configure`/gcc/reload.c;then
112                 maintainer=""
113         else
114                 :
115 #               maintainer="--enable-maintainer-mode"
116         fi
117         if test -f `dirname $configure`/bfd/elf64-x86-64.c;then
118                 test -f g77 || (test -f /usr/bin/gfortran && ln -s /usr/bin/gfortran g77)
119         fi
120         if ! $fast;then
121                 targets="$targets --enable-64-bit-bfd"
122         fi
123         if ! $fast && test -f `dirname $configure`/bfd/elf64-x86-64.c -a '(' -d CVS -o -d .git ')';then
124                 targets="$targets --enable-targets=all"
125         fi
126         if test ! -d readline;then # $fast ||
127                 targets="$targets --with-system-readline"
128         fi
129
130         if test -f `dirname $configure`/gcc/reload.c;then
131                 werror="--disable-werror"
132                 customm=""
133                 # --disable-static would fail on finding built libstdc++ due to -static-libstdc++.
134                 # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49829
135                 #customss=""
136                 customss="--disable-static --enable-shared"
137         else
138                 werror=""
139         fi
140
141         if test -d readline/doc && ! test -e readline/readline.c;then
142                 # Fedora gdb.spec prep.
143                 readline="--with-system-readline"
144         fi
145
146         test -z "$CC" && CC=gcc
147         : >errs1.c
148         # -Wp,-D_FORTIFY_SOURCE=2: /usr/include/features.h:329:3: error: #warning _FORTIFY_SOURCE requested but disabled [-Werror=cpp]
149         for flags in                                                                                                                                    \
150                 "$debug -pipe -Wall -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -ftrack-macro-expansion=0 -fno-diagnostics-show-caret $asan"        \
151                 "$debug -pipe -Wall -fexceptions -fstack-protector --param=ssp-buffer-size=4 -ftrack-macro-expansion=0 -fno-diagnostics-show-caret $asan"       \
152                 "$debug -pipe -Wall -fexceptions -fstack-protector --param=ssp-buffer-size=4 -ftrack-macro-expansion=0 -fno-diagnostics-show-caret"     \
153                 "$debug -pipe -Wall -fexceptions -fstack-protector --param=ssp-buffer-size=4"                                                           \
154                 "$debug -pipe -Wall -fexceptions"                                                                                                       \
155                 ""                                                                                                                                      \
156                 ;do
157                 if [ -z "$flags" ];then
158                         rm -f errs1.c
159                         echo >&2 "flags error"
160                         exit 1
161                 fi
162                 # Use -Werror:
163                 # cc1: warnings being treated as errors
164                 # archive.c:1: error: -fstack-protector not supported for this target
165                 "$CC" $flags -Werror -c errs1.c -o /dev/null && break
166         done
167         if test -n "$customm" && "$CC" $customm -c errs1.c -o /dev/null;then
168                 flags="$customm $flags"
169         fi
170         rm -f errs1.c
171         if ! echo "$flags"|grep -q 'fsanitize=address';then
172                 asan=""
173         fi
174         export CFLAGS="$flags"
175         export CXXFLAGS="$flags"
176         export GCJFLAGS="$flags"
177         export CFLAGS_FOR_TARGET="$flags"
178         export CXXFLAGS_FOR_TARGET="$flags"
179         export LDFLAGS="$mcheck $asan"
180
181         time nice "$configure" $target $targets $customss $readline $disablebinutils --enable-debug --disable-sim $maintainer $werror --with-separate-debug-dir=/usr/lib/debug --without-guile "$@"
182 # --enable-gold --enable-plugins
183
184         (ctags; test -d gdb && (cd gdb; ctags; cd testsuite; ctags; cd ../gdbserver; ctags)) &
185
186         errs2
187
188         touch errs1.ok
189         ) 2>&1|tee errs1
190 test -f errs1.ok
191 rc=$?
192 rm -f errs1.ok
193 exit $rc