+ -
当前位置:首页 → 问答吧 → 我的 Makefile 这样写不对么?

我的 Makefile 这样写不对么?

时间:2010-06-26

来源:互联网

target1 target2 target3:
    @make $@_compile
ifneq ($@,target1)
    @echo "#### target_name = target1"
else
    @echo "#### target_name = target_others"
endif


target1_compile:
    @echo "#### compile for target1"

target2_compile:
    @echo "#### compile for target2"

target3_compile:
    @echo "#### compile for target3"


---------------------------------------------
注释:
    我这段 Makefile 的作用很简单,目的就是:
    (1) 当输入 make target1 时,希望输出结果如下
               #### target_name = target1
               #### compile for target1
    (2) 当输出 make target2 时,希望输出结果如下
               #### target_name = target2
               #### compile for target2

    但是结果并不是,输入 make target1 结果如预期,但是 (2) 的输出结果如下:
               #### target_name = target1
               #### compile for target2

    看样子,好像是 ifneq 写的有问题?大家帮忙看下这句有啥问题啊?

作者: anank   发布时间: 2010-06-26

ifneq ($@,target1)
    @echo "#### target_name = target1"
else
    @echo "#### target_name = target_others"
endif

ifneq表示()表示参数是否不相等,不相等才进入TURE的部分。
貌似#@也有问题,它不是指全部的目标文件集吗?好好理解下逻辑

作者: cnfcpidtf111   发布时间: 2010-06-26

不知道楼主在研究什么高深秘籍

一片混乱

作者: ah13k   发布时间: 2010-06-26

make evaluates conditionals when it reads a makefile. Consequently, you cannot use automatic variables in the tests of conditionals because they are not defined until commands are run (see Automatic Variables).

作者: EricFisher   发布时间: 2010-06-26

换句话说,你可以测试一下条件判断中的$@是未定义,或者为空。

ifndef $@

ifeq ($@, )

作者: EricFisher   发布时间: 2010-06-26

回复 EricFisher

明白了。

谢谢大家的回复。

我的表达方面也有些问题,哈哈,以后改正。

作者: anank   发布时间: 2010-06-27