cmake 与autoconf automake使用的举例
目录
2、通过autscan命令,产生 configure.scan文件,修改为configure.ac
7、根据情况,创建一些常用的文档文件NEWS README AUTHORS ChangeLog
注意:通过autoreconf命令,来解决由于制作过程的automake版本,与最终使用用户版本不一致的问题
一、简介
在Linux下,编译某个程序,使用Makefile, 但对于Makefile来讲,有一定的语法;同时编译过程,也对外部环境有一定的依赖,如需要依赖某些特定的库才能编译通过。
Autoconf 及Automake 这两个软件是帮助程序开发者轻松产生 Makefile,同时在配置过程中,提示用户来安装缺失的环境。
二、示例过程如下
1、源文件
hello.c
#include <stdio.h>
extern int test(void);
int main(void)
{
printf("In %s, Hello World.\n", __FILE__);
test();
return 0;
}
test.c
#include <stdio.h>
int test()
{
printf("In test FUNC.....\n");
return 0;
}
2、通过autscan命令,产生 configure.scan文件,修改为configure.ac
root@wangxinyu-PC:/home/wangxinyu/work/temp/test_automake# autoscan
root@wangxinyu-PC:/home/wangxinyu/work/temp/test_automake# ls
autoscan.log configure.scan hello.c test.c
root@wangxinyu-PC:/home/wangxinyu/work/temp/test_automake# mv configure.scan configure.ac
root@wangxinyu-PC:/home/wangxinyu/work/temp/test_automake# cat configure.ac
# -*- 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(tt, 0.0) # Add , 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_CONFIG_FILES([Makefile]) # Add, Create Makefile
AC_OUTPUT
root@wangxinyu-PC:/home/wangxinyu/work/temp/test_automake#
3、执行aclocal,产生aclocal.m4 配置文件
root@wangxinyu-PC:/home/wangxinyu/work/temp/test_automake# aclocal
4、执行autoconf, 产生configure文件
root@wangxinyu-PC:/home/wangxinyu/work/temp/test_automake# autoconf
5、执行autoheader 产生config.h.in
root@wangxinyu-PC:/home/wangxinyu/work/temp/test_automake# autoheader
6、创建Makefile.am文件
root@wangxinyu-PC:/home/wangxinyu/work/temp/test_automake# vi Makefile.am
1 AUTOMAKE_OPTION=foreign
2 bin_PROGRAMS=tt
3 tt_SOURCES=hello.c test.c
7、根据情况,创建一些常用的文档文件NEWS README AUTHORS ChangeLog
touch NEWS README AUTHORS ChangeLog
8、根据Makefile.am产生Makefile.in
automake --add-missing
9、执行./configure 生成Makefile
./configure
make
root@wangxinyu-PC:/home/wangxinyu/work/temp/test_automake# make install
make[1]: Entering directory '/home/wangxinyu/work/temp/test_automake'
/usr/bin/mkdir -p '/usr/local/bin'
/usr/bin/install -c tt '/usr/local/bin'
make[1]: Nothing to be done for 'install-data-am'.
make[1]: Leaving directory '/home/wangxinyu/work/temp/test_automake'
root@wangxinyu-PC:/home/wangxinyu/work/temp/test_automake# tt
In hello.c, Hello World.
In test FUNC.....
三、总结
制作过程:
生成Makefile过程:
综合
注意:通过autoreconf命令,来解决由于制作过程的automake版本,与最终使用用户版本不一致的问题
autoreconf --force --install
./configure xxxx xxx xxx xxx(配置参数)