Search code examples
makefilesuppress-warnings

Inhibit all warnings from `make`


I am building Android AOSP on my server running Ubunty 16.04. I have all dependencies installed and the build completes fine. However, I get many Warnings from the make command each time. Is there a way to inhibit those from the console output (eg. via a parameter passed into the command). I have tried with some gcc flags in an attempt but the compiler either ignored them or threw errors due to unrecognised parameters.

Thank you for the kind help. Lorenzo


Solution

  • gcc has the -w option which suppresses all warnings. The warning has to be put after any other compiler flags. How you do that depend on the makefile recipes. A late CXXFLAGS += -w might work. Put the -w behind a by default empty variable and you can override from the make invocation.

    Makefile:

    ...
    EXTRA_FLAGS ?=
    # CXXFLAGS is a convention, your flag variables may be named differently
    CXXFLAGS += $(EXTRA_FLAGS)
    

    Make invocation

    make my_target EXTRA_FLAGS="-w"
    

    You can also set the environment variable EXTRA_FLAGS to set implicitly for each invocation:

    export EXTRA_FLAGS="-w"
    make my_target
    export EXTRA_FLAGS=""
    make my_target
    

    Caveats include conflict with -Werror but guessing you are not using that since it compiles with warnings.