1. 確定是否按照autotools系列工具aclocal, autoscan ,autoconf,autoheader,automake等
? ? 查看方法:rpm –qa | grep auto; ? ? ? ? ? ? ? 或者which aclocal
2. 如果沒有則安裝,F(xiàn)edora19的安裝方法。如果安裝了則跳過。
? ? yum install automake
3. 準(zhǔn)備好源文件hello.c,利用autotools系列命令生成makefile。步驟如下:
? ? ?1. ? ?運行autoscan命令,會生成autoscan.log ? ?,configure.scan兩個文件
并利用命令mv configure.scan configure.in。將生成的configure.scan更改為autoconf需要的文件模版configure.in。然后修改configure.in文件,修改的內(nèi)容如下:
#? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_PREREQ([2.69])
#AC_INIT([FULL-PACKAGE-NAME], [VERSION], [BUG-REPORT-ADDRESS])
#modified by lt
AC_INIT(hello,1.0)
#added by lt
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.
#added by lt
AC_CONFIG_FILES([Makefile])
AC_OUTPUT
-- INSERT --
4. 運行命令aclocal。會生成autom4te.cache文件夾和aclocal.m4文件。configure.in里面包含了一系列的宏命令,運行aclocal的目的是把工程需要的宏命令展開。(aclocal.m4就是configure.in中用到的宏定義)。
5. 運行命令autoconf命令,生成“configure”可執(zhí)行文件
6. 運行命令autoheader命令 --生成配置頭文件的模板config.h.in
7. 新建配置腳本文件Makefile.am。內(nèi)容如下:
AUTOMAKE_OPTIONS =foreign
bin_PROGRAMS =hello
hello_SOURCES =hello.c
8. automake --add-missing--生成Makefiel.in和所需要的腳本automake --add-missing--其中add-missing選項會讓automake自動添加一些必須的腳本文件。
9.? 運行命令./configure, --生成最終的Makefile文件
10. 運行命令make,即可編譯生成可執(zhí)行文件hello。
? ? ? ?注意:如果make不成功,試試先清除之前的可執(zhí)行文件和目標(biāo)文件,運行
? ? ? ? ? ? ? ? make clean
參考資料:http://shaoguangleo.blog.163.com/blog/static/22779832011116700660/