首页 > 代码库 > automake/autoconf的简单例子
automake/autoconf的简单例子
项目一 helloworld
整个基础上仅有一个helloworld.c文件,功能也非常简单,只是向屏蔽输出一句hello。
新建一个helloworld目录,然后在里面新建一个文件helloworld.c,内容为:
#include <stdio.h>int main(int argc, char **agrv){ printf("Hello, Merlin\n"); return 0;}
执行命令autoscan生成一个架构configure.scan,将其重新命名为configure.ac(新版本使用ac后缀名,不再使用in后缀),此时目录中含有以下文件
merlin@tfAnalysis:~/t/hellworld$ lsautoscan.log configure.ac helloworld.c
原configure.scan的内容为:
# -*- Autoconf -*-# Process this file with autoconf to produce a configure script.AC_PREREQ([2.69])AC_INIT([FULL-PACKAGE-NAME], [VERSION], [BUG-REPORT-ADDRESS])AC_CONFIG_SRCDIR([helloworld.c])AC_CONFIG_HEADERS([config.h])# 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
将其修改为以下样子:
# -*- Autoconf -*-# Process this file with autoconf to produce a configure script.AC_PREREQ([2.69])AC_INIT(helloworld, 0.1, tfa2012@foxmail.com)AC_CONFIG_SRCDIR(helloworld.c)#AC_CONFIG_HEADERS([config.h])AM_INIT_AUTOMAKE# 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)
AC_CONFIG_SRCDIR(helloworld.c)的功能是在./configure时检测文件helloworld.c是否存在,从而检测源码的正确性。
依次执行aclocal和autoconf两人个命令,此时文件夹中内容为:
merlin@tfAnalysis:~/t/hellworld$ lsaclocal.m4 autom4te.cache autoscan.log configure configure.ac helloworld.c
新建文件Makefile.am文件,并填写入以下内容:
AUTOMAKE_OPTIONS = foreignbin_PROGRAMS = helloworldhelloworld_SOURCES = helloworld.c
执行automake --add-missing
merlin@tfAnalysis:~/t/hellworld$ automake --add-missingconfigure.ac:11: installing ‘./compile‘configure.ac:8: installing ‘./install-sh‘configure.ac:8: installing ‘./missing‘Makefile.am: installing ‘./depcomp‘
此时文件夹中内容为:
merlin@tfAnalysis:~/t/hellworld$ lsaclocal.m4 compile depcomp Makefile.amautom4te.cache configure helloworld.c Makefile.inautoscan.log configure.ac install-sh missing
这个时候就可以使用./configure来生成Makefile文件了
merlin@tfAnalysis:~/t/hellworld$ ./configure checking for a BSD-compatible install... /usr/bin/install -cchecking whether build environment is sane... yeschecking for a thread-safe mkdir -p... /bin/mkdir -pchecking for gawk... gawkchecking whether make sets $(MAKE)... yeschecking whether make supports nested variables... yeschecking for gcc... gccchecking whether the C compiler works... yeschecking for C compiler default output file name... a.outchecking for suffix of executables... checking whether we are cross compiling... nochecking for suffix of object files... ochecking whether we are using the GNU C compiler... yeschecking whether gcc accepts -g... yeschecking for gcc option to accept ISO C89... none neededchecking whether gcc understands -c and -o together... yeschecking for style of include used by make... GNUchecking dependency style of gcc... gcc3checking that generated files are newer than configure... doneconfigure: creating ./config.statusconfig.status: creating Makefileconfig.status: executing depfiles commands
编译出来试试:
merlin@tfAnalysis:~/t/hellworld$ makegcc -DPACKAGE_NAME=\"helloworld\" -DPACKAGE_TARNAME=\"helloworld\" -DPACKAGE_VERSION=\"0.1\" -DPACKAGE_STRING=\"helloworld\ 0.1\" -DPACKAGE_BUGREPORT=\"tfa2012@foxmail.com\" -DPACKAGE_URL=\"\" -DPACKAGE=\"helloworld\" -DVERSION=\"0.1\" -I. -g -O2 -MT helloworld.o -MD -MP -MF .deps/helloworld.Tpo -c -o helloworld.o helloworld.cmv -f .deps/helloworld.Tpo .deps/helloworld.Pogcc -g -O2 -o helloworld helloworld.o merlin@tfAnalysis:~/t/hellworld$ lsaclocal.m4 config.log depcomp install-sh missingautom4te.cache config.status helloworld Makefileautoscan.log configure helloworld.c Makefile.amcompile configure.ac helloworld.o Makefile.inmerlin@tfAnalysis:~/t/hellworld$ ./helloworld Hello, Merlin
automake/autoconf的简单例子
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。