1、新建目录HelloWorld
2、进入该目录,编写HelloWorld.c
- int main(int argc,char** argv)
- {
- printf("Hello World!\n");
- return 0;
- }
a、使用autoscan来根据目录下的源代码生成一个configure.in的模板文件configure.scan:
- 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
- # -*- 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
- 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
- AUTOMAKE_OPTIONs=foreign
- bin_PROGRAMS=Helloworld
- HelloWorld_SOURCES=HelloWorld.c
automake会根据Makefile.am来自动生成Makefile.in
- 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
- 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
- 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
- fzuir@ubuntu:~/workspace/automake/Hellworld$ ./HelloWorld
- Hello World!