GNU make study notes

Chapter 5: The Commands of the Rules

5.1 Command echo

Before executing the command, make will output the command to be executed to the standard output device, which is called "echo".

If a rule's command begins with the character "@", make will not echo the command to be executed when it executes the command.

 

In addition, if you use make's command line parameter "-n" or "-just-print", then when make executes, it only displays the commands to be executed, but does not actually execute these commands.

Only in this case will make print out all the commands that make needs to execute, including commands starting with the "@" character. This option is very useful for us to debug the Makefile. Using this option, we can print out all the commands that need to be executed in the Makefile in order of execution.

 

The make parameter "-s" or "--slient" suppresses the display of all executed commands, as if all commands start with "@". Using the special target ".SILENT" without dependencies in the Makefile can also suppress command echo, but it is not as flexible as "@". Therefore, when writing Makefile, we recommend using "@" to control the command echo.

 

objects = hello, world

foo.o: foo.c defs.h; @echo first command demo # module for twiddling the frobs
  cc -c -g foo.c
  @echo $(objects)

hello:
  @echo hello, linux

.PHONY: clean
clean:
  -@rm -rf *.o

empty.command:


  # this is a empty command demo

PS This echo is still well understood, the echo skill Get, √.

5.2 Execution of commands

rule, when the target needs to be rebuilt. The command defined by this rule will be executed. If it is a multi-line command, then each line of command will be executed in a separate subshell process (that is, the execution of each line of command is completed in a separate shell process. of). Therefore, the execution of multi-line commands is independent of each other, and there is no dependency on each other (multiple commands are executed as multiple independent processes).

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325354291&siteId=291194637
Recommended