環境:
Ubuntu 11.04
Autoconf 2.67
Automake 1.11.1
1、新建目錄HelloWorld
2、進入該目錄,編寫HelloWorld.c
[cpp]
- int main(int argc,char** argv)
- {
- printf("Hello World!\n");
- return 0;
- }
3、生成configure
a、使用autoscan來根據目錄下的源代碼生成一個configure.in的模板文件configure.scan:
[plain]
- fzuir@ubuntu:~/workspace/automake/Hellworld$ ls
- HelloWorld.c
- fzuir@ubuntu:~/workspace/automake/Hellworld$ autoscan
- fzuir@ubuntu:~/workspace/automake/Hellworld$ ls
- autoscan.log configure.scan HelloWorld.c
b、將configure.scan改為configure.in,並修改其內容為:
[plain]
- # -*- Autoconf -*-
- # Process this file with autoconf to produce a configure script.
-
- AC_INIT(helloworld.c)
- AM_INIT_AUTOMAKE(helloworld,1.0)
-
- # 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_OUTPUT(Makefile)
c、執行aclocal生成aclocal.m4,執行autoconf生成configure
[plain]
- fzuir@ubuntu:~/workspace/automake/Hellworld$ ls
- autoscan.log configure.in HelloWorld.c
- fzuir@ubuntu:~/workspace/automake/Hellworld$ aclocal
- fzuir@ubuntu:~/workspace/automake/Hellworld$ ls
- aclocal.m4 autom4te.cache autoscan.log configure.in HelloWorld.c
- fzuir@ubuntu:~/workspace/automake/Hellworld$ autoconf
- fzuir@ubuntu:~/workspace/automake/Hellworld$ ls
- aclocal.m4 autom4te.cache autoscan.log configure configure.in HelloWorld.c
4、創建Makefile.am,內容如下:
[plain]
- AUTOMAKE_OPTIONs=foreign
- bin_PROGRAMS=Helloworld
- HelloWorld_SOURCES=HelloWorld.c
5、運行automake
automake會根據Makefile.am來自動生成Makefile.in
[plain]
- fzuir@ubuntu:~/workspace/automake/Hellworld$ automake --add-missing
- configure.in:5: installing `./install-sh'
- configure.in:5: installing `./missing'
- Makefile.am: installing `./depcomp'
- fzuir@ubuntu:~/workspace/automake/Hellworld$ ls
- aclocal.m4 autoscan.log configure.in HelloWorld.c Makefile.am missing
- autom4te.cache configure depcomp install-sh Makefile.in
6、運行configure命令生成Makefile
[plain]
- fzuir@ubuntu:~/workspace/automake/Hellworld$ ./configure
- checking for a BSD-compatible install... /usr/bin/install -c
- checking whether build environment is sane... yes
- checking for a thread-safe mkdir -p... /bin/mkdir -p
- checking for gawk... no
- checking for mawk... mawk
- checking whether make sets $(MAKE)... yes
- checking for gcc... gcc
- checking whether the C compiler works... yes
- checking for C compiler default output file name... a.out
- checking for suffix of executables...
- checking whether we are cross compiling... no
- checking for suffix of object files... o
- checking whether we are using the GNU C compiler... yes
- checking whether gcc accepts -g... yes
- checking for gcc option to accept ISO C89... none needed
- checking for style of include used by make... GNU
- checking dependency style of gcc... gcc3
- configure: creating ./config.status
- config.status: creating Makefile
- config.status: executing depfiles commands
7、運行make命令進行編譯
[plain]
- fzuir@ubuntu:~/workspace/automake/Hellworld$ make
- gcc -DPACKAGE_NAME=\"\" -DPACKAGE_TARNAME=\"\" -DPACKAGE_VERSION=\"\" -DPACKAGE_STRING=\"\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DPACKAGE=\"HelloWorld\" -DVERSION=\"1.0\" -I. -g -O2 -MT HelloWorld.o -MD -MP -MF .deps/HelloWorld.Tpo -c -o HelloWorld.o HelloWorld.c
- HelloWorld.c: In function ‘main’:
- HelloWorld.c:3: warning: incompatible implicit declaration of built-in function ‘printf’
- mv -f .deps/HelloWorld.Tpo .deps/HelloWorld.Po
- gcc -g -O2 -o HelloWorld HelloWorld.o
8、運行HelloWorld
[plain]
- fzuir@ubuntu:~/workspace/automake/Hellworld$ ./HelloWorld
- Hello World!