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