检查变量是否在makefile中定义 [英] Checking if variables are defined in a makefile

查看:54
本文介绍了检查变量是否在makefile中定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个GNU Makefile(版本3.81),如下所示:

  .PHONY:SPOneDotSPOneDot:ifndef XX = 0.05$$(信息X未定义,更改为$ X)万一ifndef YY = 0.05$$(信息Y未定义,更改为$ Y)万一python ./Submit3DSP.py -f OneDot.qdt -x $(X)-y $(Y) 

我使用以下命令行执行: make X = 0.1 Y = 0.1 SPOneDot ,但得到以下结果:

  ifndef Xmake:ifndef:找不到命令make:*** [SPOneDot]错误127 

我查看了 makefile文档,并看到了其他人使用它.感谢任何帮助,这可能是愚蠢的.

解决方案

很有可能您的make指令不得制表符缩进,而应从第一列开始.我也怀疑您想要 .if(...)或类似的,而不是简单的 ifdef .在不知道您使用哪种 make 实现的情况下很难说出来.

在GNU make中,使用条件零件,例如像这样

  ifeq($(CC),gcc)$(CC)-o foo $(对象)$(libs_for_gcc)别的$(CC)-o foo $(对象)$(normal_libs)万一 

GNU make手册包含所有详细信息.

如果您真的想测试一个环境变量(而不是一个 make变量),那么只需在命令中进行测试即可:

  SPOneDot:如果测试-z"$$ X";那么X = 0.05;回显"X undefined,更改为$$ X";fi;\如果测试-z"$$ Y";那么Y = 0.05;回显"Y未定义,更改为$$ Y";fi;\python ./Submit3DSP.py -f OneDot.qdt -x $$ X -y $$ Y 

请注意,将 $$ 作为单个 $ 传递到外壳,并且一切都必须是外壳的单个命令,因此要使用分号和反斜杠/换行符./p>

I have a GNU Makefile (version 3.81) that looks like the following:

.PHONY: SPOneDot

SPOneDot:
    ifndef X
    X=0.05
    $$(info X undefined, changed to $X)
    endif
    ifndef Y
    Y=0.05
    $$(info Y undefined, changed to $Y)
    endif
    python ./Submit3DSP.py -f OneDot.qdt -x $(X) -y $(Y)

I execute with the following command line: make X=0.1 Y=0.1 SPOneDot but I get the following result:

ifndef X
make: ifndef: Command not found
make: *** [SPOneDot] Error 127

I've looked in the makefile documentation and seen others use it. Any help is appreciated, it's likely something foolish.

解决方案

Most likely your make directives must not be tab indented but start in the first column. I also suspect you want .if(...) or similar, not plain ifdef. It's hard to tell without knowing what make implementation you use.

In GNU make, conditional parts are used e.g. like this

ifeq ($(CC),gcc)
        $(CC) -o foo $(objects) $(libs_for_gcc)
else
        $(CC) -o foo $(objects) $(normal_libs)
endif

The GNU make manual has all the details.

If you really mean to test an environment variable (as opposed to a make variable), then simply do so in the commands:

SPOneDot:
    if test -z "$$X"; then X=0.05; echo "X undefined, changed to $$X"; fi; \
    if test -z "$$Y"; then Y=0.05; echo "Y undefined, changed to $$Y"; fi; \
    python ./Submit3DSP.py -f OneDot.qdt -x $$X -y $$Y

Note that $$ is passed to the shell as a single $ and everything must be a single command for the shell, hence the semicolons and backslash/newlines.

这篇关于检查变量是否在makefile中定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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