This site uses cookies to deliver our services and to show you relevant ads and job listings.
By using our site, you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our Terms of Service.
Your use of Stack Overflow’s Products and Services, including the Stack Overflow Network, is subject to these policies and terms.

Join us in building a kind, collaborative learning community via our updated
Code of Conduct.

5 Answers
5

The general idea is that make supports (reasonably) minimal rebuilds -- i.e., you tell it what parts of your program depend on what other parts. When you update some part of the program, it only rebuilds the parts that depend on that. While you could do this with a shell script, it would be a lot more work (explicitly checking the last-modified dates on all the files, etc.) The only obvious alternative with a shell script is to rebuild everything every time. For tiny projects this is a perfectly reasonable approach, but for a big project a complete rebuild could easily take an hour or more -- using make, you might easily accomplish the same thing in a minute or two...

There are various things make does that are hard to do with shell scripts...

Of course, it checks to see what is out of date, so as to build only what it needs to build

It performs a topological sort or some other sort of tree analysis that determines what depends on what and what order to build the out-of-date things such that every prerequisite is built before every dependency, and only built once.

It's a language for declarative programming. New elements can be added without needing to merge them into an imperative control flow.

It contains an inference engine to process rules, patterns, and dates, and this, when combined with the rules in your particular Makefile, is what turns make into an expert system.

It's pretty limited as an expert system, though. E.g. each inference can use the same rule only once.
– reinierpostSep 27 '10 at 6:52

Just to elaborate on point 2) in more layman engineering terms, a shell script enforces a linear ordering, whereas a makefile is tree-like. It removes unnecessary chronological dependencies (though in practice the make process would be executed linearly).
– Sridhar-SarnobatOct 13 '14 at 7:08

...I think the trouble with Makefiles over shell scripts is analogous to the trouble with CSS over javascript. It's not nearly as obvious what chronological order each node gets executed in. Though at least with Makefiles you still get to see the actual shell command. With CSS even that is abstracted away.
– Sridhar-SarnobatOct 13 '14 at 7:22

I have a few comments I appreciate if someone clarify them . 1/ aren't your first and two points related, in the sense that that topological sort is how the incremental build is implmented? 2/ can't you point number 3 implemented using function composition as well . 3/ I would like to understand more about the advantages of 4 and 5 for the MakeFile end user, and why these advantages can't be implemented by composing shell commands together
– Amine HajyoussefAug 23 '17 at 16:22

This is the first time I've come across Make described as an Expert System. As someone who's built expert systems, it's not something I would have considered. Make obviously has an inference engine to deduce how to build your program through the declarative rules specified in the makefile, but it's less obvious that it's a knowledge based system since the (leaf) rules are shell commands to be executed rather than facts. And the term "expert system" is used to refer to a system that has successfully captured the expertise of a world class expert, which isn't the case. Jury's still out for me.
– DennisJan 7 at 15:26

make handles dependencies: the makefile describes them: the binary depends on object files, each object file depends on a source file and headers ... when make is ran, the date of the files are compared to determine what needs to be re-compiled.

One can invoke directly one target not to build everything described in the Makefile.

Moreover the make syntax provides substitution, vpath

All of this can be written in shell scripts, with make you already have it.