Inhibit all warnings from `make` - makefile

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

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.

Related

CMake: Generate Unix Makefiles which ignore errors

In Unix Makefile I can prefix a recipe line with - to ignore any error that will occur (as describe in Errors in Recipes).
hello_world: hello_world.cxx
-$(CXX) $(CXXFLAGS) $^ -o $#
I converted my Makefile to CMake:
cmake_minimum_required(VERSION 3.0)
project(HelloWorld)
add_executable(hello_world hello_world.cxx)
and run cmake and the generated Makefile looking fine, except the missing -.
Is it possible to generate Unix Makefile with CMake that will ignore errors (prefix the recipe line with -)?
The best would be to specify it per target level. I know I can run make -i to have the same behaviour but it isn't that convenient.
You cannot.
make is designed to give the user a fine control over commands it runs. CMake's under-the-hood commands are supposed to always succeed.
As a hack, you can generate makefiles and run make --ignore-errors.
But I advice making each of your examples that would fail a separate project, and run them from an external script.

Configure GCC to add compile flags globally

Can I configure GCC to add some file globally, for every project? I want to make it temporarily and only with flags like: -fdiagnostics-color.
I don't understand why do you need it but you can do a wrapper:
which gcc - will print a patch to GCC (copy it to clipboard)
mkdir somedir; cd somedir
create file with name gcc
and add into it: full path to gcc(from clipboard) -fdiagnostics-color somefile.c $# this command will add -fdiagnostics-color somefile.c before every line that came to gcc.
chmod +x gcc - set execution rights to gcc wrapper
And finally
add path to your wrapper. export PATH=somedir:$PATH
You might read about GCC spec files and alter the spec file used by your particular version of gcc. But this is generally frowned upon.
The usual practice would be to use GNU make and add a CFLAGS += -fdiagnostics-color to your Makefile. BTW with a recent enough GCC this (adding -fdiagnostics-color flag) is not even necessary since (at least by setting your GCC_COLORS environment variable) the default is -fdiagnostics-color=auto

Set -Wall on by default in gcc/g++

While testing code posted on SO, it's very helpful to turn the -Wall option on. I was able to do so by creating a Makefile whose contents are:
CFLAGS=-Wall
CXXLAGS=-Wall
I understand that one can use
make CFLAGS=-Wall <target>
make CXXFLAGS=-Wall <target>
as well.
Is this, setting CFLAGS/CXXFLAGS, the only way to turn compiler flags on by default?
Is there any configuration file(s) where one can enable/disable any of the compiler options?
if you are running bash
export CFLAGS="-Wall"
in your .bashrc is also a good place to set defaults. On BSD (Mac OSX) /etc/make.conf can be used to set default flags if you always use make. Or you can alias 'gcc' to 'gcc -Wall'. One of these should be the one you are looking for.

Make CMake use gccfilter

GCCFilter is a neat perl script that allows to color the output of GCC and thus makes debugging much more fun and, more important, faster.
You can use GCCFilter with a CMake generated Makefile by calling
gccfilter -a -c make
However, this approach has some drawbacks: Delayed output of CMake status infos, no color in the CMake commands are the most obvious.
The question: Is there a way to write some CMake module that searches for gccfilter if the compiler is gcc, checks if, say COLOR_CXX is set (rather easy up to here) and then tells CMake to replace all calls to gcc by gccfilter -a -c gcc.
CMake offers the variable CMAKE_CXX_COMPILER, but changing this one will disallow CMake to find correct include paths and the like. Is there some variable we may change after the project() command that is prefixed before each call to gcc?
You can make CMake use gccfilter by pointing the RULE_LAUNCH_COMPILE property to a wrapper script which invokes gccfilter with the desired options.
Create an executable shell script named gccfilter_wrap in the outermost CMake project directory with the following contents:
#!/bin/sh
exec gccfilter -a -c "$#"
Be sure to set the file's executable bit. Then in your CMakeLists.txt, set the RULE_LAUNCH_COMPILE directory property before adding targets:
project (HelloWorld)
set_directory_properties(PROPERTIES RULE_LAUNCH_COMPILE
"${PROJECT_SOURCE_DIR}/gccfilter_wrap")
add_executable(HelloWorld HelloWorld.cpp)
The generated makefile rules will then prefix each compiler invocation with the gccfilter_wrap script. Alternatively the RULE_LAUNCH_COMPILE property can also be set as a target property or as global property.
The RULE_LAUNCH_COMPILE property only works for Makefile-based CMake generators.
Edit by Thilo
This is how I finally solved the problem - basically a rephrased version of this solution:
# GCCFilter, if appliciable
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_GNUCPP)
option(COLOR_GCC "Use GCCFilter to color compiler output messages" ON)
set(COLOR_GCC_OPTIONS "-c -r -w" CACHE STRING "Arguments that are passed to gccfilter when output coloring is switchend on. Defaults to -c -r -w.")
if(COLOR_GCC)
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${PROJECT_SOURCE_DIR}/cmake/gccfilter ${COLOR_GCC_OPTIONS}")
endif()
endif()

What's this kind of bash syntax?

CFLAGS="-g -O0" ./configure
How's CFLAGS="-g -O0" picked up in configure?
Anyone knows this?
Here, you're setting CFLAGS as an environment variable to be passed into ./configure. You can set any number of environment variables this way if you happen to need more than one.
-g:
C compilation options which relate to optimization or debugging (usually just -g or -O). Usually this wouldn't include -I options to specify the include directories, because then you
couldn't override it on the command line easily as in the above example.
For more information, you can refer this url.
http://makepp.sourceforge.net/1.19/makepp_tutorial.html

Resources