This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Add the files from dist/meta to perl's repo
[metaconfig.git] / dist / U / Checkcc.U
1 ?RCS: $Id: Checkcc.U 1 2006-08-24 12:32:52Z rmanfredi $
2 ?RCS:
3 ?RCS: Copyright (c) 1991-1997, 2004-2006, Raphael Manfredi
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 4.0.
10 ?RCS:
11 ?RCS: Copyright (c) 2000, Jarkko Hietaniemi
12 ?RCS: 
13 ?X: 
14 ?X: This unit produces a bit of shell code that must be dotted in order
15 ?X: to make quick check on whether the current C compiler is working.
16 ?X:     
17 ?MAKE:Checkcc ccname ccversion: Myread Warn startsh cat contains test
18 ?MAKE:  -pick add $@ %<
19 ?S:ccname:
20 ?S:     This can set either by hints files or by Configure.  If using
21 ?S:     gcc, this is gcc, and if not, usually equal to cc, unimpressive, no?
22 ?S:     Some platforms, however, make good use of this by storing the
23 ?S:     flavor of the C compiler being used here.  For example if using
24 ?S:     the Sun WorkShop suite, ccname will be 'workshop'.
25 ?S:.
26 ?S:ccversion:
27 ?S:     This can set either by hints files or by Configure.  If using
28 ?S:     a (non-gcc) vendor cc, this variable may contain a version for
29 ?S:     the compiler.
30 ?S:.
31 ?F:./checkcc ./trygcc !checktmp
32 ?V:despair
33 ?T:trygcc
34 ?LINT:extern cc rm ccflags ldflags
35 ?LINT:change cc ccflags
36 ?LINT:usefile checktmp
37 ?INIT:ccname=''
38 ?INIT:ccversion=''
39 : generate the trygcc script for later perusal
40 cat <<EOS >trygcc
41 $startsh
42 EOS
43 cat <<'EOSC' >>trygcc
44 case "$cc" in
45 '') ;;
46 *)  $rm -f try try.*
47     $cat >try.c <<EOM
48 int main(int argc, char *argv[]) {
49   (void) argc;
50   (void) argv;
51   return 0;
52 }
53 EOM
54     if $cc -o try $ccflags $ldflags try.c; then
55        :
56     else
57         echo "Uh-oh, the C compiler '$cc' doesn't seem to be working." >&4
58         despair=yes
59         trygcc=yes
60         case "$cc" in
61         *gcc*) trygcc=no ;;
62         esac
63         case "`$cc -v -c try.c 2>&1`" in
64         *gcc*) trygcc=no ;;
65         esac
66         if $test X"$trygcc" = Xyes; then
67             if gcc -o try -c try.c; then
68                 echo " "
69                 echo "You seem to have a working gcc, though." >&4
70                 rp="Would you like to use it?"
71                 dflt=y
72                 if $test -f myread; then
73                     . ./myread
74                 else
75                     if $test -f UU/myread; then
76                         . ./UU/myread
77                     else
78                         echo "Cannot find myread, sorry.  Aborting." >&2
79                         exit 1
80                     fi
81                 fi  
82                 case "$ans" in
83                 [yY]*) cc=gcc; ccname=gcc; ccflags=''; despair=no;
84 ?X: Look whether we have 'call-back units' generated by hints that would
85 ?X: seemingly affect the compiling environment.
86                        $cat *.cbu >checktmp 2>/dev/null
87                        if $contains ccflags checktmp >/dev/null; then
88                            ./warn <<EOM 
89 Any previous setting of the C compiler flags has been lost.
90 It may be necessary to pass -Dcc=gcc to Configure right away.
91 EOM
92                        fi;;
93                 esac
94             fi
95         fi
96     fi
97     $rm -f try try.*
98     ;;
99 esac
100 EOSC
101
102 : generate the checkcc script for later perusal
103 cat <<EOS >checkcc
104 $startsh
105 EOS
106 cat <<'EOSC' >>checkcc
107 case "$cc" in        
108 '') ;;
109 *)  $rm -f try try.*              
110     $cat >try.c <<EOM
111 int main(int argc, char *argv[]) {
112   (void) argc;
113   (void) argv;
114   return 0;
115 }
116 EOM
117     if $cc -o try $ccflags $ldflags try.c; then
118        :
119     else
120         if $test X"$despair" = Xyes; then
121            echo "Uh-oh, the C compiler '$cc' doesn't seem to be working." >&4
122         fi
123         $cat >&4 <<EOM         
124 You need to find a working C compiler.
125 Either (purchase and) install the C compiler supplied by your OS vendor,
126 or for a free C compiler try http://gcc.gnu.org/
127 I cannot continue any further, aborting.
128 EOM
129         exit 1
130     fi
131     $rm -f try try.*
132     ;;
133 esac
134 EOSC
135