How can I suppress output of warnings when building a custom kernel?

I don't want to simply do:

make buildkernel KERNCONF=custom > /dev/null 2>&1

I still want the errors shall any arise. I just want to avoid this:


/usr/src/sys/cam/cam_sim.c:120:6: warning: variable 'error' set but not used [-Wunused-but-set-variable]
int error;
^
1 warning generated.
 
make CWARNFLAGS="-Wno-foo -Wno-bar"
That resulted in:
error: unknown warning option '-Wno-foo' [-Werror,-Wunknown-warning-option]
error: unknown warning option '-Wno-bar' [-Werror,-Wunknown-warning-option]
*** Error code 1

Stop.
make[2]: stopped in /usr/obj/usr/src/amd64.amd64/sys/custom
*** Error code 1

Stop.
make[1]: stopped in /usr/src
*** Error code 1

Stop.
make: stopped in /usr/src

I was hoping for a more elegant solution than redirecting each to separate files, but I guess that works. If there is an error, I can always cat either file or tail it.
 
Sorry, but that made me smile. The foo/bar warnings were clearly provided as an example :)

Replace the foo and bar with actual warnings you see in the output with "no-" added after "W", e.g. -Wno-unused-but-set-variable.
 
Hehe, I figured, but, so I need to first build the kernel, determine the warnings and then adjust as necessary. Eh, I like the first option better.
 
make CWARNFLAGS="-w"
(lowercase w)

I wonder why you are getting warnings. Do you maybe have a compiler from ports first in $PATH?
 
Warnings are there for a reason. Instead of ignoring them, i'd rather fix them.
I agree, but meh, that's outside of my pay grade :).

One such warning
/usr/src/sys/cam/cam_sim.c:120:6: warning: variable 'error' set but not used [-Wunused-but-set-variable]
int error;
^
1 warning generated.

What should I do to fix this, modify the kernel source, specifically on line 120 for cam_sim.c and open a PR? I suppose I could :). In this case, I need to remove the variable, 'error' because it is declared, but not used. I'd have to do that for all the warnings I get. Is anyone else getting these?
 
This?
Code:
commit c154feacc4f2e1dc0858eb93eb1994ea997e699b
Author: Scott Long <scottl@FreeBSD.org>
Date:   Thu Nov 25 03:17:54 2021 +0000

    Fix "set but not used" warnings in CAM.

diff --git a/sys/cam/cam_sim.c b/sys/cam/cam_sim.c
index abf65965fc8..2dbf581712f 100644
--- a/sys/cam/cam_sim.c
+++ b/sys/cam/cam_sim.c
@@ -144,7 +144,7 @@ void
 cam_sim_free(struct cam_sim *sim, int free_devq)
 {
        struct mtx *mtx;
-       int error;
+       int error __diagused;

        if (sim->mtx == NULL) {
                mtx = &cam_sim_free_mtx;
 
I haven't looked, there are many warnings, so point taken. I will need to open up PRs to address those warnings. I haven't written a line of any of the kernel sources or modules, not that I cannot have a look, just that that was deeper in the rabbit hole I wanted to go for the time being.
 
Back
Top