Makefile自动编写工具实例
准备源文件如下:
/*test.c*/
#include <stdio.h>
#include "phello.h"
#include "pword.h"
int
main ()
{
phello ();
pword ();
return 0;
}
/*phello.c*/
#include<stdio.h>
#include "phello.h"
int
phello ()
{
printf ("hello\n");
}
/*pword.c*/
#include <stdio.h>
#include "pword.h"
int
pword ()
{
printf ("word\n");
}
/*phello.h*/
#ifndef __PHELLO_H__
#define __PHELLO_H__
int phello ();
#endif
/*pword.h*/
#ifndef __PWORD_H__
#define __PWORD_H__
int pword ();
#endif
使用autotools(autoscan、aclocal、autoconf、autoheader、automake)自动编写Makefile步骤如下:
(1)[...@...]#autoscan
(2)[...@...]#mv configure.scan configure.in
[...@...]#vim configure.in (修改如下:红色字体为修改过的地方)
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_PREREQ(2.59)
#AC_INIT(FULL-PACKAGE-NAME, VERSION, BUG-REPORT-ADDRESS)
AC_INIT(test,1.0)
AM_INIT_AUTOMAKE(test,1.0)
AC_CONFIG_SRCDIR([phello.c])
AC_CONFIG_HEADER([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_OUTPUT([Makefile])
(3)[...@...]#aclocal
(4)[...@...]#autoconf
(5)[...@...]#autoheader
(6)自己创建Makefile.am文件,内容如下:
AUTOMAKE_OPTIONS=foreign
bin_PROGRAMS=test
test_SOURCES=test.c phello.c pword.c
[...@...]#automake --add-missing
(7)[...@...]#./configure 至此,Makefile已自动生成
(8)[...@...]#make