Editing Documentation/Maemo 5 Developer Guide/GNU Build System

Warning: You are not logged in. Your IP address will be recorded in this page's edit history.

Warning: This page is 71 kilobytes long; some browsers may have problems editing pages approaching or longer than 32kb. Please consider breaking the page into smaller sections.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision Your text
Line 600: Line 600:
=== GNU Autoconf ===
=== GNU Autoconf ===
-
Autoconf is a tool that uses the GNU m4 macro preprocessor to process the configuration file and output a shell script based on the macros used in the file. Anything that m4 does not recognize as a macro is passed verbatim to the output script. This means that almost any wanted shell script fragments can be included into the <code>configure.ac</code> file (the modern name for the default configuration file for autoconf).
+
Autoconf is a tool that uses the GNU m4 macro preprocessor to process the configuration file and output a shell script based on the macros used in the file. Anything that m4 does not recognize as a macro is passed verbatim to the output script. This means that almost any wanted shell script fragments can be included into the '''configure.ac''' (the modern name for the default configuration file for autoconf).
The first subject here is a simple example to see how the basic configuration file works. Then some limitations of m4 syntax are covered, and hints on how to avoid problems with the syntax are given. [https://vcs.maemo.org/svn/maemoexamples/tags/maemo_5.0/autoconf-automake/example1/configure.ac autoconf-automake/example1/configure.ac]
The first subject here is a simple example to see how the basic configuration file works. Then some limitations of m4 syntax are covered, and hints on how to avoid problems with the syntax are given. [https://vcs.maemo.org/svn/maemoexamples/tags/maemo_5.0/autoconf-automake/example1/configure.ac autoconf-automake/example1/configure.ac]
-
<source lang="autoconf">
+
<tt><span>''<span><font color="#9A1900"><nowiki># Specify the "application name" and application version</nowiki></font></span>''</span>
-
# Specify the "application name" and application version
+
AC_INIT<span><font color="#990000">(</font></span>hello<span><font color="#990000">,</font></span> version-<span><font color="#993399">0.1</font></span><span><font color="#990000">)</font></span>
-
AC_INIT(hello, version-0.1)
+
-
 
+
<span>''<span><font color="#9A1900"><nowiki># Because autoconf passes trough anything that it does not recognize</nowiki></font></span>''</span>
-
# Because autoconf passes trough anything that it does not recognize
+
<span>''<span><font color="#9A1900"><nowiki># into the final script ('configure'), we can use any valid shell</nowiki></font></span>''</span>
-
# into the final script ('configure'), we can use any valid shell
+
<span>''<span><font color="#9A1900"><nowiki># statements here. Note that you should restrict your shell to</nowiki></font></span>''</span>
-
# statements here. Note that you should restrict your shell to
+
<span>''<span><font color="#9A1900"><nowiki># standard features that are available in all UNIX shells, but in our</nowiki></font></span>''</span>
-
# standard features that are available in all UNIX shells, but in our
+
<span>''<span><font color="#9A1900"><nowiki># case, we are content with the most used shell on Linux systems</nowiki></font></span>''</span>
-
# case, we are content with the most used shell on Linux systems
+
<span>''<span><font color="#9A1900"><nowiki># (bash).</nowiki></font></span>''</span>
-
# (bash).
+
echo -e <span><font color="#FF0000">"</font></span><span><font color="#CC33CC">\n\n</font></span><span><font color="#FF0000">Hello from configure (using echo)!</font></span><span><font color="#CC33CC">\n\n</font></span><span><font color="#FF0000">"</font></span>
-
echo -e "\n\nHello from configure (using echo)!\n\n"
+
-
 
+
<span>''<span><font color="#9A1900"><nowiki># We can use a macro for this messages. This is much preferred as it</nowiki></font></span>''</span>
-
# We can use a macro for this messages. This is much preferred as it
+
<span>''<span><font color="#9A1900"><nowiki># is more portable.</nowiki></font></span>''</span>
-
# is more portable.
+
AC_MSG_NOTICE<span><font color="#990000">([</font></span>Hello from configure using msg-notice<span><font color="#990000"><nowiki>!])</nowiki></font></span>
-
AC_MSG_NOTICE([Hello from configure using msg-notice!])
+
-
 
+
<span>''<span><font color="#9A1900"><nowiki># Check that the C Compiler works.</nowiki></font></span>''</span>
-
# Check that the C Compiler works.
+
AC_PROG_CC
-
AC_PROG_CC
+
<span>''<span><font color="#9A1900"><nowiki># Check what is the AWK-program on our system (and that one exists).</nowiki></font></span>''</span>
-
# Check what is the AWK-program on our system (and that one exists).
+
AC_PROG_AWK
-
AC_PROG_AWK
+
<span>''<span><font color="#9A1900"><nowiki># Check whether the 'cos' function can be found in library 'm'</nowiki></font></span>''</span>
-
# Check whether the 'cos' function can be found in library 'm'
+
<span>''<span><font color="#9A1900"><nowiki># (standard C math library).</nowiki></font></span>''</span>
-
# (standard C math library).
+
AC_CHECK_LIB<span><font color="#990000">(</font></span>m<span><font color="#990000">,</font></span> cos<span><font color="#990000">)</font></span>
-
AC_CHECK_LIB(m, cos)
+
<span>''<span><font color="#9A1900"><nowiki># Check for presence of system header 'unistd.h'.</nowiki></font></span>''</span>
-
# Check for presence of system header 'unistd.h'.
+
<span>''<span><font color="#9A1900"><nowiki># This also tests a lot of other system include files (it is</nowiki></font></span>''</span>
-
# This also tests a lot of other system include files (it is
+
<span>''<span><font color="#9A1900"><nowiki># semi-intelligent in determining which ones are required).</nowiki></font></span>''</span>
-
# semi-intelligent in determining which ones are required).
+
AC_CHECK_HEADER<span><font color="#990000">(</font></span>unistd<span><font color="#990000">.</font></span>h<span><font color="#990000">)</font></span>
-
AC_CHECK_HEADER(unistd.h)
+
<span>''<span><font color="#9A1900"><nowiki># You can also check for multiple system headers at the same time,</nowiki></font></span>''</span>
-
# You can also check for multiple system headers at the same time,
+
<span>''<span><font color="#9A1900"><nowiki># but notice the different name of the test macro for this (plural).</nowiki></font></span>''</span>
-
# but notice the different name of the test macro for this (plural).
+
AC_CHECK_HEADERS<span><font color="#990000">([</font></span>math<span><font color="#990000">.</font></span>h stdio<span><font color="#990000">.</font></span>h<span><font color="#990000">])</font></span>
-
AC_CHECK_HEADERS([math.h stdio.h])
+
<span>''<span><font color="#9A1900"><nowiki># A way to implement conditional logic based on header file presence</nowiki></font></span>''</span>
-
# A way to implement conditional logic based on header file presence
+
<span>''<span><font color="#9A1900"><nowiki># (we do not have a b0rk.h in our system).</nowiki></font></span>''</span>
-
# (we do not have a b0rk.h in our system).
+
AC_CHECK_HEADER<span><font color="#990000">(</font></span>b0rk<span><font color="#990000">.</font></span>h<span><font color="#990000">,</font></span> <span><font color="#990000">[</font></span>echo <span><font color="#FF0000">"b0rk.h present in system"</font></span><span><font color="#990000">],</font></span> <span><font color="#990000">\</font></span>
-
AC_CHECK_HEADER(b0rk.h, [echo "b0rk.h present in system"], \
+
                        <span><font color="#990000">[</font></span>echo <span><font color="#FF0000">"b0rk.h not present in system"</font></span><span><font color="#990000">])</font></span>
-
                        [echo "b0rk.h not present in system"])
+
-
 
+
echo <span><font color="#FF0000">"But that does not stop us from continuing!"</font></span>
-
echo "But that does not stop us from continuing!"
+
-
 
+
echo <span><font color="#FF0000">"Directory to install binaries in is '$bindir'"</font></span>
-
echo "Directory to install binaries in is '$bindir'"
+
echo <span><font color="#FF0000">"Directory under which data files go is '$datadir'"</font></span>
-
echo "Directory under which data files go is '$datadir'"
+
echo <span><font color="#FF0000">"For more variables, check 'config.log' after running configure"</font></span>
-
echo "For more variables, check 'config.log' after running configure"
+
echo <span><font color="#FF0000">"CFLAGS is '$CFLAGS'"</font></span>
-
echo "CFLAGS is '$CFLAGS'"
+
echo <span><font color="#FF0000">"LDFLAGS is '$LDFLAGS'"</font></span>
-
echo "LDFLAGS is '$LDFLAGS'"
+
echo <span><font color="#FF0000">"LIBS is '$LIBS'"</font></span>
-
echo "LIBS is '$LIBS'"
+
echo <span><font color="#FF0000">"CC is '$CC'"</font></span>
-
echo "CC is '$CC'"
+
echo <span><font color="#FF0000">"AWK is '$AWK'"</font></span>
-
echo "AWK is '$AWK'"
+
</tt>
-
</source>
+
The listing is verbosely commented, so it should be pretty self-evident what the different macros do. The macros that test for a feature or an include file normally causes the generated configure script to generate small C code test programs that are run as part of the configuration process. If these programs run successfully, the relevant test succeeds and the configuration process continues to the next test.
The listing is verbosely commented, so it should be pretty self-evident what the different macros do. The macros that test for a feature or an include file normally causes the generated configure script to generate small C code test programs that are run as part of the configuration process. If these programs run successfully, the relevant test succeeds and the configuration process continues to the next test.
Line 655: Line 654:
The following convention holds true in respect to the names of macros that are commonly used and available:
The following convention holds true in respect to the names of macros that are commonly used and available:
-
* <code>AC_*</code>: A macro that is included in autoconf or is meant for it.
+
* '''AC_*'''<nowiki>: A macro that is included in autoconf or is meant for it. </nowiki>
-
* <code>AM_*</code>: A macro that is meant for automake.
+
* '''AM_*'''<nowiki>: A macro that is meant for automake. </nowiki>
* Others: The autoconf system can be expanded by writing custom macros which can be stored in a custom directory. Some development packages also install new macros to be used.
* Others: The autoconf system can be expanded by writing custom macros which can be stored in a custom directory. Some development packages also install new macros to be used.
-
The next step is to run <code>autoconf</code>. Without any parameters, it reads <code>configure.ac</code> by default. If <code>configure.ac</code> does not exist, it tries to read <code>configure.in</code> instead.  
+
The next step is to run ''autoconf''. Without any parameters, it reads '''configure.ac''' by default. If configure.ac does not exist, it tries to read '''configure.in''' instead.  
-
Note that using the name <code>configure.in</code> is considered obsolete.
+
Note that using the name configure.in is considered obsolete.
  <nowiki>
  <nowiki>
Line 745: Line 744:
If bad shell syntax is introduced into the configuration file, the bad syntax causes errors only when the generated script file is run (not when autoconf generates the script). In general, autoconf almost always succeeds but the generated script does not necessarily succeed. Knowing which error in the shell script corresponds to which line in the original configure.ac is not always easy but can be learned through experience.
If bad shell syntax is introduced into the configuration file, the bad syntax causes errors only when the generated script file is run (not when autoconf generates the script). In general, autoconf almost always succeeds but the generated script does not necessarily succeed. Knowing which error in the shell script corresponds to which line in the original configure.ac is not always easy but can be learned through experience.
-
There is a line that reports the result of testing for <code>unistd.h</code>. It appears twice: the first time because it is the default test to run whenever testing for headers, and the second time because it was explicitly tested for. The second test output contains text (cached), which means that the test has been already run, and the result has been saved into a cache (the mysterious <code>autom4te.cache</code> directory). This means that for large projects, which cannot necessarily perform the same tests over and over, the tests are only run once, which makes running the script faster.
+
There is a line that reports the result of testing for '''unistd.h'''. It appears twice: the first time because it is the default test to run whenever testing for headers, and the second time because it was explicitly tested for. The second test output contains text (cached), which means that the test has been already run, and the result has been saved into a cache (the mysterious '''autom4te.cache''' directory). This means that for large projects, which cannot necessarily perform the same tests over and over, the tests are only run once, which makes running the script faster.
The last line's output above contains the values of variables. When the configure script runs, it automatically creates shell variables that can be used in shell code fragments. The macros for checking what programs are available for compiling must illustrate that point. Here awk was used as an example.
The last line's output above contains the values of variables. When the configure script runs, it automatically creates shell variables that can be used in shell code fragments. The macros for checking what programs are available for compiling must illustrate that point. Here awk was used as an example.
Line 766: Line 765:
It can seem that giving the prefix does not change anything, but this is because the shell does not expand the value in this particular case. However, if the variable was used in the script for doing something, the shell would expand later on. In order to see some effect, try passing the datadir-option (because that is printed out explicitly).
It can seem that giving the prefix does not change anything, but this is because the shell does not expand the value in this particular case. However, if the variable was used in the script for doing something, the shell would expand later on. In order to see some effect, try passing the datadir-option (because that is printed out explicitly).
-
If you need to see which variables are available for configuration, read the generated <code>config.log</code> file. The variables are listed at the end of that file.
+
If you need to see which variables are available for configuration, read the generated '''config.log''' file. The variables are listed at the end of that file.
=== Substitutions ===
=== Substitutions ===

Learn more about Contributing to the wiki.


Please note that all contributions to maemo.org wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see maemo.org wiki:Copyrights for details). Do not submit copyrighted work without permission!


Cancel | Editing help (opens in new window)

Templates used on this page: