[FE training-materials-updates] slides/autotools: checkpoint progress
Boris Brezillon
boris.brezillon at free-electrons.com
Fri May 22 17:13:38 CEST 2015
Repository : git://git.free-electrons.com/training-materials.git
On branch : mtd-rework-WIP
Link : http://git.free-electrons.com/training-materials/commit/?id=1f608c7f9761e7a32daeaa7d5129d49b94a965d5
>---------------------------------------------------------------
commit 1f608c7f9761e7a32daeaa7d5129d49b94a965d5
Author: Thomas Petazzoni <thomas.petazzoni at free-electrons.com>
Date: Mon May 18 17:00:27 2015 +0200
slides/autotools: checkpoint progress
Signed-off-by: Thomas Petazzoni <thomas.petazzoni at free-electrons.com>
>---------------------------------------------------------------
1f608c7f9761e7a32daeaa7d5129d49b94a965d5
slides/autotools-advanced/autotools-advanced.tex | 461 ++++++++++++++++++++++-
slides/autotools-basics/autotools-basics.tex | 2 +
2 files changed, 452 insertions(+), 11 deletions(-)
diff --git a/slides/autotools-advanced/autotools-advanced.tex b/slides/autotools-advanced/autotools-advanced.tex
index 47e8563..e298c28 100644
--- a/slides/autotools-advanced/autotools-advanced.tex
+++ b/slides/autotools-advanced/autotools-advanced.tex
@@ -1,40 +1,479 @@
-\section{Autotools advanced}
+\setbeamerfont{block title}{size=\scriptsize}
-\subsection{Autoconf advanced topics}
+\section{Autoconf advanced}
-\begin{frame}{{\tt AC\_CONFIG\_MACRO\_DIR}}
+\subsection{Configuration header}
+
+\begin{frame}[fragile]{Configuration header}
+ \begin{itemize}
+ \item Very often, C/C++ code needs to know the result of certain
+ tests done by the \code{configure} script.
+ \item A template C header file can be automatically generated by
+ \code{autoheader}, generally named \code{config.h.in}
+ \item The final header file is generated by \code{configure},
+ generally named \code{config.h}
+ \item Declared using \code{AC_CONFIG_HEADERS}
+ \begin{block}{\code{configure.ac} extract}
+{\scriptsize
+\begin{verbatim}
+AC_CONFIG_HEADERS([config.h])
+\end{verbatim}}
+ \end{block}
+ \begin{block}{Example config.h}
+{\scriptsize
+\begin{verbatim}
+/* Define if the complete vga libraries (vga, vgagl) are installed */
+/* #undef HAVE_LIBVGA */
+
+/* Define to 1 if you have the <limits.h> header file. */
+#define HAVE_LIMITS_H 1
+\end{verbatim}}
+\end{block}
+ \end{itemize}
\end{frame}
-\begin{frame}{Checking for headers}
- \code{AC_CHECK_HEADERS} and al.
+\begin{frame}[fragile]{{\tt AC\_DEFINE}}
+
+ \begin{itemize}
+ \item \code{AC_DEFINE} allows to create C definitions in the {\em
+ configuration header}
+ \item \code{AC_DEFINE (variable, value, [description])}
+ \end{itemize}
+
+ \begin{block}{\code{configure.ac}}
+\begin{verbatim}
+AC_DEFINE([FOOBAR], [42], [This is the foobar value])
+\end{verbatim}
+ \end{block}
+
+ \begin{block}{Generated \code{config.h}}
+\begin{minted}{c}
+/* This is the foobar value */
+#define FOOBAR 42
+\end{minted}
+\end{block}
+
\end{frame}
+\subsection{Checking for functions, headers, libraries, etc.}
+
\begin{frame}{Checking for functions}
- \code{AC_FUNC_*}, \code{AC_CHECK_FUNCS} and al.
+ \begin{itemize}
+ \item You may need to check if certain functions are available
+ and/or meet certain characteristics
+ \item Family of \code{AC_FUNC_*} macros
+ \begin{itemize}
+ \item \code{AC_FUNC_FORK}, \code{AC_FUNC_GETLOADAVG}, \code{AC_FUNC_MALLOC}, etc.
+ \item See {\em autoconf} manual for details
+ \end{itemize}
+ \item \code{AC_CHECK_FUNC[S]} to check for generic functions
+ \begin{itemize}
+ \item \code{AC_CHECK_FUNC (function, [action-if-found],
+ [action-if-not-found])}
+ \item \code{AC_CHECK_FUNCS (function..., [action-if-found],
+ [action-if-not-found])}
+ \item Results available
+ \begin{itemize}
+ \item \code{ac_cv_func_<function>} variable in
+ \code{configure.ac}
+ \item \code{HAVE_<FUNCTION>} defines in {\em configuration
+ headers}
+ \end{itemize}
+ \end{itemize}
+ \end{itemize}
\end{frame}
-\begin{frame}{Checking for libraries}
- \code{AC_SEARCH_LIBS}, \code{AC_CHECK_LIB}
+\begin{frame}[fragile]{{\tt AC\_CHECK\_FUNCS()} example}
+
+\begin{block}{configure.ac}
+{\tiny
+\begin{verbatim}
+AC_CHECK_FUNCS([printf foobar])
+echo "ac_cv_func_printf: ${ac_cv_func_printf}"
+echo "ac_cv_func_foobar: ${ac_cv_func_foobar}"
+AC_CONFIG_HEADER([config.h])
+\end{verbatim}}
+\end{block}
+
+\begin{block}{Execution of \code{./configure}}
+\begin{minted}[fontsize=\tiny]{console}
+$ ./configure
+[...]
+checking for printf... yes
+checking for foobar... no
+ac_cv_func_printf: yes
+ac_cv_func_foobar: no
+[...]
+config.status: creating config.h
+\end{minted}
+\end{block}
+
+\begin{block}{Generated \code{config.h}}
+{\tiny
+\begin{verbatim}
+[...]
+/* Define to 1 if you have the `foobar' function. */
+/* #undef HAVE_FOOBAR */
+
+/* Define to 1 if you have the `printf' function. */
+#define HAVE_PRINTF 1
+[...]
+\end{verbatim}}
+\end{block}
+
\end{frame}
-\begin{frame}{Checking for programs}
- \code{AC_CHECK_PROGS}
+\begin{frame}{Checking for headers}
+
+ \begin{itemize}
+ \item Much like \code{AC_FUNC_*} and \code{AC_CHECK_FUNC[S]}, but for headers
+ \item Variety of \code{AC_HEADER_*} macros
+ \begin{itemize}
+ \item Check the autoconf manual for details
+ \end{itemize}
+ \item \code{AC_CHECK_HEADER[S]} for generic headers checking
+ \begin{itemize}
+ \item \code{AC_CHECK_HEADER (header-file, [action-if-found], [action-if-not-found], [includes])}
+ \item \code{AC_CHECK_HEADERS (header-file..., [action-if-found], [action-if-not-found], [includes])}
+ \item Results available in:
+ \begin{itemize}
+ \item \code{ac_cv_header_<header-file>} variable in
+ \code{configure.ac}
+ \item \code{HAVE_<HEADER>_H} define in \code{config.h}
+ \end{itemize}
+ \end{itemize}
+ \end{itemize}
+\end{frame}
+
+\begin{frame}[fragile]{{\tt AC\_CHECK\_HEADERS} example}
+
+\begin{block}{\code{configure.ac}}
+{\scriptsize
+\begin{verbatim}
+[...]
+AC_CHECK_HEADERS([spawn.h],
+ [echo "Header spawn.h was found"; has_spawn=yes],
+ [echo "Header spawn.h was not found"])
+echo ${has_spawn}
+[...]
+\end{verbatim}}
+\end{block}
+
+\begin{block}{Execution of \code{./configure}}
+\begin{minted}[fontsize=\scriptsize]{console}
+$ ./configure
+[...]
+checking for spawn.h... yes
+Header spawn.h was found
+yes
+[...]
+\end{minted}
+\end{block}
+
+\end{frame}
+
+\begin{frame}[fragile]{Checking for libraries}
+ \begin{block}{}
+\begin{verbatim}
+AC_SEARCH_LIBS (function, search-libs,
+ [action-if-found], [action-if-not-found],
+ [other-libraries])
+\end{verbatim}
+ \end{block}
+
+ \begin{itemize}
+ \item Search for a library defining \code{function}, by linking a
+ simple program calling \code{function}
+ \item Tries first with no library, and then with the different
+ libraries in \code{search-libs}, one after the other.
+ \item If a library is found, \code{-llibrary} is prepended to the
+ \code{LIBS} variable, so programs will be linked against
+ it. \code{action-if-found} is executed.
+ \item If not, \code{action-if-not-found} is executed
+ \item \code{other-libraries} allows to pass additional
+ \code{-l<foo>} arguments that may be needed for the link test to
+ succeed.
+ \item Result in \code{ac_cv_search_<function>}
+ \end{itemize}
+\end{frame}
+
+\begin{frame}[fragile]{{\tt AC\_SEARCH\_LIBS} example}
+
+\begin{block}{\code{configure.ac}}
+{\small
+\begin{verbatim}
+AC_SEARCH_LIBS(mvwaddstr, [ncurses cursesX curses])
+\end{verbatim}}
+\end{block}
+
+\begin{block}{Execution of \code{./configure}}
+\begin{minted}[fontsize=\small]{console}
+$ ./configure
+[...]
+checking for library containing mvwaddstr... -lncurses
+[...]
+$ grep ac_cv_search_mvwaddstr config.log
+ac_cv_search_mvwaddstr=-lncurses
+\end{minted}
+\end{block}
+
+\begin{block}{Compilation}
+\begin{minted}[fontsize=\small]{console}
+$ make
+[...]
+gcc -g -O2 -o hello main.o common.o -lncurses
+[...]
+gcc -g -O2 -o test test.o common.o -lncurses
+\end{minted}
+\end{block}
+
\end{frame}
\begin{frame}{Other checks}
\begin{itemize}
+ \item {\bf Programs} with \code{AC_CHECK_PROGS}
+ \begin{itemize}
+ \item \code{AC_CHECK_PROGS(PERL, [perl5 perl])}
+ \end{itemize}
\item {\bf Declarations} with \code{AC_CHECK_DECLS}
\item {\bf Structure members} with \code{AC_CHECK_MEMBERS}
\item {\bf Types} with \code{AC_CHECK_TYPES}
+ \begin{itemize}
+ \item \code{AC_CHECK_TYPES(int8_t)}
+ \end{itemize}
+ \item See the {\em autoconf} manual for details
\end{itemize}
\end{frame}
+\subsection{Custom tests}
+
\begin{frame}{Writing new tests}
+ \begin{itemize}
+ \item You can create your own tests by pre-processing, compiling or
+ linking small test programs:
+ \begin{itemize}
+ \item Pre-processing test\\
+ {\small \code{AC_PREPROC_IFELSE (input, [action-if-true], [action-if-false])}}
+ \item Compiling test\\
+ {\small \code{AC_COMPILE_IFELSE (input, [action-if-true], [action-if-false])}}
+ \item Link test\\
+ {\small \code{AC_LINK_IFELSE (input, [action-if-true], [action-if-false])}}
+ \end{itemize}
+ \item Input should be formatted with \code{AC_LANG_SOURCE} or
+ \code{AC_LANG_PROGRAM}
+ \item Runtime tests can also be created
+ \begin{itemize}
+ \item Beware, by nature, they cannot work for cross-compilation!
+ \item \code{AC_RUN_IFELSE}
+ \end{itemize}
+ \end{itemize}
+\end{frame}
+
+\begin{frame}[fragile]{Writing new tests: {\tt AC\_LINK\_IFELSE}}
+
+\begin{block}{\code{configure.ac}}
+{\small
+\begin{verbatim}
+AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <langinfo.h>],
+ [char *codeset = nl_langinfo (CODESET);])],
+ [glib_cv_langinfo_codeset=yes],
+ [glib_cv_langinfo_codeset=no])
+\end{verbatim}}
+\end{block}
+
+\begin{block}{Variable in \code{config.log}}
+\begin{minted}{console}
+$ grep glib_cv_langinfo_codeset config.log
+glib_cv_langinfo_codeset=yes
+\end{minted}
+\end{block}
+
+\end{frame}
+
+\begin{frame}{Printing messages}
+ \begin{itemize}
+ \item When creating new tests, you may want to show messages,
+ warnings, errors, etc.
+ \item \code{AC_MSG_CHECKING (feature-description)}
+ \begin{itemize}
+ \item Notify the user that configure is checking for a
+ particular feature.
+ \end{itemize}
+ \item \code{AC_MSG_RESULT (result-description)}
+ \begin{itemize}
+ \item Notify the user of the results of a check
+ \end{itemize}
+ \item \code{AC_MSG_NOTICE (message)}
+ \begin{itemize}
+ \item Deliver the {\em message} to the user.
+ \end{itemize}
+ \item \code{AC_MSG_ERROR (error-description, [exit-status = ‘$?/1’])}
+ \begin{itemize}
+ \item Notify the user of an error that prevents configure from
+ completing.
+ \end{itemize}
+ \item \code{AC_MSG_WARN (problem-description)}
+ \begin{itemize}
+ \item Notify the configure user of a possible problem.
+ \end{itemize}
+ \end{itemize}
+\end{frame}
+
+\begin{frame}[fragile]{Printing messages: example}
+
+\begin{block}{\code{configure.ac}}
+{\small
+\begin{verbatim}
+AC_MSG_CHECKING([for nl_langinfo])
+AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <langinfo.h>],
+ [char *codeset = nl_langinfo (CODESET);])],
+ [glib_cv_langinfo_codeset=yes],
+ [glib_cv_langinfo_codeset=no])
+AC_MSG_RESULT([$glib_cv_langinfo_codeset])
+\end{verbatim}}
+\end{block}
+
+\begin{block}{Execution of \code{./configure}}
+\begin{minted}{console}
+$ ./configure
+[...]
+checking for nl_langinfo... yes
+[...]
+\end{minted}
+\end{block}
+
+\end{frame}
+
+\subsection{External software and optional features}
+
+\begin{frame}[fragile]{Using external software}
+ \begin{itemize}
+ \item When a package uses external software,
+ \code{--with-<package>=<arg>} and \code{--without-<package>}
+ options are generally offered to control usage of the external
+ software.
+ \item Implemented using the \code{AC_ARG_WITH} macro.
+ \begin{block}{}
+{\small
+\begin{verbatim}
+AC_ARG_WITH (package, help-string,
+ [action-if-given], [action-if-not-given])
+\end{verbatim}}
+ \end{block}
+ \begin{itemize}
+ \item \code{package} gives the name of the option
+ \item \code{help-string} is the help text, visible in
+ \code{./configure --help}
+ \item \code{action-if-given} is executed when the option is used,
+ either positively (\code{--with}) or negatively (\code{--without})
+ \item \code{action-if-not-given} is executed when the option is not
+ used
+ \item \code{<arg>} available as \code{$withval} inside {\em
+ action-if-given}, \code{$with_<package>} outside.
+ \end{itemize}
+ \end{itemize}
+\end{frame}
+
+\begin{frame}[fragile]{Package options}
+
+ \begin{itemize}
+
+ \item When a package offers optional features,
+ \code{--enable-<feature>} and \code{--disable-<feature>} options
+ are generally offered to control the optional feature.
+ \item Implemented using the \code{AC_ARG_ENABLE} macro.
+\begin{block}{}
+{\small
+\begin{verbatim}
+AC_ARG_ENABLE (feature, help-string,
+ [action-if-given], [action-if-not-given])
+\end{verbatim}}
+\end{block}
+\item Usage very similar to the one of \code{AC_ARG_WITH}
+\item Value available as \code{$enableval} inside {\em
+ action-if-given}, \code{$enable_<feature>} outside.
+\end{itemize}
+
+\end{frame}
+
+\begin{frame}[fragile]{Formatting the help string}
+ \begin{itemize}
+ \item To help formatting the help string, {\em autoconf} provides
+ the \code{AS_HELP_STRING} macro
+ \item Allows to properly align the different options in the
+ \code{./configure --help} output
+\begin{block}{}
+{\small
+\begin{verbatim}
+AS_HELP_STRING (left-hand-side, right-hand-side,
+ [indent-column = ‘26’], [wrap-column = ‘79’])
+\end{verbatim}}
+\end{block}
+ \end{itemize}
+\end{frame}
+
+\begin{frame}[fragile]{{\tt AC\_ARG\_ENABLE} example}
+
+\begin{block}{configure.ac}
+{\scriptsize
+\begin{verbatim}
+AC_ARG_ENABLE([test], AS_HELP_STRING([--enable-test], [Enable tests]),
+ [echo "Action if given, val = ${enableval}"],
+ [echo "Action if not given"])
+echo "enable_test = ${enable_test}"
+\end{verbatim}}
+\end{block}
+
+\begin{block}{\code{./configure} tests}
+\begin{minted}[fontsize=\tiny]{console}
+$ ./configure --help
+[...]
+Optional Features:
+[...]
+ --enable-test Enable tests
+$ ./configure
+[...]
+Action if not given
+enable_test =
+[...]
+$ ./configure --enable-test
+[...]
+Action if given, val = yes
+enable_test = yes
+[...]
+$ ./configure --disable-test
+[...]
+Action if given, val = no
+enable_test = no
+[...]
+\end{minted}
+\end{block}
+
+\end{frame}
+
+\subsection{Misc}
+
+\begin{frame}{{\tt autoscan}}
+ \begin{itemize}
+ \item \code{autoscan} is a program provided together with \code{autoconf}
+ \item Scans the source tree in the current directory (or the one
+ passed as argument)
+ \item From that, \code{autoscan}:
+ \begin{itemize}
+ \item Searches the source files for common portability problems
+ \item Checks for incompleteness of the \code{configure.ac} file, if any
+ \item Generates \code{configure.scan}, which can be used as a
+ preliminary \code{configure.ac}
+ \end{itemize}
+ \end{itemize}
+\end{frame}
+
+\begin{frame}{{\tt AC\_CONFIG\_MACRO\_DIR}}
\end{frame}
-\subsection{Automake advanced topics}
+\section{Automake advanced}
\begin{frame}{Subdirectories}
diff --git a/slides/autotools-basics/autotools-basics.tex b/slides/autotools-basics/autotools-basics.tex
index f6ebcba..85974ea 100644
--- a/slides/autotools-basics/autotools-basics.tex
+++ b/slides/autotools-basics/autotools-basics.tex
@@ -1,3 +1,5 @@
+\setbeamerfont{block title}{size=\scriptsize}
+
\section{Autotools basics}
\begin{frame}{{\tt configure.ac} language}
More information about the training-materials-updates
mailing list