Makefile generation from Autotools <ul><ul><li>Waqqas Jabbar </li></ul></ul>
Prerequisites <ul><li>C, C++  </li></ul><ul><li>gcc and its options </li></ul><ul><li>make and Makefile </li></ul><ul><li>...
Objectives <ul><li>Use autotools to generate Makefiles, for </li></ul><ul><ul><li>Dynamic and Static libraries </li></ul><...
Autotools <ul><li>Collection of utilities </li></ul><ul><ul><li>automake </li></ul></ul><ul><ul><li>autoconf </li></ul></u...
Inputs to autotools <ul><li>configure.ac </li></ul><ul><li>Makefile.ac </li></ul><ul><li>config.h.in </li></ul><ul><li>Sou...
Outputs of autotools <ul><li>config.h </li></ul><ul><ul><li>Added in project </li></ul></ul><ul><ul><li>Conditional compil...
? config.h Makefile Makefile.in Source code configure.ac autoscan autoheader automake config.h.in Makefile.am autoconf con...
config.h Makefile Makefile.in Source code configure.ac autoscan autoheader automake config.h.in Makefile.am autoconf confi...
autoscan <ul><li>Input: Source code </li></ul><ul><li>Output: configure.scan </li></ul><ul><ul><li>Template for configure....
autoheader <ul><li>Input: configure.ac, Source code </li></ul><ul><li>Output: config.h.in </li></ul><ul><ul><li>What defin...
automake <ul><li>Input: Makefile.am </li></ul><ul><li>Output: Makefile.in </li></ul><ul><li>Convert automake variables to ...
autoconf <ul><li>Input: configure.ac </li></ul><ul><li>Output: configure </li></ul><ul><ul><li>Shell script </li></ul></ul>
configure <ul><li>Input: config.h.in, Makefile.in </li></ul><ul><li>Output: config.h, Makefile(s) </li></ul>
Makefile.in <ul><li>Syntax of Makefile </li></ul>
Makefile.am <ul><li>Executables </li></ul><ul><ul><li>Installation binaries </li></ul></ul><ul><ul><ul><li>bin_PROGRAMS = ...
Makefile.am <ul><li>Libraries </li></ul><ul><ul><li>Installation Libraries </li></ul></ul><ul><ul><ul><li>lib_LTLIBRARIES=...
Makefile.am <ul><li>Predefined variables </li></ul><ul><ul><li>$(top_srcdir) : Main directory of source-code </li></ul></u...
configure.ac <ul><li>Set of M4 Macros </li></ul><ul><li>Initialization </li></ul><ul><ul><li>AC_PREREQ </li></ul></ul><ul>...
configure.ac <ul><li>Checks for libraries </li></ul><ul><ul><li>pkg-config </li></ul></ul><ul><ul><ul><li>PKG_CHECK_MODULE...
configure.ac <ul><ul><li>No script </li></ul></ul><ul><ul><ul><li>AC_CHECK_LIB </li></ul></ul></ul><ul><ul><ul><li>AC_ARG_...
configure.ac <ul><li>Checks for header files </li></ul><ul><ul><li>AC_HEADER_STDC </li></ul></ul><ul><ul><li>AC_CHECK_HEAD...
configure.ac <ul><li>Adding option in configure script </li></ul><ul><ul><li>AC_ARG_ENABLE(option-foo,[  --enable-option-f...
References <ul><li>http://www.elitecoders.de/mags/cscene/CS2/CS2-10.html </li></ul><ul><li>http://www.openismus.com/docume...
Summary <ul><li>You can generate distributions in tar.gz or rpm </li></ul>
Thank You
Upcoming SlideShare
Loading in...5
×

Makefile Generation From Autotools

1,824

Published on

How autotools work and what you need to do get let your project build by &quot;configure;make;make install&quot;

0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,824
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
29
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Makefile Generation From Autotools

  1. 1. Makefile generation from Autotools <ul><ul><li>Waqqas Jabbar </li></ul></ul>
  2. 2. Prerequisites <ul><li>C, C++ </li></ul><ul><li>gcc and its options </li></ul><ul><li>make and Makefile </li></ul><ul><li>configure and its options </li></ul><ul><li>pkg-config </li></ul>
  3. 3. Objectives <ul><li>Use autotools to generate Makefiles, for </li></ul><ul><ul><li>Dynamic and Static libraries </li></ul></ul><ul><ul><li>Executable </li></ul></ul><ul><li>Use libtool to generate libraries </li></ul>
  4. 4. Autotools <ul><li>Collection of utilities </li></ul><ul><ul><li>automake </li></ul></ul><ul><ul><li>autoconf </li></ul></ul><ul><ul><li>libtoolize </li></ul></ul><ul><ul><li>aclocal </li></ul></ul><ul><ul><li>autoheader </li></ul></ul><ul><ul><li>autoscan </li></ul></ul><ul><ul><li>autoupdate </li></ul></ul><ul><ul><li>autoreconf </li></ul></ul><ul><li>Can be used separately or together </li></ul>
  5. 5. Inputs to autotools <ul><li>configure.ac </li></ul><ul><li>Makefile.ac </li></ul><ul><li>config.h.in </li></ul><ul><li>Source code </li></ul>
  6. 6. Outputs of autotools <ul><li>config.h </li></ul><ul><ul><li>Added in project </li></ul></ul><ul><ul><li>Conditional compilation </li></ul></ul><ul><ul><ul><li>#ifdef, #elif, #endif </li></ul></ul></ul><ul><li>Makefile(s) </li></ul><ul><ul><li>Input to make </li></ul></ul>
  7. 7. ? config.h Makefile Makefile.in Source code configure.ac autoscan autoheader automake config.h.in Makefile.am autoconf configure.scan configure configure
  8. 8. config.h Makefile Makefile.in Source code configure.ac autoscan autoheader automake config.h.in Makefile.am autoconf configure.scan configure configure
  9. 9. autoscan <ul><li>Input: Source code </li></ul><ul><li>Output: configure.scan </li></ul><ul><ul><li>Template for configure.ac </li></ul></ul>
  10. 10. autoheader <ul><li>Input: configure.ac, Source code </li></ul><ul><li>Output: config.h.in </li></ul><ul><ul><li>What defines are to be generated in config.h </li></ul></ul><ul><ul><ul><li>#undef VAR -> #define VAR 1 ( by configure) </li></ul></ul></ul>
  11. 11. automake <ul><li>Input: Makefile.am </li></ul><ul><li>Output: Makefile.in </li></ul><ul><li>Convert automake variables to their values </li></ul>
  12. 12. autoconf <ul><li>Input: configure.ac </li></ul><ul><li>Output: configure </li></ul><ul><ul><li>Shell script </li></ul></ul>
  13. 13. configure <ul><li>Input: config.h.in, Makefile.in </li></ul><ul><li>Output: config.h, Makefile(s) </li></ul>
  14. 14. Makefile.in <ul><li>Syntax of Makefile </li></ul>
  15. 15. Makefile.am <ul><li>Executables </li></ul><ul><ul><li>Installation binaries </li></ul></ul><ul><ul><ul><li>bin_PROGRAMS = foo1 </li></ul></ul></ul><ul><ul><li>Non-Installation binaries </li></ul></ul><ul><ul><ul><li>noinst_PROGRAMS = foo2 </li></ul></ul></ul><ul><ul><li>foo1_SOURCES = foo1.c foo1.h </li></ul></ul><ul><ul><li>INCLUDES=-I $HOME/usr/include </li></ul></ul><ul><ul><li>LDADD=-lpthread </li></ul></ul><ul><ul><li>AM_CFLAGS=-DMY_DEFINE </li></ul></ul><ul><ul><li>foo1extradir=$(datadir)/foo1 </li></ul></ul><ul><ul><li>foo1extra_DATA= foo1.conf </li></ul></ul>
  16. 16. Makefile.am <ul><li>Libraries </li></ul><ul><ul><li>Installation Libraries </li></ul></ul><ul><ul><ul><li>lib_LTLIBRARIES=libtest.la </li></ul></ul></ul><ul><ul><ul><li>library_includedir= The directory where header files will be installed </li></ul></ul></ul><ul><ul><ul><li>library_include_HEADERS= Header files exposed by the library </li></ul></ul></ul><ul><ul><li>Non-installation libraries </li></ul></ul><ul><ul><ul><li>noinst_LTLIBRARIES= </li></ul></ul></ul><ul><ul><li>libtest_la_SOURCES = </li></ul></ul><ul><ul><li>libtest_la_LDFLAGS = </li></ul></ul><ul><ul><li>INCLUDES = -I. </li></ul></ul><ul><ul><li>libtest_la_LIBADD= (other libraries to add) </li></ul></ul>
  17. 17. Makefile.am <ul><li>Predefined variables </li></ul><ul><ul><li>$(top_srcdir) : Main directory of source-code </li></ul></ul><ul><ul><li>$(includedir) : Path specified in configure for installing header files </li></ul></ul><ul><li>SUBDIRS = </li></ul>
  18. 18. configure.ac <ul><li>Set of M4 Macros </li></ul><ul><li>Initialization </li></ul><ul><ul><li>AC_PREREQ </li></ul></ul><ul><ul><li>AC_INIT </li></ul></ul><ul><ul><li>AC_CONFIG_HEADER(config.h) </li></ul></ul><ul><ul><li>AM_INIT_AUTOMAKE </li></ul></ul><ul><li>Checks for programs </li></ul><ul><ul><li>AC_PROG_CC </li></ul></ul><ul><ul><li>AC_PROG_CXX </li></ul></ul><ul><ul><li>AC_PROG_INSTALL </li></ul></ul><ul><ul><li>AM_PROG_LIBTOOL </li></ul></ul><ul><ul><li>AM_SANITY_CHECK </li></ul></ul>
  19. 19. configure.ac <ul><li>Checks for libraries </li></ul><ul><ul><li>pkg-config </li></ul></ul><ul><ul><ul><li>PKG_CHECK_MODULES(SNDFILE_DEPS, sndfile >= 1.0.17) </li></ul></ul></ul><ul><ul><ul><li>AC_SUBST(SNDFILE_DEPS_CFLAGS) </li></ul></ul></ul><ul><ul><ul><li>AC_SUBST(SNDFILE_DEPS_LIBS) </li></ul></ul></ul><ul><ul><li>AC_SUBST passes variable from configure.ac to Makefile.am </li></ul></ul>
  20. 20. configure.ac <ul><ul><li>No script </li></ul></ul><ul><ul><ul><li>AC_CHECK_LIB </li></ul></ul></ul><ul><ul><ul><li>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])) </li></ul></ul></ul><ul><ul><ul><li>AC_SUBST(MYSQL_PREFIX) </li></ul></ul></ul><ul><ul><ul><li>MYSQL_LIBS=&quot;-L${MYSQL_PREFIX}/lib/mysql -lmysqlclient&quot; </li></ul></ul></ul><ul><ul><ul><li>MYSQL_CFLAGS=&quot;-I${MYSQL_PREFIX}/include&quot; </li></ul></ul></ul><ul><ul><ul><li>AC_SUBST(MYSQL_LIBS) </li></ul></ul></ul><ul><ul><ul><li>AC_SUBST(MYSQL_CFLAGS) </li></ul></ul></ul>
  21. 21. configure.ac <ul><li>Checks for header files </li></ul><ul><ul><li>AC_HEADER_STDC </li></ul></ul><ul><ul><li>AC_CHECK_HEADERS([string.h]) </li></ul></ul><ul><li>Checks for typedefs, structures, and compiler characteristics </li></ul><ul><li>Checks for library functions </li></ul><ul><ul><li>AC_CHECK_FUNCS([bzero]) </li></ul></ul><ul><li>Give Makefile to generate </li></ul><ul><ul><li>AC_CONFIG_FILES([Makefile]) </li></ul></ul><ul><ul><li>AC_OUTPUT </li></ul></ul>
  22. 22. configure.ac <ul><li>Adding option in configure script </li></ul><ul><ul><li>AC_ARG_ENABLE(option-foo,[ --enable-option-foo help for option foo], [CFLAGS= &quot;$CFLAGS -DOPTION_FOO_DEFINE&quot;], []) </li></ul></ul><ul><li>Disable shared libraries </li></ul><ul><ul><li>AC_DISABLE_SHARED </li></ul></ul>
  23. 23. References <ul><li>http://www.elitecoders.de/mags/cscene/CS2/CS2-10.html </li></ul><ul><li>http://www.openismus.com/documents/linux/automake/automake.shtml </li></ul><ul><li>http://www.openismus.com/documents/linux/using_libraries/using_libraries.shtml </li></ul><ul><li>http://www.openismus.com/documents/linux/building_libraries/building_libraries.shtml </li></ul><ul><li>http://bec-systems.com/web/content/view/95/9/ </li></ul><ul><li>http://sources.redhat.com/autobook/autobook/autobook_toc.html#SEC_Contents </li></ul><ul><li>http://www.gnu.org/manual/manual.html </li></ul><ul><li>Examples </li></ul><ul><ul><li>http://www.openismus.com/documents/linux/building_libraries/examplelib-0.3.0.tar.gz </li></ul></ul><ul><ul><li>http://www.openismus.com/documents/linux/using_libraries/examplelib_example-0.3.0.tar.gz </li></ul></ul>
  24. 24. Summary <ul><li>You can generate distributions in tar.gz or rpm </li></ul>
  25. 25. Thank You
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×