Linux下使用autoconf自动生成makefile文件

系统信息:Centos7
autoconf可以自动帮我们的程序生成makefile文件,非常方便

安装autoconf

安装失败的话可能是源配置出错

yum install -y autoconf

在这里插入图片描述

切换到源码目录执行autoscan

autoscan

可以看到生成了configure.scan文件
在这里插入图片描述

复制configure.scan为configure.ac

cp configure.scan configure.ac

我们可以看一下configure.scan的信息
这是autoscan自动生成配置文件

#                                               -*- 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([src/main.c])
AC_CONFIG_HEADERS([config.h])

# Checks for programs.
AC_PROG_CC

# Checks for libraries.

# Checks for header files.
AC_CHECK_HEADERS([fcntl.h stddef.h stdint.h stdlib.h string.h unistd.h xxhash.h]) #代码中还用到了xxhash.h

# Checks for typedefs, structures, and compiler characteristics.
AC_TYPE_SIZE_T
AC_TYPE_SSIZE_T
AC_TYPE_UINT16_T
AC_TYPE_UINT32_T
AC_TYPE_UINT64_T
AC_TYPE_UINT8_T

# Checks for library functions.
AC_FUNC_MALLOC
AC_CHECK_FUNCS([memset])

AC_OUTPUT

修改configure.ac文件

vim configure.ac

添加生成的可执行文件 版本号 汇报BUG邮箱信息 以及 生成Makefile文件

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

AC_PREREQ([2.69])
AC_INIT(xxhash, 1.0, 3000y) #生成的可执行文件 版本号 汇报BUG地址
AC_COPYRIGHT([Copyright (c) 3000y STUDIO])
AM_INIT_AUTOMAKE  #automake会使用的
AC_CONFIG_SRCDIR([src/main.c])
AC_CONFIG_HEADERS([config.h])

# Checks for programs.
AC_PROG_CC

# Checks for libraries.

# Checks for header files.
AC_CHECK_HEADERS([fcntl.h stddef.h stdint.h stdlib.h string.h unistd.h])

# Checks for typedefs, structures, and compiler characteristics.
AC_TYPE_SIZE_T
AC_TYPE_SSIZE_T
AC_TYPE_UINT16_T
AC_TYPE_UINT32_T
AC_TYPE_UINT64_T
AC_TYPE_UINT8_T

# Checks for library functions.
AC_FUNC_MALLOC
AC_CHECK_FUNCS([memset])

# 生成Makefile
AC_OUTPUT([Makefile])

执行aclocal autoconf autoheader

aclocal
autoconf
autoheader

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

编写Makefile.am

详细的见https://www.cnblogs.com/AshenYi/p/14882469.html
foreign 添加后执行automake 就不会提示 NEWS README AUTHORS ChangeLog这四个文件找不到

# 关闭AUTOMAKE严格性校验
AUTOMAKE_OPTIONS=foreign

# 生成的可执行文件为xxhash
bin_PROGRAMS= xxhash

# 所用的文件
xxhash_SOURCES= src/main.c src/xxhash.c src/xxhash.h

执行automake --add-missing

automake --add-missing

执行时提示

configure.ac:7: installing './install-sh'
configure.ac:7: installing './missing'
Makefile.am: installing './INSTALL'
Makefile.am: error: required file './NEWS' not found
Makefile.am: error: required file './README' not found
Makefile.am: error: required file './AUTHORS' not found
Makefile.am: error: 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
Makefile.am: installing './depcomp'

NEWS README AUTHORS ChangeLog这四个文件找不到 这是因为没有添加AUTOMAKE_OPTIONS=foreign选项导致的
添加后重新执行
在这里插入图片描述

执行./configure 生成Makefile文件

./configure

可以看到Makefile文件自动生成了
在这里插入图片描述
执行make也可以正常编译
在这里插入图片描述
文件生成在当前目录下
在这里插入图片描述

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

三千院喵

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值