This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
metaconfig unit change for #15394.
[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 ?F:./trygcc
27 ?INIT:ccname=''
28 ?INIT:ccversion=''
29 ?LINT:extern cc
30 ?LINT:change cc
31 ?LINT:extern ccflags
32 ?LINT:change ccflags
33 ?LINT:extern ccflags
34 ?LINT:extern ldflags
35 cat <<EOS >trygcc
36 $startsh
37 EOS
38 cat <<'EOSC' >>trygcc
39 case "$cc" in
40 '') ;;
41 *)  $rm -f try try.*
42     $cat >try.c <<EOM
43 int main(int argc, char *argv[]) {
44   return 0;
45 }
46 EOM
47     if $cc -o try $ccflags $ldflags try.c; then
48        :
49     else
50         echo "Uh-oh, the C compiler '$cc' doesn't seem to be working." >&4
51         despair=yes
52         trygcc=yes
53         case "$cc" in
54         *gcc*) trygcc=no ;;
55         esac
56         case "`$cc -v -c try.c 2>&1`" in
57         *gcc*) trygcc=no ;;
58         esac
59         if $test X"$trygcc" = Xyes; then
60             if gcc -o try -c try.c; then
61                 echo " "
62                 echo "You seem to have a working gcc, though." >&4
63                 rp="Would you like to use it?"
64                 dflt=y
65                 if $test -f myread; then
66                     . ./myread
67                 else
68                     if $test -f UU/myread; then
69                         . ./UU/myread
70                     else
71                         echo "Cannot find myread, sorry.  Aborting." >&2
72                         exit 1
73                     fi
74                 fi  
75                 case "$ans" in
76                 [yY]*) cc=gcc; ccname=gcc; ccflags=''; despair=no;
77                        if $test -f usethreads.cbu; then
78                            $cat >&4 <<EOM 
79
80 *** However, any setting of the C compiler flags (e.g. for thread support)
81 *** has been lost.  It may be necessary to pass -Dcc=gcc to Configure
82 *** (together with e.g. -Dusethreads).
83
84 EOM
85                        fi;;
86                 esac
87             fi
88         fi
89     fi
90     $rm -f try try.*
91     ;;
92 esac
93 EOSC
94
95 cat <<EOS >checkcc
96 $startsh
97 EOS
98 cat <<'EOSC' >>checkcc
99 case "$cc" in        
100 '') ;;
101 *)  $rm -f try try.*              
102     $cat >try.c <<EOM
103 int main(int argc, char *argv[]) {
104   return 0;
105 }
106 EOM
107     if $cc -o try $ccflags $ldflags try.c; then
108        :
109     else
110         if $test X"$despair" = Xyes; then
111            echo "Uh-oh, the C compiler '$cc' doesn't seem to be working." >&4
112         fi
113         $cat >&4 <<EOM         
114 You need to find a working C compiler.
115 Either (purchase and) install the C compiler supplied by your OS vendor,
116 or for a free C compiler try http://gcc.gnu.org/
117 I cannot continue any further, aborting.
118 EOM
119         exit 1
120     fi
121     $rm -f try try.*
122     ;;
123 esac
124 EOSC
125