Commit | Line | Data |
---|---|---|
fd1a35d0 JH |
1 | ?RCS: $Id$ |
2 | ?RCS: | |
3 | ?RCS: Copyright (c) 2000, Jarkko Hietaniemi | |
5dcc3580 | 4 | ?RCS: |
65a32477 | 5 | ?RCS: You may redistribute only under the terms of the Artistic License, |
fd1a35d0 JH |
6 | ?RCS: as specified in the README file that comes with the distribution. |
7 | ?RCS: You may reuse parts of this distribution only within the terms of | |
65a32477 | 8 | ?RCS: that same Artistic License; a copy of which may be found at the root |
fd1a35d0 JH |
9 | ?RCS: of the source tree for dist 3.0. |
10 | ?RCS: | |
4087c32b | 11 | ?MAKE:gccversion gccosandvers gccansipedantic: cat cpp rm +cc \ |
9b04e79a | 12 | Myread Guess Options Oldconfig Loc osname osvers run |
fd1a35d0 JH |
13 | ?MAKE: -pick add $@ %< |
14 | ?S:gccversion: | |
5c7d75a6 | 15 | ?S: If GNU cc (gcc) is used, this variable holds '1' or '2' to |
fd1a35d0 JH |
16 | ?S: indicate whether the compiler is version 1 or 2. This is used in |
17 | ?S: setting some of the default cflags. It is set to '' if not gcc. | |
18 | ?S:. | |
5fc71efb | 19 | ?S:gccosandvers: |
4087c32b MB |
20 | ?S: If GNU cc (gcc) is used, this variable holds the operating system |
21 | ?S: and version used to compile gcc. It is set to '' if not gcc, | |
fcc4de7b | 22 | ?S: or if nothing useful can be parsed as the os version. |
5fc71efb | 23 | ?S:. |
4087c32b MB |
24 | ?S:gccansipedantic: |
25 | ?S: If GNU cc (gcc) is used, this variable will enable (if set) the | |
26 | ?S: -ansi and -pedantic ccflags for building core files (through | |
27 | ?S: cflags script). (See Porting/pumpkin.pod for full description). | |
28 | ?S:. | |
0065f4af MB |
29 | ?D:gccversion='' |
30 | ?D:gccansipedantic='' | |
1d83e148 MB |
31 | ?T:c99_for |
32 | ?T:flag | |
559accf2 | 33 | ?T:gccshortvers |
b2fa012f | 34 | ?T:incdir |
bf7497fb | 35 | ?T:warn |
0065f4af | 36 | ?F:!try |
fd1a35d0 | 37 | ?LINT:change cpp |
77506990 | 38 | ?LINT:extern ccflags |
fd1a35d0 | 39 | ?LINT:extern ldflags |
b2fa012f | 40 | ?LINT:extern locincpth |
3bb42500 | 41 | ?LINT:extern ccname |
b2fa012f JH |
42 | ?LINT:change ccname |
43 | ?LINT:change locincpth | |
33d8b8ec | 44 | ?LINT:change ccflags |
c6d164da | 45 | ?LINT:set gccansipedantic |
5c7d75a6 | 46 | ?X: Check if they have gcc in any guise. |
0065f4af | 47 | : Check if we are using GNU gcc and what its version is |
fd1a35d0 JH |
48 | echo " " |
49 | echo "Checking for GNU cc in disguise and/or its version number..." >&4 | |
0f00356b | 50 | $cat >try.c <<EOM |
fd1a35d0 JH |
51 | #include <stdio.h> |
52 | int main() { | |
a9c4d48e | 53 | #if defined(__GNUC__) && !defined(__INTEL_COMPILER) |
fd1a35d0 JH |
54 | #ifdef __VERSION__ |
55 | printf("%s\n", __VERSION__); | |
56 | #else | |
57 | printf("%s\n", "1"); | |
58 | #endif | |
59 | #endif | |
a4ad2925 | 60 | return(0); |
fd1a35d0 JH |
61 | } |
62 | EOM | |
0f00356b JH |
63 | if $cc -o try $ccflags $ldflags try.c; then |
64 | gccversion=`$run ./try` | |
fd1a35d0 JH |
65 | case "$gccversion" in |
66 | '') echo "You are not using GNU cc." ;; | |
67 | *) echo "You are using GNU cc $gccversion." | |
5c7d75a6 | 68 | ccname=gcc |
fd1a35d0 JH |
69 | ;; |
70 | esac | |
71 | else | |
72 | echo " " | |
73 | echo "*** WHOA THERE!!! ***" >&4 | |
74 | echo " Your C compiler \"$cc\" doesn't seem to be working!" >&4 | |
75 | ?X: using -K will prevent aborting--maybe they're cross compiling? | |
76 | case "$knowitall" in | |
77 | '') | |
78 | echo " You'd better start hunting for one and let me know about it." >&4 | |
79 | exit 1 | |
80 | ;; | |
81 | esac | |
82 | fi | |
0f00356b | 83 | $rm -f try try.* |
fd1a35d0 | 84 | case "$gccversion" in |
96178a6a | 85 | 1.*) cpp=`./loc gcc-cpp $cpp $pth` ;; |
fd1a35d0 | 86 | esac |
5fc71efb KS |
87 | case "$gccversion" in |
88 | '') gccosandvers='' ;; | |
559accf2 JH |
89 | *) gccshortvers=`echo "$gccversion"|sed 's/ .*//'` |
90 | gccosandvers=`$cc -v 2>&1|grep '/specs$'|sed "s!.*/[^-/]*-[^-/]*-\([^-/]*\)/$gccshortvers/specs!\1!"` | |
91 | gccshortvers='' | |
5fc71efb | 92 | case "$gccosandvers" in |
fcc4de7b JH |
93 | $osname) gccosandvers='' ;; # linux gccs seem to have no linux osvers, grr |
94 | $osname$osvers) ;; # looking good | |
5fc71efb KS |
95 | $osname*) cat <<EOM >&4 |
96 | ||
97 | *** WHOA THERE!!! *** | |
98 | ||
99 | Your gcc has not been compiled for the exact release of | |
100 | your operating system ($gccosandvers versus $osname$osvers). | |
101 | ||
102 | In general it is a good idea to keep gcc synchronized with | |
103 | the operating system because otherwise serious problems | |
104 | may ensue when trying to compile software, like Perl. | |
105 | ||
106 | I'm trying to be optimistic here, though, and will continue. | |
107 | If later during the configuration and build icky compilation | |
fcc4de7b JH |
108 | problems appear (headerfile conflicts being the most common |
109 | manifestation), I suggest reinstalling the gcc to match | |
5fc71efb KS |
110 | your operating system release. |
111 | ||
112 | EOM | |
113 | ;; | |
1c7fa146 | 114 | *) gccosandvers='' ;; # failed to parse, better be silent |
5fc71efb KS |
115 | esac |
116 | ;; | |
117 | esac | |
05c8895a JH |
118 | case "$ccname" in |
119 | '') ccname="$cc" ;; | |
120 | esac | |
fd1a35d0 | 121 | |
a7eb1db8 | 122 | # gcc 3.* complain about adding -Idirectories that they already know about, |
d6872425 JH |
123 | # so we will take those off from locincpth. |
124 | case "$gccversion" in | |
96178a6a | 125 | 3.*) |
6c0fca5d | 126 | echo "int main(){}">try.c |
a7eb1db8 MB |
127 | for incdir in $locincpth; do |
128 | warn=`$cc $ccflags -I$incdir -c try.c 2>&1 | \ | |
5c7d75a6 | 129 | grep '^c[cp]p*[01]: warning: changing search order '` |
a7eb1db8 MB |
130 | if test "X$warn" != X; then |
131 | locincpth=`echo " $locincpth " | sed "s! $incdir ! !"` | |
132 | fi | |
d6872425 JH |
133 | done |
134 | $rm -f try try.* | |
135 | esac | |
7ab230d2 | 136 | |
33d8b8ec MBT |
137 | # gcc 4.9 by default does some optimizations that break perl. |
138 | # see ticket 121505. | |
139 | # | |
140 | # The -fwrapv disables those optimizations (and probably others,) so | |
141 | # for gcc 4.9 (and later, since the optimizations probably won't go | |
142 | # away), add -fwrapv unless the user requests -fno-wrapv, which | |
143 | # disables -fwrapv, or if the user requests -fsanitize=undefined, | |
144 | # which turns the overflows -fwrapv ignores into runtime errors. | |
145 | case "$gccversion" in | |
72909a44 | 146 | 4.[3-9].*|4.[1-9][0-9]*|[5-9].*|[1-9][0-9]*) |
33d8b8ec MBT |
147 | case "$ccflags" in |
148 | *-fno-wrapv*|*-fsanitize=undefined*|*-fwrapv*) ;; | |
149 | *) ccflags="$ccflags -fwrapv" ;; | |
150 | esac | |
151 | esac | |
152 | ||
1d83e148 MB |
153 | # Really old versions of gcc default to C89 and will error for this code. |
154 | # See if the compiler (gcc or otherwise) needs a flag to compile C99 code | |
155 | # Initialisations in for loops seem to be the particular problem | |
156 | # (Does this syntax conflict with something else that was valid C89?) | |
157 | # We also add a declaration after a statement to detect whether the compiler | |
158 | # (or the user supplied -Accflags) consider such declarations to be errors. | |
159 | # This causes 'Configure with -Accflags="-Werror=declaration-after-statement"' | |
160 | # to fail hard and early. | |
161 | # | |
162 | # Annoyingly -std=c99 will cause gcc to tell glibc not to define prototypes for | |
163 | # syscall, drand48 etc when including <unistd.h>, which messes up our build. | |
164 | # I guess we *could* loop round trying -std=c99 first with checks both for the | |
165 | # prototype found and the code compiling (because -std=gnu99 might do other | |
166 | # things we don't want, particularly on non-GCC compilers) but | |
167 | # 1) We would need to check for the prototype first (without any flags) | |
168 | # 2) We would still end up with most Linux systems either being -std=gnu99 | |
169 | # or "" (no flag), and so both common options would not rigorously check our | |
170 | # portability to other platforms. | |
171 | # So it doesn't seem worth the complexity and chance of different failure. | |
172 | $cat >try.c <<'EOCP' | |
173 | int main(int argc, char **argv) { | |
174 | argc = argc + 1; | |
175 | /* This is deliberately a declaration after a statement. */ | |
176 | unsigned long long count = 0; | |
177 | for (char **p = argv; *p; ++p) { | |
178 | ++count; | |
179 | } | |
180 | return count == 1 ? 0 : argc; | |
181 | } | |
182 | EOCP | |
183 | c99_for=no | |
184 | for flag in '' '-std=gnu99' '-std=c99'; do | |
185 | if $cc -o try $flag $ccflags $ldflags try.c 2>/dev/null && ./try; then | |
186 | c99_for="$flag" | |
187 | break; | |
188 | fi | |
189 | done | |
190 | case "$c99_for" in | |
191 | '') echo "Your C compiler doesn't need any special flags to compile C99 code" | |
192 | ;; | |
193 | no) echo >&4 "Your C compiler doesn't seem to be able to compile C99 code" | |
194 | rp='Do you really want to continue?' | |
195 | dflt='n' | |
196 | . ./myread | |
197 | case "$ans" in | |
198 | [yY]) echo >&4 "Okay, continuing." ;; | |
199 | *) exit 1 ;; | |
200 | esac | |
201 | ;; | |
202 | *) echo "Your C compiler needs $c99_for to compile C99 code" | |
203 | ccflags="$c99_for $ccflags" | |
204 | ;; | |
205 | esac | |
206 | $rm -f try try.* | |
207 |