【转】使用autotools生成makefile文件入门

autotools是一系列工具集,要使用这些工具当然首先要确认系统已经安装了下列工具:
    autoscan
    aclocal
    autoconf
    autoheader
    automake
使用命令which ooxx可查看到命令的路径,如果没有就没装,用命令rpm -qa | grep automake 和命令rpm -qa | grep autoconf 看哪个包没有装(debin系列的就用类似的dpkg包管理命令查看)。

autotools 

 

要说入门当然是使用路人皆知的hello world程序作为示范代码了:

//hello.c
#include <stdio.h>
#include <sys/time.h>
int main(void)
{
    double sec;
    struct timeval tv;

    gettimeofday(&tv, NULL);
    sec = tv.tv_sec;
    sec += tv.tv_usec/1000000.0;
    printf ("hello word!\nsec = %e\n", sec);
    return 0;
}

 

程序文件hello.c放在test目录中,确保此目录只有hello.c一个文件,下面就开始autotools旅程:
   
    1:

运行命令$ autoscan 生成文件configure.scan,修改configure.scan,修改后文件内容如下(红色修改,蓝色添加):

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

AC_PREREQ(2.61)
AC_INIT(hello, 1.0)
AM_INIT_AUTOMAKE(hello, 1.0)
AC_CONFIG_SRCDIR([hello.c])
AC_CONFIG_HEADER([config.h])

# Checks for programs.
AC_PROG_CC

# Checks for libraries.

# Checks for header files.
AC_CHECK_HEADERS([sys/time.h])

# Checks for typedefs, structures, and compiler characteristics.
AC_HEADER_TIME

# Checks for library functions.
AC_CHECK_FUNCS([gettimeofday])

AC_CONFIG_FILES([Makefile])
AC_OUTPUT

 

相对原文件,其实就是修改了一行,添加了两行:
AC_INIT(hello,1.0)
AM_INIT_AUTOMAKE(hello,1.0)
AC_CONFIG_FILES([Makefile])

修改文件完毕后,为文件改名 $ mv configure.scan configure.in





    2:

运行命令$ aclocal 生成aclocal.m4

    3:
运行命令$ autoconf 生成configure

    4:
运行命令$ autoheader 生成config.h.in,使程序可移植


    5:
创建空文件Makefile.am,写入内容:

bin_PROGRAMS= hello
hello_SOURCES= hello.c


    6:
运行命令$ automake --add-missing   生成configure.in文件

    7:
不出意外的话,其实到上面都已经完成所有步骤了,下面就是编译运行软件三步曲:  configure  &&  make  &&  make install
这里没必要make install,直接运行当前目录下的hello文件即可:
[mgqw@localhost test]$ ./hello
hello word!
sec = 1.244798e+09
   
结束语:
    上面的步骤只是简单介绍了autotools的使用过程,其中具体含义以及其他功能上百度/狗狗一搜一大把,记住百度/狗狗永远是我们最好的老师。

 

 

 

 

 

转载于:https://www.cnblogs.com/flatfoosie/archive/2010/12/21/1912946.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值