autotools工具使用記錄

參考 http://blog.chinaunix.net/uid-25100840-id-271131.html

   http://blog.sina.com.cn/s/blog_4c2bf01a01014fwj.html

下載與安裝

下載地址 http://www.gnu.org/software/software.html

  需要下載的工具包有:autoconf-2.69  automake-1.14  m4-1.4.17 

  我下載的是最新的版本

安裝順序  m4->autoconf->automake  (參考的博文說這個順序很重要,剛開始很納悶,後來在安裝的過程中,發現之間是有依賴關係的)

  安裝方法:./configure  ->   make  ->  make install

使用方法    

autotool工具使用到的工具有:

aclocal

autoscan

autoconf

autoheader

automake

自動生成makefile的過程中需要做的有:

1 編寫Makefile.am文件

1 SUBDIRS = lib #若需要編譯的源文件在一個子目錄下(lib爲你的子目錄名),需要申明,如果沒有就沒有必要寫
2 
3 AUTOMAKE_OPTIONS = foreign #如果不添加此行,會在執行automake -a 命令時報錯,找不到“NEWS”“README”“AUTHORS”“ChangeLog"等文件
4 bin_PROGRAMS = hello   #需要生成的目標文件 5 hello_SOURCES = hello.c  #源文件 6 7 hello_LDADD = ./lib/libprint.a  #依賴到庫文件
1 noinst_LIBRARIES = libprint.a  #需生成的鏈接庫 noinst_ 只想編譯不安裝到系統中,inst_安裝到系統中
2 libprint_a_SOURCES = print.c ../include/print.h #依賴文件

注意:如果此時,print.h若又包含一個base.h頭文件,以上的寫法就要做修改,libprint_a_SOURCES 可用修改如下  

libprint_a_SOURCES = print.c

然後再添加一行:AM_CPPFLAGS= -I  ../include 即可,最後在項目根目錄的Makefile.am中添加這一行。  

2  執行命令 autoscan 生成文件configure.scan,修改此文件,另存爲configure.ac.修改或添加的內容如下:

 1 AC_PREREQ([2.69])
 2 AC_INIT(hello,0.01) #生成程序名,版本號,聯繫郵箱
 3 
 4 AM_INIT_AUTOMAKE #此處爲添加的
 5 
 6 AC_PROG_RANLIB  #此處爲添加的,沒有使用到自定義的庫的時候,不添加此行也不會報錯
 7 
 8 AC_CONFIG_SRCDIR([hello.c])
 9 AC_CONFIG_HEADERS([config.h])
10 
11 # Checks for programs.
12 AC_PROG_CC
13 
14 # Checks for libraries.
15 
16 # Checks for header files.
17 
18 # Checks for typedefs, structures, and compiler characteristics.
19 
20 # Checks for library functions.
21 
22 AC_CONFIG_FILES([Makefile
23                  lib/Makefile])    
24 AC_OUTPUT

3  執行命令  aclocal

4  執行命令  autoconf

5  執行命令  autoheader

6  執行命令  automake  -a

7  執行命令  ./configure

8   make

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章