ch03s05.html 4.0 KB

123456789101112131415161718192021222324252627282930
  1. <html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>Stand-alone Compiling on GNU/Linux</title><meta name="generator" content="DocBook XSL Stylesheets V1.76.1"><meta name="keywords" content="Intellon, Atheros, Qualcomm, HomePlug, powerline, communications, INT6000, INT6300, INT6400, AR7400, AR7420"><link rel="home" href="index.html" title="Qualcomm Atheros Open Powerline Toolkit"><link rel="up" href="ch03.html" title="Chapter 3.  Software"><link rel="prev" href="ch03s04.html" title="GNU Makefiles on Linux"><link rel="next" href="ch03s06.html" title="Cross-Compiling on GNU/Linux"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">
  2. Stand-alone Compiling on GNU/Linux
  3. </th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ch03s04.html">Prev</a> </td><th width="60%" align="center">Chapter 3. 
  4. Software
  5. </th><td width="20%" align="right"> <a accesskey="n" href="ch03s06.html">Next</a></td></tr></table><hr></div><div class="section" title="Stand-alone Compiling on GNU/Linux"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="software-stand-alone"></a>
  6. Stand-alone Compiling on GNU/Linux
  7. </h2></div></div></div><p>
  8. You do not need makefiles to build toolkit programs because source files explicitly include all required components using <span class="command"><strong>include</strong></span> statement blocks like that shown below. You will see similar blocks near the top of most programs.
  9. </p><div class="example"><a name="idp20823088"></a><p class="title"><b>Example 3.1. 
  10. The <code class="constant">MAKEFILE</code> constant
  11. </b></p><div class="example-contents"><pre class="programlisting">
  12. #ifndef MAKEFILE
  13. #include "../tools/getoptv.c"
  14. #include "../tools/putoptv.c"
  15. #include "../tools/version.c"
  16. ...
  17. #endif
  18. </pre></div></div><br class="example-break"><p>
  19. This mechanism has several advantages. First, the preprocessor <strong class="userinput"><code>include</code></strong> statements form a complete inventory of required files. Secondly, the relative pathnames help developers locate needed source files. Third, the complete program can be compiled with one <span class="command"><strong>gcc</strong></span> command, like the one shown below. This allows program compilation in environments where the <span class="application">GNU make</span> program or the Atheros <code class="filename">Makefiles</code> are not available.
  20. </p><div class="example"><a name="idp20826160"></a><p class="title"><b>Example 3.2. 
  21. Stand-alone Compiling on GNU/Linux
  22. </b></p><div class="example-contents"><pre class="screen">
  23. # gcc -o program program.c
  24. </pre></div></div><br class="example-break"><p>
  25. Most toolkit makefiles define the preprocessor constant <code class="constant">MAKEFILE</code> as a compiler option using <strong class="userinput"><code>CFLAGS= ... -DMAKEFILE ...</code></strong>. When this constant is defined, the compiler will not include components inside an include block like that shown above and so the <code class="filename">Makefile</code> is responsible for compiling and linking all components. If the constant is not defined, because no <code class="filename">Makefile</code> was used, the compiler will merely include everything needed.
  26. </p></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ch03s04.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="ch03.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="ch03s06.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">
  27. GNU Makefiles on Linux
  28.  </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 
  29. Cross-Compiling on GNU/Linux
  30. </td></tr></table></div></body></html>