一、设置基本目录结构
(1)创建源码目录,在顶层目录及src目录下分别创建Makefile.am
(2)编辑顶层Makefile.am
kf73381@ubuntu:~/workspace/UnixProgram/fileio$cat Makefile.am
AUTOMAKE_OPTIONS=foreign
SUBDIRS=src
(3)编辑下层Makefile.am
kf73381@ubuntu:~/workspace/UnixProgram/fileio$cat Makefile.am
AUTOMAKE_OPTIONS=foreign
SUBDIRS=src
二、编写源代码
#include<stdio.h>
int main(void)
{
if (lseek(STDIN_FILENO, 0, SEEK_CUR) ==-1)
printf("cannot seek\n");
else
printf("seek OK\n");
exit(0);
}
三、使用autoscan生成配置文件
(1) 使用autoscan生成configure.scan配置文件
tkf73381@ubuntu:~/devel/hello$autoscan
(2)编辑configure.scan并冲命名为configure.ac(根据Autotool版本不同,命名可能不一样)
手动添加必须编辑某些默认参数,否则工具无法识别,另外需要手动添加AM_INIT_AUTOMAKE
tkf73381@ubuntu:~/workspace/UnixProgram/fileio$cat configure.scan
# -*- Autoconf -*-
# Process thisfile with autoconf to produce a configure script.
AC_PREREQ([2.69])
AC_INIT([FileIO],[1.0], [TKF73381@com])
AM_INIT_AUTOMAKE
AC_CONFIG_SRCDIR([src/main.cpp])
AC_CONFIG_HEADERS([config.h])
# Checks forprograms.
AC_PROG_CXX
# Checks forlibraries.
# Checks forheader files.
# Checks fortypedefs, structures, and compiler characteristics.
# Checks for libraryfunctions.
AC_CONFIG_FILES([Makefile
src/Makefile])
AC_OUTPUT
四、依次执行如下命令序列编译工程
aclocal
autoheader
autoconf
automake--add-missing
./configure
make (这一步已经生成二进制文件)
makeinstall