xref: /OK3568_Linux_fs/u-boot/scripts/Makefile.host (revision 4882a59341e53eb6f0b4789bf948001014eff981)
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# SPDX-License-Identifier:	GPL-2.0
24*4882a593Smuzhiyun#
25*4882a593Smuzhiyun
26*4882a593Smuzhiyun__hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
27*4882a593Smuzhiyun
28*4882a593Smuzhiyun# C code
29*4882a593Smuzhiyun# Executables compiled from a single .c file
30*4882a593Smuzhiyunhost-csingle	:= $(foreach m,$(__hostprogs), \
31*4882a593Smuzhiyun			$(if $($(m)-objs)$($(m)-cxxobjs)$($(m)-sharedobjs),,$(m)))
32*4882a593Smuzhiyun
33*4882a593Smuzhiyun# C executables linked based on several .o files
34*4882a593Smuzhiyunhost-cmulti	:= $(foreach m,$(__hostprogs),\
35*4882a593Smuzhiyun		   $(if $($(m)-cxxobjs),,$(if $($(m)-objs),$(m))))
36*4882a593Smuzhiyun
37*4882a593Smuzhiyun# Shared object libraries
38*4882a593Smuzhiyunhost-shared	:= $(foreach m,$(__hostprogs),\
39*4882a593Smuzhiyun		   $(if $($(m)-sharedobjs),$(m))))
40*4882a593Smuzhiyun
41*4882a593Smuzhiyun# Object (.o) files compiled from .c files
42*4882a593Smuzhiyunhost-cobjs	:= $(sort $(foreach m,$(__hostprogs),$($(m)-objs)))
43*4882a593Smuzhiyun
44*4882a593Smuzhiyun# C++ code
45*4882a593Smuzhiyun# C++ executables compiled from at least one .cc file
46*4882a593Smuzhiyun# and zero or more .c files
47*4882a593Smuzhiyunhost-cxxmulti	:= $(foreach m,$(__hostprogs),$(if $($(m)-cxxobjs),$(m)))
48*4882a593Smuzhiyun
49*4882a593Smuzhiyun# C++ Object (.o) files compiled from .cc files
50*4882a593Smuzhiyunhost-cxxobjs	:= $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
51*4882a593Smuzhiyun
52*4882a593Smuzhiyun# output directory for programs/.o files
53*4882a593Smuzhiyun# hostprogs-y := tools/build may have been specified.
54*4882a593Smuzhiyun# Retrieve also directory of .o files from prog-objs or prog-cxxobjs notation
55*4882a593Smuzhiyunhost-objdirs := $(dir $(__hostprogs) $(host-cobjs) $(host-cxxobjs))
56*4882a593Smuzhiyun
57*4882a593Smuzhiyunhost-objdirs := $(strip $(sort $(filter-out ./,$(host-objdirs))))
58*4882a593Smuzhiyun
59*4882a593Smuzhiyun
60*4882a593Smuzhiyun__hostprogs     := $(addprefix $(obj)/,$(__hostprogs))
61*4882a593Smuzhiyunhost-csingle	:= $(addprefix $(obj)/,$(host-csingle))
62*4882a593Smuzhiyunhost-cmulti	:= $(addprefix $(obj)/,$(host-cmulti))
63*4882a593Smuzhiyunhost-cobjs	:= $(addprefix $(obj)/,$(host-cobjs))
64*4882a593Smuzhiyunhost-cxxmulti	:= $(addprefix $(obj)/,$(host-cxxmulti))
65*4882a593Smuzhiyunhost-cxxobjs	:= $(addprefix $(obj)/,$(host-cxxobjs))
66*4882a593Smuzhiyunhost-shared	:= $(addprefix $(obj)/,$(host-shared))
67*4882a593Smuzhiyunhost-objdirs    := $(addprefix $(obj)/,$(host-objdirs))
68*4882a593Smuzhiyun
69*4882a593Smuzhiyunobj-dirs += $(host-objdirs)
70*4882a593Smuzhiyun
71*4882a593Smuzhiyun#####
72*4882a593Smuzhiyun# Handle options to gcc. Support building with separate output directory
73*4882a593Smuzhiyun
74*4882a593Smuzhiyun_hostc_flags   = $(HOSTCFLAGS)   $(HOST_EXTRACFLAGS)   \
75*4882a593Smuzhiyun                 $(HOSTCFLAGS_$(basetarget).o)
76*4882a593Smuzhiyun_hostcxx_flags = $(HOSTCXXFLAGS) $(HOST_EXTRACXXFLAGS) \
77*4882a593Smuzhiyun                 $(HOSTCXXFLAGS_$(basetarget).o)
78*4882a593Smuzhiyun
79*4882a593Smuzhiyunifeq ($(KBUILD_SRC),)
80*4882a593Smuzhiyun__hostc_flags	= $(_hostc_flags)
81*4882a593Smuzhiyun__hostcxx_flags	= $(_hostcxx_flags)
82*4882a593Smuzhiyunelse
83*4882a593Smuzhiyun__hostc_flags	= -I$(obj) $(call flags,_hostc_flags)
84*4882a593Smuzhiyun__hostcxx_flags	= -I$(obj) $(call flags,_hostcxx_flags)
85*4882a593Smuzhiyunendif
86*4882a593Smuzhiyun
87*4882a593Smuzhiyunhostc_flags    = -Wp,-MD,$(depfile) $(__hostc_flags)
88*4882a593Smuzhiyunhostcxx_flags  = -Wp,-MD,$(depfile) $(__hostcxx_flags)
89*4882a593Smuzhiyun
90*4882a593Smuzhiyun#####
91*4882a593Smuzhiyun# Compile programs on the host
92*4882a593Smuzhiyun
93*4882a593Smuzhiyun# Create executable from a single .c file
94*4882a593Smuzhiyun# host-csingle -> Executable
95*4882a593Smuzhiyunquiet_cmd_host-csingle 	= HOSTCC  $@
96*4882a593Smuzhiyun      cmd_host-csingle	= $(HOSTCC) $(hostc_flags) -o $@ $< \
97*4882a593Smuzhiyun	  	$(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
98*4882a593Smuzhiyun$(host-csingle): $(obj)/%: $(src)/%.c FORCE
99*4882a593Smuzhiyun	$(call if_changed_dep,host-csingle)
100*4882a593Smuzhiyun
101*4882a593Smuzhiyun# Link an executable based on list of .o files, all plain c
102*4882a593Smuzhiyun# host-cmulti -> executable
103*4882a593Smuzhiyunquiet_cmd_host-cmulti	= HOSTLD  $@
104*4882a593Smuzhiyun      cmd_host-cmulti	= $(HOSTCC) $(HOSTLDFLAGS) -o $@ \
105*4882a593Smuzhiyun			  $(addprefix $(obj)/,$($(@F)-objs)) \
106*4882a593Smuzhiyun			  $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
107*4882a593Smuzhiyun$(host-cmulti): FORCE
108*4882a593Smuzhiyun	$(call if_changed,host-cmulti)
109*4882a593Smuzhiyun$(call multi_depend, $(host-cmulti), , -objs)
110*4882a593Smuzhiyun
111*4882a593Smuzhiyun# Create .o file from a single .c file
112*4882a593Smuzhiyun# host-cobjs -> .o
113*4882a593Smuzhiyunquiet_cmd_host-cobjs	= HOSTCC  $@
114*4882a593Smuzhiyun      cmd_host-cobjs	= $(HOSTCC) $(hostc_flags) -c -o $@ $<
115*4882a593Smuzhiyun$(host-cobjs): $(obj)/%.o: $(src)/%.c FORCE
116*4882a593Smuzhiyun	$(call if_changed_dep,host-cobjs)
117*4882a593Smuzhiyun
118*4882a593Smuzhiyun# Link an executable based on list of .o files, a mixture of .c and .cc
119*4882a593Smuzhiyun# host-cxxmulti -> executable
120*4882a593Smuzhiyunquiet_cmd_host-cxxmulti	= HOSTLD  $@
121*4882a593Smuzhiyun      cmd_host-cxxmulti	= $(HOSTCXX) $(HOSTLDFLAGS) -o $@ \
122*4882a593Smuzhiyun			  $(foreach o,objs cxxobjs,\
123*4882a593Smuzhiyun			  $(addprefix $(obj)/,$($(@F)-$(o)))) \
124*4882a593Smuzhiyun			  $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
125*4882a593Smuzhiyun$(host-cxxmulti): FORCE
126*4882a593Smuzhiyun	$(call if_changed,host-cxxmulti)
127*4882a593Smuzhiyun$(call multi_depend, $(host-cxxmulti), , -objs -cxxobjs)
128*4882a593Smuzhiyun
129*4882a593Smuzhiyun# Create .o file from a single .cc (C++) file
130*4882a593Smuzhiyunquiet_cmd_host-cxxobjs	= HOSTCXX $@
131*4882a593Smuzhiyun      cmd_host-cxxobjs	= $(HOSTCXX) $(hostcxx_flags) -c -o $@ $<
132*4882a593Smuzhiyun$(host-cxxobjs): $(obj)/%.o: $(src)/%.cc FORCE
133*4882a593Smuzhiyun	$(call if_changed_dep,host-cxxobjs)
134*4882a593Smuzhiyun
135*4882a593Smuzhiyuntargets += $(host-csingle)  $(host-cmulti) $(host-cobjs)\
136*4882a593Smuzhiyun	   $(host-cxxmulti) $(host-cxxobjs) $(host-shared)
137