1*4882a593Smuzhiyun# ========================================================================== 2*4882a593Smuzhiyun# Building binaries on the host system 3*4882a593Smuzhiyun# Binaries are used during the compilation of the kernel, for example 4*4882a593Smuzhiyun# to preprocess a data file. 5*4882a593Smuzhiyun# 6*4882a593Smuzhiyun# Both C and C++ are supported, but preferred language is C for such utilities. 7*4882a593Smuzhiyun# 8*4882a593Smuzhiyun# Sample syntax (see Documentation/kbuild/makefiles.txt for reference) 9*4882a593Smuzhiyun# hostprogs-y := bin2hex 10*4882a593Smuzhiyun# Will compile bin2hex.c and create an executable named bin2hex 11*4882a593Smuzhiyun# 12*4882a593Smuzhiyun# hostprogs-y := lxdialog 13*4882a593Smuzhiyun# lxdialog-objs := checklist.o lxdialog.o 14*4882a593Smuzhiyun# Will compile lxdialog.c and checklist.c, and then link the executable 15*4882a593Smuzhiyun# lxdialog, based on checklist.o and lxdialog.o 16*4882a593Smuzhiyun# 17*4882a593Smuzhiyun# hostprogs-y := qconf 18*4882a593Smuzhiyun# qconf-cxxobjs := qconf.o 19*4882a593Smuzhiyun# qconf-objs := menu.o 20*4882a593Smuzhiyun# Will compile qconf as a C++ program, and menu as a C program. 21*4882a593Smuzhiyun# They are linked as C++ code to the executable qconf 22*4882a593Smuzhiyun 23*4882a593Smuzhiyun__hostprogs := $(sort $(hostprogs-y) $(hostprogs-m)) 24*4882a593Smuzhiyun 25*4882a593Smuzhiyun# C code 26*4882a593Smuzhiyun# Executables compiled from a single .c file 27*4882a593Smuzhiyunhost-csingle := $(foreach m,$(__hostprogs), \ 28*4882a593Smuzhiyun $(if $($(m)-objs)$($(m)-cxxobjs),,$(m))) 29*4882a593Smuzhiyun 30*4882a593Smuzhiyun# C executables linked based on several .o files 31*4882a593Smuzhiyunhost-cmulti := $(foreach m,$(__hostprogs),\ 32*4882a593Smuzhiyun $(if $($(m)-cxxobjs),,$(if $($(m)-objs),$(m)))) 33*4882a593Smuzhiyun 34*4882a593Smuzhiyun# Object (.o) files compiled from .c files 35*4882a593Smuzhiyunhost-cobjs := $(sort $(foreach m,$(__hostprogs),$($(m)-objs))) 36*4882a593Smuzhiyun 37*4882a593Smuzhiyun# C++ code 38*4882a593Smuzhiyun# C++ executables compiled from at least one .cc file 39*4882a593Smuzhiyun# and zero or more .c files 40*4882a593Smuzhiyunhost-cxxmulti := $(foreach m,$(__hostprogs),$(if $($(m)-cxxobjs),$(m))) 41*4882a593Smuzhiyun 42*4882a593Smuzhiyun# C++ Object (.o) files compiled from .cc files 43*4882a593Smuzhiyunhost-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs))) 44*4882a593Smuzhiyun 45*4882a593Smuzhiyun# output directory for programs/.o files 46*4882a593Smuzhiyun# hostprogs-y := tools/build may have been specified. 47*4882a593Smuzhiyun# Retrieve also directory of .o files from prog-objs or prog-cxxobjs notation 48*4882a593Smuzhiyunhost-objdirs := $(dir $(__hostprogs) $(host-cobjs) $(host-cxxobjs)) 49*4882a593Smuzhiyun 50*4882a593Smuzhiyunhost-objdirs := $(strip $(sort $(filter-out ./,$(host-objdirs)))) 51*4882a593Smuzhiyun 52*4882a593Smuzhiyun 53*4882a593Smuzhiyun__hostprogs := $(addprefix $(obj)/,$(__hostprogs)) 54*4882a593Smuzhiyunhost-csingle := $(addprefix $(obj)/,$(host-csingle)) 55*4882a593Smuzhiyunhost-cmulti := $(addprefix $(obj)/,$(host-cmulti)) 56*4882a593Smuzhiyunhost-cobjs := $(addprefix $(obj)/,$(host-cobjs)) 57*4882a593Smuzhiyunhost-cxxmulti := $(addprefix $(obj)/,$(host-cxxmulti)) 58*4882a593Smuzhiyunhost-cxxobjs := $(addprefix $(obj)/,$(host-cxxobjs)) 59*4882a593Smuzhiyunhost-objdirs := $(addprefix $(obj)/,$(host-objdirs)) 60*4882a593Smuzhiyun 61*4882a593Smuzhiyunobj-dirs += $(host-objdirs) 62*4882a593Smuzhiyun 63*4882a593Smuzhiyun##### 64*4882a593Smuzhiyun# Handle options to gcc. Support building with separate output directory 65*4882a593Smuzhiyun 66*4882a593Smuzhiyun_hostc_flags = $(HOSTCFLAGS) $(HOST_EXTRACFLAGS) \ 67*4882a593Smuzhiyun $(HOSTCFLAGS_$(basetarget).o) 68*4882a593Smuzhiyun_hostcxx_flags = $(HOSTCXXFLAGS) $(HOST_EXTRACXXFLAGS) \ 69*4882a593Smuzhiyun $(HOSTCXXFLAGS_$(basetarget).o) 70*4882a593Smuzhiyun 71*4882a593Smuzhiyunifeq ($(KBUILD_SRC),) 72*4882a593Smuzhiyun__hostc_flags = $(_hostc_flags) 73*4882a593Smuzhiyun__hostcxx_flags = $(_hostcxx_flags) 74*4882a593Smuzhiyunelse 75*4882a593Smuzhiyun__hostc_flags = -I$(obj) $(call flags,_hostc_flags) 76*4882a593Smuzhiyun__hostcxx_flags = -I$(obj) $(call flags,_hostcxx_flags) 77*4882a593Smuzhiyunendif 78*4882a593Smuzhiyun 79*4882a593Smuzhiyunhostc_flags = -Wp,-MD,$(depfile) $(__hostc_flags) 80*4882a593Smuzhiyunhostcxx_flags = -Wp,-MD,$(depfile) $(__hostcxx_flags) 81*4882a593Smuzhiyun 82*4882a593Smuzhiyun##### 83*4882a593Smuzhiyun# Compile programs on the host 84*4882a593Smuzhiyun 85*4882a593Smuzhiyun# Create executable from a single .c file 86*4882a593Smuzhiyun# host-csingle -> Executable 87*4882a593Smuzhiyunquiet_cmd_host-csingle = HOSTCC $@ 88*4882a593Smuzhiyun cmd_host-csingle = $(HOSTCC) $(hostc_flags) -o $@ $< \ 89*4882a593Smuzhiyun $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F)) 90*4882a593Smuzhiyun$(host-csingle): $(obj)/%: $(src)/%.c FORCE 91*4882a593Smuzhiyun $(call if_changed_dep,host-csingle) 92*4882a593Smuzhiyun 93*4882a593Smuzhiyun# Link an executable based on list of .o files, all plain c 94*4882a593Smuzhiyun# host-cmulti -> executable 95*4882a593Smuzhiyunquiet_cmd_host-cmulti = HOSTLD $@ 96*4882a593Smuzhiyun cmd_host-cmulti = $(HOSTCC) $(HOSTLDFLAGS) -o $@ \ 97*4882a593Smuzhiyun $(addprefix $(obj)/,$($(@F)-objs)) \ 98*4882a593Smuzhiyun $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F)) 99*4882a593Smuzhiyun$(host-cmulti): FORCE 100*4882a593Smuzhiyun $(call if_changed,host-cmulti) 101*4882a593Smuzhiyun$(call multi_depend, $(host-cmulti), , -objs) 102*4882a593Smuzhiyun 103*4882a593Smuzhiyun# Create .o file from a single .c file 104*4882a593Smuzhiyun# host-cobjs -> .o 105*4882a593Smuzhiyunquiet_cmd_host-cobjs = HOSTCC $@ 106*4882a593Smuzhiyun cmd_host-cobjs = $(HOSTCC) $(hostc_flags) -c -o $@ $< 107*4882a593Smuzhiyun$(host-cobjs): $(obj)/%.o: $(src)/%.c FORCE 108*4882a593Smuzhiyun $(call if_changed_dep,host-cobjs) 109*4882a593Smuzhiyun 110*4882a593Smuzhiyun# Link an executable based on list of .o files, a mixture of .c and .cc 111*4882a593Smuzhiyun# host-cxxmulti -> executable 112*4882a593Smuzhiyunquiet_cmd_host-cxxmulti = HOSTLD $@ 113*4882a593Smuzhiyun cmd_host-cxxmulti = $(HOSTCXX) $(HOSTLDFLAGS) -o $@ \ 114*4882a593Smuzhiyun $(foreach o,objs cxxobjs,\ 115*4882a593Smuzhiyun $(addprefix $(obj)/,$($(@F)-$(o)))) \ 116*4882a593Smuzhiyun $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F)) 117*4882a593Smuzhiyun$(host-cxxmulti): FORCE 118*4882a593Smuzhiyun $(call if_changed,host-cxxmulti) 119*4882a593Smuzhiyun$(call multi_depend, $(host-cxxmulti), , -objs -cxxobjs) 120*4882a593Smuzhiyun 121*4882a593Smuzhiyun# Create .o file from a single .cc (C++) file 122*4882a593Smuzhiyunquiet_cmd_host-cxxobjs = HOSTCXX $@ 123*4882a593Smuzhiyun cmd_host-cxxobjs = $(HOSTCXX) $(hostcxx_flags) -c -o $@ $< 124*4882a593Smuzhiyun$(host-cxxobjs): $(obj)/%.o: $(src)/%.cc FORCE 125*4882a593Smuzhiyun $(call if_changed_dep,host-cxxobjs) 126*4882a593Smuzhiyun 127*4882a593Smuzhiyuntargets += $(host-csingle) $(host-cmulti) $(host-cobjs)\ 128*4882a593Smuzhiyun $(host-cxxmulti) $(host-cxxobjs) 129