I work on a web app whose Makefile contains the following:
dist/index.html: src/templates/index.html
@bin/insert-scripts $< --output $@
bin/insert-scripts replaces <--scripts-->
in the provided file with one of the following:
- a number of script tags (for jQuery, Underscore, etc.) when $ENV is "development", or
- a single script tag (pointing to the concatenated, minified file) when $ENV is "production".
The problem is that if one builds dist/index.html in one mode ("development", say), and then builds it again in the other mode without touching the dependency, make will say there's nothing to be done. What I would like to be able to do is to make $ENV a dependency of dist/index.html:
dist/index.html: src/templates/index.html $ENV
@bin/insert-scripts $< --output $@
This won't work, of course, so I considered having a file named ENV which contains either "development" or "production". This file would become a dependency:
dist/index.html: src/templates/index.html ENV
@bin/insert-scripts $< --output $@
Rather than setting an environment variable, one would set the content of the ENV file. This seems a little clunky, but at least accurately represents the dependency tree.
What is the best way to handle this situation?