先按照一个简单的步骤实现一个automake的helloworld例子:
mkdir amhelloworld && cd amhelloworld
mkdir -p src
vim amhelloworld.c
#include <stdio.h> #ifdef WITH_LOG4C #include <log4c.h> #endif int main(int argc, char * argv []) { #ifdef ENABLE_LOG4C PutLog(""); #else printf("Hello Automake world.\n"); #endif return 0; }
这样的话,可以在配置的时候,检测用户是否指定了log4c外部库。
如果指定了,可以通过configure.ac设置cflags和ldflags等,指定-DWITH_LOG4C以及 -I./log4c/ -L./log4c/ -llog4c等等。
cd .. && autoscan
mv configure.scan configure.ac
# -*- Autoconf -*- # Process this file with autoconf to produce a configure script. AC_PREREQ([2.68]) AC_INIT([amhelloworld], [1.0.0.1], [[email protected]]) AC_CONFIG_SRCDIR([src/amhelloworld.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_CONFIG_FILES(Makefile src/Makefile) AC_OUTPUT
aclocal是一个工具,用于扫描configure.ac里面的am宏,生成aclocal.m4宏文件
http://www.gnu.org/software/m4/
m4是一个宏处理程序,autoconf工具集使用m4作为宏处理系统。
宏的工作方式是替换,学过c语言都知道。一个简短单词,可以处理一堆的繁琐预编译操作。
m4在autoconf工具集里面的角色就是把m4宏替换成bash脚本,用于检查,设置,输出等操作。
m4的核心是AC_DEFUN()宏,用于定义新的函数。
autoconf
vim Makefile.am
SUBDIRS=src
bin_PROGRAMS=amhelloworld amhelloworld_SOURCES=amhelloworld.c
automake -ac
可能需要补足一些辅助文件
touch README AUTHORS INSTALL COPYING NEWS ChangeLog
./configure --prefix=`pwd`/distdir
make && make install && make dist
以上就是基本步骤。