Linux Makefile自动生成--实例

Linux Makefile自动生成--总体流程
Linux Makefile自动生成--实例
Linux Makefile自动生成--config.h


1. 创建程序

#include <stdio.h>

int main(int argc, char* argv[])
{
    printf("Hello, world!\n");

    return 0;
}
状态如下:

root@nova-controller:/home/spch2008/AutoMake# ls
hello.c

2. Makefile.am

AUTOMAKE_OPTIONS = foreign 

bin_PROGRAMS = hello
状态如下:

root@nova-controller:/home/spch2008/AutoMake# ls
hello.c  Makefile.am

3. autoscan

root@nova-controller:/home/spch2008/AutoMake# autoscan
root@nova-controller:/home/spch2008/AutoMake# ls
autoscan.log  configure.scan  hello.c  Makefile.am
更改configure.scan为configure.ac,查看文件。

# 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
添加宏AM_INIT_AUTOMAKE,用于初始化automake。

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

AC_PREREQ([2.68])
AC_INIT([hello], [1.0], [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
此时状态如下:

root@nova-controller:/home/spch2008/AutoMake# ls
autoscan.log  configure.ac  hello.c  Makefile.am
4.aclocal

root@nova-controller:/home/spch2008/AutoMake# aclocal
root@nova-controller:/home/spch2008/AutoMake# ls
aclocal.m4  autom4te.cache  autoscan.log  configure.ac  hello.c  Makefile.am
5.autoconf

root@nova-controller:/home/spch2008/AutoMake# autoconf
root@nova-controller:/home/spch2008/AutoMake# ls
aclocal.m4  autom4te.cache  autoscan.log  configure  configure.ac  hello.c  Makefile.am
6.autoheader

root@nova-controller:/home/spch2008/AutoMake# autoheader
root@nova-controller:/home/spch2008/AutoMake# ls
aclocal.m4      autoscan.log  configure     hello.c
autom4te.cache  config.h.in   configure.ac  Makefile.am
7.automake

root@nova-controller:/home/spch2008/AutoMake# automake --add-missing
configure.ac:8: installing `./install-sh'
configure.ac:8: installing `./missing'
Makefile.am: installing `./depcomp'
root@nova-controller:/home/spch2008/AutoMake# ls
aclocal.m4      autoscan.log  configure     depcomp  install-sh   Makefile.in
autom4te.cache  config.h.in   configure.ac  hello.c  Makefile.am  missing
8. ./configure

root@nova-controller:/home/spch2008/AutoMake# ls
aclocal.m4      config.h     config.status  depcomp     Makefile     missing
autom4te.cache  config.h.in  configure      hello.c     Makefile.am  stamp-h1
autoscan.log    config.log   configure.ac   install-sh  Makefile.in
9. make

root@nova-controller:/home/spch2008/AutoMake# ls
aclocal.m4      config.h     config.status  depcomp  hello.o     Makefile.am  stamp-h1
autom4te.cache  config.h.in  configure      hello    install-sh  Makefile.in
autoscan.log    config.log   configure.ac   hello.c  Makefile    missing
10.运行

root@nova-controller:/home/spch2008/AutoMake# ./hello 
Hello, world!


有关Makefile.am的写法,参见:http://airs.com/ian/configure/configure_2.html#SEC8

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值