Sophie

Sophie

distrib > Mageia > 7 > armv7hl > media > core-release > by-pkgid > f62edf6ed1ee9c12d8142f1e16d0986e > files > 185

bakefile-0.2.11-1.mga7.armv7hl.rpm

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>Chapter 2. Tutorial</title><link rel="stylesheet" type="text/css" href="style.css" /><meta name="generator" content="DocBook XSL Stylesheets V1.79.1" /><link rel="home" href="index.html" title="Bakefile Manual" /><link rel="up" href="index.html" title="Bakefile Manual" /><link rel="prev" href="ch01.html" title="Chapter 1. Introduction" /><link rel="next" href="ch03.html" title="Chapter 3. Bakefile Concepts" /></head><body><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Chapter 2. Tutorial</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ch01.html">Prev</a> </td><th width="60%" align="center"> </th><td width="20%" align="right"> <a accesskey="n" href="ch03.html">Next</a></td></tr></table><hr /></div><div class="chapter"><div class="titlepage"><div><div><h1 class="title"><a id="ch.tutorial"></a>Chapter 2. Tutorial</h1></div></div></div><div class="toc"><p><strong>Table of Contents</strong></p><dl class="toc"><dt><span class="section"><a href="ch02.html#sec.helloworld">Hello, world</a></span></dt></dl></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="sec.helloworld"></a>Hello, world</h2></div></div></div><p>
      By far the simplest way to generate makefiles using Bakefile is
      to use so-called <a class="link" href="ch03.html#concept.preset" title="Presets">presets</a>
      which are prepared skeletons of bakefiles that get you
      started quickly. Let's see how it works on an example of
      the famous <span class="emphasis"><em>Hello, world</em></span> program written
      in C and implemented in the <code class="filename">hello.c</code> file:
      </p><pre class="programlisting">
#include &lt;stdio.h&gt;

int main()
{
  printf("Hello, world!\n");
  return 0;
}
</pre><p>
    </p><p>
      The bakefile needed to compile it,<code class="filename">hello.bkl</code>,
      looks like this:
      </p><pre class="programlisting">
&lt;?xml version="1.0"?&gt;
&lt;makefile&gt;

  &lt;include file="presets/simple.bkl"/&gt;
  
  &lt;exe id="hello" template="simple"&gt;
    &lt;sources&gt;hello.c&lt;/sources&gt;
  &lt;/exe&gt;

&lt;/makefile&gt;
</pre><p>
    </p><p>
      Presets are included using the <a class="xref" href="ch05.html#cmd.include" title="include">include</a>
      directive. The structure of the file name is always the same:
      <code class="filename">presets/NAME-OF-PRESET.bkl</code>. In general,
      you can combine several presets, but in practice you must
      be careful when doing so. It's always a good idea to read
      the code for the preset before using it.  The "simple"
      preset we include here defines a <code class="varname">DEBUG</code>
      <a class="link" href="ch03.html#concept.option" title="Options">option</a> and a
      <a class="link" href="ch03.html#concept.template" title="Templates">template</a> called
      <code class="literal">simple</code>. Generated makefiles will allow the
      user to build all targets that are based on this template as
      either debug or release build.
    </p><p>
      Let's generate some makefiles now. The <span class="command"><strong>bakefile</strong></span>
      command is used to do it. For example:
    </p><p>
      <code class="prompt">$ </code>
      <strong class="userinput"><code>bakefile -f msvc hello.bkl</code></strong>
    </p><p>
      That's all.
      This will creates VC++ makefile <code class="filename">makefile.vc</code>. Of
      course, you can change the name of output file if you don't like the
      default:
    </p><p>
      <code class="prompt">$ </code>
      <strong class="userinput"><code>bakefile -f msvc -o makefile hello.bkl</code></strong>
    </p><p>
      Bakefile will also generate the <code class="filename">Makefile.in</code> files
      used by 
      <a class="ulink" href="http://www.gnu.org/software/autoconf/" target="_top">Autoconf</a>:
    </p><p>
      <code class="prompt">$ </code>
      <strong class="userinput"><code>bakefile -f autoconf hello.bkl</code></strong>
    </p><p>
  	  These are templates for makefiles. Autoconf also requires
      a <code class="filename">configure.ac</code> script (previously,
  	  <code class="filename">configure.in</code>), but Bakefile will not
  	  generate this for you. This script checks for platform
      features necessary to build the program; see the autoconf
  	  manual for details.
    </p><p>
      When producing autoconf format output, Bakefile will also generate a file
      called <code class="filename">autoconf_inc.m4</code> which defines macros needed
      by the generated Makefile.in files. To use this, call the
      <code class="literal">AC_BAKEFILE</code> macro within your
	    <code class="filename">configure.ac</code> script.
  	</p><p>
  	  A minimal <code class="filename">configure.ac</code> script for our
  	  example program would look like this:
      </p><pre class="programlisting">
AC_PREREQ(2.53)
AC_INIT([hello], [1.0], [author@example.com])
dnl pass some unique file file to AC_CONFIG_SRCDIR
AC_CONFIG_SRCDIR([autoconf_inc.m4])
AC_CANONICAL_HOST
DEBUG=0
AC_BAKEFILE([m4_include(autoconf_inc.m4)])
AC_CONFIG_FILES([Makefile])
AC_OUTPUT
</pre><p>
    </p><p>
      Note the part that sets the <code class="varname">DEBUG</code> variable. Any
	    options declared in your bakefile must be set to some default
  	  value before calling <code class="literal">AC_BAKEFILE</code>. The
  	  simple.bkl preset defines the <code class="varname">DEBUG</code> option,
  	  so we have to give it a default value here.
	  </p><p>
      While the above code will work, there's a better way to handle the
  	  debug option:
      </p><pre class="programlisting">
AC_PREREQ(2.53)
AC_INIT([hello], [1.0], [author@example.com])
dnl pass some unique file file to AC_CONFIG_SRCDIR
AC_CONFIG_SRCDIR([autoconf_inc.m4])
AC_CANONICAL_HOST

AC_ARG_ENABLE(debug,
              [  --enable-debug          Enable debugging information],
              USE_DEBUG="$enableval", USE_DEBUG="no")

if test $USE_DEBUG = yes ; then 
  DEBUG=1
  dnl Bakefile doesn't touch {C,CPP,CXX,LD}FLAGS in autoconf format, we
  dnl have to do it ourselves. This will work with many compilers
  dnl (but not all, proper configure script would check if the compiler
  dnl supports it):
  CFLAGS="$CFLAGS -g"
else
  DEBUG=0
fi

AC_BAKEFILE([m4_include(autoconf_inc.m4)])
AC_CONFIG_FILES([Makefile])
AC_OUTPUT
</pre><p>
    </p><p>
      You are ready to generate Autoconf's <code class="filename">configure</code>
      script now:
    </p><p>
      <code class="prompt">$ </code>
      <strong class="userinput"><code>
        bakefilize --copy &amp;&amp; aclocal &amp;&amp; autoconf
      </code></strong>
    </p></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ch01.html">Prev</a> </td><td width="20%" align="center"> </td><td width="40%" align="right"> <a accesskey="n" href="ch03.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 1. Introduction </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> Chapter 3. Bakefile Concepts</td></tr></table></div></body></html>