<html>
<head>
    <base href="https://wiki.asterisk.org/wiki">
            <link rel="stylesheet" href="/wiki/s/2041/1/7/_/styles/combined.css?spaceKey=AST&amp;forWysiwyg=true" type="text/css">
    </head>
<body style="background: white;" bgcolor="white" class="email-body">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
    <h2><a href="https://wiki.asterisk.org/wiki/display/AST/Build+System+Architecture">Build System Architecture</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://wiki.asterisk.org/wiki/display/~russell">Russell Bryant</a>
    </h4>
        <br/>
                         <h4>Changes (4)</h4>
                                 
    
<div id="page-diffs">
                    <table class="diff" cellpadding="0" cellspacing="0">
    
            <tr><td class="diff-added-lines" style="background-color: #dfd;">{numberedheadings} <br> <br>{toc} <br> <br></td></tr>
            <tr><td class="diff-unchanged" >h1. Build Architecture <br> <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >The sources are split in multiple directories, more or less divided by module type (apps/ channels/ funcs/ res/ ...) or by function, for the main binary (main/ pbx/). <br> <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">{warning} <br>This section is not complete... <br>{warning} <br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">TO BE COMPLETED <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">h1. Adding new modules <br> <br>h2. Modules with no dependencies <br> <br>If your module has no dependencies on external libraries, it can be dropped into the appropriate directory and the build system will automatically detect it and build it for you.  For example, if you write {{app_custom.c}}, drop it in the {{apps/}} directory. <br> <br>h2. Modules with dependencies <br> <br>If your module has an external dependency, you have a bit more work to do to integrate it into the build system.  First, you must determine whether the library you are using is used by any other Asterisk module.  If not, you must add the library to the following files. <br> <br>h3. {{configure.ac}} <br> <br>This is the source of the configure script.  There are _many_ examples to draw from in this file.  Search for the two instances of {{ALSA}} in this file to find one of the simpler examples of checking for a library. <br> <br>h3. {{build_tools/menuselect-deps.in}} <br> <br>Add a line in this file for your new library.  The configure script uses this file as input and outputs build_tools/menuselect-deps.  The {{menuselect}} utility reads in this file to know which libraries have been found on the system. <br> <br>h3. {{makeopts.in}} <br> <br>Add {{LIBNAME_LIB}} and {{LIBNAME_INCLUDE}} lines into this file.  The configure script will use this file as input and output the {{makeopts}} file.  When this library is found, these lines will have the appropriate {{CFLAGS}} and {{LDFLAGS}} needed to build and link a module with the library.  Follow the other examples that are already in this file for formatting. <br> <br>h3. Update your module <br> <br>Modules that have a dependency must have a special comment block in them that is used by the build system. <br> <br>{code} <br>/*** MODULEINFO <br>        &lt;depend&gt;libname&lt;/depend&gt; <br> ***/ <br>{code} <br> <br>{numberedheadings} <br></td></tr>
    
            </table>
    </div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        

<div>
<ul>
    <li><a href='#BuildSystemArchitecture-BuildArchitecture'>1. Build Architecture</a></li>
    <li><a href='#BuildSystemArchitecture-Addingnewmodules'>2. Adding new modules</a></li>
<ul>
    <li><a href='#BuildSystemArchitecture-Moduleswithnodependencies'>2.1. Modules with no dependencies</a></li>
    <li><a href='#BuildSystemArchitecture-Moduleswithdependencies'>2.2. Modules with dependencies</a></li>
<ul>
    <li><a href='#BuildSystemArchitecture-%7B%7Bconfigure.ac%7D%7D'>2.2.1. <tt>configure.ac</tt></a></li>
    <li><a href='#BuildSystemArchitecture-%7B%7Bbuildtools%2Fmenuselectdeps.in%7D%7D'>2.2.2. <tt>build_tools/menuselect-deps.in</tt></a></li>
    <li><a href='#BuildSystemArchitecture-%7B%7Bmakeopts.in%7D%7D'>2.2.3. <tt>makeopts.in</tt></a></li>
    <li><a href='#BuildSystemArchitecture-Updateyourmodule'>2.2.4. Update your module</a></li>
</ul>
</ul>
</ul></div>

<h1><a name="BuildSystemArchitecture-BuildArchitecture"></a>1. Build Architecture</h1>

<p>The asterisk build architecture relies on autoconf to detect the system configuration, and on a locally developed tool (menuselect) to select build options and modules list, and on gmake to do the build.</p>

<p>The first step, usually to be done soon after a checkout, is running "./configure", which will store its findings in two files:</p>

<ul>
        <li>include/asterisk/autoconfig.h
        <ul>
                <li>contains C macros, normally #define HAVE_FOO or HAVE_FOO_H , for all functions and headers that have been detected at build time.  These are meant to be used by C or C++ source files.</li>
        </ul>
        </li>
</ul>


<ul>
        <li>makeopts
        <ul>
                <li>contains variables that can be used by Makefiles.  In addition to the usual CC, LD, ... variables pointing to the various build tools, and prefix, includedir ... which are useful for generic compiler flags, there are variables for each package detected.  These are normally of the form FOO_INCLUDE=... FOO_LIB=... FOO_DIR=... indicating, for each package, the useful libraries and header files.</li>
        </ul>
        </li>
</ul>


<p>The next step is to run "make menuselect", to extract the dependencies existing between files and modules, and to store build options.<br/>
menuselect produces two files, both to be read by the Makefile:</p>

<ul>
        <li>menuselect.makeopts
        <ul>
                <li>Contains for each subdirectory a list of modules that must be excluded from the build, plus some additional informatiom.</li>
        </ul>
        </li>
</ul>


<ul>
        <li>menuselect.makedeps
        <ul>
                <li>Contains, for each module, a list of packages it depends on.  For each of these packages, we can collect the relevant INCLUDE and LIB files from makeopts. This file is based on information in the .c source code files for each module.</li>
        </ul>
        </li>
</ul>


<p>The top level Makefile is in charge of setting up the build environment, creating header files with build options, and recursively invoking the<br/>
subdir Makefiles to produce modules and the main executable.</p>

<p>The sources are split in multiple directories, more or less divided by module type (apps/ channels/ funcs/ res/ ...) or by function, for the main binary (main/ pbx/).</p>

<div class='panelMacro'><table class='warningMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/wiki/images/icons/emoticons/forbidden.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td>This section is not complete...</td></tr></table></div>

<h1><a name="BuildSystemArchitecture-Addingnewmodules"></a>2. Adding new modules</h1>

<h2><a name="BuildSystemArchitecture-Moduleswithnodependencies"></a>2.1. Modules with no dependencies</h2>

<p>If your module has no dependencies on external libraries, it can be dropped into the appropriate directory and the build system will automatically detect it and build it for you.  For example, if you write <tt>app_custom.c</tt>, drop it in the <tt>apps/</tt> directory.</p>

<h2><a name="BuildSystemArchitecture-Moduleswithdependencies"></a>2.2. Modules with dependencies</h2>

<p>If your module has an external dependency, you have a bit more work to do to integrate it into the build system.  First, you must determine whether the library you are using is used by any other Asterisk module.  If not, you must add the library to the following files.</p>

<h3><a name="BuildSystemArchitecture-%7B%7Bconfigure.ac%7D%7D"></a>2.2.1. <tt>configure.ac</tt></h3>

<p>This is the source of the configure script.  There are <em>many</em> examples to draw from in this file.  Search for the two instances of <tt>ALSA</tt> in this file to find one of the simpler examples of checking for a library.</p>

<h3><a name="BuildSystemArchitecture-%7B%7Bbuildtools%2Fmenuselectdeps.in%7D%7D"></a>2.2.2. <tt>build_tools/menuselect-deps.in</tt></h3>

<p>Add a line in this file for your new library.  The configure script uses this file as input and outputs build_tools/menuselect-deps.  The <tt>menuselect</tt> utility reads in this file to know which libraries have been found on the system.</p>

<h3><a name="BuildSystemArchitecture-%7B%7Bmakeopts.in%7D%7D"></a>2.2.3. <tt>makeopts.in</tt></h3>

<p>Add <tt>LIBNAME_LIB</tt> and <tt>LIBNAME_INCLUDE</tt> lines into this file.  The configure script will use this file as input and output the <tt>makeopts</tt> file.  When this library is found, these lines will have the appropriate <tt>CFLAGS</tt> and <tt>LDFLAGS</tt> needed to build and link a module with the library.  Follow the other examples that are already in this file for formatting.</p>

<h3><a name="BuildSystemArchitecture-Updateyourmodule"></a>2.2.4. Update your module</h3>

<p>Modules that have a dependency must have a special comment block in them that is used by the build system.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<script type="syntaxhighlighter" class="toolbar: false; theme: Confluence; brush: java; gutter: false"><![CDATA[
/*** MODULEINFO
        &lt;depend&gt;libname&lt;/depend&gt;
 ***/
]]></script>
</div></div>

    </div>
        <div id="commentsSection" class="wiki-content pageSection">
        <div style="float: right;">
            <a href="https://wiki.asterisk.org/wiki/users/viewnotifications.action" class="grey">Change Notification Preferences</a>
        </div>
        <a href="https://wiki.asterisk.org/wiki/display/AST/Build+System+Architecture">View Online</a>
        |
        <a href="https://wiki.asterisk.org/wiki/pages/diffpagesbyversion.action?pageId=5243137&revisedVersion=3&originalVersion=2">View Changes</a>
                |
        <a href="https://wiki.asterisk.org/wiki/display/AST/Build+System+Architecture?showComments=true&amp;showCommentArea=true#addcomment">Add Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>