http://blog.csdn.net/lusehu/article/details/6415213
autotools是個(gè)系列工具,,首先確認(rèn)你的Ubuntu系統(tǒng)是否安裝了以下工具(可以通過(guò)which命令查看):
aclocal
autoscan
autoconf
autoheader
automake
安裝方法:
root@ubuntu:~# sudo apt-get install autoconf (我只執(zhí)行了這一條安裝指令 下面的使用中沒(méi)有出錯(cuò))
顯示如下:
正在讀取軟件包列表... 完成
正在分析軟件包的依賴關(guān)系樹(shù)
正在讀取狀態(tài)信息... 完成
E: 無(wú)法找到軟件包 autoscan
將會(huì)安裝下列額外的軟件包:
automake autotools-dev m4
建議安裝的軟件包:
autoconf2.13 autobook autoconf-archive gnu-standards autoconf-doc libtool
gettext
下列【新】軟件包將被安裝:
autoconf automake autotools-dev m4
共升級(jí)了 0 個(gè)軟件包,,新安裝了 4 個(gè)軟件包,,要卸載 0 個(gè)軟件包,,有 28 個(gè)軟件未被升級(jí),。
需要下載 1315kB 的軟件包,。
解壓縮后會(huì)消耗掉 4366kB 的額外空間。
您希望繼續(xù)執(zhí)行嗎,?[Y/n]
輸入y,,安裝
最好一起安裝它建議安裝的軟件包,否則autotools工具使用可能出錯(cuò),。
root@ubuntu:~# sudo apt-get install autotools-dev m4 autoconf2.13 autobook autoconf-archive gnu-standards autoconf-doc libtool
使用:
官方文檔http://www./software/automake/manual/index.html
流程
第一部份:執(zhí)行autoscan 修改configure.scan 成 configure.in
- # -*- Autoconf -*-
- # Process this file with autoconf to produce a configure script.
-
- AC_PREREQ(2.68)
- 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
第二部份:執(zhí)行aclocal 執(zhí)行autoconf
第三部份: 執(zhí)行autoheader
第四部份: 新建makefile.am 執(zhí)行automake -a
- AUTOMAKE_OPTIONS=foreign
- bin_PROGRAMS= hello
- hello_SOURCES= hello.c
最后:
,。/configure make make install make clean
教程:
http://public0821./blog/665786
這片文章不錯(cuò) : http://www.cnblogs.com/276815076/archive/2010/09/30/1839589.html
http://www./article-22327-1.html
文庫(kù)教程: http://wenku.baidu.com/view/bcb0074669eae009581becbb.html
實(shí)例:(應(yīng)注意觀察每一步的執(zhí)行結(jié)果是否正確,是否生成了想要的文件)
實(shí)例1:精簡(jiǎn)實(shí)例很不錯(cuò)
(我測(cè)試過(guò)沒(méi)問(wèn)題 只是中間有個(gè)單詞寫(xiě)錯(cuò)了
vim Makefile.am
文件內(nèi)容為:
AUTOMAKE——OPTIONS=foreign
bin_PROGRAMS=hello
hello_SUORCES=hello.c 此處應(yīng)為 hello_SOURCES=hello.c
)
http://www.cnblogs.com/276815076/archive/2010/09/30/1839589.html
實(shí)例2:(未測(cè)試,,但流程正確)
http://blog.163.com/adam_mhl/blog/static/64278267200710291130488/
建立目錄:mkdir include src
編寫(xiě)程序:include/str.h
#include <stdio.h>
int str(char *string);
編寫(xiě)程序:src/str.c
#include "str.h"
//print string
int str(char *string){
printf("\n----PRINT STRING----\n\"%s\"\n",string);
return 0;
}
//interface of this program
int main(int argc , char **argv){
char str_read[1024];
printf("Please INPUT something end by [ENTER]\n");
scanf("%s",str_read);
return str(str_read );
}
第一部份:(執(zhí)行一條命令+修改一個(gè)文件)
3,、生成configure.in
include src
[root@localhost str]#autoscan
autom4te: configure.ac: no such file or directory
autoscan: /usr/bin/autom4te failed with exit status: 1
[root@localhost str]# ls
autoscan.log
configure.scan(上面的命令生成此文件) include src
[root@localhost str]# cp configure.scan configure.ac
修改 configure.scan 成 condigure.in:
1,修改AC_INIT(FULL-PACKAGE-NAME, VERSION, BUG-REPORT-ADDRESS)為
AC_INIT(str,0.0.1, [[email protected]])
(注解:FULL-PACKAGE-NAME 為程序名稱,,VERSION為當(dāng)前版本,, BUG-REPORT-ADDRESS為bug匯報(bào)地址)
2,添加AM_INIT_AUTOMAKE
3,,添加AC_CONFIG_FILES([Makefile])
修改后文件為:
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_PREREQ(2.59)
#AC_INIT(FULL-PACKAGE-NAME, VERSION, BUG-REPORT-ADDRESS)
AC_INIT(str, 0.0.1, [[email protected]])
AM_INIT_AUTOMAKE
AC_CONFIG_SRCDIR([include/str.h])
AC_CONFIG_HEADER([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
第二部份:(執(zhí)行兩條命令)
執(zhí)行aclocal
[root@localhost str]# aclocal
/usr/share/aclocal/libfame.m4:6: warning: underquoted definition of AM_PATH_LIBFAME
run info '(automake)Extending aclocal'
or see http://sources./automake/automake.html#Extending-aclocal
執(zhí)行autoconf
[root@localhost str]# autoconf
[root@localhost str]# ls
aclocal.m4 autoscan.log config.h.in configure.scan include Makefile.am NEWS
AUTHORS ChangeLog configure COPYING INSTALL Makefile.in README
autom4te.cache compile configure.ac depcomp install-sh missing src
第三部份(執(zhí)行一條命令)
5,、autoheader
root@localhost str]# autoheader
第四部份(新建文件+執(zhí)行automake)
6、創(chuàng)建Makefile.am
[root@localhost str]# cat Makefile.am
#Makefile.am
bin_PROGRAMS = str
str_SOURCES = include/str.h src/str.c
str_CPPFLAGS = -I include/
7,、automake必須文件(可略過(guò)此步):
* install-sh
* missing
* INSTALL
* NEWS
* README
* AUTHORS
* ChangeLog
* COPYING
* depcomp
其中
* install-sh
* missing
* INSTALL
* COPYING
* depcomp
可以通過(guò)automake -a選項(xiàng)自動(dòng)生成,,所以這里只需要建立如下文件
[root@localhost str]# touch NEWS README AUTHORS ChangeLog(也可不加這一步)
8、執(zhí)行automake
-a
[root@localhost str]# automake -a
configure.ac: installing `./install-sh'
configure.ac: installing `./missing'
Makefile.am: installing `./INSTALL'
Makefile.am: installing `./COPYING'
Makefile.am: installing `./compile'
Makefile.am: installing `./depcomp'
最后一步:
10,、執(zhí)行測(cè)試:
執(zhí)行./configure
執(zhí)行 make 此時(shí)應(yīng)該已經(jīng)生成可執(zhí)行文件,,ls看一下
執(zhí)行 make install
11、測(cè)試程序:#可執(zhí)行文件
make clean 清除編譯過(guò)程生成的文件
make uninstall 卸載
輔助知識(shí)
12. 添加測(cè)試包:make dist-gzip
13.添加一個(gè)支持子目錄,、靜態(tài)庫(kù),、自定義configure選項(xiàng)的包
支持子目錄Makefile.am 選項(xiàng) SUBDIR =
#Automake interface
SUBDIRS = src
支持靜態(tài)庫(kù)Makefile.am
EXTRA_DIST 用于添加除源碼外的文件到dist包
#Automake interface
bin_PROGRAMS = hello
hello_SOURCES = hello.c lib/sbase.h
hello_CPPFLAGS = -I lib
hello_LDFLAGS = -static lib/libsbase.a
EXTRA_DIST = lib/libsbase.a
configure.ac:
AC_PREREQ(2.59)
#AC_INIT(FULL-PACKAGE-NAME, VERSION, BUG-REPORT-ADDRESS)
AC_INIT(hello, 0.0.1, [[email protected]])
#AM 聲明
AM_INIT_AUTOMAKE
AC_CONFIG_SRCDIR([src/hello.c])
AC_CONFIG_HEADER([config.h])
# Checks for programs.
AC_PROG_CC
# Checks for libraries.
# Checks for header files.
AC_HEADER_STDC
AC_CHECK_HEADERS([stdint.h stdlib.h sys/socket.h])
# Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
AC_TYPE_SIZE_T
AC_TYPE_UINT32_T
AC_TYPE_UINT64_T
#用于自定義configure 選項(xiàng),見(jiàn)acinclude.am
AC_CHECK_EXTRA_OPTIONS
# Checks for library functions.
AC_CONFIG_FILES([Makefile
src/Makefile])
AC_OUTPUT
|