0

我需要制作一个生成文件,将我的书面命令 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
4

1 回答 1

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
于 2012-12-07T19:53:29.397 回答