This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
/\=/ does not require \ even in older awk
[metaconfig.git] / U / perl / Checkcc.U
index d674b3d..dadfe01 100644 (file)
@@ -2,11 +2,11 @@
 ?RCS: $Id$
 ?RCS:
 ?RCS: Copyright (c) 2000, Jarkko Hietaniemi
-?RCS: 
-?X: 
+?RCS:
+?X:
 ?X: This unit produces a bit of shell code that must be dotted in order
 ?X: to make quick check on whether the current C compiler is working.
-?X:    
+?X:
 ?MAKE:Checkcc ccname ccversion: rm cat test Myread startsh
 ?MAKE: -pick add $@ %<
 ?S:ccname:
@@ -32,6 +32,7 @@
 ?LINT:change ccflags
 ?LINT:extern ccflags
 ?LINT:extern ldflags
+: Check what type of C compiler we use
 cat <<EOS >trygcc
 $startsh
 EOS
@@ -53,27 +54,48 @@ EOM
         case "$cc" in
         *gcc*) trygcc=no ;;
         esac
-        case "`$cc -v -c try.c 2>&1`" in
-        *gcc*) trygcc=no ;;
-        esac
+       # Skip this test because it gives a false match on output like:
+       #    ./trygcc: line 23: cc: command not found
+        # case "`$cc -v -c try.c 2>&1`" in
+        # *gcc*) trygcc=no ;;
+        # esac
         if $test X"$trygcc" = Xyes; then
             if gcc -o try -c try.c; then
                 echo " "
                 echo "You seem to have a working gcc, though." >&4
-                rp="Would you like to use it?"
-                dflt=y
+               # Switching compilers may undo the work of hints files.
+               # The most common problem is -D_REENTRANT for threads.
+               # This heuristic catches that case, but gets false positives
+               # if -Dusethreads was not actually specified.  Better to
+               # bail out here with a useful message than fail
+               # mysteriously later. Should we perhaps just try to
+               # re-invoke Configure -Dcc=gcc config_args ?
+               if $test -f usethreads.cbu; then
+                       $cat >&4 <<EOM
+
+*** However, any setting of the C compiler flags (e.g. for thread support)
+*** will be lost.  It may be necessary for you to restart Configure and
+*** add -Dcc=gcc to your Configure command line.
+
+EOM
+                       rp="Would you like to go ahead and try gcc anyway?"
+                       dflt=n
+               else
+                       rp="Would you like to use it?"
+                       dflt=y
+               fi
                 if $test -f myread; then
                     . ./myread
                 else
                     if $test -f UU/myread; then
                         . ./UU/myread
                     else
-                        echo "Cannot find myread, sorry.  Aborting." >&2
+                        echo "Cannot find myread, sorry.  Aborting." >&4
                         exit 1
                     fi
-                fi  
+                fi
                 case "$ans" in
-                [yY]*) cc=gcc; ccname=gcc; ccflags=''; despair=no ;;
+                [yY]*) cc=gcc; ccname=gcc; ccflags=''; despair=no;
                 esac
             fi
         fi
@@ -87,9 +109,9 @@ cat <<EOS >checkcc
 $startsh
 EOS
 cat <<'EOSC' >>checkcc
-case "$cc" in        
+case "$cc" in
 '') ;;
-*)  $rm -f try try.*              
+*)  $rm -f try try.*
     $cat >try.c <<EOM
 int main(int argc, char *argv[]) {
   return 0;
@@ -101,7 +123,7 @@ EOM
         if $test X"$despair" = Xyes; then
            echo "Uh-oh, the C compiler '$cc' doesn't seem to be working." >&4
         fi
-        $cat >&4 <<EOM         
+        $cat >&4 <<EOM
 You need to find a working C compiler.
 Either (purchase and) install the C compiler supplied by your OS vendor,
 or for a free C compiler try http://gcc.gnu.org/