Makefile 处理一个目录下的所有文件,输出到另一个目录。

Makefile process all files in one directory, output to another.

如何设置 Makefile 来处理一个目录中的所有文件,将输出重定向到另一个目录(每个输入文件一个输出文件)?我有:

INPUTS := $(wildcard ./input/*.txt)
OUTPUTS := $(patsubst %.out,%.txt,$(wildcard ./input/*.txt))

$(OUTPUTS): $(INPUTS)
    python process.py $@ > ./output/${@:%.txt=%.out}

...但它不断在 ./output 中重新生成已经存在的文件。

这样写:

INPUTS := $(wildcard ./input/*.txt)

# Create a list of all the output files you want to generate
OUTPUTS := $(patsubst ./input/%.txt,./output/%.out,$(INPUTS))

# The default is to build all the OUTPUTS files
all: $(OUTPUTS)

# Tell make how to build a single output file
./output/%.out : ./input/%.txt
        python process.py $< > $@