?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 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 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 $ ?RCS: Revision 3.0.1.9 1997/02/28 15:27:07 ram ?RCS: patch61: removed support for NO_PROTOTYPE detection on SCO ?RCS: patch61: new locincpth variable ?RCS: patch61: added info on the "additional ld flags" question ?RCS: ?RCS: Revision 3.0.1.8 1995/07/25 13:48:54 ram ?RCS: patch56: re-arranged compile line to include ldflags before objects ?RCS: ?RCS: Revision 3.0.1.7 1995/05/12 12:08:33 ram ?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 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 ?RCS: patch32: propagate -posix flag from ccflags to ldflags ?RCS: ?RCS: Revision 3.0.1.4 1994/05/06 14:28:45 ram ?RCS: patch23: -fpcc-struct-return only needed in gcc 1.x (ADO) ?RCS: patch23: cppflags now computed on an option-by-option basis ?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: 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: patch7: added support for OSF/1 machines ?RCS: ?RCS: Revision 3.0.1.1 1993/08/25 14:00:24 ram ?RCS: patch6: added defaults for cppflags, ccflags and ldflags ?RCS: ?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 osname \ Myread Guess Options Oldconfig +gccversion mips_type +usrinc \ package contains rm +cc cppstdin cppminus cpprun cpplast libpth \ 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: the user. It is up to the Makefile to use this. ?S:. ?S:cppflags: ?S: This variable holds the flags that will be passed to the C pre- ?S: processor. It is up to the Makefile to use it. ?S:. ?S:optimize: ?S: This variable contains any optimizer/debugger flag that should be used. ?S: It is up to the Makefile to use it. ?S:. ?S:ldflags: ?S: This variable contains any additional C loader flags desired by ?S: the user. It is up to the Makefile to use this. ?S:. ?S:lkflags: ?S: This variable contains any additional C partial linker flags desired by ?S: the user. It is up to the Makefile to use this. ?S:. ?S:locincpth: ?S: This variable contains a list of additional directories to be ?S: searched by the compiler. The appropriate '-I' directives will ?S: be added to ccflags. This is intended to simplify setting ?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 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='' ?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:locincpth="$locincpth /opt/gnu/include /usr/GNU/include /opt/GNU/include" ?INIT:: ?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 case "$optimize" in ' '|$undef) dflt='none';; '') dflt='-O';; *) dflt="$optimize";; esac $cat </dev/null 2>&1 then # Interactive Systems (ISC) POSIX mode. dflt="$dflt -posix" fi ;; esac ?X: If the user has gcc-2.95 or greater, try adding -fno-strict-alias. ?X: Since the gcc "version" can be non-numeric, e.g. ?X: "2.95.1 19990809 (prerelease)" , we'll do the test on any version ?X: greater than 2.8. ?X: --Andy Dougherty 27 Aug 1999 case "$gccversion" in 1*) ;; 2.[0-8]*) ;; ?*) 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 ;; esac ;; esac ;; esac ?X: In USG mode, a MIPS system may need some BSD includes case "$mips_type" in *BSD*|'') inclwanted="$locincpth $usrinc";; *) inclwanted="$locincpth $inclwanted $usrinc/bsd";; esac 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 ";; esac fi fi done ?X: Include test function (header, symbol) inctest='if $contains $2 $usrinc/$1 >/dev/null 2>&1; then xxx=true; elif $contains $2 $usrinc/sys/$1 >/dev/null 2>&1; then xxx=true; else xxx=false; fi; if $xxx; then case "$dflt" in *$2*);; *) dflt="$dflt -D$2";; esac; fi' set signal.h LANGUAGE_C; eval $inctest case "$usesocks" in $define) ccflags="$ccflags -DSOCKS" ;; esac case "$hint" in default|recommended) dflt="$ccflags $dflt" ;; *) dflt="$ccflags";; esac case "$dflt" in ''|' ') dflt=none;; esac $cat <&4 set X $cppflags shift cppflags='' $cat >cpp.c <<'EOM' #define BLURFL foo BLURFL xx LFRULB EOM ?X: ?X: For each cc flag, try it out with both cppstdin and cpprun, since the ?X: first is almost surely a cc wrapper. We have to try both in case ?X: of cc flags like '-Olimit 2900' that are actually two words... ?X: previous='' for flag in $* do case "$flag" in -*) ftry="$flag";; *) ftry="$previous $flag";; esac if $cppstdin -DLFRULB=bar $cppflags $ftry $cppminus cpp1.out 2>/dev/null && \ $cpprun -DLFRULB=bar $cppflags $ftry $cpplast cpp2.out 2>/dev/null && \ $contains 'foo.*xx.*bar' cpp1.out >/dev/null 2>&1 && \ $contains 'foo.*xx.*bar' cpp2.out >/dev/null 2>&1 then cppflags="$cppflags $ftry" previous='' else previous="$flag" fi done set X $cppflags shift cppflags=${1+"$@"} case "$cppflags" in *-*) echo "They appear to be: $cppflags";; esac $rm -f cpp.c cpp?.out ;; esac : flags used in final linking phase case "$ldflags" in '') if ./venix; then dflt='-i -z' else dflt='' fi case "$ccflags" in *-posix*) dflt="$dflt -posix" ;; esac ;; *) 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 *"-L$thislibdir "*) ;; *) dflt="$dflt -L$thislibdir" ;; esac ;; esac done case "$dflt" in '') dflt='none' ;; esac $cat <&4 $cat > try.c <<'EOF' #include 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 shift $cat >try.msg <<'EOM' I've tried to compile and run the following simple program: EOM $cat try.c >> try.msg $cat >> try.msg <>try.msg 2>&1; then 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 ;; esac else echo "The program compiled OK, but exited with status $?." >>try.msg rp="You have a problem. Shall I abort Configure" dflt=y fi else echo "I can't compile the test program." >>try.msg rp="You have a BIG problem. Shall I abort Configure" dflt=y fi case "$dflt" in y) $cat try.msg >&4 ?X: using -K will prevent default aborting--maybe they're cross compiling? case "$knowitall" in '') echo "(The supplied flags or libraries might be incorrect.)" ;; *) dflt=n;; esac echo " " . ./myread case "$ans" in n*|N*) ;; *) echo "Ok. Stopping Configure." >&4 exit 1 ;; esac ;; n) echo "OK, that should do.";; esac $rm_try gcctest gcctest.out