autotools工具的使用

root@jdqiu:/home/qjd/project# ls
include  lib  main.c
root@jdqiu:/home/qjd/project#
root@jdqiu:/home/qjd/project# ls include/
test.h
root@jdqiu:/home/qjd/project# ls lib/
test.c
root@jdqiu:/home/qjd/project#


/* project/main.c */
#include
#include "include/test.h"
int main()
{
    printf("main entrance./n");
    test_method();
    return 0;
}

/* project/lib/test.c */
#include
#include "../include/test.h"
void test_method()
{
    printf("test method./n");
}

/* project/include/test.h*/
void test_method();

/project# autoscan

root@jdqiu:/home/qjd/project# ls

autoscan.log  configure.scan  include  lib  main.c

root@jdqiu:/home/qjd/project# mv configure.scan configure.ac

root@jdqiu:/home/qjd/project# vi configure.ac

#                                               -*- Autoconf -*-

# Process this file with autoconf to produce a configure script.

 

AC_PREREQ([2.67])

#AC_INIT([FULL-PACKAGE-NAME], [VERSION], [BUG-REPORT-ADDRESS])

AC_INIT(hello, 1.0, 921751743@qq.com)

AM_INIT_AUTOMAKE(hello,1.0)

AC_CONFIG_SRCDIR([main.c])

AC_CONFIG_HEADERS([config.h])

# Checks for programs.

AC_PROG_CC

 

# Checks for libraries.

 

# Checks for header files.

 

# Checks for typedefs, structures, and compiler characteristics.

 

# Checks for library functions.

AC_CONFIG_FILES([Makefile])

 

AC_OUTPUT

~ 

root@jdqiu:/home/qjd/project# aclocal

root@jdqiu:/home/qjd/project# ls

aclocal.m4  autom4te.cache  configure.ac  include  lib  main.c  

root@jdqiu:/home/qjd/project# autoconf

root@jdqiu:/home/qjd/project# ls

aclocal.m4  autom4te.cache  configure  configure.ac  include  lib  main.c 

root@jdqiu:/home/qjd/project# autoheader

root@jdqiu:/home/qjd/project# ls

aclocal.m4      config.h.in  configure.ac  lib

autom4te.cache  configure    include       main.c 

手工创建Makefile.am文件。Automake工具会根据 configure.in 中的参量把 Makefile.am 转换成 Makefile.in 文件。

root@jdqiu:/home/qjd/project# vi Makefile.am  

AUTOMAKE_OPTIONS = foreign

bin_PROGRAMS = hello

hello_SOURCES = main.c include/test.h lib/test.c

 

root@jdqiu:/home/qjd/project# automake --add-missing

configure.ac:7: installing `./install-sh'

configure.ac:7: installing `./missing'

Makefile.am: installing `./depcomp'

root@jdqiu:/home/qjd/project# automake

root@jdqiu:/home/qjd/project# ls

aclocal.m4      configure     include     main.c       missing

autom4te.cache  configure.ac  install-sh  Makefile.am

config.h.in     depcomp       lib         Makefile.in

root@jdqiu:/home/qjd/project# ./configure

checking for a BSD-compatible install... /usr/bin/install -c

checking whether build environment is sane... yes

checking for a thread-safe mkdir -p... /bin/mkdir -p

checking for gawk... no

checking for mawk... mawk

checking whether make sets $(MAKE)... yes

checking for gcc... gcc

checking whether the C compiler works... yes

checking for C compiler default output file name... a.out

checking for suffix of executables...

checking whether we are cross compiling... no

checking for suffix of object files... o

checking whether we are using the GNU C compiler... yes

checking whether gcc accepts -g... yes

checking for gcc option to accept ISO C89... none needed

checking for style of include used by make... GNU

checking dependency style of gcc... gcc3

configure: creating ./config.status

config.status: creating Makefile

config.status: creating config.h

config.status: executing depfiles commands

root@jdqiu:/home/qjd/project# ls

aclocal.m4      config.log     depcomp     main.c       missing

autom4te.cache  config.status  include     Makefile     stamp-h1

config.h        configure      install-sh  Makefile.am

config.h.in     configure.ac   lib         Makefile.in

 

请使用浏览器的分享功能分享到微信等