Sophie

Sophie

distrib > Fedora > 13 > i386 > by-pkgid > 81f0b5293ed7f99fbf540f4f8e3668df > files > 51

ocaml-omake-0.9.8.5-12.fc13.i686.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
            "http://www.w3.org/TR/REC-html40/loose.dtd">
<HTML>
<HEAD>

<META http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<META name="GENERATOR" content="hevea 1.09">
<LINK rel="stylesheet" type="text/css" href="omake-doc.css">
<TITLE>Autoconfiguration functions and variables</TITLE>
</HEAD>
<BODY >

<img src="images/omake-manual.gif" border="0" align="top" alt=""><br>

<TABLE CELLSPACING=6 CELLPADDING=0><TR><TD ALIGN=left NOWRAP>Jump to:</TD><TD VALIGN=top ALIGN=center NOWRAP>&#XA0;&#XA0;</TD><TD ALIGN=left NOWRAP><A HREF="http://omake.metaprl.org/">OMake Home</A>
&bull;&nbsp;<A HREF="omake.html">Guide Home</A>
&bull;&nbsp;<A HREF="omake-doc.html">Guide (single-page)</A>
&bull;&nbsp;<A HREF="omake-toc.html">Contents (short)</A>
&bull;&nbsp;<A HREF="omake-contents.html">Contents (long)</A></TD></TR>
<TR><TD ALIGN=left NOWRAP>Index:</TD><TD VALIGN=top ALIGN=center NOWRAP>&#XA0;&#XA0;</TD><TD ALIGN=left NOWRAP><A HREF="omake-all-index.html">All</A>
&bull;&nbsp;<A HREF="omake-var-index.html">Variables</A>
&bull;&nbsp;<A HREF="omake-fun-index.html">Functions</A>
&bull;&nbsp;<A HREF="omake-obj-index.html">Objects</A>
&bull;&nbsp;<A HREF="omake-target-index.html">Targets</A>
&bull;&nbsp;<A HREF="omake-option-index.html">Options</A></TD></TR>
</TABLE>
<H1 CLASS="chapter"><A NAME="htoc407">Chapter&#XA0;14</A>&#XA0;&#XA0;Autoconfiguration functions and variables</H1><UL>
<LI><A HREF="omake-autoconf.html#toc103">General-purpose autoconfiguration functions</A></LI>
<LI><A HREF="omake-autoconf.html#toc104">Translating <CODE>autoconf</CODE> scripts</A></LI>
<LI><A HREF="omake-autoconf.html#toc105">Predefined configuration tests</A></LI>
</UL>
<P>
<A NAME="chapter:autoconf"></A>
</P><P>
OMake standard library provides a number of functions and variables intended to help one write
build specifications that need to be capable of autoconfiguring itself to adjust to different
build environments.</P><H2 CLASS="section"><A NAME="toc103"></A><A NAME="htoc408">14.1</A>&#XA0;&#XA0;General-purpose autoconfiguration functions</H2><P>
The following general-purpose functions can be used to discover the properties of your build
environment in a fashion similar to the one used by GNU autoconf tool you may be familiar with.
It is recommended that these function be used from an appropriate <CODE>static.</CODE> block (see
Section&#XA0;<A HREF="omake-language.html#section:static.">4.14</A> for more information).</P><P>In order to use the following general-purpose functions, you need to have the line
</P><PRE CLASS="verbatim">open configure/Configure
</PRE><P>included in your <CODE>OMakefile</CODE> or <CODE>OMakeroot</CODE>.
</P><H3 CLASS="subsection"><A NAME="htoc409">14.1.1</A>&#XA0;&#XA0;ConfMsgChecking, ConfMsgResult</H3><P><A NAME="fun:ConfMsgChecking"></A><A NAME="function:ConfMsgChecking"></A><A NAME="@default510"></A><A NAME="@fun284"></A><A NAME="fun:ConfMsgResult"></A><A NAME="function:ConfMsgResult"></A><A NAME="@default511"></A><A NAME="@fun285"></A>
</P><PRE CLASS="verbatim">ConfMsgChecking(&lt;msg&gt;)
...
ConfMsgResult(&lt;msg&gt;)
</PRE><P>The <CODE>ConfMsgChecking</CODE> function output message of the form <CODE>--- Checking &lt;msg&gt;... </CODE>
<EM>without</EM> any trailing newline. After the test advertized by <CODE>ConfMsgChecking</CODE> is
performed, the <CODE>ConfMsgResult</CODE> function should be used to output the result.</P><P>In certain cases users may want to redefine these function &#X2014; for example, to use a different
output formatting and/or to copy the messages to a log file.</P><P>Example:
</P><PRE CLASS="verbatim">static. =
   ConfMsgChecking(which foo to use)
   foo = ...
   ConfMsgResult($(foo))
</PRE><H3 CLASS="subsection"><A NAME="htoc410">14.1.2</A>&#XA0;&#XA0;ConfMsgWarn, ConfMsgError</H3><P><A NAME="fun:ConfMsgWarn"></A><A NAME="function:ConfMsgWarn"></A><A NAME="@default512"></A><A NAME="@fun286"></A><A NAME="fun:ConfMsgError"></A><A NAME="function:ConfMsgError"></A><A NAME="@default513"></A><A NAME="@fun287"></A>
</P><PRE CLASS="verbatim">ConfMsgWarn(&lt;msg&gt;)
ConfMsgError(&lt;msg&gt;)
</PRE><P>Print a warning or an error message respectively. <CODE>ConfMsgError</CODE> would then abort OMake.
</P><H3 CLASS="subsection"><A NAME="htoc411">14.1.3</A>&#XA0;&#XA0;ConfMsgYesNo, ConfMsgFound</H3><P><A NAME="fun:ConfMsgYesNo"></A><A NAME="function:ConfMsgYesNo"></A><A NAME="@default514"></A><A NAME="@fun288"></A><A NAME="fun:ConfMsgFound"></A><A NAME="function:ConfMsgFound"></A><A NAME="@default515"></A><A NAME="@fun289"></A>
</P><PRE CLASS="verbatim">flag = $(ConfMsgYesNo &lt;bool expr&gt;
flag = $(ConfMsgFound &lt;bool expr&gt;
</PRE><P>The <CODE>ConfMsgFound</CODE> function expects to receive a boolean flag describing whether a test
previously announced using the <A HREF="#fun:ConfMsgChecking"><CODE>ConfMsgChecking</CODE> function</A> found what it
was looking for. <CODE>ConfMsgFound</CODE> will output the appropriate result (&#X201C;found&#X201D; or &#X201C;NOT found&#X201D;)
using the <A HREF="#fun:ConfMsgResult"><CODE>ConfMsgResult</CODE> function</A> and return its argument back.</P><P>The <CODE>ConfMsgYesNo</CODE> function is similar, outputting a simple (&#X201C;yes&#X201D; or &#X201C;NO&#X201D;).
</P><H3 CLASS="subsection"><A NAME="htoc412">14.1.4</A>&#XA0;&#XA0;TryCompileC, TryLinkC, TryRunC</H3><P><A NAME="fun:TryCompileC"></A><A NAME="function:TryCompileC"></A><A NAME="@default516"></A><A NAME="@fun290"></A><A NAME="fun:TryLinkC"></A><A NAME="function:TryLinkC"></A><A NAME="@default517"></A><A NAME="@fun291"></A><A NAME="fun:TryRunC"></A><A NAME="function:TryRunC"></A><A NAME="@default518"></A><A NAME="@fun292"></A>
</P><PRE CLASS="verbatim">success = $(TryCompileC &lt;prog_text&gt;)
success = $(TryLinkC &lt;prog_text&gt;)
success = $(TryRunC &lt;prog_text&gt;)
</PRE><P>Given the <EM>text</EM> of a C program, the <CODE>TryCompileC</CODE>, <CODE>TryLinkC</CODE>, and <CODE>TryRunC</CODE>
functions would try to compile / compile and link / compile, link, and run, the given program and return a boolean flag
indicating whether the attempt was successful.</P><P><CODE>TryCompileC</CODE> will use the <CODE><A HREF="omake-build.html#var:CC">CC</A></CODE>, <CODE><A HREF="omake-build.html#var:CFLAGS">CFLAGS</A></CODE> and <CODE><A HREF="omake-build.html#var:INCLUDES">INCLUDES</A></CODE> variables 
to run the C compiler. <CODE>TryLinkC</CODE> and <CODE>TryRunC</CODE> will also use the <A HREF="omake-build.html#var:LDFLAGS"><CODE>LDFLAGS</CODE> variable</A>
to run the C compiler and linker. However, the flags like <CODE>/WX</CODE>, <CODE>-Werror</CODE> and <CODE>-warn-error</CODE>
will be not be passed to the compiler, even if they occur in <CODE>CFLAGS</CODE>.</P><P>These functions are silent and should normally be used with an appropriate
<CODE><A HREF="#fun:ConfMsgChecking">ConfMsgChecking</A></CODE> &#X2026; <CODE><A HREF="#fun:ConfMsgResult">ConfMsgResult</A></CODE>.
</P><H3 CLASS="subsection"><A NAME="htoc413">14.1.5</A>&#XA0;&#XA0;RunCProg</H3><P><A NAME="fun:RunCProg"></A><A NAME="function:RunCProg"></A><A NAME="@default519"></A><A NAME="@fun293"></A>
</P><PRE CLASS="verbatim">output = $(RunCProg &lt;prog&gt;)
</PRE><P><CODE>RunCProg</CODE> is similar to the <A HREF="#fun:RunCProg"><CODE>RunCProg</CODE> function</A>, except that it
returns the output of the function (will return <CODE>false</CODE> if the program fails to compile
or run).
</P><H3 CLASS="subsection"><A NAME="htoc414">14.1.6</A>&#XA0;&#XA0;CheckCHeader, VerboseCheckCHeader</H3><P><A NAME="fun:CheckCHeader"></A><A NAME="function:CheckCHeader"></A><A NAME="@default520"></A><A NAME="@fun294"></A><A NAME="fun:VerboseCheckCHeader"></A><A NAME="function:VerboseCheckCHeader"></A><A NAME="@default521"></A><A NAME="@fun295"></A>
</P><PRE CLASS="verbatim">success = $(CheckCHeader &lt;files&gt;)
success = $(VerboseCheckCHeader &lt;files&gt;)
</PRE><P>Use the <A HREF="#fun:TryCompileC"><CODE>TryCompileC</CODE> function</A> to check whether your C compiler can locate
and process the specified headers files.
Will incude <CODE>&lt;stdio.h&gt;</CODE> before including the header files.</P><P>Both functions return a boolean value. The <CODE>CheckCHeader</CODE> function is silent; the
<CODE>VerboseCheckCHeader</CODE> function will use the <CODE><A HREF="#fun:ConfMsgChecking">ConfMsgChecking</A></CODE> and
<CODE><A HREF="#fun:ConfMsgResult">ConfMsgResult</A></CODE> functions to describe the test and the outcome.</P><P>Example:
</P><PRE CLASS="verbatim">static. =
   NCURSES_H_AVAILABLE = $(VerboseCheckCHeader ncurses.h)
</PRE><H3 CLASS="subsection"><A NAME="htoc415">14.1.7</A>&#XA0;&#XA0;CheckCLib, VerboseCheckCLib</H3><P><A NAME="fun:CheckCLib"></A><A NAME="function:CheckCLib"></A><A NAME="@default522"></A><A NAME="@fun296"></A><A NAME="fun:VerboseCheckCLib"></A><A NAME="function:VerboseCheckCLib"></A><A NAME="@default523"></A><A NAME="@fun297"></A>
</P><PRE CLASS="verbatim">success = $(CheckCLib &lt;libs&gt;, &lt;functions&gt;)
success = $(VerboseCheckCLib &lt;libs&gt;, &lt;functions&gt;)
</PRE><P>Use the <A HREF="#fun:TryLinkC"><CODE>TryLinkC</CODE> function</A> to check whether your C compiler and linker can
find the named functions when linking with the named libraries. Will pass the <CODE>&lt;libs&gt;</CODE> to
the compiler using the <CODE>-l</CODE> flag.</P><P>Both functions return a boolean value. The <CODE>CheckCLib</CODE> function is silent; the
<CODE>VerboseCheckCHeader</CODE> function will use the <CODE><A HREF="#fun:ConfMsgChecking">ConfMsgChecking</A></CODE> and
<CODE><A HREF="#fun:ConfMsgResult">ConfMsgResult</A></CODE> functions to describe the test and the outcome.</P><P>Example:
</P><PRE CLASS="verbatim">static. =
    NCURSES_LIB_AVAILABLE = $(VerboseCheckCLib ncurses, initscr setupterm tigetstr)
</PRE><H3 CLASS="subsection"><A NAME="htoc416">14.1.8</A>&#XA0;&#XA0;CheckProg</H3><P><A NAME="fun:CheckProg"></A><A NAME="function:CheckProg"></A><A NAME="@default524"></A><A NAME="@fun298"></A>
<CODE>success = $(CheckProg &lt;prog&gt;)</CODE></P><P>Checks whether the program <CODE>&lt;prog&gt;</CODE> exists in your path. Will use the
<CODE><A HREF="#fun:ConfMsgChecking">ConfMsgChecking</A></CODE> and
<CODE><A HREF="#fun:ConfMsgResult">ConfMsgResult</A></CODE> functions to describe the test and the outcome.</P><H2 CLASS="section"><A NAME="toc104"></A><A NAME="htoc417">14.2</A>&#XA0;&#XA0;Translating <CODE>autoconf</CODE> scripts</H2><P>
Some of the functions described above are very similar to the ones present in <CODE>autoconf</CODE>.
Below is a brief translation table for such functions.
</P><DL CLASS="description"><DT CLASS="dt-description">
</DT><DD CLASS="dd-description"><CODE>AC_MSG_CHECKING</CODE><A NAME="@default525"></A> is very similar to <A HREF="#fun:ConfMsgChecking"><CODE>ConfMsgChecking</CODE> function</A>.
</DD><DT CLASS="dt-description"></DT><DD CLASS="dd-description"><CODE>AC_MSG_RESULT</CODE><A NAME="@default526"></A> is very similar to <A HREF="#fun:ConfMsgResult"><CODE>ConfMsgResult</CODE> function</A>.
</DD><DT CLASS="dt-description"></DT><DD CLASS="dd-description"><CODE>AC_MSG_WARN</CODE><A NAME="@default527"></A> is very similar to <A HREF="#fun:ConfMsgWarn"><CODE>ConfMsgWarn</CODE> function</A>.
</DD><DT CLASS="dt-description"></DT><DD CLASS="dd-description"><CODE>AC_MSG_ERROR</CODE><A NAME="@default528"></A> is very similar to <A HREF="#fun:ConfMsgError"><CODE>ConfMsgError</CODE> function</A>.
</DD><DT CLASS="dt-description"></DT><DD CLASS="dd-description"><CODE>AC_TRY_COMPILE</CODE><A NAME="@default529"></A> is somewhat similar to <A HREF="#fun:TryCompileC"><CODE>TryCompileC</CODE> function</A>,
except the <A HREF="#fun:TryCompileC"><CODE>TryCompileC</CODE> function</A> returns a boolean value and only works for <CODE>C</CODE>. Similarly,
</DD><DT CLASS="dt-description"></DT><DD CLASS="dd-description"><CODE>AC_TRY_LINK</CODE><A NAME="@default530"></A> is approximated by <A HREF="#fun:TryLinkC"><CODE>TryLinkC</CODE> function</A>, and
</DD><DT CLASS="dt-description"></DT><DD CLASS="dd-description"><CODE>AC_TRY_RUN</CODE><A NAME="@default531"></A> is approximated by <A HREF="#fun:TryRunC"><CODE>TryRunC</CODE> function</A>.
</DD></DL><H2 CLASS="section"><A NAME="toc105"></A><A NAME="htoc418">14.3</A>&#XA0;&#XA0;Predefined configuration tests</H2><P>
A number of configuration tests are already included in the standard library.
In order to use them in your project, simply <CODE>open</CODE> (see Section&#XA0;<A HREF="omake-language.html#section:include">4.7</A>) the
corresponding build file in your <CODE>OMakefile</CODE> and the tests will run the first time OMake
is executed. Note that it is not a problem to <CODE>open</CODE> these files from more than one place in
your project &#X2014; if you do that, the test will still run only once.
</P><H3 CLASS="subsection"><A NAME="htoc419">14.3.1</A>&#XA0;&#XA0;NCurses library configuration</H3><P>
Add <CODE>open configure/ncurses</CODE> line to your <CODE>OMakefile</CODE> to get access to the following
autoconfiguration variables.
</P><H5 CLASS="paragraph">NCURSES_AVAILABLE</H5><P><A NAME="var:NCURSES_AVAILABLE"></A><A NAME="@default532"></A><A NAME="@var114"></A> A boolean flag that would be set when both
the <CODE>curses.h</CODE> header, the <CODE>term.h</CODE> header, and the <CODE>ncurses</CODE> library very found.</P><H5 CLASS="paragraph">NCURSES_TERMH_IN_NCURSES</H5><P><A NAME="var:NCURSES_TERMH_IN_NCURSES"></A><A NAME="@default533"></A><A NAME="@var115"></A> A boolean flag that would be set
when <CODE>term.h</CODE> has to be included as <CODE>&lt;ncurses/term.h&gt;</CODE> instead of <CODE>&lt;term.h&gt;</CODE>.</P><H5 CLASS="paragraph">NCURSES_CFLAGS</H5><P><A NAME="var:NCURSES_CFLAGS"></A><A NAME="@default534"></A><A NAME="@var116"></A> The <CODE>CFLAGS</CODE> to use when compiling ncurses code.
Will include <CODE>-DNCURSES</CODE> and <CODE>-DTERMH_IN_NCURSES</CODE>, respectively
when <CODE>NCURSES_AVAILABLE</CODE> and <CODE>NCURSES_TERMH_IN_NCURSES</CODE> are true.</P><H5 CLASS="paragraph">NCURSES_CLIBS</H5><P><A NAME="var:NCURSES_CLIBS"></A><A NAME="@default535"></A><A NAME="@var117"></A> The <CODE>LDFLAGS</CODE> to use when linking ncurses code.
Will normally contain <CODE>-lncurses</CODE> when ncurses is found and remain empty otherwise.
</P><H3 CLASS="subsection"><A NAME="htoc420">14.3.2</A>&#XA0;&#XA0;ReadLine library configuration</H3><P>
Add <CODE>open configure/readline</CODE> line to your <CODE>OMakefile</CODE> to get access to the following
autoconfiguration variables.
</P><H5 CLASS="paragraph">READLINE_AVAILABLE</H5><P><A NAME="var:READLINE_AVAILABLE"></A><A NAME="@default536"></A><A NAME="@var118"></A> A boolean flag that would be set when both
the <CODE>readline/readline.h</CODE> header, the <CODE>readline/history.h</CODE> header, and the <CODE>readline</CODE>
library very found.</P><H5 CLASS="paragraph">READLINE_GNU</H5><P><A NAME="var:READLINE_GNU"></A><A NAME="@default537"></A><A NAME="@var119"></A> A boolean flag that would be set
when the GNU version of the readline library is found (as opposed to the BSD one).</P><H5 CLASS="paragraph">READLINE_CFLAGS</H5><P><A NAME="var:READLINE_CFLAGS"></A><A NAME="@default538"></A><A NAME="@var120"></A> The <CODE>CFLAGS</CODE> to use when compiling readline code.
Will include <CODE>-DREADLINE_ENABLED</CODE> and <CODE>-DREADLINE_GNU</CODE>, respectively
when <CODE>READLINE_AVAILABLE</CODE> and <CODE>READLINE_GNU</CODE> are true.</P><H5 CLASS="paragraph">READLINE_CLIBS</H5><P><A NAME="var:READLINE_CLIBS"></A><A NAME="@default539"></A><A NAME="@var121"></A> The <CODE>LDFLAGS</CODE> to use when linking readline code.
Will normally contain <CODE>-lncurses -lreadline</CODE> when readline is found and remain empty otherwise.
</P><H3 CLASS="subsection"><A NAME="htoc421">14.3.3</A>&#XA0;&#XA0;Snprintf configuration</H3><P>
Add <CODE>open configure/snprintf</CODE> line to your <CODE>OMakefile</CODE> to get access to the following
autoconfiguration variables.
</P><H5 CLASS="paragraph">SNPRINTF_AVAILABLE</H5><P><A NAME="var:SNPRINTF_AVAILABLE"></A><A NAME="@default540"></A><A NAME="@var122"></A> A boolean flag telling whether the snprintf
function is available in the standard C library.</P>
<TABLE CELLSPACING=6 CELLPADDING=0><TR><TD ALIGN=left NOWRAP>Jump to:</TD><TD VALIGN=top ALIGN=center NOWRAP>&#XA0;&#XA0;</TD><TD ALIGN=left NOWRAP><A HREF="http://omake.metaprl.org/">OMake Home</A>
&bull;&nbsp;<A HREF="omake.html">Guide Home</A>
&bull;&nbsp;<A HREF="omake-doc.html">Guide (single-page)</A>
&bull;&nbsp;<A HREF="omake-toc.html">Contents (short)</A>
&bull;&nbsp;<A HREF="omake-contents.html">Contents (long)</A></TD></TR>
<TR><TD ALIGN=left NOWRAP>Index:</TD><TD VALIGN=top ALIGN=center NOWRAP>&#XA0;&#XA0;</TD><TD ALIGN=left NOWRAP><A HREF="omake-all-index.html">All</A>
&bull;&nbsp;<A HREF="omake-var-index.html">Variables</A>
&bull;&nbsp;<A HREF="omake-fun-index.html">Functions</A>
&bull;&nbsp;<A HREF="omake-obj-index.html">Objects</A>
&bull;&nbsp;<A HREF="omake-target-index.html">Targets</A>
&bull;&nbsp;<A HREF="omake-option-index.html">Options</A></TD></TR>
</TABLE>
</BODY>
</HTML>