Practical Debugging Techniques for Makefile

In the previous sections, we discussed the basic rules, functions, and patterns of makefiles. When writing makefiles in practice, we often encounter various issues. How can we quickly and effectively solve these problems? Here, I will introduce several common techniques to help us better handle and resolve the issues we encounter.

MakefileDebugging Technique1

During the makefile writing process, we often need to debug variables and runtime information in the makefile. We may need to print and pause the execution of make. We can use the error function $(error <text…>) to perform debugging.

When make is executed, it will generate an error, stopping the execution of the makefile and outputting the<text…> information.

Practical Debugging Techniques for Makefile

The above example checks whether $(LIBNAME) is empty. If the condition is met, it stops the execution of the subsequent makefile.

There is also another function $(warning <text …>), which does not cause make to exit, but only outputs a warning message, while make continues to execute.

MakefileDebugging Technique2

When make is running, if the volume of code in the makefile is large, the screen will be filled with command outputs, leaving us overwhelmed. Sometimes, we also need to suppress the displayed commands, using the @ command symbol. For example:

Practical Debugging Techniques for Makefile

When make is executed, echo Helloworld will output

echo Helloworld

helloworld

string.

@echo Helloworld will output “Helloworld”, without displaying the command.

MakefileDebugging Technique3

Sometimes, when we execute a large number of programs, suddenly, the program finishes executing, but we find that some makefile defined variable parameters have not been updated. We need to add “-n” or “–just-print” parameters during the make execution. This will cause make to only display the commands it would execute, without actually executing them. This allows us to check the debug information of the parameter variables in the make execution commands.

MakefileOther Debugging Information

Makefile also has other debugging parameters, as follows:

Practical Debugging Techniques for Makefile

Author: Beyond

Email: [email protected]

If you like this article, please follow the “IC Small House” WeChat public account for more information.

Practical Debugging Techniques for Makefile

Leave a Comment