使用相同名称但目录不同的Makefile规则 [英] Makefile rule to build with same name, but different directory

查看:102
本文介绍了使用相同名称但目录不同的Makefile规则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要类似的规则:

build/%.ext: src/%.ext
    action

我要优化的文件夹中有一个文件目录,然后将其输出到另一个文件夹.但是,这些文件在输入和输出文件夹中具有相同的名称.我已经尝试了上述规则的各种迭代,但是make会根据我如何调整上面的内容而始终重建或永不重建.有建议吗?

I have one directory of files in a folder that I want to optimize and then output to a different folder. However, the files have the same name in the input and output folders. I have tried various iterations of the rule above, but make will either always or never rebuild depending how I tweak the above. Suggestions?

我最终得到了以下解决方案,效果很好!

I ended up with the following solution, which works great!

JS = \
  src/js/script2.js \
  src/js/script1.js

JS_OPT = $(patsubst src/js/%.js,web/js/%.js, $(JS))

all: $(JS_OPT)

$(JS_OPT): web/js/%.js: src/js/%.js
  cat $@ | ./bin/jsmin > $<

推荐答案

尝试这样的想法:

INPUT_FILES = \
  src/a.txt   \
  src/b.txt   \

OPTIMIZED_FILES=$(patsubst src/%.ext,build/%.ext,$(INPUT_FILES))

$(OPTIMIZED_FILES): build/%.ext: src/%.txt
     optimize_command $@ $<

这篇关于使用相同名称但目录不同的Makefile规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆