一个用Autotools生成Makefile的简单例子


1. 建立auto文件夹,写两个简单代码文件:hello.c, hello.h

2. 使用命令autoscan 生成configure.scan  

3. 修改configure.scan如下 (添加红色部分),将修改后的configure.scan重命名为configure.in
AC_PREREQ([2.63])
#AC_INIT([FULL-PACKAGE-NAME], [VERSION], [BUG-REPORT-ADDRESS])

AC_INIT(hello, 1.0)

AM_INIT_AUTOMAKE(hello,1.0)

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)
AC_OUTPUT

4. 使用命令aclocal生成aclocal.m4 和 autom4te.cache

5. 使用命令autoconf生成configure

6. 使用autoheader生成config.h.in

7. 用Vi编辑Makefile.am文件如下:

             AUTOMAKE_OPTIONS=foreign
              bin_PROGRAMS=hello
               hello_SOURCES=hello.c hello.h

 8. 运行automake如下:

$ automake --add-missing

9. 运行./configure
10. 运行 make
11. 运行./hello
12.运行make install
13.运行hello
14. 运行:make dist
15.  在当前目录下解压hello-1.0.tar.gz:
      tar -zxvf hello-1.0.tar.gz
16. 进入目录:hello-1.0
17. 下面开始Linux常见的安装步骤:
       ./configure
18. 运行:make
19. 运行:./hello
20. 运行:make install
21. 运行:hello

相关内容