2013年4月

automake有很多内置的变量名,列出如下:

xx__SOURCES

nodist_xxx_SOURCES

dist_xxx_SOURCES

xxx_AR

xxx_LIBADD

xxx_LDADD

xxx_LDFLAGS

xxx_LIBTOOLFLAGS

xxx_DEPENDENCIES

xxx_LINK

xxx_CCASFLAGS
xxx_CFLAGS
xxx_CPPFLAGS
xxx_CXXFLAGS
xxx_FFLAGS
xxx_GCJFLAGS
xxx_LFLAGS
xxx_OBJCFLAGS
xxx_OBJCXXFLAGS
xxx_RFLAGS
xxx_UPCFLAGS
xxx_YFLAGS
xxx_SHORTNAME

我们的程序也没有使用到动态库,动态库的支持相对于静态库,要复杂许多,

动态库与静态库在一些变量名字上有不同,比如LTLIBRARIES/

通常,我们是使用libtool来创建动态库,在automake中使用libtool创建动态库时,使用的扩展名并不是so,而是la

比如我们声明创建一个动态库:

     lib_LTLIBRARIES =libgettext.la
libgettext_la_SOURCES
= gettext.c gettext.h ...

automake预定义了pkglibdir变量,因此可以使用pkglib_LTLIBRARIES将之安装在$(libdir)/@PACKAGE@/目录下

使用动态库时,应如下使用

     bin_PROGRAMS =hello
hello_SOURCES
=hello.c ...
hello_LDADD
= libgettext.la

这么写因为根据configure的选项,是可以禁止生成动态库的,那这时候,我们链接到的将会是libtool生成的静态库

无论静态库还是动态库,在使用libtool时,调用automake之前必须调用libtoolize以建一些automake必备的文件

目前我们的程序没有使用到静态库,对于静态库:

1.目标应使用xx_LIBRARIES说明,

2.lib_LIBRARIES会安装的/usr/lib目录下

3.pkglib_LIBRARIES会安装在/usr/XXX/lib目录下

4.noinst_LIBRARIES将不会被安装,只是是编译链接过来中使用到

ps:对于编译过程中生成的可执行程序,不希望安装时,也可以使用noinst_PROGRAMS

比如,创建一个静态库,但不希望安装,同时指定其编译的源文件:

noinst_LIBRARIES =libcpio.a
libcpio_a_SOURCES
= xxx yyy zzz

这里涉及到一个automake的命名正规化(canonicalizes)问题,即将一些非字母转换成下划线,记住,是所有的非字母

 

 

我们目前用的autogen.sh是很简陋的,没有测试系统中是否包含要用到的工具

正式的autogen.sh如下:

#! /bin/sh# Allow invocation from a separate build directory;in that case, we change
# to the source directory to run the auto
*, thenchange back before running configure
srcdir
=`dirname $0`
test
-z "$srcdir" && srcdir=.

ORIGDIR
=`pwd`
cd $srcdir

LIBTOOLIZE_FLAGS
="--force --automake"#ACLOCAL_FLAGS="-I autotools $ACLOCAL_FLAGS"AUTOMAKE_FLAGS="--foreign --add-missing"DIE=0(autoconf--version) < /dev/null > /dev/null 2>&1 ||{echo echo "You must have autoconf installed to compile $PROJECT." echo "Install the appropriate package for your distribution," echo "or get the source tarball at http://ftp.gnu.org/gnu/autoconf/"DIE=1}

(automake
--version) < /dev/null > /dev/null 2>&1 ||{echo echo "You must have automake installed to compile $PROJECT." echo "Install the appropriate package for your distribution," echo "or get the source tarball at http://ftp.gnu.org/gnu/automake/"DIE=1}

LIBTOOLIZE
=libtoolize
($LIBTOOLIZE
--version) < /dev/null > /dev/null 2>&1 ||{
LIBTOOLIZE
=glibtoolize
($LIBTOOLIZE
--version) < /dev/null > /dev/null 2>&1 ||{echo echo "You must have libtool installed to compile $PROJECT." echo "Install the appropriate package for your distribution," echo "or get the source tarball at http://ftp.gnu.org/gnu/libtool/"DIE=1}
}
if test "$DIE" -eq 1; thenexit1 fi rm -rf $top_srcdir/autom4te.cachetouchREADME INSTALL

aclocal $ACLOCAL_FLAGS
|| exit $?$LIBTOOLIZE $LIBTOOLIZE_FLAGS|| exit $?autoheader|| exit $?automake $AUTOMAKE_FLAGS|| exit $?autoconf|| exit $?cd $ORIGDIR|| exit 1$srcdir/configure $AUTOGEN_CONFIGURE_ARGS "$@" || exit $?