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:
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?
If you absolutely have to enforce rebuilding for changed environments, you can always use a tag file for the build environment:
.PHONY: always-rebuild
environment : always-rebuild
echo $ENV > [email protected]
diff --quiet $@ [email protected] || cp [email protected] $@
rm -f [email protected]
dist/index.html : src/templates/index.html environment
The diff
ing ensures that environment
is always re-built (<= checked), but only touched when the relevant environment variables changed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With