使用automake生成静态库

来源:互联网 发布:淘宝店铺外包有用吗 编辑:程序博客网 时间:2024/05/17 02:31
一. 主函数Makefile创建


1. autoscan->生成 configure.scan 和 autoscan.log


2.将configure.scan 修改为 configure.in:
并修改configure.in内容如下
  # Process this file with autoconf to produce a configure script.
    AC_INIT(hello.c)
    AM_INIT_AUTOMAKE(hello, 1.0)
  # Checks for programs.
    AC_PROG_CC
  # Checks for library functions.
    AC_OUTPUT(Makefile)


3. aclocal
->生成 aclocal.m4 和 autom4te.cache (生成aclocal.m4的过程中涉及到configure.in)


4. autoconf
->生成 configure (根据 configure.in, 和 aclocal.m4)


5. autoheader
        ->生成 config.h.in 宏定义


6. 编写Makefile.am


   AUTOMAKE_OPTIONS=foreign
   INCLUDES=-I../include
   bin_PROGRAMS=hello
   hello_SOURCES=hello.c
   hello_LDADD=../lib/libhello.a


7. touch NEWS AUTHORS README ChangeLog 


8. automake --add-missing
->生成 Makefile.in, depcomp, install-sh, 和 missing (根据 Makefile.am, 和 aclocal.m4)


9. ./configure
->生成 Makefile, config.log, 和 config.status


10. make


二. 静态库Makefile创建


1. configure.in创建


   # configure.in
   # Process this file with autoconf to produce a configure script.
     AC_PREREQ(2.59)
     AC_INIT(libhello.a,1.1,[])
     AM_INIT_AUTOMAKE
   # Checks for programs.
     AC_PROG_CC
   # Checks for libraries.
     AC_PROG_RANLIB//需要加入的内容,因为使用了静态库
   # Checks for header files.
   # Checks for typedefs, structures, and compiler characteristics.
   # Checks for library functions.
     AC_OUTPUT([Makefile])
     AC_INIT(FILE)


   #Makefile.am
   AUTOMAKE_OPTIONS=foreign
   noinst_LIBRARIES=libhello.a
   libhello_a_SOURCES=test.c
0 0