Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
96 views
in Technique[技术] by (71.8m points)

makefiles CFLAGS

In the process of learning tinyos I have discovered that I am totally clueless about makefiles.

There are many optional compile time features that can be used by way of declaring preprocessor variables.

To use them you have to do things like:

CFLAGS="-DPACKET_LINK" this enables a certain feature.

and

CFLAGS="-DPACKET_LINK" "-DLOW_POWER" enables two features.

Can someone dissect these lines for me and tell me whats going on? Not in terms of tinyos, but in terms of makefiles!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

CFLAGS is a variable that is most commonly used to add arguments to the compiler. In this case, it define macros.

So the -DPACKET_LINK is the equivalent of putting #define PACKET_LINK 1 at the top of all .c and .h files in your project. Most likely, you have code inside your project that looks if these macros are defined and does something depending on that:

#ifdef PACKET_LINK
// This code will be ignored if PACKET_LINK is not defined
do_packet_link_stuff();
#endif

#ifdef LOW_POWER
// This code will be ignored if LOW_POWER is not defined    
handle_powersaving_functions();
#endif

If you look further down in your makefile, you should see that $(CFLAGS) is probably used like:

$(CC) $(CFLAGS) ...some-more-arguments...

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...