3 ms·
What are the benefits of Makefiles compared to a bunch of shell scripts?
by deepsun 5y ago
What are the benefits of Makefiles compared to a bunch of shell scripts?
- enriquto 5y agoThat you get parallelism and partial re-running for free.
- andrew_ 5y agoparallelism is common in package managers these days https://pnpm.io/cli/run#--parallel https://pnpm.io/cli/run#--parallel
- monocasa 5y agoNo, make understands the directed acyclic graphs of dependencies, regardless of language, and will walk that graph in parallel. No forcing or ignoring sorting, and no enforced package level blocking on scripts.
- immibis 5y agoIt's a shame this doesn't work for Java in particular (not JS) as Java's coding conventions/requirements do not lend themselves at all to manually updating a list of file dependencies.
- JamesSwift 5y agoA single, system-and-language-agnostic entry point to the actions you want to run with very clear dependency rules built in.
- deepsun 5y agoBesides Windows, shell scripts are system-and-language agnostic (not using bash/zsh-specific syntax of course). Also I'm not sure Windows can run Makefiles out-of-the-box.
- JamesSwift 5y agoThe Makefile is the facade to the project. So you can have `make run` do `make run-windows` or `make run-nix` under the hood. And when you change hosts, or you redo the `run-X` targets into a single cross-platform binary or you put it in a Docker container, nothing changes. You don't need to remember that you need to invoke X or Y script. I'm pretty sure git-bash provides `Make` on Windows. I believe thats how I tested it for this project: https://github.com/J-Swift/cod-stats https://github.com/J-Swift/cod-stats
- mathgorges 5y agoI’ve successfully used both together before :) The makefile lets me be very expressive about task dependencies and encode some developer conveniences. Ie make can know `make bootstrap` should invoke bootstap_windows.sh on Windows and bootstrap_osx.sh on Mac. Then the work happens inside the appropriate script. They’re two tools that solve different problems but they work together quite well.
- elchief 5y agoResumability is the main one, in my mind Imagine a simple two-step process. The first takes a long time. The second one fails on occasion. You don't want to run the first one again. With Make, if the first one succeeds, it won't run again unless you `clean` Easy, but now imagine many, many steps
- deepsun 5y agoMakefile just checks whether a file exists, nothing more. if [[ -f myfile ]]; then
- Izkata 5y agoIt also compares the last-modified timestamps of the source and target files so it only runs if the target is out of date. Plus because the dependencies are explicit, it's trivial to run in parallel the parts that can be.
- deepsun 5y agoThanks, didn't know about timestamps. But it's trivial to run shell scripts in parallel as well, just add ` &` at the end.