GNU Autotools (autoconf, automake, libtool, etc.) 自动化编译 (2) 多目录和动态链接库

这篇博客介绍了如何使用GNU Autotools(autoconf, automake, libtool等)进行多目录项目的自动化编译,包括configure.ac和Makefile.am的配置解析,以及autoconf生成的Makefile中常用的目标。读者需先了解基础,并通过提供的脚本atdir.sh进行实践。" 111974110,10324841,Python自定义函数与参数详解,"['Python', '函数', '编程基础']
摘要由CSDN通过智能技术生成

0. 基础

    先阅读GNU Autotools (autoconf, automake, libtool, etc.) 自动化编译 (1) 简单示例并成功执行、理解所说内容。

1. 先提供一个脚本。拷贝所有内容保存为文件atdir.sh并添加可执行权限,然后执行。注意,最好不要以根用户身份执行它。

#!/bin/sh

echo "Autotools for autotools multi directories (stands for atdirs)"

echo_exit()
{
	echo "ERROR: $@"
	exit 1
}

# 1. prepare directories and dummy files
[ ! -e "atdirs" ] || echo_exit "atdirs exists, please remove or rename it"
mkdir atdirs && cd atdirs || echo_exit "mkdir -p atdirs or cd atdirs failed"

mkdir -p doc build-aux m4 man src/{include/atdirs,lib{1,2},tests} || \
	echo_exit "create subdirectory failed"
touch AUTHORS BUGS ChangeLog COPYING NEWS README || \
	echo_exit "touch dummy files failed"

# 2. generates source, header files
cat > src/include/atdirs/lib1.h <<EOF
#ifndef __ATDIRS_LIB1_H_
#define __ATDIRS_LIB1_H_

void lib1_print();

#endif
EOF
cat > src/include/atdirs/lib2.h <<EOF
#ifndef __ATDIRS_LIB2_H_
#define __ATDIRS_LIB2_H_

void lib2_print();

#endif
EOF

cat > src/lib1/print.c <<EOF
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <stdio.h>
#include <atdirs/lib1.h>

void lib1_print()
{
	printf("lib1-print: " PACKAGE_STRING " <lib-1>\n");
}
EOF

cat > src/lib2/print.c <<EOF
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#includ
  • 3
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值