This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
fix .gitignore: only ignore 'perl' in root of repo, not U/perl subdir
[metaconfig.git] / U / perl / Checkcc.U
CommitLineData
14054727
JH
1?RCS:
2?RCS: $Id$
3?RCS:
4?RCS: Copyright (c) 2000, Jarkko Hietaniemi
0d616ccb
MBT
5?RCS:
6?X:
14054727
JH
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.
0d616ccb 9?X:
3bb42500 10?MAKE:Checkcc ccname ccversion: rm cat test Myread startsh
14054727 11?MAKE: -pick add $@ %<
3bb42500
JH
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:.
14054727
JH
24?T: trygcc despair
25?F:./checkcc
1d4be47c 26?F:./trygcc
3bb42500
JH
27?INIT:ccname=''
28?INIT:ccversion=''
14054727
JH
29?LINT:extern cc
30?LINT:change cc
31?LINT:extern ccflags
32?LINT:change ccflags
03810f8e
JH
33?LINT:extern ccflags
34?LINT:extern ldflags
d7a2632b 35: Check what type of C compiler we use
1d4be47c 36cat <<EOS >trygcc
14054727
JH
37$startsh
38EOS
1d4be47c 39cat <<'EOSC' >>trygcc
14054727
JH
40case "$cc" in
41'') ;;
42*) $rm -f try try.*
43 $cat >try.c <<EOM
44int main(int argc, char *argv[]) {
45 return 0;
46}
47EOM
03810f8e 48 if $cc -o try $ccflags $ldflags try.c; then
14054727
JH
49 :
50 else
51 echo "Uh-oh, the C compiler '$cc' doesn't seem to be working." >&4
52 despair=yes
53 trygcc=yes
54 case "$cc" in
55 *gcc*) trygcc=no ;;
56 esac
e85c2d76
AD
57 # Skip this test because it gives a false match on output like:
58 # ./trygcc: line 23: cc: command not found
59 # case "`$cc -v -c try.c 2>&1`" in
60 # *gcc*) trygcc=no ;;
61 # esac
14054727
JH
62 if $test X"$trygcc" = Xyes; then
63 if gcc -o try -c try.c; then
64 echo " "
65 echo "You seem to have a working gcc, though." >&4
e85c2d76
AD
66 # Switching compilers may undo the work of hints files.
67 # The most common problem is -D_REENTRANT for threads.
68 # This heuristic catches that case, but gets false positives
69 # if -Dusethreads was not actually specified. Better to
0d616ccb 70 # bail out here with a useful message than fail
e85c2d76
AD
71 # mysteriously later. Should we perhaps just try to
72 # re-invoke Configure -Dcc=gcc config_args ?
73 if $test -f usethreads.cbu; then
0d616ccb 74 $cat >&4 <<EOM
e85c2d76
AD
75
76*** However, any setting of the C compiler flags (e.g. for thread support)
77*** will be lost. It may be necessary for you to restart Configure and
78*** add -Dcc=gcc to your Configure command line.
79
80EOM
81 rp="Would you like to go ahead and try gcc anyway?"
82 dflt=n
83 else
84 rp="Would you like to use it?"
85 dflt=y
86 fi
14054727
JH
87 if $test -f myread; then
88 . ./myread
89 else
90 if $test -f UU/myread; then
91 . ./UU/myread
92 else
93 echo "Cannot find myread, sorry. Aborting." >&2
94 exit 1
95 fi
0d616ccb 96 fi
14054727 97 case "$ans" in
2b39af25 98 [yY]*) cc=gcc; ccname=gcc; ccflags=''; despair=no;
14054727
JH
99 esac
100 fi
101 fi
1d4be47c
JH
102 fi
103 $rm -f try try.*
104 ;;
105esac
106EOSC
107
108cat <<EOS >checkcc
109$startsh
110EOS
111cat <<'EOSC' >>checkcc
0d616ccb 112case "$cc" in
1d4be47c 113'') ;;
0d616ccb 114*) $rm -f try try.*
1d4be47c
JH
115 $cat >try.c <<EOM
116int main(int argc, char *argv[]) {
117 return 0;
118}
119EOM
120 if $cc -o try $ccflags $ldflags try.c; then
121 :
122 else
14054727 123 if $test X"$despair" = Xyes; then
1d4be47c
JH
124 echo "Uh-oh, the C compiler '$cc' doesn't seem to be working." >&4
125 fi
0d616ccb 126 $cat >&4 <<EOM
30e1080a
MB
127You need to find a working C compiler.
128Either (purchase and) install the C compiler supplied by your OS vendor,
129or for a free C compiler try http://gcc.gnu.org/
130I cannot continue any further, aborting.
131EOM
1d4be47c 132 exit 1
14054727
JH
133 fi
134 $rm -f try try.*
135 ;;
136esac
137EOSC
138