Re:A simple makefile is a unicorn
by donatj on Thursday January 11, 2018 @03:46AM
(#16122324)
Lol, I just made the argument that ‘a simple makefile can do most of what people use grunt for’ on Twitter like 6 days ago. Worth nothing however everything in our makefile is a PHONY which makes things a ton simpler, though arguably we’re not using make to it’s full potential.
[ Parent
| on HN ]
You may want to consider using 'stamp files'. These are just empty files created via 'touch' to serve as a timestamp that Make can use to determine if a target needs to be rebuilt if the target doesn't correspond to an actual file in the build directory. This is useful for build targets such as running docker-compose build.
See https://www.technovelty.org/tips/the-stamp-idiom-with-make.h...
Re:A simple makefile is a unicorn
by TickleSteve on Thursday January 11, 2018 @05:04AM
(#16122645)
I have to disagree with this, I consider stamp files a Makefile anti-pattern.
Stamp files are an often an indication that someone is trying to turn a Makefile into a shell script.
Rules should be generated that generate a target from its dependencies. The intermediate steps should be encapsulated as the rule commands.
Sometimes it is necessary though. I have had to use this pattern in 2 scenarios:
Building a static website where the targets are wildly different from the source files. I could probably make it explicit but it will be overly verbose and brittle.
Check for and remove trailing whitespace. Because the dependency is actually the target, a stamp file is necessary.
Specifically in the second case: How do you get the timestamp on these stamp files to update, or do you just do it manually? And if you are doing it manually, why not just run a shell script instead?
The timestamp on the source files is updated by sed, when it strips the whitespace. The stamp file is then updated with touch. The advantage of using Make is that only modified files will be fed to sed and, consequently, only they will be caught by the rsync command, that I use to push the code out to the server(s).
Re:A simple makefile is a unicorn
by char_pointer on Thursday January 11, 2018 @04:17AM
(#16122461)
Yeah, I think this is what people mean when they talk about simple Makefiles: running scripts + topological ordering. Building C is just hard.