All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Grégoire Sutre" <gregoire.sutre@gmail.com>
To: The development of GRUB 2 <grub-devel@gnu.org>
Subject: [PATCH] Lexer sed post-processing instead of pragmas
Date: Tue, 16 Mar 2010 15:45:11 +0100	[thread overview]
Message-ID: <4B9F9977.1040904@gmail.com> (raw)

[-- 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


                 reply	other threads:[~2010-03-16 14:45 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4B9F9977.1040904@gmail.com \
    --to=gregoire.sutre@gmail.com \
    --cc=grub-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.