有条件的Makefile包括 [英] Makefile conditional include

查看:198
本文介绍了有条件的Makefile包括的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想写需要ALSA或者OSS或头的应用程序。基本上,我想传递一个明确的编译器,如果/etc/oss.conf不存在,因为这可能意味着soundcard.h标头不存在(随时纠正我的那一个,我还是新与OSS工作)。每OSS文件,可以使用include指令,像这样:

I'm trying to write an application that needs either ALSA or OSS headers. Basically, I want to pass a define to the compiler if /etc/oss.conf does not exist, since that probably means the soundcard.h header doesn't exist (feel free to correct me on that one, I'm still new to working with OSS). Per the OSS documentation, you would use the include directive like so:

include /etc/oss.conf
CFLAGS := -I$(OSSLIBDIR)/include/sys

一个问题。 OSS支持是可选的,所以我要检查,如果头存在,如果存在,传递一个明确的编译器。问题是,据我所知是没有办法来检查文件是否存在makefile文件的规则的外面。规则里面,如果我用一个if语句,因为某些原因,试图设置CFLAGS并不会改变它:

One problem. OSS support is optional, so I'd want to check if the header exists, and if does, pass a define to the compiler. The problem is, AFAIK there is no way to check if a file exists outside of a makefile rule. Inside the rule, if I use an if statement, for some reason, trying to set CFLAGS doesn't alter it:

test: $(objects)
    @if [ -f ${OSS_CONFIG} ]; then \
    . ${OSS_CONFIG}; \
    CFLAGS+=" -I${OSSLIBDIR} -DUSE_OSS"; \
    fi
    @echo ${CFLAGS}

(以上只是CFLAGS输出的原始值,即使 $ {OSS_CONFIG} 的存在。)这是当然的,极其难看,我想知道如果有一个更清洁的方式来做到这一点。或者是我要对此要引起涉及小猫的种族灭绝的全球灾难性事件的方式吗?

(The above just outputs the original value of CFLAGS, even if ${OSS_CONFIG} exists.) This is, of course, extremely ugly, and I'm wondering if there's a cleaner way to do it. Or is the way I'm going about this going to trigger a worldwide cataclysmic event involving the genocide of kittens?

哦,请不要告诉我使用autoconf。

Oh, and please don't tell me to use autoconf.

推荐答案

一个建议:用 -include (那么就不会发出警告+不干故障)。我不知道如果我完全得到这个语法的工作我自己,虽然。

One suggest: use -include (then it won't warn + quit on failure). I don't know if I ever quite got this syntax to work myself, though.

另一个黑客可能是沿着线的东西: DUMMY_VAR:= $(壳...)来执行任意code。我觉得这是更不可能的工作。

Another hack could be something along the lines of: DUMMY_VAR := $(shell ... ) to execute arbitrary code. I think this is even less likely to work.

除此之外,我不认为这是可能的。当我看到类似的问题最近,我发现我不能做出在makefile文件创建过程中执行任意的shell命令。

Other than that, I don' think this is possible. When I looked into a similar problem recently, I found that I can't get make to run arbitrary shell commands during the makefile creation process.

这篇关于有条件的Makefile包括的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆