使用automake一步步生成makefile

简介:

使用automake一步步生成makefile

上一篇文章我们把ffmpeg库成功在windows平台下编译成dll了,ffmpeg的编译方案是跨平台的,直接使用它的现成的configure文件用于生成makefile,但是ijkplayer的另外两个库ijkplayer和ijksdl只支持android和IOS平台,因此在windows平台的编译需要自己实现,我们打算使用automake,先熟悉一下,从网络搜罗了两个例子,在自己的环境里面一步步成功生成了makefile,其中有些坑,现在将这些步骤记录下来。

准备环境

平台 windows mingw

autoconf 版本:2.68

automake版本:1.11.1

一个简单例子

创建文件夹hello,进入文件夹后编辑一个简单的hello.c文件

#include <stdio.h>
 int main(int argc, char** argv)
 {
    printf("Hello, automake!\n");
    return 0;
}

手动创建Makefile.am,內容如下:

AUTOMAKE_OPTIONS= foreign
bin_PROGRAMS= hello

hello_SOURCES= hello.c

执行autoscan,目录变化如下:

$ ls -l
total 2
drwxr-xr-x 2 zexu Administrators   0 Oct 20 12:14 autom4te.cache
-rw-r--r-- 1 zexu Administrators   0 Oct 20 12:14 autoscan-2.68.log
-rw-r--r-- 1 zexu Administrators 495 Oct 20 12:14 configure.scan
-rw-r--r-- 1 zexu Administrators 100 Oct 18 07:46 hello.c

看一下configure.scan的内容:

#                                               -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.

AC_PREREQ([2.68])
AC_INIT([FULL-PACKAGE-NAME], [VERSION], [BUG-REPORT-ADDRESS])
AC_CONFIG_SRCDIR([hello.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_CONFIG_FILES([Makefile])
AC_OUTPUT

将此文件重命名为configure.in,执行autolocal,autoconf,生成configure:

$ ls -lh
total 111K
drwxr-xr-x 2 zexu Administrators    0 Oct 20 12:29 autom4te.cache
-rw-r--r-- 1 zexu Administrators    0 Oct 20 12:14 autoscan-2.68.log
-rwxr-xr-x 1 zexu Administrators 109K Oct 20 12:29 configure
-rw-r--r-- 1 zexu Administrators  495 Oct 20 12:14 configure.in
-rw-r--r-- 1 zexu Administrators  100 Oct 18 07:46 hello.c

执行如下automake命令:

$ automake --add-missing
configure.in: no proper invocation of AM_INIT_AUTOMAKE was found.
configure.in: You should verify that configure.in invokes AM_INIT_AUTOMAKE,
configure.in: that aclocal.m4 is present in the top-level directory,
configure.in: and that aclocal.m4 was recently regenerated (using aclocal).
configure.in:7: required file `config.h.in' not found
Makefile.am: installing `./depcomp'
/mingw/share/automake-1.11/am/depend2.am: am__fastdepCC does not appear in AM_CONDITIONAL
/mingw/share/automake-1.11/am/depend2.am:   The usual way to define `am__fastdepCC' is to add `AC_PROG_CC'
/mingw/share/automake-1.11/am/depend2.am:   to `configure.in' and run `aclocal' and `autoconf' again.
/mingw/share/automake-1.11/am/depend2.am: AMDEP does not appear in AM_CONDITIONAL
/mingw/share/automake-1.11/am/depend2.am:   The usual way to define `AMDEP' is to add one of the compiler tests
/mingw/share/automake-1.11/am/depend2.am:     AC_PROG_CC, AC_PROG_CXX, AC_PROG_CXX, AC_PROG_OBJC,
/mingw/share/automake-1.11/am/depend2.am:     AM_PROG_AS, AM_PROG_GCJ, AM_PROG_UPC
/mingw/share/automake-1.11/am/depend2.am:   to `configure.in' and run `aclocal' and `autoconf' again.

看到出错了,在configure.in中添加如下信息:

AM_INIT_AUTOMAKE([-Wall -Werror foreign])

再次执行aclocal,autoconf和automake

zexu@DESKTOP-R4T030U ~/devel/hello
$ aclocal

zexu@DESKTOP-R4T030U ~/devel/hello
$ autoconf

$ automake --add-missing
configure.in:9: installing `./install-sh'
configure.in:9: installing `./missing'
configure.in:7: required file `config.h.in' not found

执行autoheader,生成头文件后再次automake,最后成功,可见没有任何无误提示。


zexu@DESKTOP-R4T030U ~/devel/hello
$ automake --add-missing

最后执行configure,生成Makefile文件:

zexu@DESKTOP-R4T030U ~/devel/hello
$ ./configure

执行make,生成hello.exe:

zexu@DESKTOP-R4T030U ~/devel/hello
$ make
make  all-am
make[1]: Entering directory `/home/zexu/devel/hello'
gcc -DHAVE_CONFIG_H -I.     -g -O2 -MT hello.o -MD -MP -MF .deps/hello.Tpo -c -o hello.o hello.c
mv -f .deps/hello.Tpo .deps/hello.Po
gcc  -g -O2   -o hello.exe hello.o
make[1]: Leaving directory `/home/zexu/devel/hello'

zexu@DESKTOP-R4T030U ~/devel/hello
$ ls
Makefile     aclocal.m4         config.h     config.status  depcomp    hello.o     stamp-h1
Makefile.am  autom4te.cache     config.h.in  configure      hello.c    install-sh
Makefile.in  autoscan-2.68.log  config.log   configure.in   hello.exe  missing

一个复杂一些的例子

这个例子使用了libtool,我把代码提交到了github,先把其clone下来:

git clone https://github.com/harlanc/automake_examples.git

进入example_2,先看一下目录结构:

$ ls -R
.:
Makefile.am  configure.in  error.c  error.h  lib  main.c  replace

./lib:
Makefile.am  source.c  source.h

./replace:
Makefile.am  basename.c  dummy.c

执行下面的命令:

zexu@DESKTOP-R4T030U ~/automake_examples/example_2
$ aclocal

zexu@DESKTOP-R4T030U ~/automake_examples/example_2
$ autoheader

zexu@DESKTOP-R4T030U ~/automake_examples/example_2
$ automake --add-missing --copy
configure.in:11: installing `./config.guess'
configure.in:11: installing `./config.sub'
configure.in:8: installing `./install-sh'
configure.in:11: required file `./ltmain.sh' not found
configure.in:8: installing `./missing'
lib/Makefile.am: installing `./depcomp'

看到有一个错误,执行下面的语句:

$libtoolize --automake --copy --debug --force

在此执行automake:

$ automake --add-missing --copy

最后成功,执行autoconf和configure:

zexu@DESKTOP-R4T030U ~/automake_examples/example_2
$ autoconf

zexu@DESKTOP-R4T030U ~/automake_examples/example_2
$ ./configure

最后生成Makefile文件,执行make,生成可执行文件:

$ make

最后成功。

参考

Convenience-Libraries

轻轻松松生成makefile

目录
相关文章
|
C++ 容器
掌握C++定时器:构建自己的定时器的分步指南
本文是一份详细的、分步指南,旨在帮助读者掌握C++定时器的构建过程。通过本文,读者将了解到什么是定时器,以及为什么需要自己构建定时器而不仅仅使用标准库中的函数。文章将从基础开始,介绍了利用C++的基本语法和操作符创建一个简单的定时器的步骤。随后,文章逐渐深入,介绍了如何优化定时器的性能,包括减少延迟和提高精度。
874 0
|
11月前
|
前端开发 安全 Android开发
跨平台开发的新纪元:Tauri 2.0 横空出世,移动端、桌面端一网打尽!
Tauri 2.0 正式版于 2024 年 10 月 2 日发布,带来了多项重大更新。此次更新不仅全面支持 iOS 和 Android,实现“一次编写,到处运行”,还升级了插件系统,增强了灵活性与可扩展性。安全性大幅提升,引入新的权限系统,并优化了 IPC 层,支持原始有效载荷传输,大幅提高性能。此外,Tauri 2.0 还支持热模块替换(HMR),简化了应用分发流程,成为跨平台开发的重要里程碑。
1600 0
跨平台开发的新纪元:Tauri 2.0 横空出世,移动端、桌面端一网打尽!
|
10月前
|
API 定位技术
天气预报1天-中国气象局-IP查询版免费API接口教程
此接口基于IP地址自动判断并提供该地区当日的天气信息,数据源自中国气象局。支持POST/GET请求,需提供用户ID和KEY,可选输入IP地址,默认返回北京天气。返回参数包括天气详情、地理位置及IP等。示例请求与响应详见文档。
|
12月前
|
云安全 SQL 安全
揭秘DDoS与CC攻击的异同与防御策略!
本文详细解析了CC攻击与DDoS攻击这两种常见网络威胁,探讨了它们的异同及防御策略。通过一个网站遭遇攻击的真实案例,揭示了CC攻击的隐蔽性和DDoS攻击的强大破坏力。文章还介绍了德迅云的高防服务器解决方案,强调了加强网络安全意识和技术防护的重要性,帮助网站运营者有效抵御网络攻击,确保业务稳定运行。
|
JavaScript
如何在 Angular 中使用 ViewChild 来访问子组件、指令或 DOM 元素
如何在 Angular 中使用 ViewChild 来访问子组件、指令或 DOM 元素
136 0
|
前端开发 JavaScript 开发工具
vscode教程(含使用技巧、保存时自动格式化文件等设置)
vscode教程(含使用技巧、保存时自动格式化文件等设置)
1100 0
|
API 图形学
U3D客户端框架之实现基于UnityWebRequest的Http服务 实现HttpCallBackArgs参数类、HttpRoutine访问器、HttpManager管理器
Unity3D 在2018版本中弃用了WWW请求,使用UnityWebRequest 进行网络请求,这个方法是为了满足今天的 HTTP 通信的需求,而且诞生的新类,相对于WWW这个方法,会更灵活一些,但是用起来却很不方便。
U3D客户端框架之实现基于UnityWebRequest的Http服务 实现HttpCallBackArgs参数类、HttpRoutine访问器、HttpManager管理器
|
Python
解释Python中的ABC(Abstract Base Classes)是什么,如何使用它们?
【2月更文挑战第4天】【2月更文挑战第8篇】解释Python中的ABC(Abstract Base Classes)是什么,如何使用它们?
1041 2
|
安全 JavaScript 前端开发
深入解析crypto.getRandomValues():JavaScript中的高安全性随机数生成
深入解析crypto.getRandomValues():JavaScript中的高安全性随机数生成
793 0
|
Python
Python报错: No module named 'lxml'
Python报错: No module named 'lxml'
566 1

热门文章

最新文章