This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
The metaconfig unit changes for #10040.
[metaconfig.git] / U / perl / Checkcc.U
1 ?RCS:
2 ?RCS: $Id$
3 ?RCS:
4 ?RCS: Copyright (c) 2000, Jarkko Hietaniemi
5 ?RCS: 
6 ?X: 
7 ?X: This unit produces a bit of shell code that must be dotted in order
8 ?X: to make quick check on whether the current C compiler is working.
9 ?X:     
10 ?MAKE:Checkcc ccname ccversion: rm cat test Myread startsh
11 ?MAKE:  -pick add $@ %<
12 ?S:ccname:
13 ?S:     This can set either by hints files or by Configure.  If using
14 ?S:     gcc, this is gcc, and if not, usually equal to cc, unimpressive, no?
15 ?S:     Some platforms, however, make good use of this by storing the
16 ?S:     flavor of the C compiler being used here.  For example if using
17 ?S:     the Sun WorkShop suite, ccname will be 'workshop'.
18 ?S:.
19 ?S:ccversion:
20 ?S:     This can set either by hints files or by Configure.  If using
21 ?S:     a (non-gcc) vendor cc, this variable may contain a version for
22 ?S:     the compiler.
23 ?S:.
24 ?T: trygcc despair
25 ?F:./checkcc
26 ?INIT:ccname=''
27 ?INIT:ccversion=''
28 ?LINT:extern cc
29 ?LINT:change cc
30 ?LINT:extern ccflags
31 ?LINT:change ccflags
32 ?LINT:extern ccflags
33 ?LINT:extern ldflags
34 cat <<EOS >checkcc
35 $startsh
36 EOS
37 cat <<'EOSC' >>checkcc
38 case "$cc" in
39 '') ;;
40 *)  $rm -f try try.*
41     $cat >try.c <<EOM
42 int main(int argc, char *argv[]) {
43   return 0;
44 }
45 EOM
46     if $cc -o try $ccflags $ldflags try.c; then
47        :
48     else
49         echo "Uh-oh, the C compiler '$cc' doesn't seem to be working." >&4
50         despair=yes
51         trygcc=yes
52         case "$cc" in
53         *gcc*) trygcc=no ;;
54         esac
55         case "`$cc -v -c try.c 2>&1`" in
56         *gcc*) trygcc=no ;;
57         esac
58         if $test X"$trygcc" = Xyes; then
59             if gcc -o try -c try.c; then
60                 echo " "
61                 echo "You seem to have a working gcc, though." >&4
62                 rp="Would you like to use it?"
63                 dflt=y
64                 if $test -f myread; then
65                     . ./myread
66                 else
67                     if $test -f UU/myread; then
68                         . ./UU/myread
69                     else
70                         echo "Cannot find myread, sorry.  Aborting." >&2
71                         exit 1
72                     fi
73                 fi  
74                 case "$ans" in
75                 [yY]*) cc=gcc; ccname=gcc; ccflags=''; despair=no ;;
76                 esac
77             fi
78         fi
79         if $test X"$despair" = Xyes; then
80             $cat >&4 <<EOM
81 You need to find a working C compiler.
82 Either (purchase and) install the C compiler supplied by your OS vendor,
83 or for a free C compiler try http://gcc.gnu.org/
84 I cannot continue any further, aborting.
85 EOM
86             exit 1
87         fi
88     fi
89     $rm -f try try.*
90     ;;
91 esac
92 EOSC
93