Why use make on top of a shell script?

Make seems to me just a shell script with a slightly simpler processing of command line arguments.

Why it is standard to run make instead of. / Make.sh

+60
shell compilation makefile
Sep 26 '10 at 15:52
source share
5 answers

The general idea is that make supports (reasonably) minimal overhauls - that is, you tell which parts of your program depend on other parts. When you update a part of a program, it restores only those parts that depend on it. Although you could do this with a shell script, it would work a lot more (explicitly checking the dates of the last change in all files, etc.). The only obvious alternative with a shell script is rebuilding all the time. For tiny projects, this is a perfectly reasonable approach, but for a large project, a complete overhaul can easily take an hour or more - using make , you can easily do the same thing in a minute or two ...

+68
Sep 26 '10 at 16:05
source share

Make - expert system

There are various things that are difficult to do with shell scripts ...

  • Of course, he checks that he is out of date to build only what he needs to build.
  • It performs topological sorting or some other kind of tree analysis, which determines what depends on what and what to create obsolete things, so that every necessary condition is built before each dependency and built only once.
  • This is a language for declarative programming . New elements can be added without the need to merge them into an imperative flow of control.
  • It contains an output mechanism for processing rules, patterns, and dates, and this, combined with the rules in your particular Makefile, is what makes make an expert system .
  • It has a macro processor.
  • See also: earlier summary of make .
+38
Sep 26 '10 at 16:17
source share

As above, Make is a declarative (-ish) parallel programming language.

Let's say you have 4,000 image files to convert and 4 processors. Try writing a 10-line shell script (I'm generous here) that will do this reliably, saturating your processors.

Perhaps the real question is why do people write shell scripts.

+7
01 Oct 2018-10-10
source share

Make ensures that when making changes to the source files, only the necessary files will be recompiled.

For example:

 final : 1.o 2.o gcc -o final 1.o 2.o 1.o : 1.c 2.h gcc -c 1.c 2.o : 2.c 2.h gcc -c 2.c 

If I change only the 2.h file and run make , it will execute all 3 commands in reverse order.

If I change only the 1.c file and run make , it only executes the first 2 commands in reverse order.

Trying to do this with your own shell script will include many if/else checks.

+6
Sep 26 '10 at 16:10
source share

make depends on the descriptors: the make file describes them: the binary file depends on the object files, each object file depends on the source file and headers ... when make is run, the date of the files is compared to determine what needs to be recompiled.

You can call one target directly so that you don’t create everything described in the Makefile.

In addition, make syntax provides substitution, vpath

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

+3
Sep 26 '10 at 16:09
source share



All Articles