我們需要編寫的文件
- Makefile.am
Makefile.am 是定義編譯規(guī)則,需要編譯的源代碼等。 - configure.ac/configure.in
autoscan命令可以生成configure.scan文件,然后將它改名字為configure.ac或者configure.in。并且可以手動(dòng)修改之。
流程
- 用autoscan生成configure.ac
掃描源代碼以搜尋普通的可移植性問(wèn)題,比如檢查編譯器,庫(kù),頭文件等,生成文件configure.scan,它是configure.ac的一個(gè)雛形
your source files --> [autoscan*] --> [configure.scan] --> configure.ac/configure.in
- 用aclocal生成aclocal.m4文件
根據(jù)已經(jīng)安裝的宏,用戶定義宏和acinclude.m4文件中的宏將configure.ac文件所需要的宏集中定義到文件 aclocal.m4中
acinclude.m4 -----------------------------.
V
.-------,
configure.ac ------------------------>|aclocal|
{user macro files} ->| |------> aclocal.m4
`-------'
- 用autoheader生成autoconfig.h.in[可選]
autoheader(autoconf): 根據(jù)configure.ac中的某些宏,比如cpp宏定義,運(yùn)行m4,生成config.h.in
aclocal.m4 -------------------------------- .
|
V
.----------,
configure.ac -------------------------->|autoheader|----> autoconfig.h.in
`----------'
- 用automake將Makefile.am(需要手動(dòng)編寫)中定義的結(jié)構(gòu),生成Makefile.in,然后configure腳本將生成的Makefile.in文件轉(zhuǎn)換 為Makefile。如果在configure.ac中定義了一些特殊的宏,比如AC_PROG_LIBTOOL,它會(huì)調(diào)用libtoolize,否則它 會(huì)自己產(chǎn)生config.guess和config.sub
.--------,
| | - - -> COPYING
| | - - -> INSTALL
| |------> install-sh
| |------> missing
|automake|------> mkinstalldirs
configure.ac --------------------->| |
Makefile.am --------------------->| |------> Makefile.in
| |------> stamp-h.in
.---+ | - - -> config.guess
| | | - - -> config.sub
| `------+-'
| | - - - -> config.guess
|libtoolize| - - - -> config.sub
| |--------> ltmain.sh
| |--------> ltconfig
`----------'
- 用autoconf生成configure腳本
將configure.ac中的宏,aclocal.m4中定義的宏和第3步的autoconfig.h.in展開,生成configure腳本。
aclocal.m4 ,autoconfig.h.in - - - - - - -.
V
.--------,
configure.ac ----------------------->|autoconf|------> configure
`----------'
- 運(yùn)行./configure生成Makefile
運(yùn)行./configure,可以加入?yún)?shù)
.-------------> [config.cache]
configure* --------------------------+-------------> config.log
|
[config.h.in]-----. v .--> [autoconfig.h]
+-------> config.status* ---+
Makefile.in ---' `--> Makefile
例子
目標(biāo):在/hello/目錄下創(chuàng)建一個(gè)hello.c文件,并編譯運(yùn)行它
- 編寫源文件
#include<stdio.h>
int main(int argc, char** argv)
{
printf("Hello, GNU!n");
return 0;
}
- 生成configure.scan
[xxx]$ autoscan
autom4te: configure.ac: no such file or directory
autoscan: /usr/bin/autom4te failed with exit status: 1
生成了configure.scan,autoscan.log文件,將configure.scan 修改為 configure.in,最后修改的內(nèi)容如下:
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_PREREQ(2.59)
AC_INIT(FULL-PACKAGE-NAME, VERSION, BUG-REPORT-ADDRESS)
AC_CONFIG_SRCDIR([hello.c])
#AC_CONFIG_HEADER([config.h])
AM_INIT_AUTOMAKE(hello, 1.0)
# 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_OUTPUT(Makefile)
- aclocal生成aclocal.m4
運(yùn)行aclocal ,生成 aclocal.m4 和 autom4te.cache (生成aclocal.m4的過(guò)程中涉及到configure.in) - 編寫Makefiel.am
AUTOMAKE_OPTIONS= foreign
bin_PROGRAMS= hello
hello_SOURCES= hello.c
- 生成Makefile.in
生成 Makefile.in, depcomp, install-sh, 和 missing (根據(jù) Makefile.am, 和 aclocal.m4) - autoconf生成configure
生成 configure (根據(jù) configure.in, 和 aclocal.m4) - configure
生成 Makefile, config.log, 和 config.status
總結(jié)
命令流如下
autoscan==>mv configure.scan configure.in==>aclocal
==>create Makefile.am==>automake==>autoconf==>configure
參考資料
比較雜,可以看中間部分https://www.cnblogs.com/gaoshanxiaolu/p/4128146.html