2 __hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
5 # Executables compiled from a single .c file
6 host-csingle := $(foreach m,$(__hostprogs),$(if $($(m)-objs),,$(m)))
8 # C executables linked based on several .o files
9 host-cmulti := $(foreach m,$(__hostprogs),$(if $($(m)-objs),$(m)))
11 # Object (.o) files compiled from .c files
12 host-cobjs := $(sort $(foreach m,$(__hostprogs),$($(m)-objs)))
14 # output directory for programs/.o files
15 # hostprogs-y := tools/build may have been specified. Retrieve directory
16 host-objdirs := $(foreach f,$(__hostprogs), $(if $(dir $(f)),$(dir $(f))))
17 # directory of .o files from prog-objs notation
18 host-objdirs += $(foreach f,$(host-cmulti), \
19 $(foreach m,$($(f)-objs), \
20 $(if $(dir $(m)),$(dir $(m)))))
22 host-objdirs := $(strip $(sort $(filter-out ./,$(host-objdirs))))
24 __hostprogs := $(addprefix $(obj),$(__hostprogs))
25 host-csingle := $(addprefix $(obj),$(host-csingle))
26 host-cmulti := $(addprefix $(obj),$(host-cmulti))
27 host-cobjs := $(addprefix $(obj),$(host-cobjs))
28 host-objdirs := $(addprefix $(obj),$(host-objdirs))
30 obj-dirs += $(host-objdirs)
33 # Handle options to gcc. Support building with separate output directory
35 _hostc_flags = $(HOSTCFLAGS) $(HOST_EXTRACFLAGS) \
36 $(HOSTCFLAGS_$(basetarget).o)
38 # Find all -I options and call addtree
39 flags = $(foreach o,$($(1)),$(if $(filter -I%,$(o)),$(call addtree,$(o)),$(o)))
41 ifeq ($(OBJTREE),$(SRCTREE))
42 __hostc_flags = $(_hostc_flags)
44 __hostc_flags = -I$(obj) $(call flags,_hostc_flags)
47 hostc_flags = $(__hostc_flags)
50 # Compile programs on the host
52 $(host-csingle): $(obj)%: %.c
53 $(HOSTCC) $(HOSTCFLAGS) $(HOST_EXTRACFLAGS) $(HOSTLDFLAGS) $(HOSTCFLAGS_$(@F)) $(HOSTCFLAGS_$(BCURDIR)) -o $@ $<
55 $(host-cmulti): $(obj)%: $(host-cobjs)
56 $(HOSTCC) $(HOSTLDFLAGS) -o $@ $(addprefix $(obj),$($(@F)-objs)) $(HOSTLOADLIBES_$(@F))
58 $(host-cobjs): $(obj)%.o: %.c
59 $(HOSTCC) $(HOSTCFLAGS) $(HOST_EXTRACFLAGS) $(HOSTCFLAGS_$(@F)) $(HOSTCFLAGS_$(BCURDIR)) -o $@ $< -c
61 targets += $(host-csingle) $(host-cmulti) $(host-cobjs)