History

kbuild: prepare to remove C files pre-generated by flex and bison

In Linux build system convention, pre-generated files are version- controlled with a "_shipped" suffix. During the kernel building, they are simply shipped (copied) removing the suffix. This approach can reduce external tool dependency for the kernel build, but it is tedious to manually regenerate such artifacts from developers' point of view. (We need to do "make REGENERATE_PARSERS=1" every time we touch real source files such as *.l, *.y) Some months ago, I sent out RFC patches to run flex, bison, and gperf during the build. In the review and test, Linus noticed gperf-3.1 had changed the lookup function prototype. Then, the use of gperf in kernel was entirely removed by commit bb3290d91695 ("Remove gperf usage from toolchain"). This time, I tested several versions of flex and bison, and I was not hit by any compatibility issue except a flaw in flex-2.6.3; if you generate lexer for dtc and genksyms with flex-2.6.3, you will see "yywrap redefined" warning. This was not intentional, but a bug, fixed by flex-2.6.4. Otherwise, both flex and bison look fairly stable for a long time. This commit prepares some build rules to remove the _shipped files. Also, document minimal requirement for flex and bison. Rationale for the minimal version: The -Wmissing-prototypes option of GCC warns "no previous prototype" for lexers generated by flex-2.5.34 or older, so I chose 2.5.35 as the required version for flex. Flex-2.5.35 was released in 2008. Bison looks more stable. I did not see any problem with bison-2.0, released in 2004. I did not test bison-1.x, but bison-2.0 should be old enough. Tested flex versions: 2.5.35 2.5.36 2.5.37 2.5.39 2.6.0 2.6.1 2.6.2 2.6.3 (*) 2.6.4 (*) flex-2.6.3 causes "yywrap redefined" warning Tested bison versions: 2.0 2.1 2.2 2.3 2.4 2.4.1 2.5.1 2.6 2.6.1 2.6.2 2.6.3 2.6.4 2.6.5 2.7 2.7.1 3.0 3.0.1 3.0.2 3.0.3 3.0.4

Masahiro Yamada committed 8 years ago

Commit 033dba21 parent 73a4f6d2 files · +42 −3Browse files

Showing the changes to scripts (1 of 2 files). Show all

Unified · Split

scripts/Makefile.lib+17−3
@@ -186,8 +186,6 @@ $(foreach m, $(notdir $1), \ · 185 unmodified lines
186 $(addprefix $(obj)/, $(foreach s, $3, $($(m:%$(strip $2)=%$(s)))))))186 $(addprefix $(obj)/, $(foreach s, $3, $($(m:%$(strip $2)=%$(s)))))))
187endef187endef
188 188
189ifdef REGENERATE_PARSERS
190
191# LEX189# LEX
192# ---------------------------------------------------------------------------190# ---------------------------------------------------------------------------
193LEX_PREFIX = $(if $(LEX_PREFIX_${baseprereq}),$(LEX_PREFIX_${baseprereq}),yy)191LEX_PREFIX = $(if $(LEX_PREFIX_${baseprereq}),$(LEX_PREFIX_${baseprereq}),yy)
@@ -195,9 +193,15 @@ LEX_PREFIX = $(if $(LEX_PREFIX_${baseprereq}),$(LEX_PREFIX_${baseprereq}),yy) · 1 unmodified line
195quiet_cmd_flex = LEX $@193quiet_cmd_flex = LEX $@
196 cmd_flex = $(LEX) -o$@ -L -P $(LEX_PREFIX) $<194 cmd_flex = $(LEX) -o$@ -L -P $(LEX_PREFIX) $<
197 195
196ifdef REGENERATE_PARSERS
198.PRECIOUS: $(src)/%.lex.c_shipped197.PRECIOUS: $(src)/%.lex.c_shipped
199$(src)/%.lex.c_shipped: $(src)/%.l198$(src)/%.lex.c_shipped: $(src)/%.l
200 $(call cmd,flex)199 $(call cmd,flex)
200endif
201
202.PRECIOUS: $(obj)/%.lex.c
203$(filter %.lex.c,$(targets)): $(obj)/%.lex.c: $(src)/%.l FORCE
204 $(call if_changed,flex)
201 205
202# YACC206# YACC
203# ---------------------------------------------------------------------------207# ---------------------------------------------------------------------------
@@ -206,19 +210,29 @@ YACC_PREFIX = $(if $(YACC_PREFIX_${baseprereq}),$(YACC_PREFIX_${baseprereq}),yy) · 2 unmodified lines
206quiet_cmd_bison = YACC $@210quiet_cmd_bison = YACC $@
207 cmd_bison = $(YACC) -o$@ -t -l -p $(YACC_PREFIX) $<211 cmd_bison = $(YACC) -o$@ -t -l -p $(YACC_PREFIX) $<
208 212
213ifdef REGENERATE_PARSERS
209.PRECIOUS: $(src)/%.tab.c_shipped214.PRECIOUS: $(src)/%.tab.c_shipped
210$(src)/%.tab.c_shipped: $(src)/%.y215$(src)/%.tab.c_shipped: $(src)/%.y
211 $(call cmd,bison)216 $(call cmd,bison)
217endif
218
219.PRECIOUS: $(obj)/%.tab.c
220$(filter %.tab.c,$(targets)): $(obj)/%.tab.c: $(src)/%.y FORCE
221 $(call if_changed,bison)
212 222
213quiet_cmd_bison_h = YACC $@223quiet_cmd_bison_h = YACC $@
214 cmd_bison_h = bison -o/dev/null --defines=$@ -t -l -p $(YACC_PREFIX) $<224 cmd_bison_h = bison -o/dev/null --defines=$@ -t -l -p $(YACC_PREFIX) $<
215 225
226ifdef REGENERATE_PARSERS
216.PRECIOUS: $(src)/%.tab.h_shipped227.PRECIOUS: $(src)/%.tab.h_shipped
217$(src)/%.tab.h_shipped: $(src)/%.y228$(src)/%.tab.h_shipped: $(src)/%.y
218 $(call cmd,bison_h)229 $(call cmd,bison_h)
219
220endif230endif
221 231
232.PRECIOUS: $(obj)/%.tab.h
233$(filter %.tab.h,$(targets)): $(obj)/%.tab.h: $(src)/%.y FORCE
234 $(call if_changed,bison_h)
235
222# Shipped files236# Shipped files
223# ===========================================================================237# ===========================================================================
224 238

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t