Autoconf & Automake [email_address]
Agenda <ul><li>History </li></ul><ul><li>How to run configure&make </li></ul><ul><li>A Minimal Project </li></ul><ul><li>W...
History ( I)   <ul><li>The Diversity of Unix Systems   </li></ul><ul><ul><li>System III </li></ul></ul><ul><ul><li>SunOS <...
History ( II) <ul><li>#ifdef </li></ul><ul><ul><li>Cannot know which system which version had which features </li></ul></u...
Building A Program Makefile configure Makefile.am Makefile Program Makefile.in configure.in Configuration Build Make autom...
What is Autoconf (I) <ul><li>‘ configure’ script </li></ul><ul><ul><li>Shell script </li></ul></ul><ul><ul><li>Tests syste...
What is Autoconf   (II) <ul><li>‘ configure.in’ </li></ul><ul><ul><li>List the features that the program needs </li></ul><...
What is Automake <ul><li>Run by developers </li></ul><ul><li>‘ Makefile.am’ </li></ul><ul><ul><li>Which source files are u...
Agenda <ul><li>History </li></ul><ul><li>How to run configure&make </li></ul><ul><li>A Minimal Project </li></ul><ul><li>W...
Configure Parameters <ul><li>- h  (-- help)  </li></ul><ul><li>- V  (-- version) </li></ul><ul><li>--includedir=dir </li><...
Files generated by configure  ( I)   <ul><li>‘ config.cache’ </li></ul><ul><ul><ul><li>Cache the results of system tests t...
Files generated by configure ( II) <ul><li>‘ config.status’ </li></ul><ul><ul><ul><li>Used to recreate the current configu...
Files generated by configure ( III) <ul><li>‘ config.h’  </li></ul><ul><ul><ul><li>Optionally placed in  #define  preproce...
Make <ul><li>make all   </li></ul><ul><ul><li>Builds all derived files sufficient to declare the package built </li></ul><...
Agenda <ul><li>History </li></ul><ul><li>How to run configure&make </li></ul><ul><li>A Minimal Project </li></ul><ul><li>W...
A Minimal Project Input files  (I) <ul><li>‘ configuire.in’ </li></ul><ul><ul><li>A template of macro invocations and shel...
A Minimal Project Input files  (I) <ul><li>eg:   </li></ul><ul><li>dnl Process this file with autoconf to produce a config...
A Minimal Project Input files (II) <ul><li>High-level, bare-bones specification of a project's build requirements:  </li><...
A Minimal Project Output files (I) <ul><li>Macro invocations in ‘configure.in’ may are not known to   autoconf </li></ul><...
A Minimal Project Output files (II) <ul><li>$ automake --add-missing  </li></ul><ul><li>automake: configure.in: installing...
A Minimal Project  Distrbution <ul><li>Developer: </li></ul><ul><ul><li>Package up your tree in a tar file </li></ul></ul>...
Agenda <ul><li>History </li></ul><ul><li>How to run configure&make </li></ul><ul><li>A Minimal Project </li></ul><ul><li>W...
<ul><li>Review </li></ul><ul><ul><li>A template of macro invocations and shell code fragments that are used by  autoconf  ...
<ul><li>What constructs are portable and what constructs aren't portable?  </li></ul><ul><li>How do I decide what to check...
<ul><li>Boilerplate </li></ul><ul><li>Programs </li></ul><ul><li>Libraries </li></ul><ul><li>Headers </li></ul><ul><li>Typ...
<ul><li>Include standard boilerplate code </li></ul><ul><ul><li>AC_INIT (File)   </li></ul></ul><ul><ul><ul><li>Must be fi...
<ul><li>Check for programs that are either needed by the configure process, the build process, or by one of the programs b...
<ul><li>Checks for libraries come before checks for other objects visible to C (or C++, or anything else) </li></ul>Writin...
<ul><li>Checks for functions based on: </li></ul><ul><ul><li>Libraries  for correctly linking </li></ul></ul><ul><ul><li>H...
Writing ‘configure.in’   Output   <ul><li>AC_OUTPUT ([file... [, extra-cmds [, init-cmds]]])  </li></ul><ul><ul><li>file.....
Agenda <ul><li>History </li></ul><ul><li>How to run configure&make </li></ul><ul><li>A Minimal Project </li></ul><ul><li>W...
Automake’s goal <ul><li>Basic functional areas:  </li></ul><ul><ul><li>Build  </li></ul></ul><ul><ul><li>Check  </li></ul>...
Primaries <ul><li>Concept: </li></ul><ul><ul><li>A special root variable name associated with each type of object that Aut...
Easy Primaries <ul><li>DATA   </li></ul><ul><ul><ul><li>Easiest primary  </li></ul></ul></ul><ul><ul><ul><li>List files wh...
Programs & Libraries Primaries  (I) <ul><li>PROGRAMS  </li></ul><ul><ul><li>eg:   bin_PROGRAMS = doit   </li></ul></ul><ul...
Programs & Libraries Primaries  (II) <ul><li>When more than one source file, use  SOURCES </li></ul><ul><li>eg: </li></ul>...
Common Macros <ul><li>_DEPENDENCIES </li></ul><ul><ul><li>Extra dependencies </li></ul></ul><ul><ul><li>Based on the value...
Multiple Directories  <ul><li>SUBDIRS  </li></ul><ul><ul><li>eg:   SUBDIRS = . m4 tests  </li></ul></ul>Testing  <ul><li>T...
2003/12/29 References <ul><li>Autobook </li></ul><ul><li>http://192.168.1.182/ linux /tech/ autobook / autobook .html </li...
Thank you!
Upcoming SlideShare
Loading in...5
×

Autoconf&Automake

1,334

Published on

test123

Published in: Business, Technology
4 Comments
1 Like
Statistics
Notes
  • test111
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • zhuangwei's comment
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • test1
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • test1test1test1
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total Views
1,334
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
38
Comments
4
Likes
1
Embeds 0
No embeds

No notes for slide

Autoconf&Automake

  1. 1. Autoconf & Automake [email_address]
  2. 2. Agenda <ul><li>History </li></ul><ul><li>How to run configure&make </li></ul><ul><li>A Minimal Project </li></ul><ul><li>Writing ‘configure.in’ </li></ul><ul><li>Writing ‘Makefile.am’ </li></ul><ul><li>References </li></ul>
  3. 3. History ( I) <ul><li>The Diversity of Unix Systems </li></ul><ul><ul><li>System III </li></ul></ul><ul><ul><li>SunOS </li></ul></ul><ul><ul><li>…… </li></ul></ul><ul><li>Although similar, there are still various differences between different systems. </li></ul><ul><ul><li>Different sets of header files </li></ul></ul><ul><ul><li>Different lists of functions in the system libraries </li></ul></ul><ul><ul><li>…… </li></ul></ul>
  4. 4. History ( II) <ul><li>#ifdef </li></ul><ul><ul><li>Cannot know which system which version had which features </li></ul></ul><ul><li>POSIX standards </li></ul><ul><ul><li>Portable Operating System Interface </li></ul></ul><ul><ul><li>Only eliminate some of these differences </li></ul></ul><ul><li>Need more organized approach to handle the differences between Unix variants </li></ul>
  5. 5. Building A Program Makefile configure Makefile.am Makefile Program Makefile.in configure.in Configuration Build Make automake autoconf ./ configure
  6. 6. What is Autoconf (I) <ul><li>‘ configure’ script </li></ul><ul><ul><li>Shell script </li></ul></ul><ul><ul><li>Tests system features </li></ul></ul><ul><ul><li>Prepare source tree in order to build the program on a particular system </li></ul></ul><ul><ul><li>Before: had to be updated for each new Unix variant </li></ul></ul><ul><ul><li>Now: build a package on any kind of system with a simple ‘configure’ script </li></ul></ul>
  7. 7. What is Autoconf (II) <ul><li>‘ configure.in’ </li></ul><ul><ul><li>List the features that the program needs </li></ul></ul><ul><li>Autoconf </li></ul><ul><ul><li>Generate ‘configure’ script </li></ul></ul><ul><li>Run by developers </li></ul>
  8. 8. What is Automake <ul><li>Run by developers </li></ul><ul><li>‘ Makefile.am’ </li></ul><ul><ul><li>Which source files are used to build the program </li></ul></ul><ul><ul><li>A simpler syntax </li></ul></ul><ul><li>‘ Makefile.in’ </li></ul><ul><ul><li>There was a great deal of duplication </li></ul></ul><ul><li>‘ Makefile’ </li></ul><ul><ul><li>The rules for how to build the program itself </li></ul></ul><ul><ul><li>With a reasonably complex set of GNU standards </li></ul></ul>
  9. 9. Agenda <ul><li>History </li></ul><ul><li>How to run configure&make </li></ul><ul><li>A Minimal Project </li></ul><ul><li>Writing ‘configure.in’ </li></ul><ul><li>Writing ‘Makefile.am’ </li></ul><ul><li>References </li></ul>
  10. 10. Configure Parameters <ul><li>- h (-- help) </li></ul><ul><li>- V (-- version) </li></ul><ul><li>--includedir=dir </li></ul><ul><ul><li>Specifies where C header files should be installed </li></ul></ul><ul><li>--libdir=dir </li></ul><ul><ul><li>Specifies where object code library should be installed </li></ul></ul><ul><li>--srcdir=dir </li></ul><ul><ul><li>Tells where the source files may be found </li></ul></ul><ul><ul><li>Not necessary </li></ul></ul>
  11. 11. Files generated by configure ( I) <ul><li>‘ config.cache’ </li></ul><ul><ul><ul><li>Cache the results of system tests that have been performed to speed up subsequent tests </li></ul></ul></ul><ul><ul><ul><li>A plain text file </li></ul></ul></ul><ul><ul><ul><li>Can be hand-modified or removed if desired </li></ul></ul></ul><ul><li>‘ config.log’ </li></ul><ul><ul><ul><li>Outputs a message describing each test it performs and the result of each test </li></ul></ul></ul>
  12. 12. Files generated by configure ( II) <ul><li>‘ config.status’ </li></ul><ul><ul><ul><li>Used to recreate the current configuration (all generated files will be regenerated) </li></ul></ul></ul><ul><ul><ul><li>Re-run configure with --recheck option </li></ul></ul></ul>
  13. 13. Files generated by configure ( III) <ul><li>‘ config.h’ </li></ul><ul><ul><ul><li>Optionally placed in #define preprocessor directives </li></ul></ul></ul><ul><ul><ul><li>/* Define to 1 if your C compiler doesn't accept -c and -o together. */ </li></ul></ul></ul><ul><ul><ul><li>/* # undef NO_MINUS_C_MINUS_O */ </li></ul></ul></ul><ul><ul><ul><li>/* Define if you have strchr (always for CVS). */ </li></ul></ul></ul><ul><ul><ul><li>#define HAVE_STRCHR 1 </li></ul></ul></ul><ul><ul><ul><li>Source files may include the ‘config.h’ file and act accordingly: </li></ul></ul></ul><ul><ul><ul><li># if HAVE_CONFIG_H </li></ul></ul></ul><ul><ul><ul><li># include <config.h> </li></ul></ul></ul><ul><ul><ul><li># endif /* HAVE_CONFIG_H */ </li></ul></ul></ul>
  14. 14. Make <ul><li>make all </li></ul><ul><ul><li>Builds all derived files sufficient to declare the package built </li></ul></ul><ul><li>make check </li></ul><ul><ul><li>Runs any self-tests that the package may have </li></ul></ul><ul><li>make install </li></ul><ul><ul><li>Installs the package in a predetermined location </li></ul></ul><ul><li>make clean </li></ul><ul><ul><li>Removes all derived files </li></ul></ul>
  15. 15. Agenda <ul><li>History </li></ul><ul><li>How to run configure&make </li></ul><ul><li>A Minimal Project </li></ul><ul><li>Writing ‘configure.in’ </li></ul><ul><li>Writing ‘Makefile.am’ </li></ul><ul><li>References </li></ul>
  16. 16. A Minimal Project Input files (I) <ul><li>‘ configuire.in’ </li></ul><ul><ul><li>A template of macro invocations and shell code fragments that are used by autoconf to produce a ‘configure’ script </li></ul></ul><ul><li>autoconf copies the contents of ‘configure.in’ to ‘configure’, expanding macros as they occur in the input. Other text is copied verbatim. </li></ul>autoconf configure.in configure.scan autoscan Modified
  17. 17. A Minimal Project Input files (I) <ul><li>eg: </li></ul><ul><li>dnl Process this file with autoconf to produce a configure script. </li></ul><ul><li>AC_INIT(main.c) </li></ul><ul><li>AM_INIT_AUTOMAKE(foonly, 1.0) </li></ul><ul><li>AC_PROG_CC </li></ul><ul><li>AM_PROG_LEX </li></ul><ul><li>AC_PROG_YACC </li></ul><ul><li>AC_OUTPUT(Makefile) </li></ul>autoconf configure.in
  18. 18. A Minimal Project Input files (II) <ul><li>High-level, bare-bones specification of a project's build requirements: </li></ul><ul><ul><li>What needs to be built ? </li></ul></ul><ul><ul><li>Where does it go ? </li></ul></ul><ul><ul><li>When it is installed ? </li></ul></ul><ul><li>eg: bin_PROGRAMS = hello </li></ul><ul><li> hello_SOURCES = main.c foo.c foo.h nly.c </li></ul>Makefile.am automake
  19. 19. A Minimal Project Output files (I) <ul><li>Macro invocations in ‘configure.in’ may are not known to autoconf </li></ul><ul><li>‘ aclocal.m4’ </li></ul><ul><ul><li>Collect all of the macro definitions for autoconf </li></ul></ul>aclocal.m4 aclocal configure autoconf
  20. 20. A Minimal Project Output files (II) <ul><li>$ automake --add-missing </li></ul><ul><li>automake: configure.in: installing ./install-sh </li></ul><ul><li>automake: configure.in: installing ./mkinstalldirs </li></ul><ul><li>automake: configure.in: installing ./missing </li></ul><ul><li>automake: Makefile.am: installing ./INSTALL </li></ul><ul><li>automake: Makefile.am: required file ./NEWS not found </li></ul><ul><li>automake: Makefile.am: required file ./README not found </li></ul><ul><li>automake: Makefile.am: installing ./COPYING </li></ul><ul><li>automake: Makefile.am: required file ./AUTHORS not found </li></ul><ul><li>automake: Makefile.am: required file ./ChangeLog not found </li></ul>Makefile.in automake $ touch NEWS README AUTHORS ChangeLog $ automake --add-missing
  21. 21. A Minimal Project Distrbution <ul><li>Developer: </li></ul><ul><ul><li>Package up your tree in a tar file </li></ul></ul><ul><ul><li>Give the tar file to other users to install on their own systems </li></ul></ul><ul><li>User: </li></ul><ul><ul><li>Unpack the tar file </li></ul></ul><ul><ul><li>./ configure </li></ul></ul><ul><ul><li>make all </li></ul></ul>
  22. 22. Agenda <ul><li>History </li></ul><ul><li>How to run configure&make </li></ul><ul><li>A Minimal Project </li></ul><ul><li>Writing ‘configure.in’ </li></ul><ul><li>Writing ‘Makefile.am’ </li></ul><ul><li>References </li></ul>
  23. 23. <ul><li>Review </li></ul><ul><ul><li>A template of macro invocations and shell code fragments that are used by autoconf to produce a ‘configure’ script </li></ul></ul>Writing ‘configure.in’ What is ‘configure.in’ autoconf configure.in configure.scan autoscan Modified
  24. 24. <ul><li>What constructs are portable and what constructs aren't portable? </li></ul><ul><li>How do I decide what to check for? What shouldn't I check for? </li></ul><ul><li>What shouldn't I put in `configure.in'? </li></ul><ul><li>In what order should I run my checks? </li></ul>Writing ‘configure.in’ Frequent Question
  25. 25. <ul><li>Boilerplate </li></ul><ul><li>Programs </li></ul><ul><li>Libraries </li></ul><ul><li>Headers </li></ul><ul><li>Typedefs and structures </li></ul><ul><li>Functions </li></ul><ul><li>Output </li></ul>Writing ‘configure.in’ Standard Ordering
  26. 26. <ul><li>Include standard boilerplate code </li></ul><ul><ul><li>AC_INIT (File) </li></ul></ul><ul><ul><ul><li>Must be first </li></ul></ul></ul><ul><ul><ul><li>Check if File exists in srcdir </li></ul></ul></ul><ul><ul><ul><li>Generated by autoscan </li></ul></ul></ul><ul><ul><ul><li>eg: AC_INIT(src/cvs.h) </li></ul></ul></ul><ul><ul><li>AM_INIT_AUTOMAKE (Package, Version) </li></ul></ul><ul><ul><ul><li>Necessary to use automake </li></ul></ul></ul><ul><ul><ul><li>eg: AM_INIT_AUTOMAKE(cvs, 1.11.2) </li></ul></ul></ul>Writing ‘configure.in’ Boilerplate
  27. 27. <ul><li>Check for programs that are either needed by the configure process, the build process, or by one of the programs being built </li></ul><ul><ul><li>AC_CHECK_PROG (variable, progs-to-check-for [, value-if-not-found [, path]]) </li></ul></ul>Writing ‘configure.in’ Programs
  28. 28. <ul><li>Checks for libraries come before checks for other objects visible to C (or C++, or anything else) </li></ul>Writing ‘configure.in’ Libraries Headers <ul><li>Checks for existence of headers </li></ul>Typedefs and structures <ul><li>Checks for typedefs and structures inside the headers </li></ul>
  29. 29. <ul><li>Checks for functions based on: </li></ul><ul><ul><li>Libraries for correctly linking </li></ul></ul><ul><ul><li>Headers for finding prototypes </li></ul></ul><ul><ul><li>Typedefs for using types which are not built in </li></ul></ul><ul><li>AC_CHECK_FUNC (function, [action-if-found [, action-if-not-found]]) </li></ul>Writing ‘configure.in’ Functions
  30. 30. Writing ‘configure.in’ Output <ul><li>AC_OUTPUT ([file... [, extra-cmds [, init-cmds]]]) </li></ul><ul><ul><li>file... separate with space </li></ul></ul>file.in file eg: AC_OUTPUT([Makefile cvs.spec contrib/log src/Makefile src/cvsbug src/version.h ], [chmod +x contrib/log src/cvsbug])
  31. 31. Agenda <ul><li>History </li></ul><ul><li>How to run configure&make </li></ul><ul><li>A Minimal Project </li></ul><ul><li>Writing ‘configure.in’ </li></ul><ul><li>Writing ‘Makefile.am’ </li></ul><ul><li>References </li></ul>
  32. 32. Automake’s goal <ul><li>Basic functional areas: </li></ul><ul><ul><li>Build </li></ul></ul><ul><ul><li>Check </li></ul></ul><ul><ul><li>Clean </li></ul></ul><ul><ul><li>Install and uninstall </li></ul></ul><ul><ul><li>Distribution </li></ul></ul>Makefile.am Makefile.in automake
  33. 33. Primaries <ul><li>Concept: </li></ul><ul><ul><li>A special root variable name associated with each type of object that Automake understands </li></ul></ul><ul><ul><li>SCRIPTS: scripts (interpreted executable programs) </li></ul></ul><ul><ul><li>Add various prefixes to a primary to represent an actual object </li></ul></ul><ul><ul><li>bin_SCRIPTS = magic-script </li></ul></ul><ul><ul><ul><li>bin_SCRIPTS represents an actual script object which is installed in /bin directory </li></ul></ul></ul><ul><ul><ul><li>magic-script is an object file, represents a variable of bin_SCRIPTS , will be a Target in Makefile finally </li></ul></ul></ul>
  34. 34. Easy Primaries <ul><li>DATA </li></ul><ul><ul><ul><li>Easiest primary </li></ul></ul></ul><ul><ul><ul><li>List files which are installed verbatim </li></ul></ul></ul><ul><li>HEADERS </li></ul><ul><ul><ul><li>List header files </li></ul></ul></ul><ul><ul><ul><li>Allows for extra error checking </li></ul></ul></ul><ul><li>SCRIPTS </li></ul><ul><ul><ul><li>Executable scripts (interpreted programs) </li></ul></ul></ul><ul><li>MANS </li></ul><ul><ul><ul><li>List man pages </li></ul></ul></ul><ul><li>TEXINFOS </li></ul><ul><ul><ul><li>List Texinfo documentations </li></ul></ul></ul><ul><li>JAVA, LISP, PYTHON...... </li></ul>
  35. 35. Programs & Libraries Primaries (I) <ul><li>PROGRAMS </li></ul><ul><ul><li>eg: bin_PROGRAMS = doit </li></ul></ul><ul><li>LIBRARIES </li></ul><ul><ul><li>eg: lib_LIBRARIES = libzlib.a </li></ul></ul>
  36. 36. Programs & Libraries Primaries (II) <ul><li>When more than one source file, use SOURCES </li></ul><ul><li>eg: </li></ul><ul><li>1 ) bin_PROGRAMS = doit </li></ul><ul><li> doit_SOURCES = doit.c main.c </li></ul><ul><li>2 ) lib_LIBRARIES = libzlib.a </li></ul><ul><li> libzlib_a_SOURCES = adler32.c compress.c </li></ul><ul><li> crc32.c deflate.c deflate.h gzio.c infblock.c </li></ul><ul><li> infblock.h infcodes.c infcodes.h inffast.c inffast.h </li></ul>名称规范化
  37. 37. Common Macros <ul><li>_DEPENDENCIES </li></ul><ul><ul><li>Extra dependencies </li></ul></ul><ul><ul><li>Based on the value of the program's _LDADD macro. </li></ul></ul><ul><li>_LDADD </li></ul><ul><ul><li>Extra objects which are passed to the linker </li></ul></ul><ul><ul><li>Only used by programs and shared libraries </li></ul></ul><ul><li>_LIBADD </li></ul><ul><ul><li>Like _LDADD , but used for static libraries and not programs. </li></ul></ul>
  38. 38. Multiple Directories <ul><li>SUBDIRS </li></ul><ul><ul><li>eg: SUBDIRS = . m4 tests </li></ul></ul>Testing <ul><li>TESTS </li></ul><ul><li>XFAIL_TESTS </li></ul><ul><li>prefix `check' </li></ul><ul><ul><li>eg: check_PROGRAMS = test-program test_program_SOURCES = ...... </li></ul></ul>
  39. 39. 2003/12/29 References <ul><li>Autobook </li></ul><ul><li>http://192.168.1.182/ linux /tech/ autobook / autobook .html </li></ul><ul><li>Autoconf 手册 </li></ul><ul><li>http://www. cngnu .org/technology/145747f636f6e666.html </li></ul>
  40. 40. 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.

×