没有makefile的日子

1.没有makefile的日子

2.参考资料及代码下载

<1>. 没有makefile的日子

[上一篇]中介绍了makefile的编写规则,第一个标题是“没有makefile的日子”,收到[博客园]的网友zhuangzhuang1988的回复可以使用automake来自动生成makefile。如果在linux下从源代码安装过程序的话,通常的过程是这样:

./configure; make; make install

下面我们将试图如何生成这种发行版本,这里面主要使用到了aclocal, automake等工具。

1. 现在假设程序源代码已经编写完成,这里是main.c

xuqiang@ubuntu:~/automake/helloworld$ ls

main.c
xuqiang@ubuntu:~/automake/helloworld$ cat main.c
#include <stdio.h>
int main()
{
printf("hello linux world !");
return 0;
}

2. 运行autoscan,此时将生成autoscan.log,configure.scan两个文件。

xuqiang@ubuntu:~/automake/helloworld$ autoscan

xuqiang@ubuntu:~/automake/helloworld$ ls
autoscan.log configure.scan main.c

3. 我们将configure.scan作为configure.in文件的模板,以供aclocal来使用。首先将configure.scan改名为configure.in

xuqiang@ubuntu:~/automake/helloworld$ mv configure.scan configure.in

修改configure.in件:

xuqiang@ubuntu:~/automake/helloworld$ vim configure.in

xuqiang@ubuntu:~/automake/helloworld$ cat configure.in
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_PREREQ([2.63])
AC_INIT([helloauto], [1.0], [xuqiang@gmail.com])
AC_CONFIG_SRCDIR([main.c])
# comment this line, no use
# 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.
# init automake
AM_INIT_AUTOMAKE(helloauto, 1.0)
# write out the makefile
AC_OUTPUT(Makefile)
4. 执行aclocal命令,生成aclocal.m4 autom4te.cache两个文件
xuqiang@ubuntu:~/automake/helloworld$ aclocal
xuqiang@ubuntu:~/automake/helloworld$ ls
aclocal.m4 autom4te.cache autoscan.log configure.in main.c

5. 运行autoconf命令,将生成configure文件。

xuqiang@ubuntu:~/automake/helloworld$ autoconf

xuqiang@ubuntu:~/automake/helloworld$ ls
aclocal.m4 autom4te.cache autoscan.log configure configure.in main.c
6. 新建Makefile.am文件,该文件是工具automake的依赖文件。

xuqiang@ubuntu:~/automake/helloworld$ vim Makefile.am

xuqiang@ubuntu:~/automake/helloworld$ cat Makefile.am
AUTOMAKE_OPTIONS=foreign
bin_PROGRAMS=helloauto
helloauto_SOURCES=main.c
7. 运行automake命令,该命令将在该源文件目录中增加所需脚本,例如INSTALL文件等。
xuqiang@ubuntu:~/automake/helloworld$ automake --add-missing
Makefile.am: installing `./INSTALL'
Makefile.am: required file `./NEWS' not found
Makefile.am: required file `./README' not found
Makefile.am: required file `./AUTHORS' not found
Makefile.am: required file `./ChangeLog' not found
Makefile.am: installing `./COPYING' using GNU General Public License v3 file
Makefile.am: Consider adding the COPYING file to the version control system
Makefile.am: for your code, to avoid questions about which license your project uses.
xuqiang@ubuntu:~/automake/helloworld$ ls
aclocal.m4 autoscan.log config.status configure.in INSTALL Makefile.am
autom4te.cache config.log configure COPYING main.c Makefile.in

8. 下面开始测试一下上面生成的文件。

xuqiang@ubuntu:~/automake/helloworld$./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 for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables...
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: executing depfiles commands
xuqiang@ubuntu:~/automake/helloworld$ make
gcc -DPACKAGE_NAME=/"helloauto/" -DPACKAGE_TARNAME=/"helloauto/" -DPACKAGE_VERSION=/"1.0/" -DPACKAGE_STRING=/"helloauto/ 1.0/" -DPACKAGE_BUGREPORT=/"xuqiang@gmail.com/" -DPACKAGE=/"helloauto/" -DVERSION=/"1.0/" -I. -g -O2 -MT main.o -MD -MP -MF .deps/main.Tpo -c -o main.o main.c
mv -f .deps/main.Tpo .deps/main.Po
gcc -g -O2 -o helloauto main.o
xuqiang@ubuntu:~/automake/helloworld$ ls
aclocal.m4 config.log configure.in INSTALL Makefile
autom4te.cache config.status COPYING main.c Makefile.am
autoscan.log configure helloauto main.o Makefile.in
xuqiang@ubuntu:~/automake/helloworld$ ./helloauto
hello linux world !xuqiang@ubuntu:~/automake/helloworld$

通过使用这些工具,只要编写简单的几个文件就能生成Makefile,编译源代码。

<2>. 参考资料及代码下载

IBM例解 autoconf 和 automake 生成 Makefile 文件

Linux下Makefile的automake生成全攻略

A tutorial for porting to autoconf & automake

/Files/xuqiang/helloautomake.rar

 
      
     

1. 本博客中的文章均是个人在学习和项目开发中总结。其中难免存在不足之处 ,欢迎留言指正。 2. 本文版权归作者和博客园共有,转载时,请保留本文链接。


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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值