Back to home page

OSCL-LXR

 
 

    


0001 # SPDX-License-Identifier: GPL-2.0
0002 
0003 # LEX
0004 # ---------------------------------------------------------------------------
0005 quiet_cmd_flex = LEX     $@
0006       cmd_flex = $(LEX) -o$@ -L $<
0007 
0008 $(obj)/%.lex.c: $(src)/%.l FORCE
0009         $(call if_changed,flex)
0010 
0011 # YACC
0012 # ---------------------------------------------------------------------------
0013 quiet_cmd_bison = YACC    $(basename $@).[ch]
0014       cmd_bison = $(YACC) -o $(basename $@).c --defines=$(basename $@).h -t -l $<
0015 
0016 $(obj)/%.tab.c $(obj)/%.tab.h: $(src)/%.y FORCE
0017         $(call if_changed,bison)
0018 
0019 # ==========================================================================
0020 # Building binaries on the host system
0021 # Binaries are used during the compilation of the kernel, for example
0022 # to preprocess a data file.
0023 #
0024 # Both C and C++ are supported, but preferred language is C for such utilities.
0025 #
0026 # Sample syntax (see Documentation/kbuild/makefiles.rst for reference)
0027 # hostprogs := bin2hex
0028 # Will compile bin2hex.c and create an executable named bin2hex
0029 #
0030 # hostprogs     := lxdialog
0031 # lxdialog-objs := checklist.o lxdialog.o
0032 # Will compile lxdialog.c and checklist.c, and then link the executable
0033 # lxdialog, based on checklist.o and lxdialog.o
0034 #
0035 # hostprogs       := qconf
0036 # qconf-cxxobjs   := qconf.o
0037 # qconf-objs      := menu.o
0038 # Will compile qconf as a C++ program, and menu as a C program.
0039 # They are linked as C++ code to the executable qconf
0040 
0041 # C code
0042 # Executables compiled from a single .c file
0043 host-csingle    := $(foreach m,$(hostprogs), \
0044                         $(if $($(m)-objs)$($(m)-cxxobjs),,$(m)))
0045 
0046 # C executables linked based on several .o files
0047 host-cmulti     := $(foreach m,$(hostprogs),\
0048                    $(if $($(m)-cxxobjs),,$(if $($(m)-objs),$(m))))
0049 
0050 # Object (.o) files compiled from .c files
0051 host-cobjs      := $(sort $(foreach m,$(hostprogs),$($(m)-objs)))
0052 
0053 # C++ code
0054 # C++ executables compiled from at least one .cc file
0055 # and zero or more .c files
0056 host-cxxmulti   := $(foreach m,$(hostprogs),$(if $($(m)-cxxobjs),$(m)))
0057 
0058 # C++ Object (.o) files compiled from .cc files
0059 host-cxxobjs    := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
0060 
0061 host-csingle    := $(addprefix $(obj)/,$(host-csingle))
0062 host-cmulti     := $(addprefix $(obj)/,$(host-cmulti))
0063 host-cobjs      := $(addprefix $(obj)/,$(host-cobjs))
0064 host-cxxmulti   := $(addprefix $(obj)/,$(host-cxxmulti))
0065 host-cxxobjs    := $(addprefix $(obj)/,$(host-cxxobjs))
0066 
0067 #####
0068 # Handle options to gcc. Support building with separate output directory
0069 
0070 _hostc_flags   = $(KBUILD_HOSTCFLAGS)   $(HOST_EXTRACFLAGS)   \
0071                  $(HOSTCFLAGS_$(target-stem).o)
0072 _hostcxx_flags = $(KBUILD_HOSTCXXFLAGS) $(HOST_EXTRACXXFLAGS) \
0073                  $(HOSTCXXFLAGS_$(target-stem).o)
0074 
0075 # $(objtree)/$(obj) for including generated headers from checkin source files
0076 ifeq ($(KBUILD_EXTMOD),)
0077 ifdef building_out_of_srctree
0078 _hostc_flags   += -I $(objtree)/$(obj)
0079 _hostcxx_flags += -I $(objtree)/$(obj)
0080 endif
0081 endif
0082 
0083 hostc_flags    = -Wp,-MMD,$(depfile) $(_hostc_flags)
0084 hostcxx_flags  = -Wp,-MMD,$(depfile) $(_hostcxx_flags)
0085 
0086 #####
0087 # Compile programs on the host
0088 
0089 # Create executable from a single .c file
0090 # host-csingle -> Executable
0091 quiet_cmd_host-csingle  = HOSTCC  $@
0092       cmd_host-csingle  = $(HOSTCC) $(hostc_flags) $(KBUILD_HOSTLDFLAGS) -o $@ $< \
0093                 $(KBUILD_HOSTLDLIBS) $(HOSTLDLIBS_$(target-stem))
0094 $(host-csingle): $(obj)/%: $(src)/%.c FORCE
0095         $(call if_changed_dep,host-csingle)
0096 
0097 # Link an executable based on list of .o files, all plain c
0098 # host-cmulti -> executable
0099 quiet_cmd_host-cmulti   = HOSTLD  $@
0100       cmd_host-cmulti   = $(HOSTCC) $(KBUILD_HOSTLDFLAGS) -o $@ \
0101                           $(addprefix $(obj)/, $($(target-stem)-objs)) \
0102                           $(KBUILD_HOSTLDLIBS) $(HOSTLDLIBS_$(target-stem))
0103 $(host-cmulti): FORCE
0104         $(call if_changed,host-cmulti)
0105 $(call multi_depend, $(host-cmulti), , -objs)
0106 
0107 # Create .o file from a single .c file
0108 # host-cobjs -> .o
0109 quiet_cmd_host-cobjs    = HOSTCC  $@
0110       cmd_host-cobjs    = $(HOSTCC) $(hostc_flags) -c -o $@ $<
0111 $(host-cobjs): $(obj)/%.o: $(src)/%.c FORCE
0112         $(call if_changed_dep,host-cobjs)
0113 
0114 # Link an executable based on list of .o files, a mixture of .c and .cc
0115 # host-cxxmulti -> executable
0116 quiet_cmd_host-cxxmulti = HOSTLD  $@
0117       cmd_host-cxxmulti = $(HOSTCXX) $(KBUILD_HOSTLDFLAGS) -o $@ \
0118                           $(foreach o,objs cxxobjs,\
0119                           $(addprefix $(obj)/, $($(target-stem)-$(o)))) \
0120                           $(KBUILD_HOSTLDLIBS) $(HOSTLDLIBS_$(target-stem))
0121 $(host-cxxmulti): FORCE
0122         $(call if_changed,host-cxxmulti)
0123 $(call multi_depend, $(host-cxxmulti), , -objs -cxxobjs)
0124 
0125 # Create .o file from a single .cc (C++) file
0126 quiet_cmd_host-cxxobjs  = HOSTCXX $@
0127       cmd_host-cxxobjs  = $(HOSTCXX) $(hostcxx_flags) -c -o $@ $<
0128 $(host-cxxobjs): $(obj)/%.o: $(src)/%.cc FORCE
0129         $(call if_changed_dep,host-cxxobjs)
0130 
0131 targets += $(host-csingle) $(host-cmulti) $(host-cobjs) \
0132            $(host-cxxmulti) $(host-cxxobjs)