一般流程爲
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根據一般步驟最後編譯運行