.ONESHELL vs" normal"在Makefile

时间:2015-08-24 03:33:49

标签: makefile gnu-make

为了证明制作 -line配方的方式与.ONESHELL - 多个 -line配方相比,我将使用{{ 1}}命令,我们假设,其中任何一个:

  1. sed
  2. sed -e 'p; p'
    sed -e 'p
  3. 大多是等同的。对?

    然而,我们发现,Make只能在单个 -line配方上失败。

    呀!那是对的。使句柄完美地处理多个 -line版本(当然,由于p'),但不能单个 -line recipe。

    它违背了常识,但这是证据。



    Makefile

    .ONESHELL



    执行,我们得到:

    .ONESHELL :
    
    # Define a MULTIPLE-line recipe.
    define define_cmd_foo
    all : cmd_foo = echo xxx | sed -ne '
    s/xxx/yyy/
    p'
    endef
    
    # Define a SINGLE-line recipe.
    define define_cmd_bar
    all : cmd_bar = echo xxx | sed -ne 's/xxx/yyy/; p'
    endef
    
    
    
    # cmd_foo is multiple-line (3 line) recipe:
    #                                         echo xxx | sed -ne '
    #                                         s/xxx/yyy/
    #                                         p'
    $(define_cmd_foo)
    
    # cmd_foo is a one and single-line recipe:
    #                                        echo xxx | sed -ne 's/xxx/yyy/; p'
    $(define_cmd_bar)
    
    
    # This is a 1st file in a double-colon (linked list of) target 'all'.
    # This will exeucte a multipe-line recipe.
    all ::
        $(cmd_foo)
    
    # This is a 2nd file in a double-colon (linked list of) target 'all'.
    # This will exeucte a single-line recipe.
    all ::
        $(cmd_bar)
    



    你能看到2个命令吗?

    第一个命令执行多个 -line配方,成功

    事实上,第一个食谱的输出:echo xxx | sed -ne ' s/xxx/yyy/ p' yyy echo xxx | sed -ne 's/xxx/yyy/ /bin/sh: 1: Syntax error: Unterminated quoted string makefile:34: recipe for target 'all' failed make: *** [all] Error 2 正是我们所期望的。

    上面输出的 5th 以及以下行的任何输出都属于其他的执行-line食谱,看起来像是出了问题。非常错!

    任何原因,为什么一个完美的好食谱适用于{em>多个 -line版本的yyy,但是在一个普通的单行版本中失败了?

0 个答案:

没有答案