GRUB build fails to compile

1.4k views Asked by At

I cloned grub from Github https://github.com/coreos/grub, however it fails to compile and gives error. The error seems obvious but the point is how the upstream code is not compiling. Am I doing anything wrong?

I did below things to compile :

./autogen.sh
./configure --target=x86_64 --with-platform=efi
make

I get this error :

grub_script.yy.c: In function ‘yy_fatal_error’:
grub_script.yy.c:19:22: error: statement with no effect [-Werror=unused-value]
 #define fprintf(...) 0
                      ^
grub_script.yy.c:2367:2: note: in expansion of macro ‘fprintf’
  fprintf( stderr, "%s\n", msg );
  ^
cc1: all warnings being treated as errors
Makefile:35746: recipe for target 'normal_module-grub_script.yy.o' failed
make[3]: *** [normal_module-grub_script.yy.o] Error 1
make[3]: Leaving directory '/tmp/grub-2.02/grub-core'
Makefile:23531: recipe for target 'all' failed
make[2]: *** [all] Error 2
make[2]: Leaving directory '/tmp/grub-2.02/grub-core'
Makefile:10904: recipe for target 'all-recursive' failed
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory '/tmp/grub-2.02'
Makefile:3130: recipe for target 'all' failed
make: *** [all] Error 2

I tried with gcc 4.8,5 as well as 7, but the same error. My host machine is Ubuntu-18 64-bit.

1

There are 1 answers

0
Mike Kinghan On BEST ANSWER

As @jens comments, the upstream maintainers should fix this build break. On the face of it the fix seems simple. Meantime a workaround is simple too, and almost certainly safe.

As you see from the failing build log, you get this compilation error only because the -Werror flag is in effect, to promote all warnings to errors.

The promoted warning that is breaking your build occurs in file grub_script.yy.c at line 2367. It is in fact innocuous warning. You can cause it not to be promoted in either of two ways:-

The ./configure script has an option --disable-werror, which removes the -Werror flag from all compilations. So you can run:

$ ./configure --target=x86_64 --with-platform=efi --disable-werror
$ make

This solution will cause no compilation warnings to be promoted to errors, and is likely what you are "supposed" to be content with. You might prefer a somewhat more focussed workaround that disables error-promotion only for the type of warning that actually broke your build:

statement with no effect [-Werror=unused-value]

You can accomplish that with:

$ ./configure --target=x86_64 --with-platform=efi CPPFLAGS=-Wno-error=unused-value
$ make