Silent make by removing echo

To remove default output of make command start each line of the Makefile that you wish to ‘silence’ with ‘@’:

@rm -f *.o

This can cause problems when the compiler generates an error. In that case you need to catch the error and terminate the make process. You should also generate a message saying which command caused the problem since this command won’t be printed on the screen (The error message will show up though). Use following code to do just that:

default:
    @echo "Compiling helloworld.cpp";
    @gcc helloworld.cpp $(CFLAGS) -o helloworld \
    || (echo "Error in command: gcc helloworld.cpp $(CFLAGS) -o helloworld" && false)
Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s