使用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

目录
相关文章
|
存储 安全 文件存储
什么是NAS?探索无限存储的可能性
【4月更文挑战第21天】
13223 0
什么是NAS?探索无限存储的可能性
|
Linux Android开发 iOS开发
JEB Pro v5.32 (macOS, Linux, Windows) - 逆向工程平台
JEB Pro v5.32 (macOS, Linux, Windows) - 逆向工程平台
780 1
JEB Pro v5.32 (macOS, Linux, Windows) - 逆向工程平台
|
11月前
|
移动开发 运维 监控
微信游戏的外包开发流程
微信游戏外包开发需聚焦即点即玩、社交传播与微信生态集成。流程涵盖需求策划、美术设计、技术开发(含微信SDK)、平台配置、测试提审及运维交付。关键点:提前办软著、明确性能指标与源码归属,选对引擎助力长期运营。#微信游戏 #游戏外包
|
编解码 Ubuntu 算法
Ubuntu桌面图标指南:一文了解如果设置ubuntu 软件图标
Ubuntu桌面图标指南:一文了解如果设置ubuntu 软件图标
5854 0
|
网络协议 安全 Shell
【内网—内网转发】——代理转发_ew(Earthworm)代理转发
【内网—内网转发】——代理转发_ew(Earthworm)代理转发
1455 4
史上最简单给大模型注入新知识的方法(一)
史上最简单给大模型注入新知识的方法(一)
761 0
|
传感器 人工智能 API
通义灵码2.5深度评测:编程智能体与MCP工具的革新体验
通义灵码2.5通过“智能体+MCP”组合,重新定义了AI编码助手的边界。其价值不仅在于代码生成效率,更在于通过工具链整合和环境感知,推动开发流程向“声明式编程”演进。对于开发者而言,它既是提升效率的利器,也是探索AI辅助开发边界的实验场。
1142 8
【建站系列教程】2.3、分享一些小说的api接口
【建站系列教程】2.3、分享一些小说的api接口
5104 0
【建站系列教程】2.3、分享一些小说的api接口
|
IDE 测试技术 开发工具
10个必备Python调试技巧:从pdb到单元测试的开发效率提升指南
在Python开发中,调试是提升效率的关键技能。本文总结了10个实用的调试方法,涵盖内置调试器pdb、breakpoint()函数、断言机制、logging模块、列表推导式优化、IPython调试、警告机制、IDE调试工具、inspect模块和单元测试框架的应用。通过这些技巧,开发者可以更高效地定位和解决问题,提高代码质量。
1550 8
10个必备Python调试技巧:从pdb到单元测试的开发效率提升指南
|
域名解析 安全 数据建模
没有域名只有IP地址怎么申请https证书?
IP 地址 SSL 证书是一种特殊的 SSL/TLS 证书,允许直接为 IP 地址配置 HTTPS 加密,适用于内部服务、私有网络和无域名的设备管理。与基于域名的证书不同,申请过程较为复杂,需选择支持 IP 的证书颁发机构(CA),并完成额外的身份验证步骤。浏览器对 IP 地址的支持有限,可能会显示警告。通过正确配置服务器(如 Nginx 或 Apache),可以确保通信安全。
2454 12