Back to home page

LXR

 
 

    


0001 # ==========================================================================
0002 # Building binaries on the host system
0003 # Binaries are used during the compilation of the kernel, for example
0004 # to preprocess a data file.
0005 #
0006 # Both C and C++ are supported, but preferred language is C for such utilities.
0007 #
0008 # Sample syntax (see Documentation/kbuild/makefiles.txt for reference)
0009 # hostprogs-y := bin2hex
0010 # Will compile bin2hex.c and create an executable named bin2hex
0011 #
0012 # hostprogs-y    := lxdialog
0013 # lxdialog-objs := checklist.o lxdialog.o
0014 # Will compile lxdialog.c and checklist.c, and then link the executable
0015 # lxdialog, based on checklist.o and lxdialog.o
0016 #
0017 # hostprogs-y      := qconf
0018 # qconf-cxxobjs   := qconf.o
0019 # qconf-objs      := menu.o
0020 # Will compile qconf as a C++ program, and menu as a C program.
0021 # They are linked as C++ code to the executable qconf
0022 
0023 # hostcc-option
0024 # Usage: cflags-y += $(call hostcc-option,-march=winchip-c6,-march=i586)
0025 
0026 hostcc-option = $(call try-run,\
0027         $(HOSTCC) $(HOSTCFLAGS) $(HOST_EXTRACFLAGS) $(1) -c -x c /dev/null -o "$$TMP",$(1),$(2))
0028 
0029 __hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
0030 host-cshlib := $(sort $(hostlibs-y) $(hostlibs-m))
0031 host-cxxshlib := $(sort $(hostcxxlibs-y) $(hostcxxlibs-m))
0032 
0033 # C code
0034 # Executables compiled from a single .c file
0035 host-csingle    := $(foreach m,$(__hostprogs), \
0036                         $(if $($(m)-objs)$($(m)-cxxobjs),,$(m)))
0037 
0038 # C executables linked based on several .o files
0039 host-cmulti     := $(foreach m,$(__hostprogs),\
0040                    $(if $($(m)-cxxobjs),,$(if $($(m)-objs),$(m))))
0041 
0042 # Object (.o) files compiled from .c files
0043 host-cobjs      := $(sort $(foreach m,$(__hostprogs),$($(m)-objs)))
0044 
0045 # C++ code
0046 # C++ executables compiled from at least one .cc file
0047 # and zero or more .c files
0048 host-cxxmulti   := $(foreach m,$(__hostprogs),$(if $($(m)-cxxobjs),$(m)))
0049 
0050 # C++ Object (.o) files compiled from .cc files
0051 host-cxxobjs    := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
0052 
0053 # Object (.o) files used by the shared libaries
0054 host-cshobjs    := $(sort $(foreach m,$(host-cshlib),$($(m:.so=-objs))))
0055 host-cxxshobjs  := $(sort $(foreach m,$(host-cxxshlib),$($(m:.so=-objs))))
0056 
0057 # output directory for programs/.o files
0058 # hostprogs-y := tools/build may have been specified.
0059 # Retrieve also directory of .o files from prog-objs or prog-cxxobjs notation
0060 host-objdirs := $(dir $(__hostprogs) $(host-cobjs) $(host-cxxobjs))
0061 
0062 host-objdirs := $(strip $(sort $(filter-out ./,$(host-objdirs))))
0063 
0064 
0065 __hostprogs     := $(addprefix $(obj)/,$(__hostprogs))
0066 host-csingle    := $(addprefix $(obj)/,$(host-csingle))
0067 host-cmulti     := $(addprefix $(obj)/,$(host-cmulti))
0068 host-cobjs      := $(addprefix $(obj)/,$(host-cobjs))
0069 host-cxxmulti   := $(addprefix $(obj)/,$(host-cxxmulti))
0070 host-cxxobjs    := $(addprefix $(obj)/,$(host-cxxobjs))
0071 host-cshlib     := $(addprefix $(obj)/,$(host-cshlib))
0072 host-cxxshlib   := $(addprefix $(obj)/,$(host-cxxshlib))
0073 host-cshobjs    := $(addprefix $(obj)/,$(host-cshobjs))
0074 host-cxxshobjs  := $(addprefix $(obj)/,$(host-cxxshobjs))
0075 host-objdirs    := $(addprefix $(obj)/,$(host-objdirs))
0076 
0077 obj-dirs += $(host-objdirs)
0078 
0079 #####
0080 # Handle options to gcc. Support building with separate output directory
0081 
0082 _hostc_flags   = $(HOSTCFLAGS)   $(HOST_EXTRACFLAGS)   \
0083                  $(HOSTCFLAGS_$(basetarget).o)
0084 _hostcxx_flags = $(HOSTCXXFLAGS) $(HOST_EXTRACXXFLAGS) \
0085                  $(HOSTCXXFLAGS_$(basetarget).o)
0086 
0087 ifeq ($(KBUILD_SRC),)
0088 __hostc_flags   = $(_hostc_flags)
0089 __hostcxx_flags = $(_hostcxx_flags)
0090 else
0091 __hostc_flags   = -I$(obj) $(call flags,_hostc_flags)
0092 __hostcxx_flags = -I$(obj) $(call flags,_hostcxx_flags)
0093 endif
0094 
0095 hostc_flags    = -Wp,-MD,$(depfile) $(__hostc_flags)
0096 hostcxx_flags  = -Wp,-MD,$(depfile) $(__hostcxx_flags)
0097 
0098 #####
0099 # Compile programs on the host
0100 
0101 # Create executable from a single .c file
0102 # host-csingle -> Executable
0103 quiet_cmd_host-csingle  = HOSTCC  $@
0104       cmd_host-csingle  = $(HOSTCC) $(hostc_flags) -o $@ $< \
0105                 $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
0106 $(host-csingle): $(obj)/%: $(src)/%.c FORCE
0107         $(call if_changed_dep,host-csingle)
0108 
0109 # Link an executable based on list of .o files, all plain c
0110 # host-cmulti -> executable
0111 quiet_cmd_host-cmulti   = HOSTLD  $@
0112       cmd_host-cmulti   = $(HOSTCC) $(HOSTLDFLAGS) -o $@ \
0113                           $(addprefix $(obj)/,$($(@F)-objs)) \
0114                           $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
0115 $(host-cmulti): FORCE
0116         $(call if_changed,host-cmulti)
0117 $(call multi_depend, $(host-cmulti), , -objs)
0118 
0119 # Create .o file from a single .c file
0120 # host-cobjs -> .o
0121 quiet_cmd_host-cobjs    = HOSTCC  $@
0122       cmd_host-cobjs    = $(HOSTCC) $(hostc_flags) -c -o $@ $<
0123 $(host-cobjs): $(obj)/%.o: $(src)/%.c FORCE
0124         $(call if_changed_dep,host-cobjs)
0125 
0126 # Link an executable based on list of .o files, a mixture of .c and .cc
0127 # host-cxxmulti -> executable
0128 quiet_cmd_host-cxxmulti = HOSTLD  $@
0129       cmd_host-cxxmulti = $(HOSTCXX) $(HOSTLDFLAGS) -o $@ \
0130                           $(foreach o,objs cxxobjs,\
0131                           $(addprefix $(obj)/,$($(@F)-$(o)))) \
0132                           $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
0133 $(host-cxxmulti): FORCE
0134         $(call if_changed,host-cxxmulti)
0135 $(call multi_depend, $(host-cxxmulti), , -objs -cxxobjs)
0136 
0137 # Create .o file from a single .cc (C++) file
0138 quiet_cmd_host-cxxobjs  = HOSTCXX $@
0139       cmd_host-cxxobjs  = $(HOSTCXX) $(hostcxx_flags) -c -o $@ $<
0140 $(host-cxxobjs): $(obj)/%.o: $(src)/%.cc FORCE
0141         $(call if_changed_dep,host-cxxobjs)
0142 
0143 # Compile .c file, create position independent .o file
0144 # host-cshobjs -> .o
0145 quiet_cmd_host-cshobjs  = HOSTCC  -fPIC $@
0146       cmd_host-cshobjs  = $(HOSTCC) $(hostc_flags) -fPIC -c -o $@ $<
0147 $(host-cshobjs): $(obj)/%.o: $(src)/%.c FORCE
0148         $(call if_changed_dep,host-cshobjs)
0149 
0150 # Compile .c file, create position independent .o file
0151 # Note that plugin capable gcc versions can be either C or C++ based
0152 # therefore plugin source files have to be compilable in both C and C++ mode.
0153 # This is why a C++ compiler is invoked on a .c file.
0154 # host-cxxshobjs -> .o
0155 quiet_cmd_host-cxxshobjs        = HOSTCXX -fPIC $@
0156       cmd_host-cxxshobjs        = $(HOSTCXX) $(hostcxx_flags) -fPIC -c -o $@ $<
0157 $(host-cxxshobjs): $(obj)/%.o: $(src)/%.c FORCE
0158         $(call if_changed_dep,host-cxxshobjs)
0159 
0160 # Link a shared library, based on position independent .o files
0161 # *.o -> .so shared library (host-cshlib)
0162 quiet_cmd_host-cshlib   = HOSTLLD -shared $@
0163       cmd_host-cshlib   = $(HOSTCC) $(HOSTLDFLAGS) -shared -o $@ \
0164                           $(addprefix $(obj)/,$($(@F:.so=-objs))) \
0165                           $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
0166 $(host-cshlib): FORCE
0167         $(call if_changed,host-cshlib)
0168 $(call multi_depend, $(host-cshlib), .so, -objs)
0169 
0170 # Link a shared library, based on position independent .o files
0171 # *.o -> .so shared library (host-cxxshlib)
0172 quiet_cmd_host-cxxshlib = HOSTLLD -shared $@
0173       cmd_host-cxxshlib = $(HOSTCXX) $(HOSTLDFLAGS) -shared -o $@ \
0174                           $(addprefix $(obj)/,$($(@F:.so=-objs))) \
0175                           $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
0176 $(host-cxxshlib): FORCE
0177         $(call if_changed,host-cxxshlib)
0178 $(call multi_depend, $(host-cxxshlib), .so, -objs)
0179 
0180 targets += $(host-csingle)  $(host-cmulti) $(host-cobjs)\
0181            $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs) $(host-cxxshlib) $(host-cxxshobjs)