jetway_loves_programming之linuxC学习之Linux 下Makefile的automake生成简单例子

Makefile 是用于自动编译和链接的,一个工程文件可以由很多文件组成,每一个文件的改变都会导致工程的重新链接,但是不是所有的文件都需要重新编译,Makefile 中记录有文件的信息,在make时会决定在链接的时候需要重新编译哪些文件。Makefile 的宗旨就是:让编译器知道如果要编译一个文件,那么需要依赖其他的哪些文件。

使用automake,程序员只需要写一些简单的含有预定义宏的文件,由autoconf根据一个宏文件生成configure,由automake根据另一个宏文件生成Makefile.in,再使用configure,依据Makefile.in生成一个符合惯例的Makefile。接下来介绍automake生成Makefile的简单例子。

1、建目录

[root@localhost jetway]# mkdir fuckworld

[root@localhost jetway]# cd fuckworld/

 

2、编写程序fuckworld.c

[root@localhost fuckworld]# vi fuckworld.c

 

#include<stdio.h>

 

int main(int argc,char ** argv)

{

    printf("fuck the pool world!!!/n");

    return 0;

}

 

3、生成configure

[root@localhost fuckworld]# autoscan

[root@localhost fuckworld]# ls

autoscan.log  configure.scan  fuckworld.c

 

configure.scan作为configure.in的蓝本,重命名:

mv configure.scan configure.in

 

修改configure.in里面的内容:

[root@localhost fuckworld]# vim configure.in

#                                               -*- Autoconf -*-

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

 

AC_INIT(fuckworld.c)

AM_INIT_AUTOMAKE(fuckworld,1.0)

 

# 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_OUTPUT(Makefile)

 

 

然后执行命令aclocalautoconf

[root@localhost fuckworld]# aclocal

[root@localhost fuckworld]# ls

aclocal.m4  autom4te.cache  autoscan.log  configure.in  fuckworld.c

[root@localhost fuckworld]# autoconf

[root@localhost fuckworld]# ls

aclocal.m4  autom4te.cache  autoscan.log  configure  configure.in  fuckworld.c

 

4、新建Makefile.am

[root@localhost fuckworld]# vi Makefile.am

AUTOMAKE_OPTIONS = foreign

bin_PROGRAMS = fuckworld

fuckworld_SOURCES = fuckworld.c

 

5、运行automake

[root@localhost fuckworld]# automake --add-missing

 

6、执行configure生成Makefile

[root@localhost fuckworld]# ./configure

 

7、使用Makefile编译代码

[root@localhost fuckworld]# make

 

运行程序

[root@localhost fuckworld]# ./fuckworld

fuck the pool world!!!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值