自动化生成Makefile的方法

首先,sudo apt-get install autoconf
用autoscan描源代码目录生成configure.scan文件
修改configure.scan
将configure.scan改名为configure.in
用aclocal根据configure.in文件的内容,自动生成aclocal.m4文件
使用autoconf,根据configure.in和aclocal.m4来产生configure文件
手工写Makefile.am
使用automake -a,根据configure.in和Makefile.am来产生Makefile.in
./configure
make

例如,hello.c文件:
#include<stdio.h>
int main(int argc, char **argv)
{
printf("Hello, World!/n");
return 0;
}
修改后的configure.scan文件:
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_PREREQ([2.63])
AC_INIT(Hello, 1.0.0, [email protected])
AM_INIT_AUTOMAKE(Hello, 1.0)
#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_OUTPUT(Makefile)
编辑的Makefile.am文件:
AUTOMAKE_OPTIONS=foreign
bin_PROGRAMS=Hello
Hello_SOURCES=hello.c

你可能感兴趣的:(makefile)