1. 程式人生 > >一步步實現windows版ijkplayer系列文章之五——使用automake生成makefile

一步步實現windows版ijkplayer系列文章之五——使用automake生成makefile

一步步實現windows版ijkplayer系列文章之一——Windows10平臺編譯ffmpeg 4.0.2,生成ffplay
一步步實現windows版ijkplayer系列文章之二——Ijkplayer播放器原始碼分析之音視訊輸出——視訊篇
一步步實現windows版ijkplayer系列文章之三——Ijkplayer播放器原始碼分析之音視訊輸出——音訊篇
一步步實現windows版ijkplayer系列文章之四——windows下編譯ijkplyer版ffmpeg
一步步實現windows版ijkplayer系列文章之五——使用automake一步步生成makefile

一步步實現windows版ijkplayer系列文章之五——使用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

[email protected] ~/devel/hello
$ aclocal

[email protected] ~/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,最後成功,可見沒有任何無誤提示。

[email protected] ~/devel/hello
$ automake --add-missing

最後執行configure,生成Makefile檔案:

[email protected] ~/devel/hello
$ ./configure

執行make,生成hello.exe:

[email protected] ~/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'

[email protected] ~/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

執行下面的命令:

[email protected] ~/automake_examples/example_2
$ aclocal

[email protected] ~/automake_examples/example_2
$ autoheader

[email protected] ~/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:

[email protected] ~/automake_examples/example_2
$ autoconf

[email protected] ~/automake_examples/example_2
$ ./configure

最後生成Makefile檔案,執行make,生成可執行檔案:

$ make

最後成功。

參考

Convenience-Libraries

輕輕鬆鬆生成makefile