autoconf&&automake sample

一般流程为
1. 运行autoscan进行目录的扫描声称configure.scan.
2. 修改后缀为configure.in,同时修改部分内容保存
3. 运行aclocal依赖2的文件生成aclocal.m4
4. 运行autoconf命令,根据2,3文件生成configure文件
5. 手动编辑一个文件Makefile.am
6. automake --add-missing生成Makefile.in
7. ./configure运行生成Makefile
8. make程序



sample1:
1. 建立一个目录下面两个文件another.c another.h, main.c,在建立一个目录
nested/test_foo.h, test_fool.c
2. main.c:
#include <stdio.h>
#include "another.h"
#include "test_foo.h"

int main(int argc, char* argv[])
{
    int a = 100;
    int b = 20;

    printf("a plus b=%d/n", test_add(a,b));
    printf("a minus b=%d/n", foo_1(a,b));

}


another.c:
#include "another.h"

int test_add( int a, int b)
{
        return a + b;
}


test_foo.c
#include "test_foo.h"

int foo_1( int a, int b)
{
    return a-b;
}


3. 运行autoscan会在目录下看到configure.scan,都是AC_**的宏
我们修改后缀为.in,修改内部宏的内容,
AC_CONFIG_SRCDIR([nested/test_foo.c])
#表示首先会查找这个目录下的文件,我们main依赖于nested中的文件那要表示一下
AC_CONFIG_HEADERS([config.h])
AC_INIT(main.c)
AM_INIT_AUTOMAKE(main, 1.0)
#这个是定义关联程序版本

AC_PROG_RANLIB
#这个如果是编译连接库需要增加这个检测,不加也会提示的
AC_OUTPUT([Makefile nested/Makefile])
#定义关联输出的MAKEFILE文件

整个文件:
#                                               -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.

AC_PREREQ([2.64])
#AC_INIT([FULL-PACKAGE-NAME], [VERSION], [BUG-REPORT-ADDRESS])
AC_CONFIG_SRCDIR([nested/test_foo.c])
AC_CONFIG_HEADERS([config.h])
AC_INIT(main.c)
AM_INIT_AUTOMAKE(main, 1.0)
# 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 nested/Makefile])

4.根据一般步骤4来声称configue
5.定义Makefile.am文件:


当前目录下的
#SUBDIRS = nested
INCLUDES=-I./nested
bin_PROGRAMS=test
test_SOURCES= another.h another.c main.c
#test_LDADD=nested/libfoo.a
test_LDADD=nested/test_foo.o #引用生成的库或者obj

nested目录下的:
#noinst_LIBRARIES=libfoo.a   #生成库或者obj的语法是定义的man一下
noinst_PROGRAMS=foo.o
#libfoo_a_SOURCES=test_foo.c #libfoo.a-->libfoo_a_*
foo_o_SOURCES=test_foo.c     #foo_o_SOURCES来源于foo.o-->foo_O_*,
DEFS+=-D_GNU_SOURCE


6根据一般步骤最后编译运行

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章