How to print in a Makefile

Makefiles and especially recursive Makefiles can be hard to understand and debug. But the good old debugging method of printing out values from certain locations in the source code can be employed here too.

  • To print a message when make parses past that location in the Makefile:
$(info Hello World Make just parsed past this line)

Note that make typically parses a file twice before it executes what is needed to satisfy its targets. So, you will see the message you are printing twice.

  • To print the value of a make variable at a certain location in the Makefile:
$(info $(FOOBAR_VAR))

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.