我需要制作一个makefile,将我的书写命令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
答案 0 :(得分: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