详解linux下auto工具制作Makefile源码包(制作篇)(autoconf 2.61版本之前) .

来源:互联网 发布:新网怎么解析域名 编辑:程序博客网 时间:2024/05/22 03:02
 

                             automake 实例hello.c

平台与工具:
[root@my
linux hello]# uname -a
Linux my
linux.xiaodao.com 2.6.9-5.EL #1 Wed Jan 5 19:22:18 EST 2005 i686 athlon i386 GNU/Linux
autoscan (GNU Autoconf) 2.59
autoconf (GNU Autoconf) 2.59
automake (GNU automake) 1.9.2
==============================================================================
[root@mylinux c]# mkdir hello         //新建工程目录hello
[root@mylinux c]# cd hello            //进入工程目录hello
[root@mylinux hello]# vi hello.c      //创建源文件hello.c
#include <stdio.h>
#include <stdlib.h>
int
main(void)
{
    printf("Hello, world\n");
    exit(0);
}
[root@mylinux hello]# autoscan        //生成autoscan.log与configure.scan
autom4te: configure.ac: no such file or directory
autoscan: /usr/bin/autom4te failed with exit status: 1
[root@mylinux hello]# cp configure.scan configure.ac       //生成configure.ac
[root@mylinux hello]# vi configure.ac                      //编辑configure.ac
#                                               -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_PREREQ(2.59)
AC_INIT(hello, 1.0, abc@abc.com)              //修改
AM_INIT_AUTOMAKE(hello,1.0)                            //增加
AC_CONFIG_SRCDIR([hello.c])
AC_CONFIG_HEADER([config.h])
# Checks for programs.
AC_PROG_CC
# Checks for libraries.
# Checks for header files.
AC_HEADER_STDC
AC_CHECK_HEADERS([stdlib.h])
# Checks for typedefs, structures, and compiler characteristics.
# Checks for library functions.
AC_CONFIG_FILES([Makefile])                             //增加
AC_OUTPUT
[root@mylinux hello]# aclocal                 //生成aclocal.m4与autom4te.cache文件
[root@mylinux hello]# autoheader              //生成config.h.in文件
[root@mylinux hello]# vi Makefile.am          //创建文件Makefile.am 
AUTOMAKE_OPTIONS= foreign 
bin_PROGRAMS = hello
hello_SOURCES = hello.c
[root@mylinux hello]# touch README NEWS AUTHORS ChangeLog//创建README NEWS AUTHORS ChangeLog文件
[root@mylinux hello]# automake --add-missing  //生成install-sh, missing, depcomp文件
configure.ac: installing `./install-sh'
configure.ac: installing `./missing'
Makefile.am: installing `./depcomp'
[root@mylinux hello]# autoconf                //生成configure脚本
[root@mylinux hello]# ./configure             //执行configure脚本生成Makefile
checking for a
BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
.....省略
config.status: executing depfiles commands
[root@mylinux hello]# make                     //make编译生成hello可执行文件
make  all-am
make[1]: Entering directory `/root/c/hello'
if gcc -DHAVE_CONFIG_H -I. -I. -I.     -g -O2 -MT hello.o -MD -MP -MF ".deps/hello.Tpo" -c -o hello.o hello.c; \
then mv -f ".deps/hello.Tpo" ".deps/hello.Po"; else rm -f ".deps/hello.Tpo"; exit 1; fi
gcc  -g -O2   -o hello  hello.o  
make[1]: Leaving directory `/root/c/hello'
[root@mylinux hello]# ./hello                   //执行hello程序
Hello, world
[root@mylinux hello]#

原创粉丝点击