searchusermenu
  • 发布文章
  • 消息中心
点赞
收藏
评论
分享
原创

Automake 使用简介

2023-03-28 01:47:49
10
0

1.创建hello.c并插入代码

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

2. 执行autoscan命令

[root@21b2e14c089e automake]# autoscan
[root@21b2e14c089e automake]# ls -l
total 8
-rw-r--r-- 1 root root   0 Dec 22 09:13 autoscan.log
-rw-r--r-- 1 root root 467 Dec 22 09:13 configure.scan
-rw-r--r-- 1 root root 100 Dec 22 09:13 hello.c

3.修改自动生成的configure.scan并改名

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

# 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

说明:

  • AC_PREREQ 宏声明本文件要求的autoconf版本,这里是2.69
  • AC_INIT 定义软件的名称和信息。(DULL-PACKAGE-NAME为软件名,VERSION为软件的版本号,BUG-REPORT-ADDRESS为bug的报告地址,一般为软件作者的邮箱)
  • AC_CONFIG_SRCDIR 用来侦测指定的源码文件是否存在,确定源码目录的有效性。此处为当前目录下hello.c
  • AC_CONFIG_HEADER 用于生成config.h文件,以便autoheader使用
  • AC_PROG_CC 用来指定编译器,以便不指定的时候默认为gcc
  • AC_OUTPUT 用来设定config要产生的文件。如果是Makefile,config会把它检查出来的结果带入Makefile.in文件产生合适的Makefile.

修改后内容:

#                                               -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.

AC_PREREQ([2.69])
AC_INIT(testdemo, 1.0.1, xxx@163.com)
AM_INIT_AUTOMAKE(testdemo, 1.0.1)
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_OUTPUT(Makefile)

AM_INIT_AUTOMAKE(PACKAGE, VERSION) 这个宏是必须的,它描述了我们将要生成的软件包的名字及其版本号:PACKAGE是软件包的名字,VERSION是版本号。
当使用make dist命令时,它会给你生成一个类似helloworld-1.0.tar.gz的软件发行包,其中就有对应的软件包的名字和版本号。
说明:不增加这个会导致下一步的m4文件无法生成。
改名:

[root@21b2e14c089e automake]# mv configure.scan configure.ac

4. aclocal工具生成aclocal.m4

[root@21b2e14c089e automake]# aclocal
[root@21b2e14c089e automake]# ls -l
total 52
-rw-r--r-- 1 root root 37794 Dec 22 09:56 aclocal.m4
drwxr-xr-x 2 root root  4096 Dec 22 09:56 autom4te.cache
-rw-r--r-- 1 root root     0 Dec 22 09:13 autoscan.log
-rw-r--r-- 1 root root   487 Dec 22 09:55 configure.ac
-rw-r--r-- 1 root root   100 Dec 22 09:13 hello.c

5. autoconf工具生成configure文件

[root@21b2e14c089e automake]# autoconf
[root@21b2e14c089e automake]# ls -l
total 192
-rw-r--r-- 1 root root  37794 Dec 22 09:56 aclocal.m4
drwxr-xr-x 2 root root   4096 Dec 22 09:59 autom4te.cache
-rw-r--r-- 1 root root      0 Dec 22 09:13 autoscan.log
-rwxr-xr-x 1 root root 141825 Dec 22 09:59 configure
-rw-r--r-- 1 root root    487 Dec 22 09:55 configure.ac
-rw-r--r-- 1 root root    100 Dec 22 09:13 hello.c

6. autoheader工具生成config.h.in文件

autoheader命令可以为使用configure创建C定义的模板文件。

[root@21b2e14c089e automake]# autoheader
[root@21b2e14c089e automake]# ls -l
total 196
-rw-r--r-- 1 root root  37794 Dec 22 09:56 aclocal.m4
drwxr-xr-x 2 root root   4096 Dec 22 09:59 autom4te.cache
-rw-r--r-- 1 root root      0 Dec 22 09:13 autoscan.log
-rw-r--r-- 1 root root    625 Dec 22 10:02 config.h.in
-rwxr-xr-x 1 root root 141825 Dec 22 09:59 configure
-rw-r--r-- 1 root root    487 Dec 22 09:55 configure.ac
-rw-r--r-- 1 root root    100 Dec 22 09:13 hello.c

7. 创建Makefile.am文件
Automake工具会根据config.in中的参量把Makefile.am转换成Makefile.in文件。在使用Automake之前,要先手动建立Makefile.am文件

UTOMAKE_OPTIONS=foreign
bin_PROGRAMS=testdemo
testdemo_SOURCES=hello.c
  • AUTOMAKE_OPTIONS为设置的Automake选项。它有三种等级提供给用户选择:foreign,gnu,gnits,默认等级为gnu.在此使用foreign,它只检测必须的文件。
  • bin_PROGRAMS定义要产生的执行文件名。如果要产生多个可执行文件,则每个文件名用空格隔开。
  • testdemo_SOURCES定义为程序所需要的原始文件。如果其中由多个文件组成的,则必须用空格进行隔开。

8.Automake生成Makefile.in文件

使用选项"--add-missing"可以让Automake自动添加一些必要的脚本文件。

[root@21b2e14c089e automake]# automake --add-missing
configure.ac:6: warning: AM_INIT_AUTOMAKE: two- and three-arguments forms are deprecated.  For more info, see:
configure.ac:6: http://www.gnu.org/software/automake/manual/automake.html#Modernize-AM_005fINIT_005fAUTOMAKE-invocation
configure.ac:6: installing './install-sh'
configure.ac:6: installing './missing'
Makefile.am: installing './INSTALL'
Makefile.am: error: required file './NEWS' not found
Makefile.am: error: required file './README' not found
Makefile.am: error: required file './AUTHORS' not found
Makefile.am: error: required file './ChangeLog' not found
Makefile.am: installing './COPYING' using GNU General Public License v3 file
Makefile.am:     Consider adding the COPYING file to the version control system
Makefile.am:     for your code, to avoid questions about which license your project uses
Makefile.am: installing './depcomp'
Makefile.am:3: warning: variable 'hello_SOURCES' is defined but no program or
Makefile.am:3: library has 'hello' as canonical name (possible typo)

出错提示缺少相关文件,这里直接创建空的文件即可.

[root@21b2e14c089e automake]# touch NEWS README ChangeLog AUTHORS
[root@21b2e14c089e automake]# automake --add-missing
configure.ac:6: warning: AM_INIT_AUTOMAKE: two- and three-arguments forms are deprecated.  For more info, see:
configure.ac:6: http://www.gnu.org/software/automake/manual/automake.html#Modernize-AM_005fINIT_005fAUTOMAKE-invocation
Makefile.am:3: warning: variable 'hello_SOURCES' is defined but no program or
Makefile.am:3: library has 'hello' as canonical name (possible typo)

9. config && make and run

[root@21b2e14c089e automake]# ./configure
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /usr/bin/mkdir -p
checking for gawk... gawk
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 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
[root@21b2e14c089e automake]# make
make  all-am
make[1]: Entering directory `/home/avd/automake'
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 testdemo hello.o  
make[1]: Leaving directory `/home/avd/automake'

[root@21b2e14c089e automake]# ./testdemo
Hello, world!

10. 打包
使用”make dist”命令将程序和相关的文档打包为一个压缩文档以供发布。

[root@21b2e14c089e automake]# make dist
查看生产了tar.gz文件
[root@21b2e14c089e automake]# ls -l
....
-rw-r--r-- 1 root root  88666 Dec 22 10:30 testdemo-1.0.1.tar.gz

官网地址

https://www.gnu.org/software/automake/#documentation

https://www.gnu.org/software/automake/manual/automake.html

0条评论
0 / 1000
张****龙
18文章数
0粉丝数
张****龙
18 文章 | 0 粉丝
张****龙
18文章数
0粉丝数
张****龙
18 文章 | 0 粉丝
原创

Automake 使用简介

2023-03-28 01:47:49
10
0

1.创建hello.c并插入代码

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

2. 执行autoscan命令

[root@21b2e14c089e automake]# autoscan
[root@21b2e14c089e automake]# ls -l
total 8
-rw-r--r-- 1 root root   0 Dec 22 09:13 autoscan.log
-rw-r--r-- 1 root root 467 Dec 22 09:13 configure.scan
-rw-r--r-- 1 root root 100 Dec 22 09:13 hello.c

3.修改自动生成的configure.scan并改名

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

# 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

说明:

  • AC_PREREQ 宏声明本文件要求的autoconf版本,这里是2.69
  • AC_INIT 定义软件的名称和信息。(DULL-PACKAGE-NAME为软件名,VERSION为软件的版本号,BUG-REPORT-ADDRESS为bug的报告地址,一般为软件作者的邮箱)
  • AC_CONFIG_SRCDIR 用来侦测指定的源码文件是否存在,确定源码目录的有效性。此处为当前目录下hello.c
  • AC_CONFIG_HEADER 用于生成config.h文件,以便autoheader使用
  • AC_PROG_CC 用来指定编译器,以便不指定的时候默认为gcc
  • AC_OUTPUT 用来设定config要产生的文件。如果是Makefile,config会把它检查出来的结果带入Makefile.in文件产生合适的Makefile.

修改后内容:

#                                               -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.

AC_PREREQ([2.69])
AC_INIT(testdemo, 1.0.1, xxx@163.com)
AM_INIT_AUTOMAKE(testdemo, 1.0.1)
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_OUTPUT(Makefile)

AM_INIT_AUTOMAKE(PACKAGE, VERSION) 这个宏是必须的,它描述了我们将要生成的软件包的名字及其版本号:PACKAGE是软件包的名字,VERSION是版本号。
当使用make dist命令时,它会给你生成一个类似helloworld-1.0.tar.gz的软件发行包,其中就有对应的软件包的名字和版本号。
说明:不增加这个会导致下一步的m4文件无法生成。
改名:

[root@21b2e14c089e automake]# mv configure.scan configure.ac

4. aclocal工具生成aclocal.m4

[root@21b2e14c089e automake]# aclocal
[root@21b2e14c089e automake]# ls -l
total 52
-rw-r--r-- 1 root root 37794 Dec 22 09:56 aclocal.m4
drwxr-xr-x 2 root root  4096 Dec 22 09:56 autom4te.cache
-rw-r--r-- 1 root root     0 Dec 22 09:13 autoscan.log
-rw-r--r-- 1 root root   487 Dec 22 09:55 configure.ac
-rw-r--r-- 1 root root   100 Dec 22 09:13 hello.c

5. autoconf工具生成configure文件

[root@21b2e14c089e automake]# autoconf
[root@21b2e14c089e automake]# ls -l
total 192
-rw-r--r-- 1 root root  37794 Dec 22 09:56 aclocal.m4
drwxr-xr-x 2 root root   4096 Dec 22 09:59 autom4te.cache
-rw-r--r-- 1 root root      0 Dec 22 09:13 autoscan.log
-rwxr-xr-x 1 root root 141825 Dec 22 09:59 configure
-rw-r--r-- 1 root root    487 Dec 22 09:55 configure.ac
-rw-r--r-- 1 root root    100 Dec 22 09:13 hello.c

6. autoheader工具生成config.h.in文件

autoheader命令可以为使用configure创建C定义的模板文件。

[root@21b2e14c089e automake]# autoheader
[root@21b2e14c089e automake]# ls -l
total 196
-rw-r--r-- 1 root root  37794 Dec 22 09:56 aclocal.m4
drwxr-xr-x 2 root root   4096 Dec 22 09:59 autom4te.cache
-rw-r--r-- 1 root root      0 Dec 22 09:13 autoscan.log
-rw-r--r-- 1 root root    625 Dec 22 10:02 config.h.in
-rwxr-xr-x 1 root root 141825 Dec 22 09:59 configure
-rw-r--r-- 1 root root    487 Dec 22 09:55 configure.ac
-rw-r--r-- 1 root root    100 Dec 22 09:13 hello.c

7. 创建Makefile.am文件
Automake工具会根据config.in中的参量把Makefile.am转换成Makefile.in文件。在使用Automake之前,要先手动建立Makefile.am文件

UTOMAKE_OPTIONS=foreign
bin_PROGRAMS=testdemo
testdemo_SOURCES=hello.c
  • AUTOMAKE_OPTIONS为设置的Automake选项。它有三种等级提供给用户选择:foreign,gnu,gnits,默认等级为gnu.在此使用foreign,它只检测必须的文件。
  • bin_PROGRAMS定义要产生的执行文件名。如果要产生多个可执行文件,则每个文件名用空格隔开。
  • testdemo_SOURCES定义为程序所需要的原始文件。如果其中由多个文件组成的,则必须用空格进行隔开。

8.Automake生成Makefile.in文件

使用选项"--add-missing"可以让Automake自动添加一些必要的脚本文件。

[root@21b2e14c089e automake]# automake --add-missing
configure.ac:6: warning: AM_INIT_AUTOMAKE: two- and three-arguments forms are deprecated.  For more info, see:
configure.ac:6: http://www.gnu.org/software/automake/manual/automake.html#Modernize-AM_005fINIT_005fAUTOMAKE-invocation
configure.ac:6: installing './install-sh'
configure.ac:6: installing './missing'
Makefile.am: installing './INSTALL'
Makefile.am: error: required file './NEWS' not found
Makefile.am: error: required file './README' not found
Makefile.am: error: required file './AUTHORS' not found
Makefile.am: error: required file './ChangeLog' not found
Makefile.am: installing './COPYING' using GNU General Public License v3 file
Makefile.am:     Consider adding the COPYING file to the version control system
Makefile.am:     for your code, to avoid questions about which license your project uses
Makefile.am: installing './depcomp'
Makefile.am:3: warning: variable 'hello_SOURCES' is defined but no program or
Makefile.am:3: library has 'hello' as canonical name (possible typo)

出错提示缺少相关文件,这里直接创建空的文件即可.

[root@21b2e14c089e automake]# touch NEWS README ChangeLog AUTHORS
[root@21b2e14c089e automake]# automake --add-missing
configure.ac:6: warning: AM_INIT_AUTOMAKE: two- and three-arguments forms are deprecated.  For more info, see:
configure.ac:6: http://www.gnu.org/software/automake/manual/automake.html#Modernize-AM_005fINIT_005fAUTOMAKE-invocation
Makefile.am:3: warning: variable 'hello_SOURCES' is defined but no program or
Makefile.am:3: library has 'hello' as canonical name (possible typo)

9. config && make and run

[root@21b2e14c089e automake]# ./configure
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /usr/bin/mkdir -p
checking for gawk... gawk
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 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
[root@21b2e14c089e automake]# make
make  all-am
make[1]: Entering directory `/home/avd/automake'
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 testdemo hello.o  
make[1]: Leaving directory `/home/avd/automake'

[root@21b2e14c089e automake]# ./testdemo
Hello, world!

10. 打包
使用”make dist”命令将程序和相关的文档打包为一个压缩文档以供发布。

[root@21b2e14c089e automake]# make dist
查看生产了tar.gz文件
[root@21b2e14c089e automake]# ls -l
....
-rw-r--r-- 1 root root  88666 Dec 22 10:30 testdemo-1.0.1.tar.gz

官网地址

https://www.gnu.org/software/automake/#documentation

https://www.gnu.org/software/automake/manual/automake.html

文章来自个人专栏
linux相关
18 文章 | 1 订阅
0条评论
0 / 1000
请输入你的评论
1
1