环境:Ubuntu 11.04Autoconf 2.67Automake 1.11.11、新建目录HelloWorld2、进入该目录,编写HelloWorld.c
[cpp] - int main(int argc,char** argv)
- {
- printf("Hello World!
");
- 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!