目的 从复杂的工作中简化出来。
网上有一些制作Makfile的文章,只停留在Makefile而已。用autotools的工具相对来说要简单的多,其它一些介绍autotools文章又有很多漏洞,而且步骤烦琐。
制作一个最简单的helloworld程序:
现有目录test
mkdir src 建立src目录存放 源代码
在src下。
编辑hello.c文件
#include <stdio.h>
int main()
{
printf("hello world/n");
return 0;
}
在src目录下建立Makefile.am文件 (src/Makefile.am)
AUTOMAKE_OPTIONS=foreign
bin_PROGRAMS = hello
hello_SOURCES = hello.c
hello_LDADD = -lpthread (只是测试,实际不需要连接该库)
保存退出
退到test目录
编辑Makefile.am文件 (Makefile.am)
SUBDIRS = src
退出保存
然后
执行
autoscan
生成configure.scan文件
按此编辑此文件
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_PREREQ(2.59)
AC_INIT(hello,1.0, [miaoquan@nou.com.cn])
AM_INIT_AUTOMAKE
AC_CONFIG_SRCDIR([src/hello.c])
AC_CONFIG_HEADER([config.h])
# Checks for programs.
AC_PROG_CC
# Checks for libraries.
# FIXME: Replace `main' with a function in `-lpthread':
AC_CHECK_LIB([pthread], [main])
# Checks for header files.
# Checks for typedefs, structures, and compiler characteristics.
# Checks for library functions.
#AC_CONFIG_FILES([Makefile
# src/Makefile])
AC_OUTPUT(Makefile src/Makefile)
退出保存
将此文件更名 mv configure.scan configure.in
然后执行
touch NEWS README AUTHORS ChangeLog
然后执行
autoreconf -fvi
至此生成configure文件
执行configure文件
生成Makefile文件
make
make install
make uninstall
make dist
试验一下吧。
网上有一些制作Makfile的文章,只停留在Makefile而已。用autotools的工具相对来说要简单的多,其它一些介绍autotools文章又有很多漏洞,而且步骤烦琐。
制作一个最简单的helloworld程序:
现有目录test
mkdir src 建立src目录存放 源代码
在src下。
编辑hello.c文件
CODE
#include <stdio.h>
int main()
{
printf("hello world/n");
return 0;
}
在src目录下建立Makefile.am文件 (src/Makefile.am)
CODE
AUTOMAKE_OPTIONS=foreign
bin_PROGRAMS = hello
hello_SOURCES = hello.c
hello_LDADD = -lpthread (只是测试,实际不需要连接该库)
保存退出
退到test目录
编辑Makefile.am文件 (Makefile.am)
SUBDIRS = src
退出保存
然后
执行
autoscan
生成configure.scan文件
按此编辑此文件
CODE
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_PREREQ(2.59)
AC_INIT(hello,1.0, [miaoquan@nou.com.cn])
AM_INIT_AUTOMAKE
AC_CONFIG_SRCDIR([src/hello.c])
AC_CONFIG_HEADER([config.h])
# Checks for programs.
AC_PROG_CC
# Checks for libraries.
# FIXME: Replace `main' with a function in `-lpthread':
AC_CHECK_LIB([pthread], [main])
# Checks for header files.
# Checks for typedefs, structures, and compiler characteristics.
# Checks for library functions.
#AC_CONFIG_FILES([Makefile
# src/Makefile])
AC_OUTPUT(Makefile src/Makefile)
退出保存
将此文件更名 mv configure.scan configure.in
然后执行
touch NEWS README AUTHORS ChangeLog
然后执行
autoreconf -fvi
至此生成configure文件
执行configure文件
生成Makefile文件
make
make install
make uninstall
make dist
试验一下吧。
--------------------------------------------------------------------------------------------