Makefile自动生成: 一些资料链接记录

Makefile自动生成 一些资料链接记录

Makefile自动生成初识于Linux Makefile自动生成–实例 ;而从
configure.ac和Makefile.am的格式解析概述博文则认识官网。

以下列出一些官网的相关链接以及书籍。

自动工具文档

自动工具关系

Makefile.am 查看 automake 手册。使用autoscan前用先建好Makefile.am文件

  • 使用autoscan命令把源码生成configure.scan,把configure.scan为configure.ac或者configure.in

      your source files --> [autoscan*] --> [configure.scan] --> configure.ac
    
  • 使用aclocal命令把源码生成aclocal.m4;

      [acinclude.m4] --.
      	                 |
      	[local macros] --+--> aclocal* --> aclocal.m4
      	                 |
      	configure.ac ----'
    
  • 使用autoconf命令生成configure;
    使用autoheader命令生成config.h;

      configure.ac --.
                     |   .------> autoconf* -----> configure
      [aclocal.m4] --+---+
                     |   `-----> [autoheader*] --> [config.h.in]
      [acsite.m4] ---'
      
      Makefile.in
    
  • 使用automake --add-missing命令生成Makefile.in;
    编写或者修改 「 c o n f i g u r e . a c 」 \color{#4285f4}{「configure.ac」} configure.ac 「 M a k e f i l e . a m 」 \color{#4285f4}{「Makefile.am」} Makefile.am

      configure.ac --.
                     +--> automake* --> Makefile.in
      Makefile.am ---'
    
  • 使用./configure命令生成config.h;
    make

                             .-------------> [config.cache]
      configure* ------------+-------------> config.log
                             |
      [config.h.in] -.       v            .-> [config.h] -.
                     +--> config.status* -+               +--> make*
      Makefile.in ---'                    `-> Makefile ---'
    

hello例程

(base) root@e9b213d41038:/home/work/usb/hellotest# ls
Makefile.am  hello.c
(base) root@e9b213d41038:/home/work/usb/hellotest# cat Makefile.am
AUTOMAKE_OPTIONS = foreign

bin_PROGRAMS = hello
(base) root@e9b213d41038:/home/work/usb/hellotest# cat hello.c
#include "stdio.h"

int main(void)
{
    printf("hello world\n");
}
(base) root@e9b213d41038:/home/work/usb/hellotest# autoscan && ls
Makefile.am  autoscan.log  configure.scan  hello.c
(base) root@e9b213d41038:/home/work/usb/hellotest# mv configure.scan configure.ac
(base) root@e9b213d41038:/home/work/usb/hellotest# vim configure.ac
(base) root@e9b213d41038:/home/work/usb/hellotest# cat configure.ac
#                                               -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.

AC_PREREQ([2.69])
AC_INIT([FULL-PACKAGE-NAME], [VERSION], [BUG-REPORT-ADDRESS])
AC_CONFIG_SRCDIR([hello.c])
AC_CONFIG_HEADERS([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_CONFIG_FILES([Makefile])
AC_OUTPUT
(base) root@e9b213d41038:/home/work/usb/hellotest# aclocal && ll
total 44
drwxrwxrwx 1 root root  4096 Nov  9 12:20 ./
drwxrwxrwx 1 root root  4096 Nov  9 11:43 ../
-rw-r--r-- 1 root root    50 Nov  9 11:53 Makefile.am
-rw-r--r-- 1 root root 42147 Nov  9 12:20 aclocal.m4
drwxr-xr-x 1 root root  4096 Nov  9 12:20 autom4te.cache/
-rw-r--r-- 1 root root     0 Nov  9 12:19 autoscan.log
-rw-r--r-- 1 root root   523 Nov  9 12:19 configure.ac
-rwxrwxrwx 1 root root    67 Nov  9 11:47 hello.c*
(base) root@e9b213d41038:/home/work/usb/hellotest# ls
Makefile.am  aclocal.m4  autom4te.cache  autoscan.log  configure.ac  hello.c
(base) root@e9b213d41038:/home/work/usb/hellotest# autoconf && ls
Makefile.am  aclocal.m4  autom4te.cache  autoscan.log  configure  configure.ac  hello.c
(base) root@e9b213d41038:/home/work/usb/hellotest# autoheader && ls
Makefile.am  aclocal.m4  autom4te.cache  autoscan.log  config.h.in  configure  configure.ac  hello.c
(base) root@e9b213d41038:/home/work/usb/hellotest# automake --add-missing && ls
configure.ac:8: warning: AM_INIT_AUTOMAKE: two- and three-arguments forms are deprecated.  For more info, see:
configure.ac:8: http://www.gnu.org/software/automake/manual/automake.html#Modernize-AM_005fINIT_005fAUTOMAKE-invocation
configure.ac:10: installing './compile'
configure.ac:8: installing './install-sh'
configure.ac:8: installing './missing'
Makefile.am: installing './depcomp'
Makefile.am  Makefile.in  aclocal.m4  autom4te.cache  autoscan.log  compile  config.h.in  configure  configure.ac  depcomp  hello.c  install-sh  missing
(base) root@e9b213d41038:/home/work/usb/hellotest# ./configure && ls
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... no
checking for mawk... mawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking whether gcc understands -c and -o together... yes
checking for style of include used by make... GNU
checking dependency style of gcc... gcc3
checking that generated files are newer than configure... done
configure: creating ./config.status
config.status: creating Makefile
config.status: creating config.h
config.status: executing depfiles commands
Makefile     Makefile.in  autom4te.cache  compile   config.h.in  config.status  configure.ac  hello.c     missing
Makefile.am  aclocal.m4   autoscan.log    config.h  config.log   configure      depcomp       install-sh  stamp-h1
(base) root@e9b213d41038:/home/work/usb/hellotest# make && ls
make  all-am
make[1]: Entering directory '/home/work/usb/hellotest'
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 hello.o
make[1]: Leaving directory '/home/work/usb/hellotest'
Makefile     Makefile.in  autom4te.cache  compile   config.h.in  config.status  configure.ac  hello    hello.o     missing
Makefile.am  aclocal.m4   autoscan.log    config.h  config.log   configure      depcomp       hello.c  install-sh  stamp-h1
(base) root@e9b213d41038:/home/work/usb/hellotest# ./hello
hello world

自动生成的configure.scan:

使用autoconf和automake的步骤
-> 策划你的项目目录结构,将编写好的第一版源码文件放到各个位置上;
-> 在顶层目录下运行autoscan获得configure.ac模板 (configure.scan->configure.ac)
-> 手工编辑configure.in,满足个性化需要
-> 手工建立并编辑各个层次的Makefile.am
-> 在顶层目录下运行autoheader,生成相应config.h.in
-> 在顶层目录下运行aclocal,生成aclocal.m4
-> 在顶层目录下运行autoconf,生成configure
-> 在顶层目录下运行automake,生成各级Makefile.in

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值