automake快速搭建工程

1 Automake简介

GNU Automake是Linux环境下常用的开发工具,可以产生供make使用的Makefile,省却了开发人员编写Makefile的繁琐事情。

2 搭建流程

Automake搭建工程的一般流程,如下图所示:椭圆或圆形代表动作,长方形代表数据


上图的流程比较繁琐,GNU提供了一个工具Autoreconf,将automake,autoconf等调用顺序隐藏起来,可以更便利的生成工程。流程图如下所示




流程图解析:

1.       $autoscan,对源码进行扫描,生成configure.scan,并修改为configure.ac

2.       准备Makefile.am

3.       $autoreconf –install生成config.h,Makefile

4.       $make编译工程

3 实例

这个例子是生成一个动态库libmymath.so,供主程序test调用。

3.1 源码目录结构


总共是1个目录,9个文件。

3.2 步骤

1. $autoscan

2.  $mv   configure.scan       configure.ac

3.  $vi    configure.ac

        修改AC_INIT([test], [1.0], BUG-REPORT-ADDRESS)

  增加AM_INIT_AUTOMAKE,初始化automake

  增加AC_PROG_LIBTOOL,支持库文件

4.   $autoreconf      --install

5.   $./configure

6.   $make

4 附录

4.1 顶层Makefile.am

SUBDIRS=src

 

4.2   src的Makefile.am

#指定生成的二进制的名字

bin_PROGRAMS=test

#test依赖的C文件

test_SOURCES=main.c \

             usage.c

#test依赖的库文件

test_LDADD=libmymath.la

include_HEADERS=del.h \

                add.h


#生成的共享库libmymath.so

lib_LTLIBRARIES=libmymath.la

#共享库的依赖文件

libmymath_la_SOURCES=add.c \

                     del.c

4.3 main.c

#include

#include "add.h"

#include "del.h"


#include "usage.h"

int main(char *argv[], int argc)

{

    if (argc > 1)

    {

        usage();

        return -1;

    }

    int a = 1;

    int b = -1;

    int c;

    c = add(a, b);

    printf("c = %d\n", c);


    c = del(a, b);

    printf("c = %d\n", c);

    return 0;

}

 

4.4 add.c

int add(int a, int b)

{

    return a+b;

}

4.5 add.h

int add(int a, int b);

4.6   del.c

int del(int a, int b)

{

    return a-b;

}

4.7  del.h

int del(int a, int b);

4.8  usage.c

void usage(void)

{

    printf("usage: ./bin");

}

4.9 usage.h

void usage(void);

<script>window._bd_share_config={"common":{"bdSnsKey":{},"bdText":"","bdMini":"2","bdMiniList":false,"bdPic":"","bdStyle":"0","bdSize":"16"},"share":{}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)];</script>
阅读(1419) | 评论(0) | 转发(3) |
0

上一篇:X SERVER 优化

下一篇:vundle管理VIM插件

给主人留下些什么吧!~~
评论热议
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

kelsel

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值