【问题标题】:Makefile: test makefile for comparisonMakefile:测试makefile以进行比较
【发布时间】:2012-12-07 16:40:46
【问题描述】:

我需要制作一个生成文件,将我的书面命令 grep 输出与 .out 文件进行比较。 grep 搜索的输入文本文件在tests/*.test 中。

Beta 的回答非常有帮助,但我不明白为什么这个 makefile

INPUT_DIR=tests

OUTPUT_DIR=outputs

FILES=$(wildcard ${INPUT_DIR}/*.test)

TEST_LIST = ${FILES:${INPUT_DIR}/%.test=%.diff}

.PHONY: all clean distclean

all: ${TEST_LIST}
    echo ${FILES}
    echo ${TEST_LIST}
${TEST_LIST}: ${INPUT_DIR}/%.test ${OUTPUT_DIR}/%.out
    ./grep apple $< >STDOUT
    diff STDOUT ${OUTPUT_DIR}/$*.out > $@
${INPUT_DIR}/%.test:
    echo $@
${OUTPUT_DIR}/%.out:
    echo $@
clean:
    rm -f ${FILES}

使用make makefile all -n

make: Nothing to be done for `makefile'. 
echo tests/%.test 
echo outputs/%.out 
./grep apple tests/%.test >STDOUT diff STDOUT outputs/.out > 1.diff 
./grep apple tests/%.test >STDOUT diff STDOUT outputs/.out > 2.diff 
./grep apple tests/%.test >STDOUT diff STDOUT outputs/.out > 3.diff 
echo tests/1.test tests/2.test tests/3.test 
echo 1.diff 2.diff 3.diff

并使用make makefile all

make: Nothing to be done for `makefile'. 
echo tests/%.test tests/%.test 
echo outputs/%.out outputs/%.out 
./grep apple tests/%.test >STDOUT

【问题讨论】:

  • 我不确定你的问题是什么(或者你到底想做什么),但你的 all 规则几乎肯定不会达到你的预期。

标签: makefile grep


【解决方案1】:

你的问题不清楚,但是由于你使用文件STDOUT作为中间文件,每次比较都使用它,并且没有其他用途,我建议你结合规则:

%.diff: ${INPUT_DIR}/%.test ${OUTPUT_DIR}/%.out
    ./grep apple $< >STDOUT  # Do you really have an executable called "grep"?
    diff STDOUT ${OUTPUT_DIR}/$*.out > $@

另外,您的 all 规则并没有达到您的预期。试试这个:

all:
    @echo you must specify a target, e.g. outputs/foo.diff

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多