简体   繁体   English

Makefile重新编译未更改的文件

[英]Makefile recompiling unchanged files

I'm attempting to get my Makefile(s) to only recompile when files have changed and it works brilliantly for the Java target, but not for JS. 我试图让我的Makefile仅在文件更改时才重新编译,并且对于Java目标(而非JS)非常有效。 There aren't any errors reported, but when I run make bundle the second time around, it still re-runs all of those commands. 没有报告任何错误,但是当我第二次运行make bundle时,它仍然重新运行所有这些命令。

The output of running find ... manually seems to produce exactly what is expected, with no extra or missing lines. 手动运行find ...的输出似乎产生了预期的效果,没有多余或缺少行。

JAVA_SRC_DIR := .
JAVA_SOURCES := $(shell find $(JAVA_SRC_DIR) -name '*.java' -o -name '*pom.xml')

JS_SRC_DIR := ./ui-bundle
JS_EXCLUDE := \(node_modules\|coverage\)
JS_SOURCES := $(shell find $(JS_SRC_DIR) -name '*.js' -o -name '*.jsx' -o -name '.babelrc' -o -name 'package.json' | grep -v $(JS_EXCLUDE) | grep -v -e '^$')

bundle: $(JS_SOURCES)
    npm install
    ./node_modules/jest-cli/bin/jest.js --verbose
    ./node_modules/gulp/bin/gulp.js package

service: $(JAVA_SOURCES)
    mvn clean install -pl "!integration"

I'm guessing this has something to do with it, but when I try to find what files make thinks has changed with make -d | grep "\\(older\\|newer\\)" 我猜想这与它有关,但是当我尝试查找make认为哪些文件已更改时, make -d | grep "\\(older\\|newer\\)" make -d | grep "\\(older\\|newer\\)" it doesn't find anything, but make -d concludes with: make -d | grep "\\(older\\|newer\\)"找不到任何东西,但是make -d结论是:

 Finished prerequisites of target file `bundle'.
 Must remake target `bundle'.

Additionally make -d seems to try to run some sort of npm command. 另外, make -d似乎尝试运行某种npm命令。

Where am I going wrong? 我要去哪里错了?

The problem is that bundle is just a name for the rule, and the rule doesn't actually build a file named "bundle". 问题在于bundle只是规则的名称,而该规则实际上并未构建名为“捆绑包”的文件。 No matter how new or old the prerequisites are, when you make bundle , Make sees that no such file exists, deduces that it must be built, and executes the rule. 无论新旧的先决条件是什么,当make bundle ,Make都会发现不存在这样的文件,推论必须构建该文件并执行规则。

If you want Make to refrain from executing the rule when the prerequisites have not changed, you must give it something to compare them to. 如果您希望Make在先决条件没有改变的情况下不执行规则,则必须给它做些比较。 If you can identify some file that the rule always modifies, you can make that file the target. 如果您可以确定规则总是修改的某个文件,则可以将该文件作为目标。 I can't suggest a candidate because I don't know what npm , jest and gulp do, but suppose it's jest_output : 我不能提出一个候选人,因为我不知道是什么npmjestgulp做,但想这是jest_output

jest_output: $(JS_SOURCES)
    ...

Or you could have an actual file called bundle , which serves as a marker for Make, an empty file that has a name and modification time and nothing else: 或者,您可能有一个称为bundle的实际文件,该文件用作Make的标记,一个具有名称和修改时间且没有其他内容的空文件:

bundle: $(JS_SOURCES)
    npm install
    ./node_modules/jest-cli/bin/jest.js --verbose
    ./node_modules/gulp/bin/gulp.js package
    touch bundle

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM