GUN automake,autoconf写Makefile(一)

来源:互联网 发布:淘宝商城加盟代理 编辑:程序博客网 时间:2024/05/01 07:08

摘要

 网上这方面的文章不少,也有很多错误的,如何去伪存真也不容易,英文好的同学最好还是看官方的介绍,毕竟是原版专业的,最近刚好用到这个工具,写下我自己的认识,抛砖引玉希望能给大家一点参考。

首先还是从helloword一步一步来。

内容

  1. automake,autoconf安装
  2. Helloword程序
  3. automake生成Makefile

一.automake,autoconf 安装

  
         http://www.gnu.org/software/automake/
  hello word之旅前需要准备上面几个安装包,都可以在GUN官网上面下。

二.Helloword程序

OK,安装完,我们来写helloword,这个大家熟悉,做IT入门招式,万变不离其宗。新建hello.cpp

#include <iostream>using namespace std;int main(int argc,char *argv[]){    std::cout<<"hello automake"<<endl;    return 0;}

三. automake生成Makefile

  1. autoscan
  2. 修改configure.scan,重命名configure.in
  3. 写Makefile.am
  4. 执行aclocal
  5. autoconf
  6. automake --add-missing
  7. ./configure --prefix=/home/app  && make && make install
下面给大家介绍一下上面helloword生成Makefile.

1. autoscan 生成configure.scan

2. 修改configure.scan

mv configure.scan configure.in

#                                               -*- Autoconf -*-# Process this file with autoconf to produce a configure script.AC_PREREQ([2.69])AC_INIT([hello], [1.1.0], [417356935@qq.com])#AC_CONFIG_SRCDIR([hello.cpp])#AC_CONFIG_HEADERS([config.h])AM_INIT_AUTOMAKE() # Checks for programs.AC_PROG_CXX# Checks for libraries.# Checks for header files.# Checks for typedefs, structures, and compiler characteristics.# Checks for library functions.AC_OUTPUT(Makefile)~

3. 写Makefile.am文件

AUTOMAKE_OPTIONS=foreignbin_PROGRAMS= hellohello_SOURCES= hello.cpp

hello目录下面就有下面几个文件,下面就是几个命令步骤了。

4. 执行aclocal

有如下告警,不做理会,生成aclocal.m4。

<span style="font-family:SimSun;font-size:12px;">[centos@server hello]$aclocalaclocal: warning: autoconf input should be named 'configure.ac', not 'configure.in'</span>

5. 执行autoconf生成configure

6. 运行automake --add-missing,生成Makefile.in文件

7.运行./configure --prefix=/home/app/hello, 生成Makefile

[centos@server hello]$makeg++ -DPACKAGE_NAME=\"hello\" -DPACKAGE_TARNAME=\"hello\" -DPACKAGE_VERSION=\"1.0.1\" -DPACKAGE_STRING=\"hello\ 1.0.1\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DPACKAGE=\"hello\" -DVERSION=\"1.0.1\" -I.     -g -O2 -MT hello.o -MD -MP -MF .deps/hello.Tpo -c -o hello.o hello.cppmv -f .deps/hello.Tpo .deps/hello.Pog++  -g -O2   -o helloword hello.o  

[centos@server hello]$./helloword hello automake

这样helloword的Makefile就写完了。这只是开始,后面动态库,静态库,工程的目录架构后续在介绍。

附件:automake流程图








0 0
原创粉丝点击