<p>In the process of learning <a href="https://en.wikipedia.org/wiki/TinyOS" rel="nofollow noreferrer">TinyOS</a> I have discovered that I am totally clueless about makefiles.</p>
<p>There are many optional compile time features that can be used by way of declaring preprocessor variables.</p>
<p>To use them you have to do things like:</p>
<p><code>CFLAGS=&quot;-DPACKET_LINK&quot;</code>        this enables a certain feature.</p>
<p>and</p>
<p><code>CFLAGS=&quot;-DPACKET_LINK&quot; &quot;-DLOW_POWER&quot;</code> enables two features.</p>
<p>Can someone dissect these lines for me and tell me whats going on? Not in terms of TinyOS, but in terms of makefiles!</p>

[{'answer_id': 80689, 'author': 'Ilya', 'author_id': 6807, 'author_profile': 'https://Stackoverflow.com/users/6807', 'pm_score': 3, 'selected': False, 'text': '<p>Somewhere in the makefile the CFLAG will be used in compilation line like this:<br>\n<code>$(CC) $(CFLAGS) $(C_INCLUDES) $&lt;</code></p>\n\n<p>and eventually in the execution will be translated to : </p>\n\n<p><code>gcc -DPACKET_LINK -DLOW_POWER -c filename.c -o filename.o</code></p>\n\n<p>This define will be passed to the source code as it was define in the header file </p>\n'}, {'answer_id': 80698, 'author': 'Isak Savo', 'author_id': 8521, 'author_profile': 'https://Stackoverflow.com/users/8521', 'pm_score': 5, 'selected': False, 'text': '<p>CFLAGS is a variable that is most commonly used to add arguments to the compiler. In this case, it define macros. </p>\n\n<p>So the <code>-DPACKET_LINK</code> is the equivalent of putting <code>#define PACKET_LINK 1</code> 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:</p>\n\n<pre><code>#ifdef PACKET_LINK\n// This code will be ignored if PACKET_LINK is not defined\ndo_packet_link_stuff();\n#endif\n\n#ifdef LOW_POWER\n// This code will be ignored if LOW_POWER is not defined    \nhandle_powersaving_functions();\n#endif\n</code></pre>\n\n<p>If you look further down in your makefile, you should see that <code>$(CFLAGS)</code> is probably used like:</p>\n\n<pre><code>$(CC) $(CFLAGS) ...some-more-arguments...\n</code></pre>\n'}, {'answer_id': 80710, 'author': 'Flame', 'author_id': 5387, 'author_profile': 'https://Stackoverflow.com/users/5387', 'pm_score': 1, 'selected': False, 'text': '<p>-D stands for <em>define</em> (in gcc) at least, which lets you #define on the command line instead of a file somewhere. A common thing to see would be -DDEBUG or -DNDEBUG which respectively activate or disable debugging code.</p>\n'}, {'answer_id': 80717, 'author': 'Jonas Engström', 'author_id': 7634, 'author_profile': 'https://Stackoverflow.com/users/7634', 'pm_score': 2, 'selected': False, 'text': '<p>The -D option set pre-processor variables, so in your case, all code that is in the specified "#ifdef / #endif" blocks will be compiled.</p>\n\n<p>I.e.</p>\n\n<pre><code>#ifdef PACKET_LINK\n/* whatever code here */\n#endif\n</code></pre>\n\n<p>The CFLAGS is a variable used in the makefile which will be expanded to it\'s contents when the compiler is invoked.</p>\n\n<p>E.g.</p>\n\n<pre><code>gcc $(CFLAGS) source.c\n</code></pre>\n'}, {'answer_id': 80880, 'author': 'Michael Burr', 'author_id': 12711, 'author_profile': 'https://Stackoverflow.com/users/12711', 'pm_score': 1, 'selected': False, 'text': "<p>Just for completeness in this - if you're using Microsoft's nmake utility, you might not actually see the $(CFLAGS) macro used in the makefile because nmake has some defaults for things like compiling C/C++ files.  Among others, the following are pre-defined in nmake (I'm not sure if GNU Make does anything like this), so you might not see it in a working makefile on Windows:</p>\n\n<pre><code>.c.exe:\n    commands:          $(CC) $(CFLAGS) $&lt;\n\n.c.obj:\n    commands:          $(CC) $(CFLAGS) /c $&lt;\n\n.cpp.exe:\n    commands:          $(CXX) $(CXXFLAGS) $&lt;\n\n.cpp.obj:\n    commands:          $(CXX) $(CXXFLAGS) /c $&lt;\n</code></pre>\n"}]
['https://Stackoverflow.com/questions/80657', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/-1/']