configure.ac和Makefile.am结合 实现条件编译

configure.ac和Makefile.am结合 实现条件编译


)

1、configure.ac代码

#在configure.in中自定义一个./configure命令选项
#AC_ARG_ENABLE (feature, help-string, [action-if-given], [action-if-not-given]) 如果给定的选项,就执行action-if-given,否则执行action-if-not-given 最后两个参数可以缺省
#使用AC_ARG_ENABLE宏可以为configure增加–enable-feature 或者 –disable-feature这样的选项。

举例:
AC_ARG_ENABLE( compile_asan,
[–enable-compile-asan compile with asan.],
[ case “${enableval}” in
yes) compile_asan=true ;;
no) compile_asan=false ;;
*) AC_MSG_ERROR(bad value ${enableval} for -enable-compile-asan) ;;
esac],
[compile_asan=“false”]
)

#如果compile_asan的值为true,那么将会定义DPI_ENABLE_ASAN这个宏
AM_CONDITIONAL(DPI_ENABLE_ASAN, test “x$compile_asan” = “xyes”

2、Makefile.am代码

if DPI_ENABLE_ASAN
CFLAGS += -fsanitize=address -DTHREAD_TEST
LIBS += -lpthread
endif

3、cpp代码

#ifdef THREAD_TEST
。。。
pthread_t thread_id;
pthread_create(&thread_id, NULL, threadTest, NULL);
pthread_join(thread_id, NULL);
。。。
#endif

4、总结

我们在上面通过AC_ARG_ENABLE增加了–enable-compile-asan这个编译选项,在执行configure时,将是这样的一种方式执行./configure --enable-compile-asan=yes或者–enable-compile-asan=no

1、当–enable-compile-asan=yes,将是compile_asan=true,接着AM_CONDITIONAL将会因为compile_asan=true而#define DPI_ENABLE_ASAN;
2、当–enable-compile-asan=no,将是compile_asan=false,接着AM_CONDITIONAL没有进行任何操作;
3、当我们在./configure时忽略–enable-compile-asan选项,AC_ARG_ENABLE定义的第四个参数为默认值,即[compile_asan=false]

  • 9
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值