📄 automake.texi
字号:
@cindex Uniform naming schemeAutomake macros (from here on referred to as @emph{variables}) generallyfollow a @dfn{uniform naming scheme} that makes it easy to decide howprograms (and other derived objects) are built, and how they areinstalled. This scheme also supports @code{configure} timedetermination of what should be built.@cindex _PROGRAMS primary variable@cindex PROGRAMS primary variable@cindex Primary variable, PROGRAMS@cindex Primary variable, definedAt @code{make} time, certain variables are used to determine whichobjects are to be built. These variables are called @dfn{primaryvariables}. For instance, the primary variable @code{PROGRAMS} holds alist of programs which are to be compiled and linked.@vindex PROGRAMS@cindex pkglibdir, defined@cindex pkgincludedir, defined@cindex pkgdatadir, defined@vindex pkglibdir@vindex pkgincludedir@vindex pkgdatadirA different set of variables is used to decide where the built objectsshould be installed. These variables are named after the primaryvariables, but have a prefix indicating which standard directory shouldbe used as the installation directory. The standard directory names aregiven in the GNU standards (@pxref{Directory Variables, , , standards,The GNU Coding Standards}). Automake extends this list with@code{pkglibdir}, @code{pkgincludedir}, and @code{pkgdatadir}; these arethe same as the non-@samp{pkg} versions, but with @samp{@@PACKAGE@@}appended. For instance, @code{pkglibdir} is defined as@code{$(datadir)/@@PACKAGE@@}.@cvindex PACKAGE@cindex EXTRA_, prependingFor each primary, there is one additional variable named by prepending@samp{EXTRA_} to the primary name. This variable is used to listobjects which may or may not be built, depending on what@code{configure} decides. This variable is required because Automakemust statically know the entire list of objects that may be built inorder to generate a @file{Makefile.in} that will work in all cases.@cindex EXTRA_PROGRAMS, defined@cindex Example, EXTRA_PROGRAMS@cindex cpio exampleFor instance, @code{cpio} decides at configure time which programs arebuilt. Some of the programs are installed in @code{bindir}, and someare installed in @code{sbindir}:@exampleEXTRA_PROGRAMS = mt rmtbin_PROGRAMS = cpio paxsbin_PROGRAMS = @@PROGRAMS@@@end exampleDefining a primary variable without a prefix (e.g. @code{PROGRAMS}) isan error.Note that the common @samp{dir} suffix is left off when constructing thevariable names; thus one writes @samp{bin_PROGRAMS} and not@samp{bindir_PROGRAMS}.Not every sort of object can be installed in every directory. Automakewill flag those attempts it finds in error. Automake will also diagnoseobvious misspellings in directory names.@cindex Extending list of installation directories@cindex Installation directories, extending listSometimes the standard directories---even as augmented by Automake---are not enough. In particular it is sometimes useful, for clarity, toinstall objects in a subdirectory of some predefined directory. To thisend, Automake allows you to extend the list of possible installationdirectories. A given prefix (e.g. @samp{zar}) is valid if a variable ofthe same name with @samp{dir} appended is defined (e.g. @code{zardir}).@cindex HTML support, exampleFor instance, until HTML support is part of Automake, you could use thisto install raw HTML documentation:@examplehtmldir = $(prefix)/htmlhtml_DATA = automake.html@end example@cindex noinst primary prefix, definitionThe special prefix @samp{noinst} indicates that the objects in questionshould not be installed at all.@cindex check primary prefix, definitionThe special prefix @samp{check} indicates that the objects in questionshould not be built until the @code{make check} command is run.Possible primary names are @samp{PROGRAMS}, @samp{LIBRARIES},@samp{LISP}, @samp{SCRIPTS}, @samp{DATA}, @samp{HEADERS}, @samp{MANS},and @samp{TEXINFOS}.@vindex PROGRAMS@vindex LIBRARIES@vindex LISP@vindex SCRIPTS@vindex DATA@vindex HEADERS@vindex MANS@vindex TEXINFOS@node Canonicalization, , Uniform, Generalities@section How derived variables are named@cindex canonicalizing Automake macrosSometimes a Makefile variable name is derived from some text the usersupplies. For instance, program names are rewritten into Makefile macronames. Automake canonicalizes this text, so that it does not have tofollow Makefile macro naming rules. All characters in the name exceptfor letters, numbers, and the underscore are turned into underscoreswhen making macro references. For example, if your program is named@code{sniff-glue}, the derived variable name would be@code{sniff_glue_SOURCES}, not @code{sniff-glue_SOURCES}.@node Examples, Invoking Automake, Generalities, Top@chapter Some example packages@menu* Complete:: A simple example, start to finish* Hello:: A classic program* etags:: Building etags and ctags@end menu@node Complete, Hello, Examples, Examples@section A simple example, start to finish@cindex Complete exampleLet's suppose you just finished writing @code{zardoz}, a program to makeyour head float from vortex to vortex. You've been using Autoconf toprovide a portability framework, but your @file{Makefile.in}s have beenad-hoc. You want to make them bulletproof, so you turn to Automake.@cindex AM_INIT_AUTOMAKE, example useThe first step is to update your @file{configure.in} to include thecommands that @code{automake} needs. The simplest way to do this is toadd an @code{AM_INIT_AUTOMAKE} call just after @code{AC_INIT}:@exampleAM_INIT_AUTOMAKE(zardoz, 1.0)@end exampleSince your program doesn't have any complicating factors (e.g., itdoesn't use @code{gettext}, it doesn't want to build a shared library),you're done with this part. That was easy!@cindex aclocal program, introduction@cindex aclocal.m4, preexisting@cindex acinclude.m4, definedNow you must regenerate @file{configure}. But to do that, you'll needto tell @code{autoconf} how to find the new macro you've used. Theeasiest way to do this is to use the @code{aclocal} program to generateyour @file{aclocal.m4} for you. But wait... you already have an@file{aclocal.m4}, because you had to write some hairy macros for yourprogram. The @code{aclocal} program lets you put your own macros into@file{acinclude.m4}, so simply rename and then run:@examplemv aclocal.m4 acinclude.m4aclocalautoconf@end example@cindex zardoz exampleNow it is time to write your @file{Makefile.am} for @code{zardoz}.Since @code{zardoz} is a user program, you want to install it where therest of the user programs go. Additionally, @code{zardoz} has someTexinfo documentation. Your @file{configure.in} script uses@code{AC_REPLACE_FUNCS}, so you need to link against @samp{@@LIBOBJS@@}.So here's what you'd write:@examplebin_PROGRAMS = zardozzardoz_SOURCES = main.c head.c float.c vortex9.c gun.czardoz_LDADD = @@LIBOBJS@@info_TEXINFOS = zardoz.texi@end exampleNow you can run @code{automake --add-missing} to generate your@file{Makefile.in} and grab any auxiliary files you might need, andyou're done!@node Hello, etags, Complete, Examples@section A classic program@cindex Example, GNU Hello@cindex Hello example@cindex GNU Hello, example@uref{ftp://prep.ai.mit.edu/pub/gnu/hello-1.3.tar.gz, GNU hello} isrenowned for its classic simplicity and versatility. This section showshow Automake could be used with the GNU Hello package. The examplesbelow are from the latest beta version of GNU Hello, but with all of themaintainer-only code stripped out, as well as all copyright comments.Of course, GNU Hello is somewhat more featureful than your traditionaltwo-liner. GNU Hello is internationalized, does option processing, andhas a manual and a test suite. GNU Hello is a deep package.@cindex configure.in, from GNU Hello@cindex GNU Hello, configure.in@cindex Hello, configure.inHere is the @file{configure.in} from GNU Hello:@examplednl Process this file with autoconf to produce a configure script.AC_INIT(src/hello.c)AM_INIT_AUTOMAKE(hello, 1.3.11)AM_CONFIG_HEADER(config.h)dnl Set of available languages.ALL_LINGUAS="de fr es ko nl no pl pt sl sv"dnl Checks for programs.AC_PROG_CCAC_ISC_POSIXdnl Checks for libraries.dnl Checks for header files.AC_STDC_HEADERSAC_HAVE_HEADERS(string.h fcntl.h sys/file.h sys/param.h)dnl Checks for library functions.AC_FUNC_ALLOCAdnl Check for st_blksize in struct statAC_ST_BLKSIZEdnl internationalization macrosAM_GNU_GETTEXTAC_OUTPUT([Makefile doc/Makefile intl/Makefile po/Makefile.in \ src/Makefile tests/Makefile tests/hello], [chmod +x tests/hello])@end exampleThe @samp{AM_} macros are provided by Automake (or the Gettext library);the rest are standard Autoconf macros.The top-level @file{Makefile.am}:@exampleEXTRA_DIST = BUGS ChangeLog.OSUBDIRS = doc intl po src tests@end exampleAs you can see, all the work here is really done in subdirectories.The @file{po} and @file{intl} directories are automatically generatedusing @code{gettextize}; they will not be discussed here.@cindex Texinfo file handling example@cindex Example, handling Texinfo filesIn @file{doc/Makefile.am} we see:@exampleinfo_TEXINFOS = hello.texihello_TEXINFOS = gpl.texi@end exampleThis is sufficient to build, install, and distribute the GNU Hellomanual.@cindex Regression test example@cindex Example, regression testHere is @file{tests/Makefile.am}:@exampleTESTS = helloEXTRA_DIST = hello.in testdata@end exampleThe script @file{hello} is generated by @code{configure}, and is theonly test case. @code{make check} will run this test.@cindex INCLUDES, example usageLast we have @file{src/Makefile.am}, where all the real work is done:@examplebin_PROGRAMS = hellohello_SOURCES = hello.c version.c getopt.c getopt1.c getopt.h system.h hello_LDADD = @@INTLLIBS@@ @@ALLOCA@@localedir = $(datadir)/localeINCLUDES = -I../intl -DLOCALEDIR=\"$(localedir)\"@end example@node etags, , Hello, Examples@section Building etags and ctags@cindex Example, ctags and etags@cindex ctags Example@cindex etags ExampleHere is another, trickier example. It shows how to generate twoprograms (@code{ctags} and @code{etags}) from the same source file(@file{etags.c}). The difficult part is that each compilation of@file{etags.c} requires different @code{cpp} flags.@examplebin_PROGRAMS = etags ctagsctags_SOURCES =ctags_LDADD = ctags.oetags.o: etags.c $(COMPILE) -DETAGS_REGEXPS -c etags.cctags.o: etags.c $(COMPILE) -DCTAGS -o ctags.o -c etags.c@end exampleNote that @code{ctags_SOURCES} is defined to be empty---that way noimplicit value is substituted. The implicit value, however, is used togenerate @code{etags} from @file{etags.o}.@code{ctags_LDADD} is used to get @file{ctags.o} into the link line.@code{ctags_DEPENDENCIES} is generated by Automake.The above rules won't work if your compiler doesn't accept both@samp{-c} and @samp{-o}. The simplest fix for this is to introduce abogus dependency (to avoid problems with a parallel @code{make}):@exampleetags.o: etags.c ctags.o $(COMPILE) -DETAGS_REGEXPS -c etags.cctags.o: etags.c $(COMPILE) -DCTAGS -c etags.c && mv etags.o ctags.o@end exampleAlso, these explicit rules do not work if the de-ANSI-fication featureis used (@pxref{ANSI}). Supporting de-ANSI-fication requires a littlemore work:@exampleetags._o: etags._c ctags.o $(COMPILE) -DETAGS_REGEXPS -c etags.cctags._o: etags._c $(COMPILE) -DCTAGS -c etags.c && mv etags._o ctags.o@end example
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -