autoconf automake libtool
这是一个 autoconf / automake 的 "Hello World"
gztt.ll@gmail.com
主要步骤是
- 准备工程目录结构和程序
- autoscan 生成 configure.scan
- 编辑修改 configure.scan,重命名为 configure.ac 或 configure.in
- aclocal; libtoolize; autoheader; autoconf 生成 'configure' 可执行文件
- 写 Makefile.am
- automake 生成 Makefile
- 完成。后面就可以 ./configure; make; make install; make dist; ...
试验工程结构如下
hello
|
|---- src
| |---- main
| | |---- main.c
| |
| |---- foo
| | |---- foo.c
| |
| |---- bar
| |---- bar.c
|
|---- include
|---- foo.h
|---- bar.h
说明一下
"hello" 工程的$(top_srcdir)
"src/main" 生成可执行文件 hello 主目录
"src/foo" 生成静态库的目录 libfoo.a;hello 主程序 link 时用
"src/bar" 生成动态库的目录 libbar.so;hello 主程序运行时加载
"include" 头文件目录
$mkdir hello && cd hello
准备示例程序,如下
### 文件内容 ###
/* ### src/main/main.c ### */
#include <stdio.h>
#include "foo.h"
#include "bar.h"
int main(int argc, char *argv[])
{
printf("main +\n");
func_foo();
func_bar();
printf("main -\n");
return 0;
}
/* ### include/foo.h ### */
#include <stdio.h>
void func_foo(void);
/* ### src/foo/foo.c ### */
#include "foo.h"
void func_foo(void)
{
printf("foo +-\n");
}
/* ### include/bar.h ### */
#include <stdio.h>
void func_bar(void);
/* ### src/bar/bar.c ### */
#include "bar.h"
void func_bar(void)
{
printf("bar +-\n");
}
下面进入顶层目录 $(top_srcdir)
$cd hello
$autoscan
自动生成 configure.scan 文件,我们要作稍许修改,重命名为 configure.ac 或 configure.in
(configure.in 是老版本 autoconf 支持的)
$mv configure.scan configure.ac
修改 configure.ac 如下
/* ### configure.ac ### */
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_PREREQ(2.61)
AC_INIT(hello, 1.0.0, gztt.ll@gmail.com) ### Modified
AM_INIT_AUTOMAKE(hello,1.0.0, gztt.ll@gmail.com) ### Added
AC_CONFIG_SRCDIR([src/main/main.c])
AC_CONFIG_HEADER([config.h])
# Checks for programs.
AC_PROG_CC
AC_PROG_RANLIB ### Added if static libary used
AC_PROG_LIBTOOL ### Added if dynamic libary used
# Checks for libraries.
# Checks for header files.
# Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
# Checks for library functions.
AC_OUTPUT(Makefile ### Added
include/Makefile
src/main/Makefile
src/foo/Makefile
src/bar/Makefile
)
说明一下:
如果不使用静态库或动态库 'AC_PROG_RANLIB' 和'AC_PROG_LIBTOOL' 则都不需要
如果仅使用静态库,增加 'AC_PROG_RANLIB' 即可
如果需要使用动态库,需加上 'AC_PROG_LIBTOOL'
'AC_CONFIG_HEADER(...)',我在 RedHat9 上试的时候,这行要改面 'AM_CONFIG_HEADER(...)',原因未知。
用 RedHat 9 时,最后 'AC_OUTPUT(...)' 里文件也不太一样, RedHat9 需要多一行 'src/Makefile',详见下面说明。
(我默认是用 debian 5)
接着执行下面的命令
$aclocal
$libtoolize
$autoheader
$autoconf
注:只有用到动态库时,才需要 '$libtoolize'
否则,只需要运行
$aclocal
$autoheader
$autoconf
即可。
此时应该可以生成 'configure' 可执行文件
然后我们写 Makefile.am
/* ### Makefile.am ### */
SUBDIRS = include src/bar src/foo src/main
/* ### include/Makefile.am ### */
helloincludedir=$(includedir)
helloinclude_HEADERS=foo.h bar.h
/* ### src/main/Makefile.am ### */
bin_PROGRAMS=hello
hello_SOURCES=main.c
hello_LDADD=$(top_srcdir)/src/foo/libfoo.a
LIBS=-lbar
INCLUDES=-I$(top_srcdir)/include
hello_LDFLAGS=-L$(top_srcdir)/src/bar
/* ### src/foo/Makefile.am ### */
noinst_LIBRARIES=libfoo.a
libfoo_a_SOURCES=foo.c
INCLUDES=-I$(top_srcdir)/include
/* ### src/bar/Makefile.am ### */
lib_LTLIBRARIES=libbar.la
libbar_la_SOURCES=bar.c
INCLUDES=-I$(top_srcdir)/include
说明一下,
第一个 'Makefile.am' 文件,即'$(top_srcdir)/Makefile.am' 只说了子目录说明,按编译顺序排的。
RedHat 9 会报错,说不能含 '/' 符号;解决办法是,我们新增加一个 '$(top_srcdir)/src/Makefile.am'
这样:
/* ### Makefile.am ### */
SUBDIRS = include src
/* ### src/Makefile.am ### */
SUBDIRS = bar foo main
此时,如前面所讲 'configure.ac' 最后的'AC_OUTPUT' 就需多一行'src/Makefile' 了
'$(top_srcdir)/src/main/Makefile.am' 相对复杂一点,
特别指出的是 'hello_LDFLAGS' 后,应是'...=-L$(top_srcdir)/...',而不是'...=-L $(top_srcdir)/...'
多一个空格,后面就有错误。
接着 automake 的话,无法通过的,还需要下面几个文件,我们暂时 touch 一下即可
$touch README NEWS AUTHORS ChangeLog
注意是在 $(top_srcdir) 目录下面
然后
$automake --add-missing
$./configure
至此,所有 Makefile 文件应该全部生成
我们可以执行
$make
$make clean
$make install
$make uninstall
$make dist
$make ...
autoconf automake libtool的更多相关文章
- 手动安装m4, autoconf, automake, libtool
转自http://ruby-china.org/topics/2434 系列文章原载于自己的博客,TOPI.CO (http://topi.co) ,某天不小心就push错啦,懒得从头再来,上传到Ru ...
- 安装 Autoconf, Automake & Libtool
今天在使用sudo apt-get install命令安装autoconf和automake时,出现了问题,说是不能sudo apt-get install安装这些软件似乎不是最新的.由此,我通过搜索 ...
- Autoconf/Automake工具简介
在linux下编程的时候,有时候工程项目很大,文件比较多,此时需要使用自动创建Makefile文件功能.也就是使用Autoconf/Automake工具自动生成Makefile,为编译程序带来了方便, ...
- cmake与autoconf+automake
cmake与autoconf+automakes是同类的编译工具,本人常用的是cmake. 这有一篇对比的文章,记录一下. cmake与autoconf+automake的对比
- [strongswan][autoconf][automake][cento] 在CentOS上编译strongswan git源码时遇到的autoconf问题
编译strongswan的git源码问题 1. 概述 首先,我们想要通过源码编译strongswan.当满足以下条件时,通常你会遇见此问题: 源码时通过git clone的得来的,而不是官网下载的源码 ...
- 安装m4,autoconf,automake
###安装m4 wget http://mirrors.kernel.org/gnu/m4/m4-1.4.13.tar.gz \ && tar -xzvf m4-1.4.13.tar. ...
- autoscan; aclocal; autoconf; automake --add-missing; ./configure; make
1.autoscan 在源码目录下执行autoscan,生成configure.scan,重命名为configure.in或者configure.ac,然后编辑文件内容: ============== ...
- Mac下安装MacProt,并GNU autotools的安装和使用 autoconf,automake
1 MacPort的下载:http://www.macports.org/install.php, 需要安装xCode支持macport 2 安装MacPorts 与其他Mac的软件的安装方式相同,挂 ...
- autoconf / automake工具使用介绍
本文转自:http://blog.csdn.net/gulansheng/article/details/42683809 一.简介 作为Linux下的程序开发人员,一定都遇到过Makefile,用m ...
随机推荐
- 解析xlsx与xls--使用2012poi.jar
1.导入Jar包:poi-3.8-20120326.jar.poi-ooxml-3.8-20120326.jar.poi-ooxml-schemas-3.8-20120326.jar.xbean.ja ...
- Java通过代理server上网
完整代码 package com.proj.net; //导入编码的jar文件 import it.sauronsoftware.base64.Base64; import java.io.Buffe ...
- 构建tcpdump/wireshark pcap文件
pcap文件格式是bpf保存原始数据包的格式,很多软件都在使用,比如tcpdump.wireshark等等,了解pcap格式可以加深对原始数据包的了解,自己也可以手工构造任意的数据包进行测试. p ...
- Quartz Enterprise Job Scheduler 1.x Tutorial---转载
Lesson 10: Configuration, Resource Usage and SchedulerFactory http://www.quartz-scheduler.org/docume ...
- iOS创建界面方法的讨论
以前在入门的时候,找的入门书籍上编写的 demo 都是基于 Storyboards 拖界面的.后来接触公司项目,发现界面都是用纯代码去写复杂的 autoLayout 的.再然后,领导给我发了个 Mas ...
- Android(java)学习笔记173:BroadcastReceiver之 静态注册 和 动态注册
1. 广播接受者>什么是广播.收音机.电台:对外发送信号.收音机:接收电台的信号. >在android系统里面,系统有很多重要的事件: 电池电量低,插入充电器,sd卡被移除,有电话打出去, ...
- Android(java)学习笔记171:Service生命周期
1.Service的生命周期 Android中的Service(服务)与Activity不同,它是不能和用户交互,不能自己启动的,运行在后台的程序,如果我们退出应用的时候,Servic ...
- CentOS 6.7安装Java JDK
1.下载Java JDK 下载地址:http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.htm ...
- ui-router的使用
使用时需要ui中用ui-view指令指定 如: <div ui-view></div> 首先配置注册 ui-route var mainModule = angular.mod ...
- webrtc学习———记录一
最近导师让研究一下webrtc,希望将来用到我们的ICT2系统中. 但是从来没有过做web的基础,无论前端还是后端,html.js全都从头学起.html还好说,没有太过复杂的东西. js就有点难度了, ...