\documentclass{beamer}

\usepackage{ulem}
\usepackage{graphicx}
\usepackage{verbatim}

\date{\today}

\newcommand{\command}[1]{\texttt{#1}}
\newcommand{\autoconf}{\command{autoconf}}
\newcommand{\automake}{\command{automake}}

\mode<presentation>
	{ \usetheme{PaloAlto}}

\author{Danny Robson}
\title{
	A Short Introduction to Autotools
}

\AtBeginSection[] {
   \begin{frame}
       \frametitle{Outline}
       \tableofcontents[currentsection]
   \end{frame}
}


%% Front matter
%%
\begin{document}
\begin{frame}
	\titlepage
	\tiny{Parts drawn from: Alexandre Duret-Lutz's `Introduction to the GNU Build System and GNU Autotools'}
\end{frame}


\section[Outline]{}
\frame{\tableofcontents}


\section{What is autotools?}
\begin{frame}
	\frametitle{What is autotools?}
	\begin{itemize}
		\item `Those three commands...'
	\end{itemize}

	\begin{block}{}
		\verbatiminput{autotools/configuremakeinstall.txt}
	\end{block}
\end{frame}


%\begin{frame}
%	\frametitle{What does autotools do?}
%
%	\begin{itemize}
%		\item Build automation
%		\item Portability toolset
%	\end{itemize}
%\end{frame}


\begin{frame}
	\frametitle{Why?}

	\begin{itemize}
		\item Why use it?
		\begin{itemize}
			%\item Dependency analysis
			\item Useful makefile targets
			\begin{itemize}
				\item \command{clean}, \command{install}, \command{uninstall}, \command{dist}, \command{check}, \command{distcheck}
			\end{itemize}
			\item Supporting tools
			\begin{itemize}
				\item \command{pkg-config}, \command{gnulib}
			\end{itemize}
			\item Portability and configuration

			\pause
			\item All the cool kids are doing it...
		\end{itemize}

		\pause
		\item Why leave it?
		\begin{itemize}
			\item GNU all the way
%			\item Using `odd' languages, data formats
		\end{itemize}
	\end{itemize}
\end{frame}


\begin{frame}
	\frametitle{What does autotools consist of?}

	\begin{itemize}
		\item \alert{\autoconf}
		\item \alert{\automake}
		\item \command{autoheader}
		\item \command{libtool}
		\item ...
	\end{itemize}
\end{frame}


\begin{frame}
	\frametitle{Simple automake/autoconf data flow}
	\includegraphics[width=0.9\linewidth]{autotools/fileflow}
\end{frame}


\section{A Basic Project}
\subsection{Setup}
\subsubsection{autoconf}
\begin{frame}[fragile]
	\frametitle{A basic \textit{configure.ac}}
	\begin{block}{configure.ac}
		\begin{semiverbatim}
\alert<2>{AC\_INIT([helloworld], [2.7.4], [fred@nerks.com])}
\alert<3>{AM\_INIT\_AUTOMAKE}

\alert<4>{AC\_PROG\_CC}

\alert<5>{AC\_OUTPUT([Makefile])}
		\end{semiverbatim}
	\end{block}

	\begin{itemize}
		\only<1>{\item A skeleton input for \autoconf}

		\only<2>{\item Initialise \autoconf: project, version, bug reporting}
		\only<3>{\item Initialise \automake}
		\only<4>{\item Check for C compilers}
		\only<5>{\item Specify which files should be generated}
	\end{itemize}
\end{frame}


\subsubsection{automake}
\begin{frame}[fragile]
	\frametitle{A basic \textit{Makefile.am}}

	\begin{block}{Makefile.am}
		\begin{semiverbatim}
\alert<2>{\alert<4>{bin}\_\alert<3>{PROGRAMS}  = helloworld}

\alert<5>{helloworld\_SOURCES = helloworld.c}
\alert<6>{helloworld\_LDADD   = -lm}
		\end{semiverbatim}
	\end{block}

	\begin{itemize}
		\only<1>{\item A skeleton input for \automake}
		\only<2>{\item A list of targets to build}
		\only<3>{\item What?}
		\only<4>{\item Where?}
		\only<5>{\item Source components for target}
		\only<6>{\item Link arguments for target}
	\end{itemize}
\end{frame}


\subsection{Compiling}
\begin{frame}[fragile]
	\frametitle{The standard \textit{autogen.sh}}

	\begin{block}{autogen.sh}
		\begin{semiverbatim}
#!/bin/sh
aclocal
autoconf
autoheader
automake
		\end{semiverbatim}
	\end{block}

	\begin{itemize}
		\item The `standard' \command{autogen.sh}
		\uncover<2->{\item Or just use \alert{\command{autoreconf}}}
	\end{itemize}
\end{frame}


\begin{frame}[fragile]
	\frametitle{Starting off}

	\begin{block}{Commands}
		\begin{semiverbatim}
\$ vim configure.ac
\$ vim Makefile.am
\alert<2>{\$ touch NEWS README AUTHORS ChangeLog}
\alert<3>{\$ autoreconf --install}
\$ ./configure
\$ make
		\end{semiverbatim}
	\end{block}
\end{frame}


\subsection{Distribution}
\begin{frame}[fragile]
	\frametitle{Distributing your application}

	\begin{block}{Distrubution targets}
		\begin{enumerate}
			\uncover<1->{\item \begin{semiverbatim}make dist\end{semiverbatim}}
			\uncover<2->{\item \begin{semiverbatim}make distcheck\end{semiverbatim}}
		\end{enumerate}
	\end{block}

	\begin{enumerate}
		\uncover<1->{\item Good:\ \ Create a tarball}
		\uncover<2->{\item Better: Create a tarball and test the installation}
	\end{enumerate}
\end{frame}



\section{Further}
\begin{frame}[fragile]
	\frametitle{Further reading}

	\begin{itemize}
		\item The \alert<1>{autobook} 
		\item \autoconf, \automake\ info pages
		\item \url{http://www.lrde.epita.fr/~adl/autotools.html}

		\uncover<2->{\item \alert<2>{Google}}
	\end{itemize}
\end{frame}

\begin{frame}
	\frametitle{Further reading}

	\begin{itemize}
		\item \alert{\url{http://cs.anu.edu.au/~Danny.Robson/}}
		\begin{itemize}
			\item A skeleton autotools project: `autoskel'
			\item The previous links
		\end{itemize}
	\end{itemize}
\end{frame}

\begin{frame}
	\begin{figure}
		\centering
		\includegraphics[width=0.5\linewidth]{autotools/gnu-head}
	\end{figure}
\end{frame}


\appendix
\section{Additional}

\subsection{Tricks}


\begin{frame}[fragile]
	\frametitle{Using pkg-config}
	\begin{block}{configure.ac}
		\begin{semiverbatim}
PKG\_CHECK\_MODULES(PCI, libpci >= 3.0.0)
		\end{semiverbatim}
	\end{block}

	\begin{block}{Makefile.am}
		\begin{semiverbatim}
helloworld\_CFLAGS = \$(PCI\_CFLAGS)
helloworld\_LDADD = \$(PCI\_LIBS)
		\end{semiverbatim}
	\end{block}
\end{frame}


\begin{frame}[fragile]
	\frametitle{A simple conditional}

	\begin{block}{configure.ac}
		\begin{semiverbatim}
PKG\_CHECK\_EXISTS(foo >= 3.0.0,
	[ HAVE\_FOO=true  ],
	[ HAVE\_FOO=false ]
)
AM\_CONDITIONAL(BUILD\_FOO, [test x\$HAVE\_FOO = xtrue])
		\end{semiverbatim}
	\end{block}

	\begin{block}{Makefile.am}
		\begin{semiverbatim}
if BUILD\_FOO
prog\_SOURCES += foosupport.cpp foosupport.hpp
endif
		\end{semiverbatim}
	\end{block}
\end{frame}


\end{document}
