automake安装及使用

安装

sudo apt install automake

实例

源文件

以一个简单的例子为例:
automake安装及使用_第1张图片
add .c

#include "add.h"

int add(int a, int b){
	return a + b;
}

add.h

int add(int a, int b);

main.c

#include 
#include "add.h"

int main()
{

    int a = 10, b = 100;
    printf("%d + %d = %d\n", a, b, add(a, b));

    return 0;
}

执行 autoscan

首先执行 autoscan
然后将configure.scan 修改为 configure.ac
最后配置ac文件
automake安装及使用_第2张图片

配置 configure.ac 文件

改动前的文件

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

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

autoconf.am 文件修改

修改 :

AC_INIT([FULL-PACKAGE-NAME], [VERSION], [BUG-REPORT-ADDRESS])

AC_CONFIG_SRCDIR([add.h])

添加:

AM_INIT_AUTOMAKE([foreign])

AC_CONFIG_FILES([Makefile])

改动后的文件

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

AC_PREREQ([2.71])
AC_INIT([main], [1.0], [1095075717@qq.com])
AC_CONFIG_SRCDIR([main.c])
AC_CONFIG_HEADERS([config.h])

AM_INIT_AUTOMAKE([foreign])

AC_CONFIG_FILES([Makefile])

# 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
~          

执行 aclocal , autoheader, 写Makefile.am文件

automake安装及使用_第3张图片

编写Makefile.am文件

bin_PROGRAMS = main
main_SOURCES = main.c add.c                                 

执行 autoconf 得到 makefile 文件

执行 autoconf 生成 configure 文件

./configure 生成 Makefile文件; 不成功的话执行 autoreconf -i 之后再重新执行 ./configure
automake安装及使用_第4张图片

完美结束

automake安装及使用_第5张图片

你可能感兴趣的:(开发语言,linux)