| .. | .. |
|---|
| 1 | 1 | # 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 | + |
|---|
| 2 | 19 | # ========================================================================== |
|---|
| 3 | 20 | # Building binaries on the host system |
|---|
| 4 | 21 | # Binaries are used during the compilation of the kernel, for example |
|---|
| .. | .. |
|---|
| 6 | 23 | # |
|---|
| 7 | 24 | # Both C and C++ are supported, but preferred language is C for such utilities. |
|---|
| 8 | 25 | # |
|---|
| 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 |
|---|
| 11 | 28 | # Will compile bin2hex.c and create an executable named bin2hex |
|---|
| 12 | 29 | # |
|---|
| 13 | | -# hostprogs-y := lxdialog |
|---|
| 30 | +# hostprogs := lxdialog |
|---|
| 14 | 31 | # lxdialog-objs := checklist.o lxdialog.o |
|---|
| 15 | 32 | # Will compile lxdialog.c and checklist.c, and then link the executable |
|---|
| 16 | 33 | # lxdialog, based on checklist.o and lxdialog.o |
|---|
| 17 | 34 | # |
|---|
| 18 | | -# hostprogs-y := qconf |
|---|
| 35 | +# hostprogs := qconf |
|---|
| 19 | 36 | # qconf-cxxobjs := qconf.o |
|---|
| 20 | 37 | # qconf-objs := menu.o |
|---|
| 21 | 38 | # Will compile qconf as a C++ program, and menu as a C program. |
|---|
| 22 | 39 | # They are linked as C++ code to the executable qconf |
|---|
| 23 | 40 | |
|---|
| 24 | | -__hostprogs := $(sort $(hostprogs-y) $(hostprogs-m)) |
|---|
| 25 | | -host-cshlib := $(sort $(hostlibs-y) $(hostlibs-m)) |
|---|
| 26 | | -host-cxxshlib := $(sort $(hostcxxlibs-y) $(hostcxxlibs-m)) |
|---|
| 27 | | - |
|---|
| 28 | 41 | # C code |
|---|
| 29 | 42 | # Executables compiled from a single .c file |
|---|
| 30 | | -host-csingle := $(foreach m,$(__hostprogs), \ |
|---|
| 43 | +host-csingle := $(foreach m,$(hostprogs), \ |
|---|
| 31 | 44 | $(if $($(m)-objs)$($(m)-cxxobjs),,$(m))) |
|---|
| 32 | 45 | |
|---|
| 33 | 46 | # C executables linked based on several .o files |
|---|
| 34 | | -host-cmulti := $(foreach m,$(__hostprogs),\ |
|---|
| 47 | +host-cmulti := $(foreach m,$(hostprogs),\ |
|---|
| 35 | 48 | $(if $($(m)-cxxobjs),,$(if $($(m)-objs),$(m)))) |
|---|
| 36 | 49 | |
|---|
| 37 | 50 | # 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))) |
|---|
| 39 | 52 | |
|---|
| 40 | 53 | # C++ code |
|---|
| 41 | 54 | # C++ executables compiled from at least one .cc file |
|---|
| 42 | 55 | # 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))) |
|---|
| 44 | 57 | |
|---|
| 45 | 58 | # C++ Object (.o) files compiled from .cc files |
|---|
| 46 | 59 | 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)))) |
|---|
| 51 | 60 | |
|---|
| 52 | 61 | host-csingle := $(addprefix $(obj)/,$(host-csingle)) |
|---|
| 53 | 62 | host-cmulti := $(addprefix $(obj)/,$(host-cmulti)) |
|---|
| 54 | 63 | host-cobjs := $(addprefix $(obj)/,$(host-cobjs)) |
|---|
| 55 | 64 | host-cxxmulti := $(addprefix $(obj)/,$(host-cxxmulti)) |
|---|
| 56 | 65 | 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)) |
|---|
| 61 | 66 | |
|---|
| 62 | 67 | ##### |
|---|
| 63 | 68 | # Handle options to gcc. Support building with separate output directory |
|---|
| 64 | 69 | |
|---|
| 65 | 70 | _hostc_flags = $(KBUILD_HOSTCFLAGS) $(HOST_EXTRACFLAGS) \ |
|---|
| 66 | | - $(HOSTCFLAGS_$(basetarget).o) |
|---|
| 71 | + $(HOSTCFLAGS_$(target-stem).o) |
|---|
| 67 | 72 | _hostcxx_flags = $(KBUILD_HOSTCXXFLAGS) $(HOST_EXTRACXXFLAGS) \ |
|---|
| 68 | | - $(HOSTCXXFLAGS_$(basetarget).o) |
|---|
| 73 | + $(HOSTCXXFLAGS_$(target-stem).o) |
|---|
| 69 | 74 | |
|---|
| 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 |
|---|
| 76 | 81 | endif |
|---|
| 77 | 82 | |
|---|
| 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) |
|---|
| 80 | 85 | |
|---|
| 81 | 86 | ##### |
|---|
| 82 | 87 | # Compile programs on the host |
|---|
| .. | .. |
|---|
| 85 | 90 | # host-csingle -> Executable |
|---|
| 86 | 91 | quiet_cmd_host-csingle = HOSTCC $@ |
|---|
| 87 | 92 | cmd_host-csingle = $(HOSTCC) $(hostc_flags) $(KBUILD_HOSTLDFLAGS) -o $@ $< \ |
|---|
| 88 | | - $(KBUILD_HOSTLDLIBS) $(HOSTLDLIBS_$(@F)) |
|---|
| 93 | + $(KBUILD_HOSTLDLIBS) $(HOSTLDLIBS_$(target-stem)) |
|---|
| 89 | 94 | $(host-csingle): $(obj)/%: $(src)/%.c FORCE |
|---|
| 90 | 95 | $(call if_changed_dep,host-csingle) |
|---|
| 91 | 96 | |
|---|
| .. | .. |
|---|
| 93 | 98 | # host-cmulti -> executable |
|---|
| 94 | 99 | quiet_cmd_host-cmulti = HOSTLD $@ |
|---|
| 95 | 100 | 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)) |
|---|
| 98 | 103 | $(host-cmulti): FORCE |
|---|
| 99 | 104 | $(call if_changed,host-cmulti) |
|---|
| 100 | 105 | $(call multi_depend, $(host-cmulti), , -objs) |
|---|
| .. | .. |
|---|
| 111 | 116 | quiet_cmd_host-cxxmulti = HOSTLD $@ |
|---|
| 112 | 117 | cmd_host-cxxmulti = $(HOSTCXX) $(KBUILD_HOSTLDFLAGS) -o $@ \ |
|---|
| 113 | 118 | $(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)) |
|---|
| 116 | 121 | $(host-cxxmulti): FORCE |
|---|
| 117 | 122 | $(call if_changed,host-cxxmulti) |
|---|
| 118 | 123 | $(call multi_depend, $(host-cxxmulti), , -objs -cxxobjs) |
|---|
| .. | .. |
|---|
| 123 | 128 | $(host-cxxobjs): $(obj)/%.o: $(src)/%.cc FORCE |
|---|
| 124 | 129 | $(call if_changed_dep,host-cxxobjs) |
|---|
| 125 | 130 | |
|---|
| 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) |
|---|