使用Linux的Autotools来生成Makefile
#-----------------------------------------------------
$ mkdir Autotools_DemoHello
$ cd Autotools_DemoHello
#-----------------------------------------------------
# 我们的 源文件是myprintMain.c 包名是hello 版本号是1.0
echo >> myprintMain.c << EOF
#include <stdio.h>
void myprint(const char *str)
{
printf("%s\n", str);
}
int main(void)
{
myprint("Hello Autotools!");
return 0;
}
EOF
#-----------------------------------------------------
# 扫描 当前目录下 或 指定目录下 的源文件
# 生成configure.scan autoscan.log
$ autoscan
$ cp configure.scan configure.ac
#-----------------------------------------------------
$ vim configure.ac
# 修改后的效果见 - 本文件夹下的configure.ac文件
# 删除 AC_INIT([FULL-PACKAGE-NAME], [VERSION], [BUG-REPORT-ADDRESS])
# 添加 AC_INIT([hello], [1.0], [123@qq.com])
# 这是指定包名 版本号 联系方式
# 添加 AM_INIT_AUTOMAKE(hello,1.0) 指定包名 和 版本号
# 添加 AC_CONFIG_FILES([Makefile]) 指定Makefile的文件名
#-----------------------------------------------------
# 根据 configure.ac 文件的内容, 生成 aclocal.m4
$ aclocal
#-----------------------------------------------------
# 生成config.h.in
$ autoheader
#-----------------------------------------------------
# 在每个源码目录编辑 Makefile.am
echo >> Makefile.am << EOF
AUTOMAKE_OPTIONS = foreign
#INCLUDES = `pkg-config --cflags dbus-1`
#LIBS = `pkg-config --libs dbus-1`
bin_PROGRAMS = hello
hello_SOURCES = myprintMain.c
EOF
#-----------------------------------------------------
#根据 Makefile.am 生成 Makefile.in
$ automake --add-missing --copy --foreign
#-----------------------------------------------------
# 生成 configure 文件
autoconf
#-----------------------------------------------------
#通过 configure 生成 Makefile
./configure --prefix=/tmp/zzz
make
make install
# 删除编译生成的二进制文件 和 .o 文件
make clean
# 生成 tar.gz 包
make dist
#删除 configure 之后生成的所有中间文件
make distclean
#-----------------------------------------------------