AutoMake 使用实例

来源:互联网 发布:mac os 10.7的升级包 编辑:程序博客网 时间:2024/06/07 03:32
AutoMake 的使用实例
mkdir src includes
放两个文件在/src 与 /includes 下,分别为helloworld.c 与 helloworld.h
$autoscan
$mv configure.scan configure.in
$vim configure.in
将configure.in改为如下


# ImageBroswer for double screen project-
# Process this file with autoconf to produce a configure script.




AC_PREREQ(2.67)
AC_INIT(Imagebroswer, 1.0, keenite@gmail.com)
AC_CONFIG_SRCDIR([src/Imagebroswer.c])
AC_CONFIG_HEADERS([condefs.h])




# Checks for programs.
AC_PROG_CC
AM_INIT_AUTOMAKE(imagebroswer,1.0)
AC_PROG_MAKE_SET




# Checks for libraries.
build_arm="no"
have_libminigui="no"
AC_CHECK_HEADERS(minigui/common.h, have_libminigui=yes, foo=bar)




AC_ARG_ENABLE(arm,
[--enable-arm enable the arm mode for the makefile <default = no>],
build_arm=$enableval)




threads version=”no”
AC_CHECK_DECLS(_MGRM_THREADS, threads_version="yes", foo=bar, [#include <minigui/common.h>])




use_newgal="no"
AC_CHECK_DECLS(_USE_NEWGAL, use_newgal="yes", foo=bar, [#include <minigui/common.h>])




LIBS="$LIBS -L/usr/local/lib -ljpeg -lminigui_ths -lpthread -ldl"
AC_CHECK_DECLS(_HAVE_MATH_LIB, LIBS="$LIBS -lm", foo=bar, [#include <minigui/common.h>])
AC_CHECK_DECLS(_MGIMAGE_PNG, LIBS="$LIBS -lpng", foo=bar, [#include <minigui/common.h>])
AC_CHECK_DECLS(_MGFONT_TTF, LIBS="$LIBS -lttf", foo=bar, [#include <minigui/common.h>])
AC_CHECK_DECLS(_MGFONT_FT2, LIBS="$LIBS -lfreetype", foo=bar, [#include <minigui/common.h>])




if test "x$build_arm" = "xyes"; then
AC_DEFINE(ARM_VERSION,1,[define the arm])
fi




# Checks for header files.




# Checks for typedefs, structures, and compiler characteristics.




# Checks for library functions.




AC_CONFIG_FILES(
Makefile
src/Makefile
)
AC_OUTPUT


需要注意几点:

1. 因为需要根据--enable-arm参数来决定是否定义#define ARM_VERSION, 所以与此相关的几行代码为:


AC_CONFIG_HEADERS([condefs.h])


AC_ARG_ENABLE(arm,
[--enable-arm enable the arm mode for the makefile <default = no>],
build_arm=$enableval)


if test "x$build_arm" = "xyes"; then
AC_DEFINE(ARM_VERSION,1,[define the arm])
fi


第一段是需要在代码中添加的头文件,第二段是启用 --enable-arm这个参数来获取开关,第三段是决定是否定义ARM_VERSION这个宏(注意条件判断的=号两边要有空格)


2. autoheader 用来生成头文件,不可或缺的一步



建立两个Makefile.am在src下和项目根目录下
$cat Makefile.am
SUBDIRS=src


$cat src/Makefile.am
AUTOMAKE_OPTIONS=foreign
bin_PROGRAMS=helloworld
helloworld_SOURCES=helloworld.c


然后:
$aclocal
$autoconf
$autoheader




$touch NEWS README AUTHORS ChangeLog

$automake --add-missing


$./configure

$./make

原创粉丝点击