linux下的Makefile的自动生成

王朝system·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

初学linux,看到linux程序的install有./configure,make,make install等命令感到奇怪便找了

一些文章看.

GNU autoconf和GNU automake是GNU用来协助自动产生makefile文档的,能方便地安装你开发的软件

make根据makefile编译、联结程序,手写makefile很困难因此有了autoconf,automake.

请先确认你的系统已经安装以下的软件

1.GNU Automake

2.GNU Autoconf

3.GNU m4

4.perl

5.GNU Libtool(如果你需要产生sharedlibrary)

假设有一个hello.c文件 在该文件的目录下

a ./autoscan 产生 configure.scan 文件

b 编辑configure.scan为configure.in

configure.in档的内容是一连串GNU m4的巨集

dnl Process this file with autoconf to produce a con figure script. //dnl是一个注解标志

AC_INIT(hello.c) // 用来检查原码路径

AM_INIT_AUTOMAKE(hello, 1.0) //产生软件的名称和版本

dnl Checks for programs.

AC_PROG_CC //检查编译器

dnl Checks for libraries.

dnl Checks for header files.

dnl Checks for typedefs,structures,and compiler ch aracteristics.

dnl Checks for library functions.

AC_OUTPUT(Makefile) //configure产生的文件

c 执行aclocal,autoconf 产生 aclocal.m4 configure configure.in

aclocal产生的aclocal.m4是一个巨集同configure.in供autoconf使用

Autoconf会读取configure.in档然後产生''configure''这个 shell script

''configure''他使程序能在各种LINUX平台产生合适的Makefile或是C的头文

件(header file),让原程序可以很方便地在这些不同的平台上被编 译出来。

d 编辑Makefile.am

AUTOMAKE_OPTIONS=foreign//必须

bin_PROGRAMS=hello//

hello_SOURCES=hello.c//指定原文件hello_SOURCES=hello.c main.c hello.h,

filename_SOURCES

e automake - -add-missing automake根据makefile.am产生makefile.in

- -add-missing选项是告诉automake顺便帮我们加 入包装一个软体套件所必备的档案

f 执行./configure 产生makefile文件然后使用 make编译hello.c为执行文 。

注意:Automake只需用到一些已经定义好的巨集(am),我们把巨集及目标(target)写在Makefile.am档内,Automake读入Makefile.am档後会把这一串已经定义好的巨集展开并且产生对应的Ma

kefile.in档,然後再由configure这个shellscript根据Makefile.in产生适合的Makefile。

d 使用makefile

make all 编译程序可写为make

make clean,make disclean,

make install 程式会被安装至/usr/local/bin这个目录

make dist 执行完在目录下会产生一个以PACKAGE-VERSION.tar.gz为名称的档案

make distcheck 比前一个多了检查相关套件

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航