⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 autobook_39.html

📁 Autoconf使用手册
💻 HTML
字号:
<HTML><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><!-- Created on September, 12  2004 by texi2html 1.64 --><!-- Written by: Lionel Cons <Lionel.Cons@cern.ch> (original author)            Karl Berry  <karl@freefriends.org>            Olaf Bachmann <obachman@mathematik.uni-kl.de>            and many others.Maintained by: Olaf Bachmann <obachman@mathematik.uni-kl.de>Send bugs and suggestions to <texi2html@mathematik.uni-kl.de> --><HEAD><TITLE>Autoconf, Automake, and Libtool: Programs and libraries</TITLE><META NAME="description" CONTENT="Autoconf, Automake, and Libtool: Programs and libraries"><META NAME="keywords" CONTENT="Autoconf, Automake, and Libtool: Programs and libraries"><META NAME="resource-type" CONTENT="document"><META NAME="distribution" CONTENT="global"><META NAME="Generator" CONTENT="texi2html 1.64"><script language="Javascript"><!--    // Check the browser version.    function checkVersion() {      if (navigator.appVersion.charAt(0)>=3) return true;      if (navigator.appVersion.charAt(0)>=4) return true;      else return false;    }      if (checkVersion()) {             homeon = new Image();             homeon.src = "homeon.png";             homeoff = new Image();             homeoff.src = "home.png";             tocon = new Image();             tocon.src = "tocon.png";             tocoff = new Image();             tocoff.src = "toc.png";             indexon = new Image();             indexon.src = "indexon.png";             indexoff = new Image();             indexoff.src = "index.png";             helpon = new Image();             helpon.src = "helpon.png";             helpoff = new Image();             helpoff.src = "help.png";             backon = new Image();             backon.src = "backon.png";             backoff = new Image();             backoff.src = "back.png";             forwardon = new Image();             forwardon.src = "forwardon.png";             forwardoff = new Image();             forwardoff.src = "forward.png";             prevon = new Image();             prevon.src = "prevon.png";             prevoff = new Image();             prevoff.src = "prev.png";             nexton = new Image();             nexton.src = "nexton.png";             nextoff = new Image();             nextoff.src = "next.png";             upon = new Image();             upon.src = "upon.png";             upoff = new Image();             upoff.src = "up.png";         }     function img_act(imgName) {             if (checkVersion()) {             imgOn = eval(imgName + "on.src");             document [imgName].src = imgOn;             }     }     function img_inact(imgName) {             if (checkVersion()) {             imgOff = eval(imgName + "off.src");             document [imgName].src = imgOff;             }     }// --></SCRIPT></HEAD><BODY LANG="EN" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#6688AA" VLINK="#336688" ALINK="#808080"><A NAME="SEC39"></A><TABLE BORDER=0 CELLPADDING=0 CELLSPACING=10><TR VALIGN="TOP"><TD ALIGN="MIDDLE" WIDTH=50 BGCOLOR="#e6e6e6"><TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0><TR VALIGN="TOP" ALIGN="LEFT"><TD VALIGN="MIDDLE" ALIGN="LEFT"><A HREF="autobook_38.html#SEC38" onMouseover="img_act('prev')" onMouseout="img_inact('prev')"><IMG SRC="prev.png" BORDER="0" ALT="Back: The easy primaries" ALIGN="MIDDLE" NAME="prev"></A></TD></TR><TR VALIGN="TOP" ALIGN="LEFT"><TD VALIGN="MIDDLE" ALIGN="LEFT"><A HREF="autobook_40.html#SEC40" onMouseover="img_act('next')" onMouseout="img_inact('next')"><IMG SRC="next.png" BORDER="0" ALT="Forward: Frequently Asked Questions" ALIGN="MIDDLE" NAME="next"></A></TD></TR><TR VALIGN="TOP" ALIGN="LEFT"><TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TR VALIGN="TOP" ALIGN="LEFT"><TD VALIGN="MIDDLE" ALIGN="LEFT"><A HREF="autobook_40.html#SEC40" onMouseover="img_act('back')" onMouseout="img_inact('back')"><IMG SRC="back.png" BORDER="0" ALT="FastBack: Frequently Asked Questions" ALIGN="MIDDLE" NAME="back"></A></TD></TR><TR VALIGN="TOP" ALIGN="LEFT"><TD VALIGN="MIDDLE" ALIGN="LEFT"><A HREF="autobook_35.html#SEC35" onMouseover="img_act('up')" onMouseout="img_inact('up')"><IMG SRC="up.png" BORDER="0" ALT="Up: Introducing GNU Automake" ALIGN="MIDDLE" NAME="up"></A></TD></TR><TR VALIGN="TOP" ALIGN="LEFT"><TD VALIGN="MIDDLE" ALIGN="LEFT"><A HREF="autobook_43.html#SEC43" onMouseover="img_act('forward')" onMouseout="img_inact('forward')"><IMG SRC="forward.png" BORDER="0" ALT="FastForward: Bootstrapping" ALIGN="MIDDLE" NAME="forward"></A></TD></TR><TR VALIGN="TOP" ALIGN="LEFT"><TD VALIGN="MIDDLE" ALIGN="LEFT"><A HREF="autobook.html#SEC_Top" onMouseover="img_act('home')" onMouseout="img_inact('home')"><IMG SRC="home.png" BORDER="0" ALT="Top: Autoconf, Automake, and Libtool" ALIGN="MIDDLE" NAME="home"></A></TD></TR><TR VALIGN="TOP" ALIGN="LEFT"><TD VALIGN="MIDDLE" ALIGN="LEFT"><A HREF="autobook_toc.html#SEC_Contents" onMouseover="img_act('toc')" onMouseout="img_inact('toc')"><IMG SRC="toc.png" BORDER="0" ALT="Contents: Table of Contents" ALIGN="MIDDLE" NAME="toc"></A></TD></TR><TR VALIGN="TOP" ALIGN="LEFT"><TD VALIGN="MIDDLE" ALIGN="LEFT"><A HREF="autobook_285.html#SEC285" onMouseover="img_act('index')" onMouseout="img_inact('index')"><IMG SRC="index.png" BORDER="0" ALT="Index: Index" ALIGN="MIDDLE" NAME="index"></A></TD></TR><TR VALIGN="TOP" ALIGN="LEFT"><TD VALIGN="MIDDLE" ALIGN="LEFT"><A HREF="autobook_abt.html#SEC_About" onMouseover="img_act('help')" onMouseout="img_inact('help')"><IMG SRC="help.png" BORDER="0" ALT="About: About this document" ALIGN="MIDDLE" NAME="help"></A></TD></TR></TABLE></TD><TD ALIGN="LEFT"><H2> 7.4 Programs and libraries </H2><!--docid::SEC39::--><P>The preceding primaries have all been relatively easy to use.  Now we'lldiscuss a more complicated set, namely those used to build programs andlibraries.  These primaries are more complex because building a programis more complex than building a script (which often doesn't even needbuilding at all).</P><P>Use the <CODE>PROGRAMS</CODE> primary for programs, <CODE>LIBRARIES</CODE> forlibraries, and <CODE>LTLIBRARIES</CODE> for Libtool libraries(see section <A HREF="autobook_68.html#SEC68">10. Introducing GNU Libtool</A>).  Here is a minimal example:</P><P><TABLE width=100%><tr><td>&nbsp;</td><td class=example bgcolor=#6688aa><br><pre>bin_PROGRAMS = doit</pre></td></tr></table></P><P>This creates the program <CODE>doit</CODE> and arranges to install it in<CODE>bindir</CODE>.  First <CODE>make</CODE> will compile <TT>`doit.c'</TT> to produce<TT>`doit.o'</TT>.  Then it will link <TT>`doit.o'</TT> to create <TT>`doit'</TT>.</P><P>Of course, if you have more than one source file, and most programs do,then you will want to be able to list them somehow.  You will do thisvia the program's <CODE>SOURCES</CODE> variable.  Each program or library hasa set of associated variables whose names are constructed by appendingsuffixes to the `normalized' name of the program.  The <EM>normalizedname</EM> is the name of the object with non-alphanumeric characters changedto underscores.  For instance, the normalized name of <SAMP>`quux'</SAMP> is<SAMP>`quux'</SAMP>, but the normalized name of <SAMP>`install-info'</SAMP> is<SAMP>`install_info'</SAMP>.  Normalized names are used because they correspondto <CODE>make</CODE> syntax, and, like all macros, Automake propagates thesedefinitions into the resulting <TT>`Makefile.in'</TT>.</P><P>So if <TT>`doit'</TT> is to be built from files <TT>`main.c'</TT> and<TT>`doit.c'</TT>, we would write:</P><P><TABLE width=100%><tr><td>&nbsp;</td><td class=example bgcolor=#6688aa><br><pre>bin_PROGRAMS = doitdoit_SOURCES = doit.c main.c</pre></td></tr></table></P><P>The same holds for libraries.  In the zlib package we might make alibrary called <TT>`libzlib.a'</TT>.  Then we would write:</P><P><TABLE width=100%><tr><td>&nbsp;</td><td class=example bgcolor=#6688aa><br><pre>lib_LIBRARIES = libzlib.alibzlib_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 \inffixed.h inflate.c inftrees.c inftrees.h infutil.c infutil.h trees.c \trees.h uncompr.c zconf.h zlib.h zutil.c zutil.h</pre></td></tr></table></P><P>We can also do this with libtool libraries.  For instance, suppose wewant to build <TT>`libzlib.la'</TT> instead:</P><P><TABLE width=100%><tr><td>&nbsp;</td><td class=example bgcolor=#6688aa><br><pre>lib_LTLIBRARIES = libzlib.lalibzlib_la_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 \inffixed.h inflate.c inftrees.c inftrees.h infutil.c infutil.h trees.c \trees.h uncompr.c zconf.h zlib.h zutil.c zutil.h</pre></td></tr></table></P><P>As you can see, making shared libraries with Automake and Libtool isjust as easy as making static libraries.</P><P>In the above example, we listed header files in the <CODE>SOURCES</CODE>variable.  These are ignored (except by <CODE>make dist</CODE><A NAME="DOCF1" HREF="autobook_fot.html#FOOT1">(1)</A>) but can serve to makeyour <TT>`Makefile.am'</TT> a bit clearer (and sometimes shorter, if youaren't installing headers).</P><P>Note that you can't use <TT>`configure'</TT> substitutions in a<CODE>SOURCES</CODE> variable.  Automake needs to know the <EM>static</EM> listof files which can be compiled into your program.  There are stillvarious ways to conditionally compile files, for instance Automakeconditionals or the use of the <CODE>LDADD</CODE> variable.</P><P>The static list of files is also used in some versions of Automake'sautomatic dependency tracking.  The general rule is that each sourcefile which might be compiled should be listed in some <CODE>SOURCES</CODE>variable.  If the source is conditionally compiled, it can be listed inan <CODE>EXTRA</CODE> variable.  For instance, suppose in this example<SAMP>`@FOO_OBJ@'</SAMP> is conditionally set by <TT>`configure'</TT> to<SAMP>`foo.o'</SAMP> when <SAMP>`foo.c'</SAMP> should be compiled:</P><P><TABLE width=100%><tr><td>&nbsp;</td><td class=example bgcolor=#6688aa><br><pre>bin_PROGRAMS = foofoo_SOURCES = main.cfoo_LDADD = @FOO_OBJ@foo_DEPENDENCIES = @FOO_OBJ@EXTRA_foo_SOURCES = foo.c</pre></td></tr></table></P><P>In this case, <SAMP>`EXTRA_foo_SOURCES'</SAMP> is used to list sources which areconditionally compiled; this tells Automake that they exist even thoughit can't deduce their existence automatically.</P><P>In the above example, note the use of the <SAMP>`foo_LDADD'</SAMP> macro.  Thismacro is used to list other object files and libraries which should belinked into the <CODE>foo</CODE> program.  Each program or library has severalsuch associated macros which can be used to customize the link step;here we list the most common ones:</P><P><DL COMPACT><DT><SAMP>`_DEPENDENCIES'</SAMP><DD>Extra dependencies which are added to the program's dependency list.  Ifnot specified, this is automatically computed based on the value of theprogram's <SAMP>`_LDADD'</SAMP> macro.<P><DT><SAMP>`_LDADD'</SAMP><DD>Extra objects which are passed to the linker.  This is only used byprograms and shared libraries.<P><DT><SAMP>`_LDFLAGS'</SAMP><DD>Flags which are passed to the linker.  This is separate from<SAMP>`_LDADD'</SAMP> to allow <SAMP>`_DEPENDENCIES'</SAMP> to be auto-computed.<P><DT><SAMP>`_LIBADD'</SAMP><DD>Like <SAMP>`_LDADD'</SAMP>, but used for static libraries and not programs.</DL><P>You aren't required to define any of these macros.</P><P><A NAME="Frequently Asked Questions"></A></TR></TABLE><BR>  <FONT SIZE="-1">This document was generatedby <I>Gary V. Vaughan</I> on <I>September, 12  2004</I>using <A HREF="http://www.mathematik.uni-kl.de/~obachman/Texi2html"><I>texi2html</I></A></BODY></HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -