linux 系统自动生成 Makefile

1. 安装相关工具 : sudo apt-get install autoconf

2.自动生成Makefile

(1)运行 autoscan命令
(2)重命名configure.scan为configure.ac,并且修改其相关内容
(3)运行 aclocal命令
(4)运行 autoheader命令
(5)运行autoconf命令
(6)在项目目录下创建Makefile.am文件,并且修改
(7)运行automake  --add-missing命令
(8)运行configure生成Makefile。

3.具体过程

原测试文件main.c

#include <stdio.h>

int main(int argc, char* argv[])
{   
    printf("\nRun successfully\n");
    return 0;
} 

(1)运行 autoscan

autoscan.log  configure.scan  main.c
(2)运行  mv configure.scan configure.ac
修改如下:

#                                               -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_PREREQ([2.69])
AC_INIT([test], [1.0], [test@163.com])
AC_CONFIG_SRCDIR([main.c])
AC_CONFIG_HEADERS([config.h])
AM_INIT_AUTOMAKE(test,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

(3)运行 aclocal

aclocal.m4  autom4te.cache  autoscan.log  configure.ac  main.c

(4)运行 autoheader

aclocal.m4  autom4te.cache  autoscan.log  config.h.in  configure.ac  main.c

(5)运行 autoconf

aclocal.m4  autom4te.cache  autoscan.log  config.h.in  configure  configure.ac  main.c

(6)创建 Makefile.am文件

AUTOMARK_OPTIONS=foreign
noinst_PROGRAMS=test
HelloWorld_SOURCES=main.c

(7)运行 touch NEWS README AUTHORS ChangeLog 和 automake --add-missing

aclocal.m4  autom4te.cache  ChangeLog  config.h.in  configure.ac  depcomp  install-sh  Makefile.am  missing  README
AUTHORS     autoscan.log    compile    configure    COPYING       INSTALL  main.c      Makefile.in  NEWS

(8)运行 ./configure 

aclocal.m4  autom4te.cache  ChangeLog  config.h     config.log     configure     COPYING  INSTALL     main.c    Makefile.am  missing  README
AUTHORS     autoscan.log    compile    config.h.in  config.status  configure.ac  depcomp  install-sh  Makefile  Makefile.in  NEWS     stamp-h

(9)运行 make

aclocal.m4      autoscan.log  config.h     config.status  COPYING  install-sh  Makefile     missing  stamp-h1
AUTHORS         ChangeLog     config.h.in  configure      depcomp  main.c      Makefile.am  NEWS     test
autom4te.cache  compile       config.log   configure.ac   INSTALL  main.o      Makefile.in  README

(10)运行 test

~/tmp/c/test$ ./test 

Run successfully

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值