autoconf-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: meaning of CFLAGS


From: Paul Eggert
Subject: Re: meaning of CFLAGS
Date: Thu, 20 Jul 2006 14:29:23 -0700
User-agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/21.4 (gnu/linux)

Bruno Haible <address@hidden> writes:

> A user on Solaris/x86_64 tried to use
>
>    CC=cc CFLAGS=-xarch=amd64
>
> and it didn't work with my Makefile.in. Is the user supposed to use such
> setting? Or does he need to use
>
>    CC="cc -xarch=amd64"

It is a messy area, I'm afraid.  In this case CFLAGS is definitely
wrong, though, since the -xarch option also affects the preprocessor:

   $ printf '#include <limits.h>\n"LONG_MAX equals" LONG_MAX\n' >t.c
   $ cc -E -xarch=v9 t.c | grep LONG_MAX
   "LONG_MAX equals"  9223372036854775807L
   $ cc -E t.c | grep LONG_MAX
   "LONG_MAX equals"  2147483647L

and CFLAGS is not passed to preprocessor-only invocations.  In
retrospect this was probably a bad design decision, but changing this
will be painful.

I installed the following patch into the Autoconf documentation to try
to explain things better.

2006-07-20  Paul Eggert  <address@hidden>

        * doc/autoconf.texi (Preset Output Variables): Document CFLAGS,
        CPPFLAGS, and LDFLAGS better.  Problem reported by Bruno Haible.
        Similarly for CXXFLAGS, OBJCFLAGS, ERLCFLAGS.

--- autoconf.texi       17 Jul 2006 16:15:34 -0000      1.1061
+++ autoconf.texi       20 Jul 2006 21:21:14 -0000      1.1063
@@ -2228,7 +2228,18 @@ precious variables (@pxref{Setting Outpu
 Debugging and optimization options for the C compiler.  If it is not set
 in the environment when @command{configure} runs, the default value is set
 when you call @code{AC_PROG_CC} (or empty if you don't).  @command{configure}
-uses this variable when compiling programs to test for C features.
+uses this variable when compiling or linking programs to test for C features.
+
+If a compiler option affects only the behavior of the preprocessor
+(e.g., @option{-D @var{name}}), it should be put into @code{CPPFLAGS}
+instead.  If it affects only the linker (e.g., @option{-L
address@hidden), it should be put into @code{LDFLAGS} instead.  If it
+affects only the compiler proper, @code{CFLAGS} is the natural home for
+it.  If an option affects multiple phases of the compiler, though,
+matters get tricky.  One approach to put such options directly into
address@hidden, e.g., @code{CC='gcc -m64'}.  Another is to put them into both
address@hidden and @code{LDFLAGS}, but not into @code{CFLAGS}.
+
 @end defvar
 
 @defvar configure_input
@@ -2252,22 +2263,32 @@ needs to be processed by @command{config
 
 @defvar CPPFLAGS
 @ovindex CPPFLAGS
-Header file search directory (@address@hidden) and any other
-miscellaneous options for the C and C++ preprocessors and compilers.  If
+Preprocessor options for the C, C++, and Objective C preprocessors and
+compilers.  If
 it is not set in the environment when @command{configure} runs, the default
-value is empty.  @command{configure} uses this variable when compiling or
-preprocessing programs to test for C and C++ features.
+value is empty.  @command{configure} uses this variable when preprocessing
+or compiling programs to test for C, C++, and Objective C features.
+
+This variable's contents should contain options like @option{-I},
address@hidden, and @option{-U} that affect only the behavior of the
+preprocessor.  Please see the explanation of @code{CFLAGS} for what you
+can do if an option affects other phases of the compiler as well.
+
+Currently, @command{configure} always links as part of a single
+invocation of the compiler that also preprocesses and compiles, so it
+uses this variable also when linking programs.  However, it is unwise to
+depend on this behavior because the @acronym{GNU} coding standards do
+not require it and many packages do not use @code{CPPFLAGS} when linking
+programs.
+
 @xref{Special Chars in Variables}, for limitations that @code{CPPFLAGS}
 might run into.
 @end defvar
 
 @defvar CXXFLAGS
 @ovindex CXXFLAGS
-Debugging and optimization options for the C++ compiler.  If it is not
-set in the environment when @command{configure} runs, the default value is
-set when you call @code{AC_PROG_CXX} (or empty if you don't).
address@hidden uses this variable when compiling programs to test for
-C++ features.
+Debugging and optimization options for the C++ compiler.  It acts like
address@hidden, but for C++ instead of C.
 @end defvar
 
 @defvar DEFS
@@ -2305,8 +2326,8 @@ want to use it.
 @ovindex ERLCFLAGS
 Debugging and optimization options for the Erlang compiler.  If it is not set
 in the environment when @command{configure} runs, the default value is empty.
address@hidden uses this variable when compiling programs to test for
-Erlang features.
address@hidden uses this variable when compiling
+programs to test for Erlang features.
 @end defvar
 
 @defvar FCFLAGS
@@ -2314,8 +2335,8 @@ Erlang features.
 Debugging and optimization options for the Fortran compiler.  If it
 is not set in the environment when @command{configure} runs, the default
 value is set when you call @code{AC_PROG_FC} (or empty if you don't).
address@hidden uses this variable when compiling programs to test for
-Fortran features.
address@hidden uses this variable when compiling or linking
+programs to test for Fortran features.
 @end defvar
 
 @defvar FFLAGS
@@ -2323,18 +2344,24 @@ Fortran features.
 Debugging and optimization options for the Fortran 77 compiler.  If it
 is not set in the environment when @command{configure} runs, the default
 value is set when you call @code{AC_PROG_F77} (or empty if you don't).
address@hidden uses this variable when compiling programs to test for
-Fortran 77 features.
address@hidden uses this variable when compiling or linking
+programs to test for Fortran 77 features.
 @end defvar
 
 @defvar LDFLAGS
 @ovindex LDFLAGS
-Stripping (@option{-s}), path (@option{-L}), and any other miscellaneous
-options for the linker.  Don't use this variable to pass library names
-(@option{-l}) to the linker, use @code{LIBS} instead.  If it is not set
+Options for the linker.  If it is not set
 in the environment when @command{configure} runs, the default value is empty.
 @command{configure} uses this variable when linking programs to test for
-C, C++, and Fortran features.
+C, C++, Objective C, and Fortran features.
+
+This variable's contents should contain options like @option{-s} and
address@hidden that affect only the behavior of the linker.  Please see the
+explanation of @code{CFLAGS} for what you can do if an option also
+affects other phases of the compiler.
+
+Don't use this variable to pass library names
+(@option{-l}) to the linker; use @code{LIBS} instead.
 @end defvar
 
 @defvar LIBS
@@ -2348,11 +2375,8 @@ programs to test for C, C++, and Fortran
 
 @defvar OBJCFLAGS
 @ovindex OBJCFLAGS
-Debugging and optimization options for the Objective C compiler.  If it is
-not set in the environment when @command{configure} runs, the default value
-is set when you call @code{AC_PROG_OBJC} (or empty if you don't).
address@hidden uses this variable when compiling programs to test for
-Objective C features.
+Debugging and optimization options for the Objective C compiler.  It
+acts like @code{CFLAGS}, but for Objective C instead of C.
 @end defvar
 
 @defvar builddir
@@ -7979,7 +8003,7 @@ Erlang tests must exit themselves the Er
 function: the given status code is used to determine the success of the test
 (status is @code{0}) or its failure (status is different than @code{0}), as
 explained above.  It must be noted that data output through the standard output
-(e.g. using @code{io:format/2}) may be truncated when halting the VM.
+(e.g., using @code{io:format/2}) may be truncated when halting the VM.
 Therefore, if a test must output configuration information, it is recommended
 to create and to output data into the temporary file named @file{conftest.out},
 using the functions of module @code{file}.  The @code{conftest.out} file is




reply via email to

[Prev in Thread] Current Thread [Next in Thread]