Makefile的automake生成(HelloWorld)

10 篇文章 0 订阅

环境:

Ubuntu 11.04

Autoconf 2.67

Automake 1.11.1

1、新建目录HelloWorld

2、进入该目录,编写HelloWorld.c

int main(int argc,char** argv)
{
	printf("Hello World!\n");
	return 0;
}

3、生成configure

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

b、将configure.scan改为configure.in,并修改其内容为:

#                                               -*- 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

4、创建Makefile.am,内容如下:

AUTOMAKE_OPTIONs=foreign
bin_PROGRAMS=Helloworld
HelloWorld_SOURCES=HelloWorld.c

5、运行automake

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

6、运行configure命令生成Makefile

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命令进行编译

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!

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值