This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: What options should be set in Make variables CFLAGS, CXXFLAGS, CPPFLAGS and LDFLAGS?


On Thu, Jan 24, 2019 at 12:31 PM Paul Smith <psmith@gnu.org> wrote:
>
> On Thu, 2019-01-24 at 12:10 -0600, Peng Yu wrote:
> > So only the following in the gcc manual go to CPPFLAGS. All other
> > options go to other GNU Make variables.
> >
> >   Preprocessor Options
> >        -Aquestion=answer -A-question[=answer] -C  -dD  -dI  -dM  -dN
> >        -Dmacro[=defn]  -E  -H -idirafter dir -include file  -imacros file
> >        -iprefix file  -iwithprefix dir -iwithprefixbefore dir  -isystem
> >        dir -imultilib dir -isysroot dir -M  -MM  -MF  -MG  -MP  -MQ  -MT
> >        -nostdinc -P  -fdebug-cpp -ftrack-macro-expansion
> >        -fworking-directory -remap -trigraphs  -undef  -Umacro -Wp,option
> >        -Xpreprocessor option -no-integrated-cpp
>
> I don't think you can really make that statement: it depends on your
> environment.
>
> As I said, one idea behind using a separate variable is that there may
> be other tools that you want to use which also take preprocessor
> arguments.  It's not uncommon (or at least was not in the past) for
> other tools to use the preprocessor to process source code for other
> reasons than compilation; those other tools would need the -I and -D
> options (and -U although that's rarely used).  However, most of the
> less standard flags above will not be recognized by most of these other
> tools and could cause them to throw errors.
>
> There's no one-size-fits-all definition, IMO.  The answer to all your
> questions is, "it depends on what you want to do".  If you have no
> reason to ever use the preprocessor separately maybe you don't need a
> separate CPPFLAGS at all.
>
> There's just a general rule-of-thumb:
>  * preprocessor options go into CPPFLAGS
>  * options that can be used with BOTH C compilers and C linkers go into
>    CFLAGS
>  * options that can be used with BOTH C++ compilers and C++ linkers go
>    into CXXFLAGS
>  * options that can be used ONLY with linkers, but not compilers, go
>    into LDFLAGS, except -l which goes into LDLIBS.
>
> Is there a particular reason you want to be so precise about this?

There is quite a confusion about how to use make variables. Different
sources give different bits of advice. I'd like to make it clear about
it.

-- 
Regards,
Peng


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]