makefile.am



 

1.autoscan (autoconf): 扫描源代码以搜寻普通的可移植性问题,比如检查编译器,库,头文件等,生成文件configure.scan,它是configure.ac的一个雏形。

    your source files --> [autoscan*] --> [configure.scan] --> configure.ac

2.aclocal (automake):根据已经安装的宏,用户定义宏和acinclude.m4文件中的宏将configure.ac文件所需要的宏集中定义到文件 aclocal.m4中。aclocal是一个perl 脚本程序,它的定义是:“aclocal - create aclocal.m4 by scanning configure.ac”
user input files   optional input     process          output files
================ ============== ======= ============

acinclude.m4 - - - - -.
V
.-------,
configure.ac ------------------------>|aclocal|
{user macro files} ->| |------> aclocal.m4
`-------'
3.autoheader(autoconf): 根据configure.ac中的某些宏,比如cpp宏定义,运行m4,声称config.h.in

user input files optional input process output files
================ ============== ======= ============

aclocal.m4 - - - - - - - .
|
V
.----------,
configure.ac ----------------------->|autoheader|----> autoconfig.h.in
`----------'

4.automake: automake将Makefile.am中定义的结构建立Makefile.in,然后configure脚本将生成的Makefile.in文件转换 为Makefile。如果在configure.ac中定义了一些特殊的宏,比如AC_PROG_LIBTOOL,它会调用libtoolize,否则它 会自己产生config.guess和config.sub

user input files   optional input   processes          output files
================ ============== ========= ============

.--------,
| | - - -> 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
`----------'

5.autoconf:将configure.ac中的宏展开,生成configure脚本。这个过程可能要用到aclocal.m4中定义的宏。

user input files   optional input   processes          output files
================ ============== ========= ============

aclocal.m4 ,autoconfig.h.in - - - - - - -.
V
.--------,
configure.ac ----------------------->|autoconf|------> configure
 
6. ./configure的过程

.-------------> [config.cache]
configure* --------------------------+-------------> config.log
|
[config.h.in] -. v .--> [autoconfig.h]
+-------> config.status* -+
Makefile.in ---' `--> Makefile
 
7. make过程
 
[autoconfig.h] -.
+--> make* ---> 程序
Makefile ---'
 
.---------,
config.site - - ->| |
config.cache - - ->|configure| - - -> config.cache
| +-,
`-+-------' |
| |----> config.status
config.h.in ------->|config- |----> config.h
Makefile.in ------->| .status|----> Makefile
| |----> stamp-h
| +--,
.-+ | |
| `------+--' |
ltmain.sh ------->|ltconfig|-------> libtool
| | |
`-+------' |
|config.guess|
| config.sub |
`------------'

 

.--------,
Makefile ------>| |
config.h ------>| make |
{project sources} ---------------->| |--------> {project targets}
.-+ +--,
| `--------' |
| libtool |
| missing |
| install-sh |
|mkinstalldirs|
`-------------'
实例
在/hello/目录下创建一个hello.c文件,并编译运行它:

#cd /hello/

(1) 编写源文件hello.c:

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

[litao@vm0000131 hello]$ ll
total 4
-rw-rw-r-- 1 litao litao 68 Aug 12 12:02 hello.c

一、autoscan

[litao@vm0000131 hello]$ autoscan
autom4te: configure.ac: no such file or directory
autoscan: /usr/bin/autom4te failed with exit status: 1
[litao@vm0000131 hello]$ ll
total 8
-rw-rw-r-- 1 litao litao   0 Aug 12 12:03 autoscan.log
-rw-rw-r-- 1 litao litao 457 Aug 12 12:03 configure.scan
-rw-rw-r-- 1 litao litao  68 Aug 12 12:02 hello.c

已经生成了configure.scan,autoscan.log文件

将configure.scan 修改为 configure.in,最后修改的内容如下:

[litao@vm0000131 hello]$ mv configure.scan configure.in    
[litao@vm0000131 hello]$ vim configure.in 

#                                               -*- 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)

二、acloacl

[litao@vm0000131 hello]$ aclocal 

生成 aclocal.m4 和 autom4te.cache (生成aclocal.m4的过程中涉及到configure.in)

[litao@vm0000131 hello]$ ll
total 44
-rw-rw-r-- 1 litao litao 31120 Aug 12 12:08 aclocal.m4
drwxr-xr-x 2 litao litao  4096 Aug 12 12:08 autom4te.cache
-rw-rw-r-- 1 litao litao     0 Aug 12 12:03 autoscan.log
-rw-rw-r-- 1 litao litao   496 Aug 12 12:08 configure.in
-rw-rw-r-- 1 litao litao    68 Aug 12 12:02 hello.c

三、antoconf

[litao@vm0000131 hello]$ autoconf
生成 configure (根据 configure.in, 和 aclocal.m4)

[litao@vm0000131 hello]$ ll
total 168
-rw-rw-r-- 1 litao litao  31120 Aug 12 12:08 aclocal.m4
drwxr-xr-x 2 litao litao   4096 Aug 12 12:11 autom4te.cache
-rw-rw-r-- 1 litao litao      0 Aug 12 12:03 autoscan.log
-rwxrwxr-x 1 litao litao 122297 Aug 12 12:11 configure
-rw-rw-r-- 1 litao litao    496 Aug 12 12:08 configure.in
-rw-rw-r-- 1 litao litao     68 Aug 12 12:02 hello.c

四、编写Makefile.am:

AUTOMAKE_OPTIONS= foreign
bin_PROGRAMS= hello
hello_SOURCES= hello.c

五、automake

生成 Makefile.in, depcomp, install-sh, 和 missing (根据 Makefile.am, 和 aclocal.m4)

[litao@vm0000131 hello]$ automake
configure.in: required file `./install-sh' not found
configure.in: required file `./missing' not found
Makefile.am: required file `./depcomp' not found
[litao@vm0000131 hello]$ automake --add-missing
configure.in: installing `./install-sh'
configure.in: installing `./missing'
Makefile.am: installing `./depcomp'
[litao@vm0000131 hello]$ ll
total 192
-rw-rw-r-- 1 litao litao  31120 Aug 12 12:08 aclocal.m4
drwxr-xr-x 2 litao litao   4096 Aug 12 12:14 autom4te.cache
-rw-rw-r-- 1 litao litao      0 Aug 12 12:03 autoscan.log
-rwxrwxr-x 1 litao litao 122297 Aug 12 12:11 configure
-rw-rw-r-- 1 litao litao    496 Aug 12 12:08 configure.in
lrwxrwxrwx 1 litao litao     31 Aug 12 12:16 depcomp -> /usr/share/automake-1.9/depcomp
-rw-rw-r-- 1 litao litao     68 Aug 12 12:02 hello.c
lrwxrwxrwx 1 litao litao     34 Aug 12 12:16 install-sh -> /usr/share/automake-1.9/install-sh
-rw-rw-r-- 1 litao litao     69 Aug 12 12:15 Makefile.am
-rw-rw-r-- 1 litao litao  16561 Aug 12 12:16 Makefile.in
lrwxrwxrwx 1 litao litao     31 Aug 12 12:16 missing -> /usr/share/automake-1.9/missing

六、configure
生成 Makefile, config.log, 和 config.status


<think>我们正在解决编译时出现的`libguile.h`缺失问题,并探讨`Makefile.am`和`Makefile.in`在自动生成流程中的作用。用户的问题集中在如何通过安装开发包、配置构建系统来解决头文件缺失,以及理解Autotools(automake)的工作流程。###解决`fatalerror:libguile.h:Nosuchfileordirectory`####1.**安装Guile开发包**必须安装GNUGuile的开发包(包含头文件和库)。根据系统选择:-**Debian/Ubuntu**:```bashsudoapt-getinstalllibguile-3.0-dev#安装Guile3.0开发包```-**RHEL/CentOS**:```bashsudoyuminstallguile-devel```-**Fedora**:```bashsudodnfinstallguile-devel```安装后,头文件通常位于`/usr/include/guile/3.0/`(版本号可能不同)[^1]。####2.**验证头文件路径**检查`libguile.h`是否存在:```bashfind/usr-name'libguile.h'2>/dev/null```####3.**配置构建环境**如果使用Autotools(`configure`脚本)构建项目:-确保开发包安装后重新运行`configure`:```bash./configure```它会自动检测Guile并设置正确的头文件路径[^2]。####4.**手动指定头文件路径(备选)**如果构建系统未自动处理,可手动添加编译标志:```bashCFLAGS="-I/usr/include/guile/3.0"./configure```---###理解`Makefile.am`和`Makefile.in`的自动生成流程Autotools(automake+autoconf)用于生成可移植的构建系统。流程如下:####1.**编写`Makefile.am`**-开发者定义项目构建规则(例如编译目标、依赖):```makefilebin_PROGRAMS=my_programmy_program_SOURCES=main.cmy_program_CPPFLAGS=$(GUILE_CFLAGS)#头文件搜索路径my_program_LDADD=$(GUILE_LIBS)#链接库```-`GUILE_CFLAGS`和`GUILE_LIBS`由`configure`脚本通过`pkg-config`填充[^3]。####2.**生成`Makefile.in`**-运行`automake`将`Makefile.am`转换为模板`Makefile.in`:```bashautomake--add-missing#通常与autoreconf一起使用```-`Makefile.in`包含占位符(如`@GUILE_CFLAGS@`),将在`configure`运行时被替换。####3.**生成`configure`脚本**-使用`autoconf`处理`configure.ac`生成`configure`:```bashautoconf```-`configure.ac`中需包含Guile依赖检查:```m4PKG_CHECK_MODULES([GUILE],[guile-3.0])#检查Guile并设置GUILE_CFLAGS/GUILE_LIBS```####4.**用户构建流程**用户执行标准步骤:```bash./configure#检测系统环境,生成Makefilemake#使用Makefile编译sudomakeinstall#安装```####依赖关系图```mermaidgraphLRA[Makefile.am]-->|automake|B[Makefile.in]C[configure.ac]-->|autoconf|D[configure]D-->|运行|E[Makefile]B-->E```>**关键点**:>-`Makefile.am`是开发者编写的抽象规则;>-`Makefile.in`是Autotools生成的中间模板;>-`configure`根据系统配置将`Makefile.in`转为最终`Makefile`[^4]。§§相关问题§§1.Autotools中`configure.ac`如何检查第三方库的存在?2.如何为项目添加自定义的编译选项(如启用调试模式)?3.当`./configure`报告“Guilenotfound”时如何解决?4.`pkg-config`在构建过程中起什么作用?[^1]:开发包提供头文件和链接库,编译器需要它们完成预处理和链接。[^2]:`configure`脚本通过环境变量或`pkg-config`探测依赖库路径。[^3]:`pkg-config`提供标准化的编译和链接标志查询接口。[^4]:Autotools通过生成脚本适配不同Unix系统,解决兼容性问题。</think>### 解决 "fatal error: libguile.h: No such file or directory" 及 Makefile 自动生成流程 #### 一、问题根本原因 该错误表明编译时缺少 GNU Guile 库的开发文件(头文件和链接库)。解决方案需同时处理**依赖安装**和**构建系统配置**。 #### 二、完整解决步骤 1. **安装 Guile 开发包** ```bash # Debian/Ubuntu sudo apt-get install libguile-3.0-dev # 或 libguile-2.2-dev # RHEL/CentOS sudo yum install guile-devel # Fedora sudo dnf install guile-devel ``` 验证安装: ```bash find /usr -name 'libguile.h' 2>/dev/null # 典型输出: /usr/include/guile/3.0/libguile.h ``` 2. **配置构建系统(Autotools 流程)** Autotools 构建链的关系: ```mermaid graph LR A[configure.ac] -->|autoconf| B[configure] C[Makefile.am] -->|automake| D[Makefile.in] B -->|运行| E[Makefile] D --> E ``` **关键文件作用**: - `configure.ac`:定义项目依赖和系统检查 - `Makefile.am`:声明构建规则 - `Makefile.in`:Autotools 生成的模板 - `Makefile`:最终构建文件 3. **添加 Guile 依赖检测** 在 `configure.ac` 中添加: ```m4 PKG_CHECK_MODULES([GUILE], [guile-3.0]) AC_SUBST(GUILE_CFLAGS) AC_SUBST(GUILE_LIBS) ``` 4. **配置 Makefile.am** ```makefile bin_PROGRAMS = your_program your_program_SOURCES = main.c your_program_CPPFLAGS = $(GUILE_CFLAGS) # 头文件路径 your_program_LDADD = $(GUILE_LIBS) # 链接库 ``` 5. **重新生成构建系统** ```bash autoreconf -fiv # 重新生成 configure 和 Makefile.in ./configure # 检测依赖并生成 Makefile make # 正常编译 ``` #### 三、工作流程详解 1. **开发者编写**: - `configure.ac`:使用 M4 宏定义依赖检查 - `Makefile.am`:声明目标、源文件和编译规则 2. **生成中间文件**: ```bash aclocal # 收集宏 autoconf # 生成 configure 脚本 automake --add-missing # 生成 Makefile.in ``` 3. **用户构建**: ```bash ./configure # 扫描系统环境,替换 Makefile.in 中的变量 make # 使用最终 Makefile 编译 ``` > **关键点**: > `PKG_CHECK_MODULES` 会通过 `pkg-config` 查询 `guile-3.0.pc` 文件,自动设置 `GUILE_CFLAGS` 和 `GUILE_LIBS`[^1]。 > `Makefile.in` 中的占位符如 `@GUILE_CFLAGS@` 在 `./configure` 阶段被替换为实际路径[^2]。 #### 四、验证配置结果 检查生成的 `Makefile` 中是否包含正确路径: ```makefile # 应包含类似内容: your_program_CPPFLAGS = -I/usr/include/guile/3.0 your_program_LDADD = -lguile-3.0 ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值