aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMasahiro Yamada <yamada.masahiro@socionext.com>2019-07-20 12:27:39 -0400
committerMasahiro Yamada <yamada.masahiro@socionext.com>2019-08-13 12:10:42 -0400
commit6ba7dc6616ce69ef667204df29597767c1c9ebcf (patch)
tree728b95152c9dbd98b45f4562c9aa2ddd35e57793
parent49d5089d926c2bf0c76410bf32e5c48b296ec6f6 (diff)
kbuild: make bison create C file and header in a single pattern rule
We generally expect bison to create not only a C file, but also a header, which will be included from the lexer. Currently, Kbuild generates them in separate rules. So, for instance, when building Kconfig, you will notice bison is invoked twice: HOSTCC scripts/kconfig/conf.o HOSTCC scripts/kconfig/confdata.o HOSTCC scripts/kconfig/expr.o LEX scripts/kconfig/lexer.lex.c YACC scripts/kconfig/parser.tab.h HOSTCC scripts/kconfig/lexer.lex.o YACC scripts/kconfig/parser.tab.c HOSTCC scripts/kconfig/parser.tab.o HOSTCC scripts/kconfig/preprocess.o HOSTCC scripts/kconfig/symbol.o HOSTLD scripts/kconfig/conf Make handles such cases nicely in pattern rules [1]. Merge the two rules so that one invokcation of bison can generate both of them. HOSTCC scripts/kconfig/conf.o HOSTCC scripts/kconfig/confdata.o HOSTCC scripts/kconfig/expr.o LEX scripts/kconfig/lexer.lex.c YACC scripts/kconfig/parser.tab.[ch] HOSTCC scripts/kconfig/lexer.lex.o HOSTCC scripts/kconfig/parser.tab.o HOSTCC scripts/kconfig/preprocess.o HOSTCC scripts/kconfig/symbol.o HOSTLD scripts/kconfig/conf [1] Pattern rule GNU Make manual says: "Pattern rules may have more than one target. Unlike normal rules, this does not act as many different rules with the same prerequisites and recipe. If a pattern rule has multiple targets, make knows that the rule's recipe is responsible for making all of the targets. The recipe is executed only once to make all the targets. When searching for a pattern rule to match a target, the target patterns of a rule other than the one that matches the target in need of a rule are incidental: make worries only about giving a recipe and prerequisites to the file presently in question. However, when this file's recipe is run, the other targets are marked as having been updated themselves." https://www.gnu.org/software/make/manual/html_node/Pattern-Intro.html Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
-rw-r--r--scripts/Makefile.lib12
-rw-r--r--scripts/genksyms/Makefile9
2 files changed, 4 insertions, 17 deletions
diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
index 41c50f9461e5..67d1165ab2ab 100644
--- a/scripts/Makefile.lib
+++ b/scripts/Makefile.lib
@@ -197,18 +197,12 @@ $(obj)/%.lex.c: $(src)/%.l FORCE
197 197
198# YACC 198# YACC
199# --------------------------------------------------------------------------- 199# ---------------------------------------------------------------------------
200quiet_cmd_bison = YACC $@ 200quiet_cmd_bison = YACC $(basename $@).[ch]
201 cmd_bison = $(YACC) -o$@ -t -l $< 201 cmd_bison = $(YACC) -o $(basename $@).c --defines=$(basename $@).h -t -l $<
202 202
203$(obj)/%.tab.c: $(src)/%.y FORCE 203$(obj)/%.tab.c $(obj)/%.tab.h: $(src)/%.y FORCE
204 $(call if_changed,bison) 204 $(call if_changed,bison)
205 205
206quiet_cmd_bison_h = YACC $@
207 cmd_bison_h = $(YACC) -o/dev/null --defines=$@ -t -l $<
208
209$(obj)/%.tab.h: $(src)/%.y FORCE
210 $(call if_changed,bison_h)
211
212# Shipped files 206# Shipped files
213# =========================================================================== 207# ===========================================================================
214 208
diff --git a/scripts/genksyms/Makefile b/scripts/genksyms/Makefile
index 66c314bc5933..baf44ed0a93a 100644
--- a/scripts/genksyms/Makefile
+++ b/scripts/genksyms/Makefile
@@ -18,16 +18,9 @@ quiet_cmd_bison_no_warn = $(quiet_cmd_bison)
18 cmd_bison_no_warn = $(YACC) --version >/dev/null; \ 18 cmd_bison_no_warn = $(YACC) --version >/dev/null; \
19 $(cmd_bison) 2>/dev/null 19 $(cmd_bison) 2>/dev/null
20 20
21$(obj)/parse.tab.c: $(src)/parse.y FORCE 21$(obj)/pars%.tab.c $(obj)/pars%.tab.h: $(src)/pars%.y FORCE
22 $(call if_changed,bison_no_warn) 22 $(call if_changed,bison_no_warn)
23 23
24quiet_cmd_bison_h_no_warn = $(quiet_cmd_bison_h)
25 cmd_bison_h_no_warn = $(YACC) --version >/dev/null; \
26 $(cmd_bison_h) 2>/dev/null
27
28$(obj)/parse.tab.h: $(src)/parse.y FORCE
29 $(call if_changed,bison_h_no_warn)
30
31endif 24endif
32 25
33# -I needed for generated C source (shipped source) 26# -I needed for generated C source (shipped source)