4970709604f82f19d6349fc7fe1b00f106139b7c
[nethome.git] / bin / errs12
1 #! /bin/bash
2 # $Id$
3
4 renice +19 -p $$; ionice -c3 -p $$
5
6 # Do not use for ctags - it would override $PATH:
7 # PS1=x; . ~/.bashrc
8 function ctags {(unset ctags; PS1=x; . ~/.bashrc; ctags; );}
9
10 customss="--enable-static --disable-shared"
11 customm="-m64"
12 target=
13 targets=
14 configure="./configure"
15 # >=4.7 has small macros section.
16 if gcc --version|perl -ne 'exit(!(/(\d+)\.(\d+)/&&($1>4||($1==4&&$2>=7))));';then
17   debug="-g3"
18 else
19   debug="-g2"
20 fi
21 ldflags="-lmcheck"
22 fast=false
23 readline=""
24
25 while true
26 do
27         if [ "$1" = "--origss" ];then
28                 customss=
29                 shift
30                 continue
31         fi
32         if [ "$1" = "--fast" ];then
33                 fast=true
34                 shift
35                 continue
36         fi
37         if [ "$1" = "--shared" ];then
38                 customss="--disable-static --enable-shared"
39                 shift
40                 continue
41         fi
42
43         if [ "$1" = "-m" ];then
44                 customm=
45                 shift
46                 continue
47         fi
48         if [ "$1" = "-m32" ];then
49                 customm=-m32
50                 case `uname -m` in
51                   i?86|x86_64|ia64) target=i386-unknown-linux-gnu ;;
52                   ppc*)             target=powerpc64-unknown-linux-gnu ;;
53                   s390*)            target=s390-unknown-linux-gnu ;;
54                 esac
55                 shift
56                 continue
57         fi
58
59         if [ "${1#*/configure}" != "$1" ];then
60                 configure="$1"
61                 shift
62                 continue
63         fi
64
65         if [ "$1" = "-s" ];then
66                 # -O0 is important to override GCC -O2.
67                 debug="-O0 -s"
68                 #ldflags=""
69                 shift
70                 continue
71         fi
72
73         break
74 done
75
76 rm -f errs1.ok
77 (
78         set -ex
79         find -name config.cache|xargs rm -f
80
81         # sourceware.org?
82         if test -f `dirname $configure`/bfd/elf64-x86-64.c \
83              -o -f `dirname $configure`/gcc/reload.c;then
84                 maintainer=""
85         else
86                 :
87 #               maintainer="--enable-maintainer-mode"
88         fi
89         if test -f `dirname $configure`/bfd/elf64-x86-64.c;then
90                 test -f g77 || (test -f /usr/bin/gfortran && ln -s /usr/bin/gfortran g77)
91         fi
92         if ! $fast;then
93                 targets="$targets --enable-64-bit-bfd"
94         fi
95         if ! $fast && test -f `dirname $configure`/bfd/elf64-x86-64.c -a '(' -d CVS -o -d .git ')';then
96                 targets="$targets --enable-targets=all"
97         fi
98
99         if test -f `dirname $configure`/gcc/reload.c;then
100                 werror="--disable-werror"
101                 customm=""
102                 # --disable-static would fail on finding built libstdc++ due to -static-libstdc++.
103                 # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49829
104                 #customss=""
105                 customss="--disable-static --enable-shared"
106         else
107                 werror=""
108         fi
109
110         if test -d readline/doc && ! test -e readline/readline.c;then
111                 # Fedora gdb.spec prep.
112                 readline="--with-system-readline"
113         fi
114
115         test -z "$CC" && CC=gcc
116         : >errs1.c
117         for flags in                                                                                                    \
118                 "$debug -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4"   \
119                 "$debug -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions"                                               \
120                 ""                                                                                                      \
121                 ;do
122                 if [ -z "$flags" ];then
123                         rm -f errs1.c
124                         echo >&2 "flags error"
125                         exit 1
126                 fi
127                 # Use -Werror:
128                 # cc1: warnings being treated as errors
129                 # archive.c:1: error: -fstack-protector not supported for this target
130                 "$CC" $flags -Werror -c errs1.c -o /dev/null && break
131         done
132         if test -n "$customm" && "$CC" $customm -c errs1.c -o /dev/null;then
133                 flags="$customm $flags"
134         fi
135         rm -f errs1.c
136         export CFLAGS="$flags"
137         export CXXFLAGS="$flags"
138         export GCJFLAGS="$flags"
139         export CFLAGS_FOR_TARGET="$flags"
140         export CXXFLAGS_FOR_TARGET="$flags"
141         export LDFLAGS="$ldflags"
142
143         time nice "$configure" $target $targets $customss $readline --enable-debug --disable-sim --enable-gold --enable-plugins $maintainer $werror --with-separate-debug-dir=/usr/lib/debug "$@"
144
145         (ctags; test -d gdb && (cd gdb; ctags; cd testsuite; ctags; cd ../gdbserver; ctags)) &
146
147         errs2
148
149         touch errs1.ok
150         ) 2>&1|tee errs1
151 test -f errs1.ok
152 rc=$?
153 rm -f errs1.ok
154 exit $rc