系统信息: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也可以正常编译
文件生成在当前目录下