This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
metaconfig unit changes for #18923. The gccvers unit
[metaconfig.git] / U / perl / gccvers.U
1 ?RCS: $Id$
2 ?RCS:
3 ?RCS: Copyright (c) 2000, Jarkko Hietaniemi
4 ?RCS: 
5 ?RCS: You may redistribute only under the terms of the Artistic Licence,
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
8 ?RCS: that same Artistic Licence; a copy of which may be found at the root
9 ?RCS: of the source tree for dist 3.0.
10 ?RCS:
11 ?MAKE:gccversion gccosandvers gccansipedantic: cat cpp rm +cc \
12         Mcc Myread Guess Options Oldconfig Loc osname osvers run
13 ?MAKE:  -pick add $@ %<
14 ?S:gccversion:
15 ?S:     If GNU cc (gcc) is used, this variable holds '1' or '2' to
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:.
19 ?S:gccosandvers:
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,
22 ?S:     or if nothing useful can be parsed as the os version.
23 ?S:.
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:.
29 ?T:gccshortvers
30 ?T:incdir
31 ?T:warn
32 ?D:gccversion=''
33 ?D:gccansipedantic=''
34 ?LINT:change cpp
35 ?LINT:extern ccflags
36 ?LINT:extern ldflags
37 ?LINT:extern locincpth
38 ?LINT:extern ccname
39 ?LINT:change ccflags
40 ?LINT:change ccname
41 ?LINT:change locincpth
42 ?X: Check if they have gcc in any guise.
43 echo " "
44 echo "Checking for GNU cc in disguise and/or its version number..." >&4
45 $cat >try.c <<EOM
46 #include <stdio.h>
47 int main() {
48 #ifdef __GNUC__
49 #ifdef __VERSION__
50         printf("%s\n", __VERSION__);
51 #else
52         printf("%s\n", "1");
53 #endif
54 #endif
55         (int)exit(0);
56 }
57 EOM
58 if $cc -o try $ccflags $ldflags try.c; then
59         gccversion=`$run ./try`
60         case "$gccversion" in
61         '') echo "You are not using GNU cc." ;;
62         *)  echo "You are using GNU cc $gccversion."
63             ccname=gcc
64             ;;
65         esac
66 else
67         echo " "
68         echo "*** WHOA THERE!!! ***" >&4
69         echo "    Your C compiler \"$cc\" doesn't seem to be working!" >&4
70 ?X: using -K will prevent aborting--maybe they're cross compiling?
71         case "$knowitall" in
72         '')
73         echo "    You'd better start hunting for one and let me know about it." >&4
74                 exit 1
75                 ;;
76         esac
77 fi
78 $rm -f try try.*
79 case "$gccversion" in
80 1*) cpp=`./loc gcc-cpp $cpp $pth` ;;
81 esac
82 case "$gccversion" in
83 '') gccosandvers='' ;;
84 *) gccshortvers=`echo "$gccversion"|sed 's/ .*//'`
85    gccosandvers=`$cc -v 2>&1|grep '/specs$'|sed "s!.*/[^-/]*-[^-/]*-\([^-/]*\)/$gccshortvers/specs!\1!"`
86    gccshortvers=''
87    case "$gccosandvers" in
88    $osname) gccosandvers='' ;; # linux gccs seem to have no linux osvers, grr
89    $osname$osvers) ;; # looking good
90    $osname*) cat <<EOM >&4
91
92 *** WHOA THERE!!! ***
93
94     Your gcc has not been compiled for the exact release of
95     your operating system ($gccosandvers versus $osname$osvers).
96
97     In general it is a good idea to keep gcc synchronized with
98     the operating system because otherwise serious problems
99     may ensue when trying to compile software, like Perl.
100
101     I'm trying to be optimistic here, though, and will continue.
102     If later during the configuration and build icky compilation
103     problems appear (headerfile conflicts being the most common
104     manifestation), I suggest reinstalling the gcc to match
105     your operating system release.
106
107 EOM
108       ;;
109    *) gccosandvers='' ;; # failed to parse, better be silent
110    esac
111    ;;
112 esac
113 case "$ccname" in
114 '') ccname="$cc" ;;
115 esac
116
117 # gcc 3.* complain about adding -Idirectories that they already know about,
118 # so we will take those off from locincpth.
119 case "$gccversion" in
120 3*)
121     echo "main(){}">try.c
122     for incdir in $locincpth; do
123        warn=`$cc $ccflags -I$incdir -c try.c 2>&1 | \
124              grep '^c[cp]p*[01]: warning: changing search order '`
125        if test "X$warn" != X; then
126            locincpth=`echo " $locincpth " | sed "s! $incdir ! !"`
127        fi
128     done
129     $rm -f try try.*
130 esac
131