顯示具有 Automake 標籤的文章。 顯示所有文章
顯示具有 Automake 標籤的文章。 顯示所有文章

2012年3月23日 星期五

Automake 的測試套件 make check-TESTS

在寫程式的時候會想要寫一些測試套件來驗證程式的功能是否正常,Automake 支援了這種需求。

一般來說寫一個給 Hello World 程式的 Makefile.am 會長得像以下這樣:
bin_PROGRAMS = hello
hello_SOURCES = hello.c
如果說希望能夠在編譯完程式後,順便執行一下來檢查,就可以加一行:
bin_PROGRAMS = hello
hello_SOURCES = hello.c
TESTS = $(bin_PROGRAMS)
這樣一來就可以執行 make check 來自動編譯並且執行測試; 只是通常不會想要把測試程式釋出給一般人使用,所以就會改寫成:
check_PROGRAMS = hello
hello_SOURCES = hello.c
TESTS = $(check_PROGRAMS)
這樣就只會在 make check 的時候,編譯 hello 這隻程式並且自動執行它來做測試。

如果想要看到彩色的測試結果,就要修改 configure.ac 加上 color-tests 像是以下這樣:
AC_PREREQ([2.68])
AC_INIT([hello], [0.1], [foo@bar.com])
AC_CONFIG_SRCDIR([hello.c])
AC_CONFIG_HEADERS([config.h])
AM_INIT_AUTOMAKE([foreign color-tests])                                                                                                                        
AM_MAINTAINER_MODE([enable])
其實 GNU Build System 很好用的,只是要多看 info Automake 的文件來理解它的使用方法。:)
對以上內容不太瞭解的,可以先看看簡報 GNU Build System (aka Autotools) 入門一下。

2011年3月21日 星期一

使用 Automake 的 silent-rules 來簡化編譯過程的輸出訊息

使用前
ubuntu@maverick:~/hello$ make
make  all-am
make[1]: Entering directory `/home/ubuntu/hello'
gcc -DHAVE_CONFIG_H -I.     -g -O2 -MT hello.o -MD -MP -MF .deps/hello.Tpo -c -o hello.o hello.c
mv -f .deps/hello.Tpo .deps/hello.Po
gcc  -g -O2   -o hello hello.o  
make[1]: Leaving directory `/home/ubuntu/hello'
使用後
ubuntu@maverick:~/hello$ make
make  all-am
make[1]: Entering directory `/home/ubuntu/hello'
  CC     hello.o
  CCLD   hello
make[1]: Leaving directory `/home/ubuntu/hello'
使用方法,修改 configure.ac 加入 silent-rules
...
AM_INIT_AUTOMAKE([silent-rules])
...
然後在編譯前的設定執行
./configure --enable-silent-rules
或是預設打開 silent-rules
...
AM_INIT_AUTOMAKE
AM_SILENT_RULES([yes])
...
P.S. 此時可以省略掉 AM_INIT_AUTOMAKE 裡面的 silent-rules 選項
參考資料 http://www.gnu.org/software/hello/manual/automake/Options.html