Using Automake and Autoconf to manage large project
2007-04-11 10:50
309 查看
I. Hello world!
a. 建立源码树
proj
|---- NEWS
|---- README
|---- AUTHORS
|---- ChangeLog
|---- src ----------------> 源码目录
| |---- Makefile.am
| `---- hello.c
|
|---- Makefile.am
`---- configure.ac
b. 撰写 proj/configure.ac
Autoconf 据此生成configure脚本。
基本功能的configure.ac应包括以下的宏:
AC_INIT(Full-Package-Name, Version, Bug-Report-Address)
AM_INIT_AUTOMAKE # 初始化
AM_CONFIG_HEADER(config.h) #生成项目的配置头文件
#如:项目支持国际化,则其中会定义ENABLE_NLS 为1
AC_PROG_CC # 检查C编译器
AC_PROG_CXX # 检查C++编译器
AC_PROG_INSTALL # 检查install 工具
AC_CONFIG_FILES([Makefile po/Makefile]) # 要输出的Makefile
AC_OUTPUT
也可以在源码根目录下执行autoscan,自动分析,写入您可能需要的宏到
configure.scan中,修改之,并改名为configure.ac即可。
c. 撰写 proj/Makefile.am
此为顶层 Makefile.am, 仅需告诉Automake,哪些目录需要Automake 去处理:
SUBDIRS = src
哪些文件需要发布,但无须编译:
EXTRA_DIST = README ChangLog
d. 在 proj 下建立 GNU-Style 项目所要求的文件
touch NEWS README AUTHORS ChangLog
如不想使用GNU-Style,可在proj/Makefile.am 中指定:
AUTOMAKE_OPTIONS = foreign
否则automake会报错。
e. 为每个子目录撰写Makefile.am
src子目录下是为构建hello程序的源码,则其下Makefile.am中写入:
bin_PROGRAMES = hello
hello_SOURCES = hello.c
如果要链接库,可加入:
hello_LDADD = -ldl -lpthread
f. 完整的build步骤
aclocal -I. ------------> 生成aclocal.m4
autoheader -f ------------> 生成config.h.in
automake -a -c -f ------------> 从makefile.am生成Makefile.in
autoconf ------------> 从configure.ac生成configure
./configure ------------> 从Makefile.in生成Makefile
make
II. 开发中常用的Autoconf 宏
AC_INIT(Full-Package-Name, Version, Bug-Report-Address)
AM_INIT_AUTOMAKE
AM_CONFIG_HEADER(config.h) #生成项目的配置头文件
#如项目支持国际化,则其中会定义ENABLE_NLS 为1
AC_CONFIG_SRCDIR([src/hello.c])
AC_PROG_CC
AC_PROG_CXX
AC_PROG_INSTALL
AC_PROG_MAKE_SET
# 构建动态共享库支持
AC_PROG_LIBTOOL
AC_PROG_RANLIB
# 国际化支持
AC_PROG_INTLTOOL([Intltoolize_Version])
ALL_LINGUAS=””
AM_GLIB_GNU_GETTEXT #使用GLib库的gettext机制
AM_GNU_GETTEXT #使用Libc库的gettext机制
AC_CONFIG_FILES([Makefile po/Makefile])
AC_OUTPUT
III. 开发中常用的Automake变量
# 通用变量
_SOURCES =
noinst_HEADERS =
INCLUDES =
_CFLAGS =
_CPPFLAGS =
_CXXFLAGS =
_LDFLAGS = # 没有libtool时,是否可用?
# 构建可执行程序
bin_PROGRAMS =
_LDADD =
# 构建静态库
bin_LIBRARIES = libhello.a
libhello_a_LIBADD =
# 构建动态库
lib_LTLIBRARIES = libhello.la
libhello_la_LIBADD = -rpath ./
IV. 参考源码树
proj
|---- NEWS
|---- README
|---- AUTHORS
|---- ChangeLog
|---- doc ----------------> 文档目录
|---- test ----------------> 测试代码目录
|---- src ----------------> 源码目录
|---- po ----------------> 国际化文件目录
|---- res ----------------> 资源目录
|---- glade ----------------> glade文件
`---- image ----------------> 图像文件
a. 建立源码树
proj
|---- NEWS
|---- README
|---- AUTHORS
|---- ChangeLog
|---- src ----------------> 源码目录
| |---- Makefile.am
| `---- hello.c
|
|---- Makefile.am
`---- configure.ac
b. 撰写 proj/configure.ac
Autoconf 据此生成configure脚本。
基本功能的configure.ac应包括以下的宏:
AC_INIT(Full-Package-Name, Version, Bug-Report-Address)
AM_INIT_AUTOMAKE # 初始化
AM_CONFIG_HEADER(config.h) #生成项目的配置头文件
#如:项目支持国际化,则其中会定义ENABLE_NLS 为1
AC_PROG_CC # 检查C编译器
AC_PROG_CXX # 检查C++编译器
AC_PROG_INSTALL # 检查install 工具
AC_CONFIG_FILES([Makefile po/Makefile]) # 要输出的Makefile
AC_OUTPUT
也可以在源码根目录下执行autoscan,自动分析,写入您可能需要的宏到
configure.scan中,修改之,并改名为configure.ac即可。
c. 撰写 proj/Makefile.am
此为顶层 Makefile.am, 仅需告诉Automake,哪些目录需要Automake 去处理:
SUBDIRS = src
哪些文件需要发布,但无须编译:
EXTRA_DIST = README ChangLog
d. 在 proj 下建立 GNU-Style 项目所要求的文件
touch NEWS README AUTHORS ChangLog
如不想使用GNU-Style,可在proj/Makefile.am 中指定:
AUTOMAKE_OPTIONS = foreign
否则automake会报错。
e. 为每个子目录撰写Makefile.am
src子目录下是为构建hello程序的源码,则其下Makefile.am中写入:
bin_PROGRAMES = hello
hello_SOURCES = hello.c
如果要链接库,可加入:
hello_LDADD = -ldl -lpthread
f. 完整的build步骤
aclocal -I. ------------> 生成aclocal.m4
autoheader -f ------------> 生成config.h.in
automake -a -c -f ------------> 从makefile.am生成Makefile.in
autoconf ------------> 从configure.ac生成configure
./configure ------------> 从Makefile.in生成Makefile
make
II. 开发中常用的Autoconf 宏
AC_INIT(Full-Package-Name, Version, Bug-Report-Address)
AM_INIT_AUTOMAKE
AM_CONFIG_HEADER(config.h) #生成项目的配置头文件
#如项目支持国际化,则其中会定义ENABLE_NLS 为1
AC_CONFIG_SRCDIR([src/hello.c])
AC_PROG_CC
AC_PROG_CXX
AC_PROG_INSTALL
AC_PROG_MAKE_SET
# 构建动态共享库支持
AC_PROG_LIBTOOL
AC_PROG_RANLIB
# 国际化支持
AC_PROG_INTLTOOL([Intltoolize_Version])
ALL_LINGUAS=””
AM_GLIB_GNU_GETTEXT #使用GLib库的gettext机制
AM_GNU_GETTEXT #使用Libc库的gettext机制
AC_CONFIG_FILES([Makefile po/Makefile])
AC_OUTPUT
III. 开发中常用的Automake变量
# 通用变量
_SOURCES =
noinst_HEADERS =
INCLUDES =
_CFLAGS =
_CPPFLAGS =
_CXXFLAGS =
_LDFLAGS = # 没有libtool时,是否可用?
# 构建可执行程序
bin_PROGRAMS =
_LDADD =
# 构建静态库
bin_LIBRARIES = libhello.a
libhello_a_LIBADD =
# 构建动态库
lib_LTLIBRARIES = libhello.la
libhello_la_LIBADD = -rpath ./
IV. 参考源码树
proj
|---- NEWS
|---- README
|---- AUTHORS
|---- ChangeLog
|---- doc ----------------> 文档目录
|---- test ----------------> 测试代码目录
|---- src ----------------> 源码目录
|---- po ----------------> 国际化文件目录
|---- res ----------------> 资源目录
|---- glade ----------------> glade文件
`---- image ----------------> 图像文件
相关文章推荐
- Using Automake and Autoconf with C++
- Using C/C++ libraries with Automake and Autoconf
- Makefile 管理工具 — Automake and Autoconf
- USING GIT AND GITHUB TO MANAGE YOUR DOTFILES
- 在mac os 中安装 autoconf and automake
- Using GDI+ in a Single Document MFC Project to Rotate, Zoom, and Constraint an Image
- The GNU build system体验教程:Hello world example with Autoconf and Automake
- Building C/C++ libraries with Automake and Autoconf
- use autotools to make project
- How to make awesome UI components in iOS 8 using Swift and XCode 6
- Using a batch file to automatically build a Windows CE 5.0 and 6.0 project
- Makefile 管理工具 — Automake and Autoconf
- 在mac os 中安装 autoconf and automake
- Makefile 管理工具 — Automake and Autoconf
- Effective IT Project Management: Using Teams to Get Projects Completed on Time and Under Budget
- 【记录】AutoMapper Project To not support ResolveUsing
- 在mac os 中安装 autoconf and automake
- How to auto build and deploy project
- Using Branching to manage your project
- 在mac os 中安装 autoconf and automake