All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Lexer sed post-processing instead of pragmas
@ 2010-03-16 14:45 Grégoire Sutre
  0 siblings, 0 replies; only message in thread
From: Grégoire Sutre @ 2010-03-16 14:45 UTC (permalink / raw)
  To: The development of GRUB 2

[-- Attachment #1: Type: text/plain, Size: 946 bytes --]

Hi,

The lexer code in script/yylex.l uses pragmas that are not supported by
gcc < 4.2.  However, without these pragmas, the build fails because of
warnings in the lexer code generated by flex (recall that some targets
are built with -Werror by default).

I've discussed this issue with sethmeisterg on irc.  Of course, dropping
compatibility with gcc 4.1.3 is a possible solution, but we believe that
a better alternative would be to modify the generated lexer so that it
does not trigger any warning.

There are already some sed commands in conf/common.rmk that remove
#includes from the generated lexer.  The attached patch extends the sed
post-processing of the lexer to get rid of the warnings, and removes the
pragmas.  This way, grub can still be compiled with gcc 4.1.3 (which is
the current required version in INSTALL).

The patch also replaces the non-portable -i sed option with temporary
files.

Thanks for your comments,

Grégoire


[-- Attachment #2: lexer_no_pragma.diff --]
[-- Type: text/x-patch, Size: 2054 bytes --]

=== modified file 'conf/common.rmk'
--- conf/common.rmk	2010-03-14 16:50:55 +0000
+++ conf/common.rmk	2010-03-16 14:13:32 +0000
@@ -95,10 +95,21 @@
 grub_bin2h_SOURCES = gnulib/progname.c util/bin2h.c
 
 # For the lexer.
+lex_fix_includes = '/^\#include[[:space:]]*<(stdio|string|errno|stdlib|unistd)\.h>/d'
+lex_fix_h  = '/^(static)?[[:space:]]*void[[:space:]]*yy_flex_strncpy[[:space:]]*\(.*\)[[:space:]]*;$$/d'
+lex_fix_c1 = '/^(static)?[[:space:]]*void[[:space:]]*yy_fatal_error[[:space:]]*\(.*\)[[:space:]]*;$$/d'
+lex_fix_c2 = '/^(static)?[[:space:]]*(int|void)[[:space:]]*yy(get_column|set_column|_fatal_error)[[:space:]]*\(.*\)$$/,/^}$$/d'
+lex_fix_c3 = '/^static[[:space:]]*void[[:space:]]*yy_flex_strncpy[[:space:]]*\(.*\)$$/{\
+s/yyscanner/yyscanner __attribute__ ((unused))/;\
+};'
+
 grub_script.yy.c grub_script.yy.h: script/yylex.l
 	$(LEX) -o grub_script.yy.c --header-file=grub_script.yy.h $(srcdir)/script/yylex.l
-	sed -i 's/^#include.*\(<stdio\.h>\|<string\.h>\|<errno\.h>\|<stdlib\.h>\|<unistd\.h>\)//g' grub_script.yy.h
-	sed -i 's/^#include.*\(<stdio\.h>\|<string\.h>\|<errno\.h>\|<stdlib\.h>\|<unistd\.h>\)//g' grub_script.yy.c
+	mv grub_script.yy.h grub_script.yy.h.tmp
+	mv grub_script.yy.c grub_script.yy.c.tmp
+	sed -r -e $(lex_fix_includes) -e $(lex_fix_h) grub_script.yy.h.tmp > grub_script.yy.h
+	sed -r -e $(lex_fix_includes) -e $(lex_fix_c1) -e $(lex_fix_c2) -e $(lex_fix_c3) grub_script.yy.c.tmp > grub_script.yy.c
+	rm grub_script.yy.h.tmp grub_script.yy.c.tmp
 DISTCLEANFILES += grub_script.yy.c grub_script.yy.h
 
 # For grub-script-check.

=== modified file 'script/yylex.l'
--- script/yylex.l	2010-01-25 16:31:14 +0000
+++ script/yylex.l	2010-03-16 14:11:34 +0000
@@ -94,12 +94,6 @@
 #define fprintf(...) 0
 #define exit(...)
 
-#pragma GCC diagnostic warning "-Wunused-variable"
-#pragma GCC diagnostic warning "-Wunused-function"
-#pragma GCC diagnostic warning "-Wunused-parameter"
-#pragma GCC diagnostic warning "-Wstrict-prototypes"
-#pragma GCC diagnostic warning "-Wmissing-prototypes"
-
 }
 
 %option ecs


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2010-03-16 14:45 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-03-16 14:45 [PATCH] Lexer sed post-processing instead of pragmas Grégoire Sutre

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.