autoconfig,automake 編譯project

autoconfig,automake編譯project

編輯文件:

helloworld.c

configure.ac

Makefile.am

創建過程:

autoscan; aclocal; autocconf; automake --add-missing; ./configure ; make

下面給出helloworld 的例子

  1. $cat helloworld.c
#include <stdio.h>
int main()
{
    printf("hello world\n");
    return 0;
}
  1. configure.ac 的編寫

autoscan ;

cp configure.scan configure.ac ;

vim configure.ac

configure.ac 主要是定義一些宏
其中AC_INIT_AUTOMAKE是需要手動添加的

$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([main.c])
AM_INIT_AUTOMAKE
#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, AC_CONFIG_FILES([Makefile])是手工添加的, 意思是configure 配置中要生成Makefile

  1. aclocal

aclocal; 是一個perl腳本, 以configure.ac 爲輸入,生成aclocal.m4 及autom4te.cache 目錄

  1. autoconf

autoconf 是一個shell腳本, 它以configure.ac爲輸入, 輸出configre 腳本文件.

  1. 編輯Makefile.am

cat Makefile.am

AUTOMAKE_OPTIONS=foreign
bin_PROGRAMS=hello
hello_SOURCES=main.c
  1. 運行automake --addmissing

可以簡單的寫爲: automake -a
添加一些必要的軟鏈接,同時生成makefile.in

  1. 運行./configure 生成Makefile

  2. 執行make 生成執行文件

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章