This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Backporting work on AmigaOS
[metaconfig.git] / U / compline / ccflags.U
index 013a66d..4226327 100644 (file)
@@ -1,11 +1,11 @@
 ?RCS: $Id: ccflags.U,v 3.0.1.9 1997/02/28 15:27:07 ram Exp $
 ?RCS:
 ?RCS: Copyright (c) 1991-1993, Raphael Manfredi
-?RCS: 
-?RCS: You may redistribute only under the terms of the Artistic Licence,
+?RCS:
+?RCS: You may redistribute only under the terms of the Artistic License,
 ?RCS: as specified in the README file that comes with the distribution.
 ?RCS: You may reuse parts of this distribution only within the terms of
-?RCS: that same Artistic Licence; a copy of which may be found at the root
+?RCS: that same Artistic License; a copy of which may be found at the root
 ?RCS: of the source tree for dist 3.0.
 ?RCS:
 ?RCS: $Log: ccflags.U,v $
@@ -21,7 +21,7 @@
 ?RCS: patch54: now checks for cc/ccflags/ldflags coherency
 ?RCS:
 ?RCS: Revision 3.0.1.6  1994/10/29  16:07:02  ram
-?RCS: patch36: gcc versionning no longer relies on the C compiler's name
+?RCS: patch36: gcc versioning no longer relies on the C compiler's name
 ?RCS: patch36: simplified check for gcc version checking (ADO)
 ?RCS:
 ?RCS: Revision 3.0.1.5  1994/08/29  16:06:35  ram
@@ -33,7 +33,7 @@
 ?RCS: patch23: magically added cc flags now only done the first time
 ?RCS:
 ?RCS: Revision 3.0.1.3  1993/09/13  15:58:29  ram
-?RCS: patch10: explicitely mention -DDEBUG just in case they need it (WAD)
+?RCS: patch10: explicitly mention -DDEBUG just in case they need it (WAD)
 ?RCS: patch10: removed all the "tans" variable usage (WAD)
 ?RCS:
 ?RCS: Revision 3.0.1.2  1993/08/27  14:39:38  ram
 ?RCS: Revision 3.0  1993/08/18  12:05:31  ram
 ?RCS: Baseline for dist 3.0 netwide release.
 ?RCS:
-?MAKE:ccflags ldflags lkflags cppflags optimize locincpth: test cat \
+?MAKE:ccflags ldflags lkflags cppflags optimize locincpth: test cat osname \
        Myread Guess Options Oldconfig +gccversion mips_type +usrinc \
        package contains rm +cc cppstdin cppminus cpprun cpplast libpth \
-       libs loclibpth hint usesocks sh
+       libs loclibpth hint usesocks sh run rm_try sysroot
 ?MAKE: -pick add $@ %<
 ?S:ccflags:
 ?S:    This variable contains any additional C compiler flags desired by
 ?S:    local directories from the Configure command line.
 ?S:    It's not much, but it parallels the loclibpth stuff in libpth.U.
 ?S:.
-?T:inctest thisincl xxx flag inclwanted ftry previous thislibdir
+?T:inctest thisincl xxx inclwanted ftry previous thislibdir
+?T:EBUGGING DEBUGGING
+?T:check flag callback checkccflag
+?F:!cpp.c !gcctest !try
 ?D:cppflags=''
 ?D:ccflags=''
 ?D:ldflags=''
 ?D:optimize=''
-?F:!try
+?LINT:extern _sysroot
 ?INIT:: Possible local include directories to search.
 ?INIT:: Set locincpth to "" in a hint file to defeat local include searches.
 ?INIT:locincpth="/usr/local/include /opt/local/include /usr/gnu/include"
 ?INIT:: no include file wanted by default
 ?INIT:inclwanted=''
 ?INIT:
+?INIT:: Enable -DEBUGGING and -DDEBUGGING from the command line
+?INIT:EBUGGING=''
+?INIT:DEBUGGING=''
+?INIT:
 : determine optimization, if desired, or use for debug flag also
 ?X: Allow for Configure -Uoptimize -- it's not strictly sensible, but
 ?X: it has happened and we know what they mean.   AD  2/16/98
@@ -114,22 +121,80 @@ case "$optimize" in
 'none') optimize=" ";;
 esac
 
+: Check what DEBUGGING is required from the command line
+: -DEBUGGING      or -DDEBUGGING or
+: -DEBUGGING=both                      = -g + -DDEBUGGING
+: -DEBUGGING=-g   or -Doptimize=-g     = -g
+: -DEBUGGING=none or -UDEBUGGING       =
+: -DEBUGGING=old  or -DEBUGGING=default        = ? $optimize
+case "$EBUGGING" in
+'')    ;;
+*)     DEBUGGING=$EBUGGING ;;
+esac
+
+case "$DEBUGGING" in
+-g|both|$define)
+    case "$optimize" in
+       *-g*) ;;
+       *)    optimize="$optimize -g" ;;
+    esac ;;
+none|$undef)
+    case "$optimize" in
+       *-g*)   set `echo "X $optimize " | sed 's/ -g / /'`
+               shift
+               optimize="$*"
+               ;;
+    esac ;;
+esac
+
 dflt=''
+case "$DEBUGGING" in
+both|$define) dflt='-DDEBUGGING'
+esac
+
+: argument order is deliberate, as the flag will start with - which set could
+: think is an option
+checkccflag='check=$1; flag=$2; callback=$3;
+echo " ";
+echo "Checking if your compiler accepts $flag" 2>&1;
+[ "X$sysroot" != "X" ] && echo "For sysroot = $sysroot";
+echo "int main(void) { return 0; }" > gcctest.c;
+if $cc $_sysroot -O2 $flag -o gcctest gcctest.c 2>gcctest.out && $run ./gcctest; then
+    echo "Yes, it does." 2>&1;
+    if $test -s gcctest.out ; then
+        echo "But your platform does not like it:";
+        cat gcctest.out;
+    else
+       case "$ccflags" in
+       *$check*)
+           echo "Leaving current flags $ccflags alone." 2>&1
+           ;;
+       *) dflt="$dflt $flag";
+           eval $callback
+           ;;
+       esac
+    fi
+else
+    echo "Nope, it does not, but that is ok." 2>&1;
+fi
+'
+
 : We will not override a previous value, but we might want to
 : augment a hint file
 case "$hint" in
 default|recommended)
        case "$gccversion" in
-       1*) dflt='-fpcc-struct-return' ;;
+       1*) dflt="$dflt -fpcc-struct-return" ;;
        esac
-       case "$optimize" in
-       *-g*) dflt="$dflt -DDEBUGGING";;
+       case "$optimize:$DEBUGGING" in
+       *-g*:old) dflt="$dflt -DDEBUGGING";;
        esac
 ?X: check for POSIXized ISC
        case "$gccversion" in
-       2*) if test -d /etc/conf/kconfig.d &&
+       2*) if $test -d /etc/conf/kconfig.d &&
                        $contains _POSIX_VERSION $usrinc/sys/unistd.h >/dev/null 2>&1
                then
+                       # Interactive Systems (ISC) POSIX mode.
                        dflt="$dflt -posix"
                fi
                ;;
@@ -142,20 +207,44 @@ default|recommended)
        case "$gccversion" in
        1*) ;;
        2.[0-8]*) ;;
-       ?*)     echo " "
-               echo "Checking if your compiler accepts -fno-strict-aliasing" 2>&1
-               echo 'int main(void) { return 0; }' > gcctest.c
-               if $cc -O2 -fno-strict-aliasing -o gcctest gcctest.c; then
-                       echo "Yes, it does." 2>&1
-                       case "$ccflags" in
-                       *strict-aliasing*) 
-                               echo "Leaving current flags $ccflags alone." 2>&1
-                               ;;
-                       *) dflt="$dflt -fno-strict-aliasing" ;;
+       ?*)     set strict-aliasing -fno-strict-aliasing
+               eval $checkccflag
+               ;;
+       esac
+?X: HMB 200405
+?X: -pipe has shown a compile time speedup of about 40% on Linux and HP-UX
+?X: and also worked on cygwin-1.5.9
+?X: If a system fails, disable it in the hints. 99% of gcc uses binutils
+       # For gcc, adding -pipe speeds up compilations for some, but apparently
+       # some assemblers can't read from stdin.  (It also slows down compilations
+       # in other cases, but those are apparently rarer these days.)  AD 5/2004.
+       case "$gccversion" in
+       ?*)     set pipe -pipe
+               eval $checkccflag
+               ;;
+       esac
+
+?X: NWC 200712
+       # on x86_64 (at least) we require an extra library (libssp) in the
+       # link command line. This library is not named, so I infer that it is
+       # an implementation detail that may change. Hence the safest approach
+       # is to add the flag to the flags passed to the compiler at link time,
+       # as that way the compiler can do the right implementation dependant
+       # thing. (NWC)
+       case "$osname" in
+       amigaos) ;; # -fstack-protector builds but doesn't work
+       *)      case "$gccversion" in
+               ?*)     set stack-protector-strong -fstack-protector-strong
+                       eval $checkccflag
+                       case "$dflt" in
+                       *-fstack-protector-strong*) ;; # It got added.
+                       *) # Try the plain/older -fstack-protector.
+                          set stack-protector -fstack-protector
+                          eval $checkccflag
+                          ;;
                        esac
-               else
-                       echo "Nope, it doesn't, but that's ok." 2>&1
-               fi
+                       ;;
+               esac
                ;;
        esac
        ;;
@@ -170,8 +259,8 @@ for thisincl in $inclwanted; do
        if $test -d $thisincl; then
                if $test x$thisincl != x$usrinc; then
                        case "$dflt" in
-                        *" -I$thisincl "*);;
-                        *) dflt="$dflt -I$thisincl ";;
+                       *" -I$thisincl "*);;
+                       *) dflt="$dflt -I$thisincl ";;
                        esac
                fi
        fi
@@ -232,7 +321,10 @@ none) ccflags='';;
 esac
 
 : the following weeds options from ccflags that are of no interest to cpp
-cppflags="$ccflags"
+case "$cppflags" in
+'') cppflags="$ccflags" ;;
+*)  cppflags="$cppflags $ccflags" ;;
+esac
 case "$gccversion" in
 1*) cppflags="$cppflags -D__GNUC__"
 esac
@@ -301,12 +393,27 @@ case "$ldflags" in
        ;;
 *) dflt="$ldflags";;
 esac
+# See note above about -fstack-protector
+case "$ccflags" in
+*-fstack-protector-strong*)
+       case "$dflt" in
+       *-fstack-protector-strong*) ;; # Don't add it again
+       *) dflt="$dflt -fstack-protector-strong" ;;
+       esac
+       ;;
+*-fstack-protector*)
+       case "$dflt" in
+       *-fstack-protector*) ;; # Don't add it again
+       *) dflt="$dflt -fstack-protector" ;;
+       esac
+       ;;
+esac
 
 : Try to guess additional flags to pick up local libraries.
 for thislibdir in $libpth; do
        case " $loclibpth " in
        *" $thislibdir "*)
-               case "$dflt " in 
+               case "$dflt " in
                *"-L$thislibdir "*) ;;
                *)  dflt="$dflt -L$thislibdir" ;;
                esac
@@ -363,7 +470,7 @@ esac
 ?X: possible that the suggested ccflags/ldflags will be wrong.  Try to
 ?X: compile and run a simple test program.  Let the user see all the
 ?X: error messages. -- ADO and RAM
-?X: Sometimes, particularly on Linux systems, there is a bad library 
+?X: Sometimes, particularly on Linux systems, there is a bad library
 ?X: (e.g. a dangling symlink or incompatible library or a "run-time"
 ?X: version but not a "development" version of a library).  This test
 ?X: will catch those sorts of problems too, though how to fix them
@@ -374,7 +481,7 @@ echo " "
 echo "Checking your choice of C compiler and flags for coherency..." >&4
 $cat > try.c <<'EOF'
 #include <stdio.h>
-int main() { printf("Ok\n"); exit(0); }
+int main() { printf("Ok\n"); return(0); }
 EOF
 ?X: Strip extra blanks in case some of the following variables are empty
 set X $cc -o try $optimize $ccflags $ldflags try.c $libs
@@ -390,7 +497,7 @@ $cat >> try.msg <<EOM
 I used the command:
 
        $*
-       ./try
+       $run ./try
 
 and I got the following output:
 
@@ -400,31 +507,12 @@ dflt=y
 ?X: We need to try the resulting executable, because cc might yield a 0 status
 ?X: even when ld failed, in which case the executable will not run properly,
 ?X: if its x bit is set at all...
-?X:
-?X: Also check the xxx=`./try` output to check for misconfigured -lsfio.
-?X: If sfio's iffe goofed and it uses _exit instead of exit, then the
-?X: output buffers don't get flushed and we don't see any output
-?X: when run from within `backticks`.  What fun.  
-?X: --Andy Dougherty 2/13/1998
 if $sh -c "$cc -o try $optimize $ccflags $ldflags try.c $libs" >>try.msg 2>&1; then
-       if $sh -c './try' >>try.msg 2>&1; then
-               xxx=`./try`
+       if $sh -c "$run ./try " >>try.msg 2>&1; then
+               xxx=`$run ./try`
                case "$xxx" in
                "Ok") dflt=n ;;
-               *)      echo 'The program compiled OK, but produced no output.' >> try.msg
-                       case " $libs " in
-                       *" -lsfio "*)
-                               cat >> try.msg <<'EOQS'
-If $libs contains -lsfio, and sfio is mis-configured, then it
-sometimes (apparently) runs and exits with a 0 status, but with no
-output!  It may have to do with sfio's use of _exit vs. exit.
-
-EOQS
-                               rp="You have a big problem.  Shall I abort Configure"
-                               dflt=y
-                               ;;
-                       esac
-                       ;;
+               *)    echo 'The program compiled OK, but produced no output.' >> try.msg ;;
                esac
        else
                echo "The program compiled OK, but exited with status $?." >>try.msg
@@ -457,5 +545,5 @@ y)
        ;;
 n) echo "OK, that should do.";;
 esac
-$rm -f try try.* core
+$rm_try gcctest gcctest.out