使用Linux的Autotools来生成Makefile

使用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

#-----------------------------------------------------


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值