Linux Makefile自动生成--实例

来源:互联网 发布:动不动就说直男癌 知乎 编辑:程序博客网 时间:2024/05/26 20:19

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# lshello.c

2. Makefile.am

AUTOMAKE_OPTIONS = foreign bin_PROGRAMS = hello
状态如下:

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

3. autoscan

root@nova-controller:/home/spch2008/AutoMake# autoscanroot@nova-controller:/home/spch2008/AutoMake# lsautoscan.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# lsautoscan.log  configure.ac  hello.c  Makefile.am
4.aclocal

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

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

root@nova-controller:/home/spch2008/AutoMake# autoheaderroot@nova-controller:/home/spch2008/AutoMake# lsaclocal.m4      autoscan.log  configure     hello.cautom4te.cache  config.h.in   configure.ac  Makefile.am
7.automake

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

root@nova-controller:/home/spch2008/AutoMake# lsaclocal.m4      config.h     config.status  depcomp     Makefile     missingautom4te.cache  config.h.in  configure      hello.c     Makefile.am  stamp-h1autoscan.log    config.log   configure.ac   install-sh  Makefile.in
9. make

root@nova-controller:/home/spch2008/AutoMake# lsaclocal.m4      config.h     config.status  depcomp  hello.o     Makefile.am  stamp-h1autom4te.cache  config.h.in  configure      hello    install-sh  Makefile.inautoscan.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

原创粉丝点击