autotools 工程管理

Project 文件目录如下

|-- include

|   |-- funca.h

|   `-- funcb.h

|-- src

|   |-- funca.c

|   `-- funcb.c

`-- test

    `-- test.c

--include:

-- funca.h

       #ifndef __FUNCA_H__

#define __FUNCA_H__

void funca();

#endif

-- funcb.h

    

      #ifndef __FUNCB_H__

#define __FUNCB_H__

void funcb();

#endif

|-- src

|   |-- funca.c

 

      #include <stdio.h>

void funca(){

         printf("this is the funca.....\n");

}

 

 

|   `-- funcb.c

     #include <stdio.h>

void funcb(){

            printf("this is the funca.....\n");

}

 

`-- test

    `-- test.c

     #include <stdio.h>

#include "funca.h"

#include "funcb.h"

 

int main(){

   funca();

   funcb();

   printf("this is the test \n");

   return 0;

}

其中AUTHORS, ChangeLog, NEWS, README四个文件是手工新建的空文件,里面啥都没有,真实项目写入相应信息即可。

.使用autotools,目的是管理我的工程,并生成一个可以发布的软件包。用户通过

 .configure make make install 就可以安装我们开发的软件包,当然为了autotools

能识别用户的安装的选项,如果安装的路径,关闭软件的某些,打开软件的某些功能

这就需要生成一个configure 配置文件。

.autotools并不能文件完全自动生成其所需的所有文件,因此我们必须手动添加一些文件,.

.configue.in 各级目录下的Makefile.am 文件。

 

.configue.in 的产生过程。

1.       执行autoscan命令生成configure.scan文件

新增加文件autoscan.log  configure.scan

 2 修改 configure.scan,并且把configure.scan改为configure.in文件

#configue.in 内容如下:

#             -*- Autoconf -*-

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

 

AC_PREREQ([2.65])

AC_INIT([test], [1.0], [xx@xx])

AC_CONFIG_SRCDIR([test/test.c])

AC_CONFIG_HEADERS([config.h])

AM_INIT_AUTOMAKE

# Checks for programs.

AC_PROG_CC

AC_PROG_LIBTOOL

# Checks for libraries.

 

# Checks for header files.

 

# Checks for typedefs, structures, and compiler characteristics.

 

# Checks for library functions.

 

AC_OUTPUT

3新建  projrct   src  test  目录下的Makefile.am 文件

.project

      |---Makefile.am

               SOURDIRS =  src  test

      |---src

              Makefile.am 内容:

              .libtest_LTLIBRARES  =  libtest.la

              .libtest_la_SOURCES  =  funca.c \

                                   .funcb.c

             

      |---test

INCLUDES= -I$(top_srcdir)/include
bin_PROGRAMS = test
test_SOURCES = test.c
test_LDADD = $(top_builddir)/src/libtest.la

4修改完成后执行如下命令尝试能否生存configure 文件

       不幸的是出现了错误:

       configure.in:8: error: possibly undefined macro: AM_INIT_AUTOMAKE

       If this token and others are legitimate, please use m4_pattern_allow.

       See the Autoconf documentation.

       configure.in:11: error: possibly undefined macro: AC_PROG_LIBTOOL

       因为找不到AM_INIT_AUTOMAKE宏,不要担心,因为我们少做了一步,先要把这些宏生成一下,当然是自动的。

      $aclocal

      $autoconf

   现在的autoconf没有报错。这个时候再看看目录下面,发现多了一个aclocal.m4文件,这就是aclocal声称的宏命令文件,autoconf会使用它来生成新的configure脚本。
 
是不是现在就能够自动搞定Makefile了?我们现在再执行一下configure,看看输出:
configure: error: cannot find install-sh, install.sh, or shtool in "." "./.." "./../.."
 
和我们想的有点不同,我们还要用到automake命令做一些其它的事情,我们先执行一下:$automake

configure.in:11: required file `./config.guess' not found

configure.in:11:   `automake --add-missing' can install `config.guess'

configure.in:11: required file `./config.sub' not found

configure.in:11:   `automake --add-missing' can install `config.sub'

configure.in:8: required file `./install-sh' not found

configure.in:8:   `automake --add-missing' can install `install-sh'

configure.in:11: required file `./ltmain.sh' not found

configure.in:8: required file `./missing' not found

configure.in:8:   `automake --add-missing' can install `missing'

automake: no `Makefile.am' found for any configure output

automake: Did you forget AC_CONFIG_FILES([Makefile]) in configure.in?

 哦,不行,还要install-sh,missing文件,错误信息中,还提到AC_CONFIG_FILES([Makefile]),是的,我们还要修改一下configure.ac,在最后一行AC_OUTPUT前面增加一行:
 AC_CONFIG_FILES([Makefile])
 
现在再执行一次automake吧,但是我们要加一个参数:
 $automake --add-missing
configure.in:11: installing `./config.guess'

configure.in:11: installing `./config.sub'

configure.in:8: installing `./install-sh'

configure.in:11: required file `./ltmain.sh' not found

configure.in:8: installing `./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.

configure.in:7: required file `config.h.in' not found

现在发现还有几个文件需要我手动创建

NEWS  README AUTHORS ChangeLog

 前面缺的四个文件简单,我们按照自己的情况编辑保存即可,config.h.in从哪里来呢? 现在让我们把config.h.in搞出来,这个要用到autoheader,我们执行命令:
 $autoheader
 config.h.in
文件就生成好了。准备好了其它几个文本文件,我们再执行一次,这次不用加参数了,不过我们还要再执行一次autoconf,因为我们修改了configure.in之后还没有执行过          autoconf 
$autoconf
然后我生存需要Makefile文件执automake命令

$automake

结果和我们想的不一样。

configure.in:11: required file `./ltmain.sh' not found

原来是缺少了库依赖关系处理脚本,解决方法配置即可:

$ libtoolize --automake --copy --debug --force

在执行命令automake

$ automake

未见异常,该到了configure步骤了。

$./configure

生成了我要的Makefile 文件

$make

make  all-am

make[1]: Entering directory `/home/kaiyuan/Templates/autool2'

make[1]: Leaving directory `/home/kaiyuan/Templates/autool2'

 

 但是没有结果;

 进入src

 $ make

 …………………………………………………………….

 在进入 test

 $make

   /bin/sh ../libtool --tag=CC   --mode=link gcc  -g -O2   -o test test.o ../src/libtest.la

   libtool: link: gcc -g -O2 -o .libs/test test.o  ../src/.libs/libtest.so

 生成了我想看到的文件test

 $ ./test

this is the funca.....

this is the funcb.....

this is the test

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值