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

时间:2015-05-16 20:17:24

标签: makefile

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

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

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

...但它会继续在已经存在的./output中重新生成文件。

1 个答案:

答案 0 :(得分:3)

像这样写:

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 $< > $@