Reputation: 282895
I have this make rule:
dist/node/%.js: src/%.node.js yarn.lock .babelrc | $(NODE_DIST_DIRS)
$(BIN)/babel $< -o $@
It works fine when my source file ends with .node.js
. e.g.,
$ make dist/node/fs.js
mkdir -p dist/node/
node_modules/.bin/babel src/fs.node.js -o dist/node/fs.js
However, I want to compile dist/node/fs.js
from either src/fs.node.js
or src/fs.js
, whichever exists.
The reason for this is that I have some shared files with just the .js
extension (work in both browser and node), and then more specific files with the .node.js
extension. If there's a more specific version, I want to use that.
I don't know how to do conditional dependencies in combination with %
. Is this possible? Can I give precedence to dependencies and take the best match?
Upvotes: 1
Views: 52
Reputation: 100856
There is no way to do that in a single rule. You'll have to write two rules with different prerequisites but otherwise the same:
dist/node/%.js: src/%.node.js yarn.lock .babelrc | $(NODE_DIST_DIRS)
$(BIN)/babel $< -o $@
dist/node/%.js: src/%.js yarn.lock .babelrc | $(NODE_DIST_DIRS)
$(BIN)/babel $< -o $@
Upvotes: 2
Reputation: 8591
I suppose you could try using a double-colon rule, but those cannot be pattern rules.
As an alternative, consider generating and including a makefile containing just those dependencies.
Upvotes: 1