前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >autoconf/automake最快速使用

autoconf/automake最快速使用

作者头像
十毛
发布2019-03-27 11:42:11
7910
发布2019-03-27 11:42:11
举报

autoconf和automake的使用 这个资料是非常完整的,本文大部分内容都是从这篇资料借鉴过来的 感谢作者YuChen

1:准备源文件hello.c

代码语言:javascript
复制
➜  project git:(master) ✗ ls
hello.c
➜  project git:(master) ✗ cat hello.c
#include <stdio.h>

int main(int argc, const char *argv[]) {
    printf("Hello World!\n");
    return 0;
}
➜  project git:(master) ✗

2:使用autoscan工具生成configure.scan并重命名

代码语言:javascript
复制
➜  project git:(master) ✗ autoscan
➜  project git:(master) ✗ mv configure.scan configure.ac
➜  project git:(master) ✗ ls
autoscan.log   configure.ac hello.c

3:修改configure.ac

初始内容如下

代码语言:javascript
复制
➜  project git:(master) ✗
#                                               -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.

AC_PREREQ([2.69])
AC_INIT([FULL-PACKAGE-NAME], [VERSION], [BUG-REPORT-ADDRESS])
AC_CONFIG_SRCDIR([hello.c])
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.

AC_OUTPUT

修改后内容

代码语言:javascript
复制
#                                               -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.

AC_PREREQ([2.69])
AC_INIT([FULL-PACKAGE-NAME], [VERSION], [BUG-REPORT-ADDRESS])
AM_INIT_AUTOMAKE #1 :是automake所必备的宏。新版本中该宏不需要任何参数
AC_CONFIG_SRCDIR([hello.c])
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.

AC_OUTPUT(Makefile) #这里输出为Makefile

4:使用aclocal工具生成aclocal.m4

代码语言:javascript
复制
➜  project git:(master) ✗ aclocal
➜  project git:(master) ✗ ls
aclocal.m4     autom4te.cache autoscan.log   configure.ac   hello.c
➜  project git:(master) ✗

5:使用autoconf工具生成configure文件

代码语言:javascript
复制
➜  project git:(master) ✗ autoconf
➜  project git:(master) ✗ ls
aclocal.m4     autom4te.cache autoscan.log   configure      configure.ac   hello.c
➜  project git:(master) ✗

6:使用autoheader工具生成config.h.in

代码语言:javascript
复制
➜  project git:(master) ✗ autoheader
➜  project git:(master) ✗ ls
aclocal.m4     autom4te.cache autoscan.log   config.h.in    configure      configure.ac   hello.c
➜  project git:(master) ✗

7:创建Makefile.am文件

automake工具会根据config.in中的参量把Makefile.am转换成Makefile.in文件。在使用Automake之前,要先手动建立Makefile.am文件。 Makefile.am的内容如下:

代码语言:javascript
复制
AUTOMAKE_OPTIONS=foreign
bin_PROGRAMS=hello
hello_SOURCES=hello.c

Makefile.am的内容解释:

AUTOMAKE_OPTIONS为设置的Automake选项。它有三种等级提供给用户选择:foreign,gnu,gnits,默认等级为gnu.在此使用foreign,它只检测必须的文件。 bin_PROGRAMS定义要产生的执行文件名。如果要产生多个可执行文件,则每个文件名用空格隔开。 hello_SOURCES定义为产生hello这个可执行程序所需要的原始文件。如果其是由多个文件组成的,则必须用空格进行隔开。

8:使用automake工具生成Makefile.in文件

要使用选项“—add-missing”可以让Automake自动添加一些必要的脚本文件。

代码语言:javascript
复制
➜  project git:(master) ✗ automake --add-missing
configure.ac:11: installing './compile'
configure.ac:6: installing './install-sh'
configure.ac:6: installing './missing'
Makefile.am: installing './depcomp'
➜  project git:(master) ✗ ls
Makefile.am    aclocal.m4     autoscan.log   config.h.in    configure.ac   hello.c        missing
Makefile.in    autom4te.cache compile        configure      depcomp        install-sh
➜  project git:(master) ✗

9:运行自动配置设置文件configure,根据Makefile.in生成最终的Makefile

代码语言:javascript
复制
➜  project git:(master) ✗ ./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... ./install-sh -c -d
checking for gawk... no
checking for mawk... no
checking for nawk... no
checking for awk... awk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
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 whether gcc understands -c and -o together... yes
checking for style of include used by make... GNU
checking dependency style of gcc... gcc3
checking that generated files are newer than configure... done
configure: creating ./config.status
config.status: creating Makefile
config.status: creating config.h
config.status: executing depfiles commands
➜  project git:(master) ✗

10:运行make命令进行编译、测试

代码语言:javascript
复制
➜  project git:(master) ✗ make
/Library/Developer/CommandLineTools/usr/bin/make  all-am
gcc -DHAVE_CONFIG_H -I.     -g -O2 -MT hello.o -MD -MP -MF .deps/hello.Tpo -c -o hello.o hello.c
mv -f .deps/hello.Tpo .deps/hello.Po
gcc  -g -O2   -o hello hello.o
➜  project git:(master) ✗ ./hello
Hello World!
➜  project git:(master) ✗

参考资料

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2018.08.06 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 1:准备源文件hello.c
  • 2:使用autoscan工具生成configure.scan并重命名
  • 3:修改configure.ac
  • 4:使用aclocal工具生成aclocal.m4
  • 5:使用autoconf工具生成configure文件
  • 6:使用autoheader工具生成config.h.in
  • 7:创建Makefile.am文件
  • 8:使用automake工具生成Makefile.in文件
  • 9:运行自动配置设置文件configure,根据Makefile.in生成最终的Makefile
  • 10:运行make命令进行编译、测试
  • 参考资料
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档