一. 安裝工具 automake, autoconf, 編寫來源程式:mycc.c
#include <stdio.h>#include "config.h"int main(int argc, char** argv){ if(argv == 1) { printf("version: %s\n", PACKAGE_STRING); } else { printf("name : %s\n", PACKAGE); printf("version : %s\n", VERSION); printf("bugreport: %s\n", PACKAGE_BUGREPORT); } return 0;}
需要說明的是mycc.c中用到的宏來自config.h, 而config.h又是工具產生的(見後文)
二. 運行autoscan , 產生 configure.scan
[root@waf mypkg]# autoscan[root@waf mypkg]# lsautoscan.log configure.scan mycc.c[root@waf mypkg]#
重新命名configure.scan 為 configure.in ,並編輯configure.in
# -*- Autoconf -*-# Process this file with autoconf to produce a configure script.AC_PREREQ([2.63])AC_INIT([mycc], [1.0.0], [www.mycc.org])AC_CONFIG_SRCDIR([mycc.c])AC_CONFIG_HEADERS([config.h])AM_INIT_AUTOMAKE([mycc], [1.0.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_OUTPUT(Makefile)
三. 運行aclocal , autoconf
[root@waf mypkg]# aclocal[root@waf mypkg]# lsaclocal.m4 autom4te.cache autoscan.log configure.in mycc.c[root@waf mypkg]# autoconf[root@waf mypkg]# lsaclocal.m4 autom4te.cache autoscan.log configure configure.in mycc.c
四. 建立 Makefile.am, 內容:
AUTOMAKE_OPTIONS=foreignbin_PROGRAMS=myccmycc_SOURCES=mycc.c
五. 運行 autoheader, 產生config.h.in (automake要用到)
[root@waf mypkg]# lsaclocal.m4 autom4te.cache autoscan.log configure configure.in mycc.c[root@waf mypkg]# vim Makefile.am[root@waf mypkg]# autoheader[root@waf mypkg]# lsaclocal.m4 autoscan.log configure Makefile.amautom4te.cache config.h.in configure.in mycc.c
六. 運行automake ,產生configure
[root@waf mypkg]# automake --add-missingconfigure.in:8: installing `./install-sh'configure.in:8: installing `./missing'Makefile.am: installing `./depcomp'[root@waf mypkg]#
七. 試試configure
./configuremakemake install
參考:
http://www.ibm.com/developerworks/cn/linux/l-makefile/