0% found this document useful (0 votes)
89 views25 pages

Makefile Generation From Autotools

This document discusses how to use autotools to generate Makefiles for building C/C++ projects. Autotools is a collection of tools including automake, autoconf, and libtool that generate Makefiles and configuration scripts from common template files. The key inputs are Makefile.am, configure.ac, and source code files. Autotools processes these inputs to produce outputs like config.h, Makefile, and configure scripts. The generated Makefiles can then be used to build libraries, executables, and install targets. The document provides an overview of each autotools tool and how they are used as part of the overall build system generation process.

Uploaded by

Waqqas Jabbar
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
89 views25 pages

Makefile Generation From Autotools

This document discusses how to use autotools to generate Makefiles for building C/C++ projects. Autotools is a collection of tools including automake, autoconf, and libtool that generate Makefiles and configuration scripts from common template files. The key inputs are Makefile.am, configure.ac, and source code files. Autotools processes these inputs to produce outputs like config.h, Makefile, and configure scripts. The generated Makefiles can then be used to build libraries, executables, and install targets. The document provides an overview of each autotools tool and how they are used as part of the overall build system generation process.

Uploaded by

Waqqas Jabbar
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 25

Makefile generation from Autotools

Waqqas Jabbar
Prerequisites
• C, C++
• gcc and its options
• make and Makefile
• configure and its options
• pkg-config
Objectives
• Use autotools to generate Makefiles, for
o Dynamic and Static libraries
o Executable
• Use libtool to generate libraries
Autotools
• Collection of utilities
o automake
o autoconf
o libtoolize
o aclocal
o autoheader
o autoscan
o autoupdate
o autoreconf
• Can be used separately or together
Inputs to autotools
• configure.ac
• Makefile.ac
• config.h.in
• Source code
Outputs of autotools
• config.h
o Added in project
o Conditional compilation
 #ifdef, #elif, #endif
• Makefile(s)
o Input to make
Makefile.am Source code autoscan

configure.scan

autoheader configure.ac

automake config.h.in autoconf

Makefile.in configure configure

config.h Makefile

?
Makefile.am Source code autoscan

configure.scan

autoheader configure.ac

automake config.h.in autoconf

Makefile.in configure configure

config.h Makefile
autoscan
• Input: Source code
• Output: configure.scan
o Template for configure.ac
autoheader
• Input: configure.ac, Source code
• Output: config.h.in
o What defines are to be generated in config.h
 #undef VAR -> #define VAR 1 ( by configure)
automake
• Input: Makefile.am
• Output: Makefile.in
• Convert automake variables to their values
autoconf
• Input: configure.ac
• Output: configure
o Shell script
configure
• Input: config.h.in, Makefile.in
• Output: config.h, Makefile(s)
Makefile.in
• Syntax of Makefile
Makefile.am
• Executables
o Installation binaries
 bin_PROGRAMS = foo1
o Non-Installation binaries
 noinst_PROGRAMS = foo2
o foo1_SOURCES = foo1.c foo1.h
o INCLUDES=-I $HOME/usr/include
o LDADD=-lpthread
o AM_CFLAGS=-DMY_DEFINE
o foo1extradir=$(datadir)/foo1
o foo1extra_DATA= foo1.conf
Makefile.am
• Libraries
o Installation Libraries
 lib_LTLIBRARIES=libtest.la
 library_includedir= The directory where header files
will be installed
 library_include_HEADERS= Header files exposed by
the library
o Non-installation libraries
 noinst_LTLIBRARIES=
o libtest_la_SOURCES =
o libtest_la_LDFLAGS =
o INCLUDES = -I.
o libtest_la_LIBADD= (other libraries to add)
Makefile.am
• Predefined variables
o $(top_srcdir) : Main directory of source-code
o $(includedir) : Path specified in configure for
installing header files
• SUBDIRS =
configure.ac
• Set of M4 Macros
• Initialization
o AC_PREREQ
o AC_INIT
o AC_CONFIG_HEADER(config.h)
o AM_INIT_AUTOMAKE
• Checks for programs
o AC_PROG_CC
o AC_PROG_CXX
o AC_PROG_INSTALL
o AM_PROG_LIBTOOL
o AM_SANITY_CHECK
configure.ac
• Checks for libraries
o pkg-config
 PKG_CHECK_MODULES(SNDFILE_DEPS, sndfile
>= 1.0.17)
 AC_SUBST(SNDFILE_DEPS_CFLAGS)
 AC_SUBST(SNDFILE_DEPS_LIBS)
o AC_SUBST passes variable from configure.ac to
Makefile.am
configure.ac
• No script
o AC_CHECK_LIB
o AC_ARG_WITH(mysql, [ --with-mysql=<path> prefix of
MySQL installation. e.g. /usr/local or /usr],
[MYSQL_PREFIX=$with_mysql],
AC_MSG_ERROR([You must call configure with the
--with-mysql option. This tells configure where to find the
MySql C library and headers. e.g. --with-mysql=/usr/local
or --with-mysql=/usr]))
o AC_SUBST(MYSQL_PREFIX)
o MYSQL_LIBS="-L${MYSQL_PREFIX}/lib/mysql
-lmysqlclient"
o MYSQL_CFLAGS="-I${MYSQL_PREFIX}/include"
o AC_SUBST(MYSQL_LIBS)
o AC_SUBST(MYSQL_CFLAGS)
configure.ac
• Checks for header files
o AC_HEADER_STDC
o AC_CHECK_HEADERS([string.h])
• Checks for typedefs, structures, and
compiler characteristics
• Checks for library functions
o AC_CHECK_FUNCS([bzero])
• Give Makefile to generate
o AC_CONFIG_FILES([Makefile])
o AC_OUTPUT
configure.ac
• Adding option in configure script
o AC_ARG_ENABLE(option-foo,[ --enable-option-
foo help for option foo], [CFLAGS= "$CFLAGS
-DOPTION_FOO_DEFINE"], [])
• Disable shared libraries
o AC_DISABLE_SHARED
References
• http://www.elitecoders.de/mags/cscene/CS2/
CS2-10.html
• http://www.openismus.com/documents/linux/
automake/automake.shtml
• http://www.openismus.com/documents/linux/
using_libraries/using_libraries.shtml
• http://www.openismus.com/documents/linux/
building_libraries/building_libraries.shtml
• http://bec-
systems.com/web/content/view/95/9/
• http://sources.redhat.com/autobook/autoboo
Summary
• You can generate distributions in tar.gz or
rpm
Thank You

You might also like