kbuild: add %.lex.c and %.tab.[ch] to 'targets' automatically
authorMasahiro Yamada <yamada.masahiro@socionext.com>
Fri, 23 Mar 2018 13:04:33 +0000 (22:04 +0900)
committerMasahiro Yamada <yamada.masahiro@socionext.com>
Sat, 7 Apr 2018 10:04:02 +0000 (19:04 +0900)
Files generated by if_changed* must be added to 'targets' to include
*.cmd files.  Otherwise, they would be regenerated every time.

The build system automatically adds objects to 'targets' where
appropriate, such as obj-y, extra-y, etc. but does nothing for
intermediate files.  So, each Makefile needs to add them by itself.

There are some common cases where objects are generated by chained
rules.  Lexers and parsers are compiled like follows:

   %.lex.o <- %.lex.c <- %.l
   %.tab.o <- %.tab.c <- %.y

They are common patterns, so it is reasonable to take care of them
in the core Makefile instead of requiring each Makefile to do so.

At this moment, you cannot delete 'target += zconf.lex.c' in the
Kconfig Makefile because zconf.lex.c is included from zconf.tab.c
instead of being compiled separately.  It should be deleted after
Kconfig is more refactored.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Acked-by: Frank Rowand <frowand.list@gmail.com>
scripts/Makefile.build
scripts/dtc/Makefile
scripts/genksyms/Makefile
scripts/kconfig/Makefile

index 77cce68..36f7990 100644 (file)
@@ -538,6 +538,17 @@ $(call multi_depend, $(multi-used-m), .o, -objs -y -m)
 targets += $(multi-used-m)
 targets := $(filter-out $(PHONY), $(targets))
 
+# Add intermediate targets:
+# When building objects with specific suffix patterns, add intermediate
+# targets that the final targets are derived from.
+intermediate_targets = $(foreach sfx, $(2), \
+                               $(patsubst %$(strip $(1)),%$(sfx), \
+                                       $(filter %$(strip $(1)), $(targets))))
+# %.lex.o <- %.lex.c <- %.l
+# %.tab.o <- %.tab.[ch] <- %.y
+targets += $(call intermediate_targets, .lex.o, .lex.c) \
+          $(call intermediate_targets, .tab.o, .tab.c .tab.h)
+
 # Descending
 # ---------------------------------------------------------------------------
 
index d17ba64..9cac65b 100644 (file)
@@ -27,6 +27,3 @@ HOSTCFLAGS_dtc-parser.tab.o := $(HOSTCFLAGS_DTC)
 
 # dependencies on generated files need to be listed explicitly
 $(obj)/dtc-lexer.lex.o: $(obj)/dtc-parser.tab.h
-
-# generated files need to include *.cmd
-targets := dtc-lexer.lex.c dtc-parser.tab.c dtc-parser.tab.h
index a9565eb..ef0287e 100644 (file)
@@ -36,5 +36,3 @@ HOSTCFLAGS_lex.lex.o := -I$(src)
 
 # dependencies on generated files need to be listed explicitly
 $(obj)/lex.lex.o: $(obj)/parse.tab.h
-
-targets := lex.lex.c parse.tab.c parse.tab.h
index 1dcd797..5def877 100644 (file)
@@ -207,7 +207,7 @@ gconf-objs  := gconf.o zconf.tab.o
 
 hostprogs-y := conf nconf mconf kxgettext qconf gconf
 
-targets                += zconf.tab.c zconf.lex.c
+targets                += zconf.lex.c
 clean-files    := qconf.moc .tmp_qtcheck .tmp_gtkcheck
 clean-files    += gconf.glade.h
 clean-files     += config.pot linux.pot