如何使用autotools系列工具生成makefile

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兩個文件


1. 使用autoscan命令

并利用命令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中用到的宏定義)。

4 aclocal命令

5. 運行命令autoconf命令,生成“configure”可執(zhí)行文件

6. 運行命令autoheader命令 --生成配置頭文件的模板config.h.in


6 autoheader命令

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/

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容