管道在makefile中不起作用

时间:2013-01-22 03:02:07

标签: bash makefile grep

我已经拉出了重要的线条:

SHELL := /bin/bash

leaks: build_eagle_test
    grep EagleMemory_Allocate -r eagle | perl -nle 'm/"(.*)"/; print $1' | sort | uniq > leaks.alloc.tmp
    grep "EagleMemory_Mock(" -r eagle_test | perl -nle 'm/"(.*)"/; print $1' | sort | uniq > leaks.alloc_test.tmp

当我在bash中运行行没问题。但是从make文件中它只将grep传递到out文件中(实际上忽略了两者之间的阶段......)

1 个答案:

答案 0 :(得分:8)

$需要引用为$$,例如,

SHELL := /bin/bash

leaks:
    grep EagleMemory_Allocate -r eagle | perl -nle 'm/"(.*)"/; print $$1' | sort | uniq > leaks.alloc.tmp
    grep "EagleMemory_Mock(" -r eagle_test | perl -nle 'm/"(.*)"/; print $$1' | sort | uniq > leaks.alloc_test.tmp

问题是Make对bash语法一无所知,忽略了命令行上的所有'"引用。它将$1解释为Make上下文中变量1的值 - 但是没有这样的变量,因此它变为空白。

当它从原始Makefile回显它运行的命令时,你可以在Make的输出中看到这个:

$ make
grep EagleMemory_Allocate -r eagle | perl -nle 'm/"(.*)"/; print ' | sort | uniq > leaks.alloc.tmp
grep "EagleMemory_Mock(" -r eagle_test | perl -nle 'm/"(.*)"/; print ' | sort | uniq > leaks.alloc_test.tmp

请注意$1已消失。