hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/scripts/Makefile.host
....@@ -1,4 +1,21 @@
11 # SPDX-License-Identifier: GPL-2.0
2
+
3
+# LEX
4
+# ---------------------------------------------------------------------------
5
+quiet_cmd_flex = LEX $@
6
+ cmd_flex = $(LEX) -o$@ -L $<
7
+
8
+$(obj)/%.lex.c: $(src)/%.l FORCE
9
+ $(call if_changed,flex)
10
+
11
+# YACC
12
+# ---------------------------------------------------------------------------
13
+quiet_cmd_bison = YACC $(basename $@).[ch]
14
+ cmd_bison = $(YACC) -o $(basename $@).c --defines=$(basename $@).h -t -l $<
15
+
16
+$(obj)/%.tab.c $(obj)/%.tab.h: $(src)/%.y FORCE
17
+ $(call if_changed,bison)
18
+
219 # ==========================================================================
320 # Building binaries on the host system
421 # Binaries are used during the compilation of the kernel, for example
....@@ -6,77 +23,65 @@
623 #
724 # Both C and C++ are supported, but preferred language is C for such utilities.
825 #
9
-# Sample syntax (see Documentation/kbuild/makefiles.txt for reference)
10
-# hostprogs-y := bin2hex
26
+# Sample syntax (see Documentation/kbuild/makefiles.rst for reference)
27
+# hostprogs := bin2hex
1128 # Will compile bin2hex.c and create an executable named bin2hex
1229 #
13
-# hostprogs-y := lxdialog
30
+# hostprogs := lxdialog
1431 # lxdialog-objs := checklist.o lxdialog.o
1532 # Will compile lxdialog.c and checklist.c, and then link the executable
1633 # lxdialog, based on checklist.o and lxdialog.o
1734 #
18
-# hostprogs-y := qconf
35
+# hostprogs := qconf
1936 # qconf-cxxobjs := qconf.o
2037 # qconf-objs := menu.o
2138 # Will compile qconf as a C++ program, and menu as a C program.
2239 # They are linked as C++ code to the executable qconf
2340
24
-__hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
25
-host-cshlib := $(sort $(hostlibs-y) $(hostlibs-m))
26
-host-cxxshlib := $(sort $(hostcxxlibs-y) $(hostcxxlibs-m))
27
-
2841 # C code
2942 # Executables compiled from a single .c file
30
-host-csingle := $(foreach m,$(__hostprogs), \
43
+host-csingle := $(foreach m,$(hostprogs), \
3144 $(if $($(m)-objs)$($(m)-cxxobjs),,$(m)))
3245
3346 # C executables linked based on several .o files
34
-host-cmulti := $(foreach m,$(__hostprogs),\
47
+host-cmulti := $(foreach m,$(hostprogs),\
3548 $(if $($(m)-cxxobjs),,$(if $($(m)-objs),$(m))))
3649
3750 # Object (.o) files compiled from .c files
38
-host-cobjs := $(sort $(foreach m,$(__hostprogs),$($(m)-objs)))
51
+host-cobjs := $(sort $(foreach m,$(hostprogs),$($(m)-objs)))
3952
4053 # C++ code
4154 # C++ executables compiled from at least one .cc file
4255 # and zero or more .c files
43
-host-cxxmulti := $(foreach m,$(__hostprogs),$(if $($(m)-cxxobjs),$(m)))
56
+host-cxxmulti := $(foreach m,$(hostprogs),$(if $($(m)-cxxobjs),$(m)))
4457
4558 # C++ Object (.o) files compiled from .cc files
4659 host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
47
-
48
-# Object (.o) files used by the shared libaries
49
-host-cshobjs := $(sort $(foreach m,$(host-cshlib),$($(m:.so=-objs))))
50
-host-cxxshobjs := $(sort $(foreach m,$(host-cxxshlib),$($(m:.so=-objs))))
5160
5261 host-csingle := $(addprefix $(obj)/,$(host-csingle))
5362 host-cmulti := $(addprefix $(obj)/,$(host-cmulti))
5463 host-cobjs := $(addprefix $(obj)/,$(host-cobjs))
5564 host-cxxmulti := $(addprefix $(obj)/,$(host-cxxmulti))
5665 host-cxxobjs := $(addprefix $(obj)/,$(host-cxxobjs))
57
-host-cshlib := $(addprefix $(obj)/,$(host-cshlib))
58
-host-cxxshlib := $(addprefix $(obj)/,$(host-cxxshlib))
59
-host-cshobjs := $(addprefix $(obj)/,$(host-cshobjs))
60
-host-cxxshobjs := $(addprefix $(obj)/,$(host-cxxshobjs))
6166
6267 #####
6368 # Handle options to gcc. Support building with separate output directory
6469
6570 _hostc_flags = $(KBUILD_HOSTCFLAGS) $(HOST_EXTRACFLAGS) \
66
- $(HOSTCFLAGS_$(basetarget).o)
71
+ $(HOSTCFLAGS_$(target-stem).o)
6772 _hostcxx_flags = $(KBUILD_HOSTCXXFLAGS) $(HOST_EXTRACXXFLAGS) \
68
- $(HOSTCXXFLAGS_$(basetarget).o)
73
+ $(HOSTCXXFLAGS_$(target-stem).o)
6974
70
-ifeq ($(KBUILD_SRC),)
71
-__hostc_flags = $(_hostc_flags)
72
-__hostcxx_flags = $(_hostcxx_flags)
73
-else
74
-__hostc_flags = -I$(obj) $(call flags,_hostc_flags)
75
-__hostcxx_flags = -I$(obj) $(call flags,_hostcxx_flags)
75
+# $(objtree)/$(obj) for including generated headers from checkin source files
76
+ifeq ($(KBUILD_EXTMOD),)
77
+ifdef building_out_of_srctree
78
+_hostc_flags += -I $(objtree)/$(obj)
79
+_hostcxx_flags += -I $(objtree)/$(obj)
80
+endif
7681 endif
7782
78
-hostc_flags = -Wp,-MD,$(depfile) $(__hostc_flags)
79
-hostcxx_flags = -Wp,-MD,$(depfile) $(__hostcxx_flags)
83
+hostc_flags = -Wp,-MMD,$(depfile) $(_hostc_flags)
84
+hostcxx_flags = -Wp,-MMD,$(depfile) $(_hostcxx_flags)
8085
8186 #####
8287 # Compile programs on the host
....@@ -85,7 +90,7 @@
8590 # host-csingle -> Executable
8691 quiet_cmd_host-csingle = HOSTCC $@
8792 cmd_host-csingle = $(HOSTCC) $(hostc_flags) $(KBUILD_HOSTLDFLAGS) -o $@ $< \
88
- $(KBUILD_HOSTLDLIBS) $(HOSTLDLIBS_$(@F))
93
+ $(KBUILD_HOSTLDLIBS) $(HOSTLDLIBS_$(target-stem))
8994 $(host-csingle): $(obj)/%: $(src)/%.c FORCE
9095 $(call if_changed_dep,host-csingle)
9196
....@@ -93,8 +98,8 @@
9398 # host-cmulti -> executable
9499 quiet_cmd_host-cmulti = HOSTLD $@
95100 cmd_host-cmulti = $(HOSTCC) $(KBUILD_HOSTLDFLAGS) -o $@ \
96
- $(addprefix $(obj)/,$($(@F)-objs)) \
97
- $(KBUILD_HOSTLDLIBS) $(HOSTLDLIBS_$(@F))
101
+ $(addprefix $(obj)/, $($(target-stem)-objs)) \
102
+ $(KBUILD_HOSTLDLIBS) $(HOSTLDLIBS_$(target-stem))
98103 $(host-cmulti): FORCE
99104 $(call if_changed,host-cmulti)
100105 $(call multi_depend, $(host-cmulti), , -objs)
....@@ -111,8 +116,8 @@
111116 quiet_cmd_host-cxxmulti = HOSTLD $@
112117 cmd_host-cxxmulti = $(HOSTCXX) $(KBUILD_HOSTLDFLAGS) -o $@ \
113118 $(foreach o,objs cxxobjs,\
114
- $(addprefix $(obj)/,$($(@F)-$(o)))) \
115
- $(KBUILD_HOSTLDLIBS) $(HOSTLDLIBS_$(@F))
119
+ $(addprefix $(obj)/, $($(target-stem)-$(o)))) \
120
+ $(KBUILD_HOSTLDLIBS) $(HOSTLDLIBS_$(target-stem))
116121 $(host-cxxmulti): FORCE
117122 $(call if_changed,host-cxxmulti)
118123 $(call multi_depend, $(host-cxxmulti), , -objs -cxxobjs)
....@@ -123,42 +128,5 @@
123128 $(host-cxxobjs): $(obj)/%.o: $(src)/%.cc FORCE
124129 $(call if_changed_dep,host-cxxobjs)
125130
126
-# Compile .c file, create position independent .o file
127
-# host-cshobjs -> .o
128
-quiet_cmd_host-cshobjs = HOSTCC -fPIC $@
129
- cmd_host-cshobjs = $(HOSTCC) $(hostc_flags) -fPIC -c -o $@ $<
130
-$(host-cshobjs): $(obj)/%.o: $(src)/%.c FORCE
131
- $(call if_changed_dep,host-cshobjs)
132
-
133
-# Compile .c file, create position independent .o file
134
-# Note that plugin capable gcc versions can be either C or C++ based
135
-# therefore plugin source files have to be compilable in both C and C++ mode.
136
-# This is why a C++ compiler is invoked on a .c file.
137
-# host-cxxshobjs -> .o
138
-quiet_cmd_host-cxxshobjs = HOSTCXX -fPIC $@
139
- cmd_host-cxxshobjs = $(HOSTCXX) $(hostcxx_flags) -fPIC -c -o $@ $<
140
-$(host-cxxshobjs): $(obj)/%.o: $(src)/%.c FORCE
141
- $(call if_changed_dep,host-cxxshobjs)
142
-
143
-# Link a shared library, based on position independent .o files
144
-# *.o -> .so shared library (host-cshlib)
145
-quiet_cmd_host-cshlib = HOSTLLD -shared $@
146
- cmd_host-cshlib = $(HOSTCC) $(KBUILD_HOSTLDFLAGS) -shared -o $@ \
147
- $(addprefix $(obj)/,$($(@F:.so=-objs))) \
148
- $(KBUILD_HOSTLDLIBS) $(HOSTLDLIBS_$(@F))
149
-$(host-cshlib): FORCE
150
- $(call if_changed,host-cshlib)
151
-$(call multi_depend, $(host-cshlib), .so, -objs)
152
-
153
-# Link a shared library, based on position independent .o files
154
-# *.o -> .so shared library (host-cxxshlib)
155
-quiet_cmd_host-cxxshlib = HOSTLLD -shared $@
156
- cmd_host-cxxshlib = $(HOSTCXX) $(KBUILD_HOSTLDFLAGS) -shared -o $@ \
157
- $(addprefix $(obj)/,$($(@F:.so=-objs))) \
158
- $(KBUILD_HOSTLDLIBS) $(HOSTLDLIBS_$(@F))
159
-$(host-cxxshlib): FORCE
160
- $(call if_changed,host-cxxshlib)
161
-$(call multi_depend, $(host-cxxshlib), .so, -objs)
162
-
163
-targets += $(host-csingle) $(host-cmulti) $(host-cobjs)\
164
- $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs) $(host-cxxshlib) $(host-cxxshobjs)
131
+targets += $(host-csingle) $(host-cmulti) $(host-cobjs) \
132
+ $(host-cxxmulti) $(host-cxxobjs)