]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | # ========================================================================== |
2 | # Building binaries on the host system | |
3 | # Binaries are used during the compilation of the kernel, for example | |
4 | # to preprocess a data file. | |
5 | # | |
3156fd05 | 6 | # Both C and C++ are supported, but preferred language is C for such utilities. |
1da177e4 | 7 | # |
3156fd05 | 8 | # Sample syntax (see Documentation/kbuild/makefiles.txt for reference) |
1da177e4 LT |
9 | # hostprogs-y := bin2hex |
10 | # Will compile bin2hex.c and create an executable named bin2hex | |
11 | # | |
12 | # hostprogs-y := lxdialog | |
13 | # lxdialog-objs := checklist.o lxdialog.o | |
14 | # Will compile lxdialog.c and checklist.c, and then link the executable | |
15 | # lxdialog, based on checklist.o and lxdialog.o | |
16 | # | |
17 | # hostprogs-y := qconf | |
18 | # qconf-cxxobjs := qconf.o | |
19 | # qconf-objs := menu.o | |
20 | # Will compile qconf as a C++ program, and menu as a C program. | |
21 | # They are linked as C++ code to the executable qconf | |
22 | ||
8f5cbd7e | 23 | __hostprogs := $(sort $(hostprogs-y) $(hostprogs-m)) |
24403874 ER |
24 | host-cshlib := $(sort $(hostlibs-y) $(hostlibs-m)) |
25 | host-cxxshlib := $(sort $(hostcxxlibs-y) $(hostcxxlibs-m)) | |
1da177e4 | 26 | |
1da177e4 LT |
27 | # C code |
28 | # Executables compiled from a single .c file | |
edb950c1 MY |
29 | host-csingle := $(foreach m,$(__hostprogs), \ |
30 | $(if $($(m)-objs)$($(m)-cxxobjs),,$(m))) | |
1da177e4 LT |
31 | |
32 | # C executables linked based on several .o files | |
33 | host-cmulti := $(foreach m,$(__hostprogs),\ | |
34 | $(if $($(m)-cxxobjs),,$(if $($(m)-objs),$(m)))) | |
35 | ||
36 | # Object (.o) files compiled from .c files | |
37 | host-cobjs := $(sort $(foreach m,$(__hostprogs),$($(m)-objs))) | |
38 | ||
39 | # C++ code | |
d8d9efe2 | 40 | # C++ executables compiled from at least one .cc file |
1da177e4 LT |
41 | # and zero or more .c files |
42 | host-cxxmulti := $(foreach m,$(__hostprogs),$(if $($(m)-cxxobjs),$(m))) | |
43 | ||
44 | # C++ Object (.o) files compiled from .cc files | |
45 | host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs))) | |
46 | ||
24403874 ER |
47 | # Object (.o) files used by the shared libaries |
48 | host-cshobjs := $(sort $(foreach m,$(host-cshlib),$($(m:.so=-objs)))) | |
49 | host-cxxshobjs := $(sort $(foreach m,$(host-cxxshlib),$($(m:.so=-objs)))) | |
50 | ||
7b5b8203 | 51 | # output directory for programs/.o files |
1791ff71 MY |
52 | # hostprogs-y := tools/build may have been specified. |
53 | # Retrieve also directory of .o files from prog-objs or prog-cxxobjs notation | |
54 | host-objdirs := $(dir $(__hostprogs) $(host-cobjs) $(host-cxxobjs)) | |
7b5b8203 SR |
55 | |
56 | host-objdirs := $(strip $(sort $(filter-out ./,$(host-objdirs)))) | |
57 | ||
58 | ||
1da177e4 LT |
59 | __hostprogs := $(addprefix $(obj)/,$(__hostprogs)) |
60 | host-csingle := $(addprefix $(obj)/,$(host-csingle)) | |
61 | host-cmulti := $(addprefix $(obj)/,$(host-cmulti)) | |
62 | host-cobjs := $(addprefix $(obj)/,$(host-cobjs)) | |
63 | host-cxxmulti := $(addprefix $(obj)/,$(host-cxxmulti)) | |
64 | host-cxxobjs := $(addprefix $(obj)/,$(host-cxxobjs)) | |
24403874 ER |
65 | host-cshlib := $(addprefix $(obj)/,$(host-cshlib)) |
66 | host-cxxshlib := $(addprefix $(obj)/,$(host-cxxshlib)) | |
67 | host-cshobjs := $(addprefix $(obj)/,$(host-cshobjs)) | |
68 | host-cxxshobjs := $(addprefix $(obj)/,$(host-cxxshobjs)) | |
9870a93d PR |
69 | host-objdirs := $(addprefix $(obj)/,$(host-objdirs)) |
70 | ||
71 | obj-dirs += $(host-objdirs) | |
1da177e4 LT |
72 | |
73 | ##### | |
74 | # Handle options to gcc. Support building with separate output directory | |
75 | ||
5e8d780d SR |
76 | _hostc_flags = $(HOSTCFLAGS) $(HOST_EXTRACFLAGS) \ |
77 | $(HOSTCFLAGS_$(basetarget).o) | |
78 | _hostcxx_flags = $(HOSTCXXFLAGS) $(HOST_EXTRACXXFLAGS) \ | |
79 | $(HOSTCXXFLAGS_$(basetarget).o) | |
1da177e4 LT |
80 | |
81 | ifeq ($(KBUILD_SRC),) | |
82 | __hostc_flags = $(_hostc_flags) | |
83 | __hostcxx_flags = $(_hostcxx_flags) | |
84 | else | |
85 | __hostc_flags = -I$(obj) $(call flags,_hostc_flags) | |
86 | __hostcxx_flags = -I$(obj) $(call flags,_hostcxx_flags) | |
87 | endif | |
88 | ||
89 | hostc_flags = -Wp,-MD,$(depfile) $(__hostc_flags) | |
90 | hostcxx_flags = -Wp,-MD,$(depfile) $(__hostcxx_flags) | |
91 | ||
92 | ##### | |
93 | # Compile programs on the host | |
94 | ||
95 | # Create executable from a single .c file | |
96 | # host-csingle -> Executable | |
97 | quiet_cmd_host-csingle = HOSTCC $@ | |
e0af0d85 MU |
98 | cmd_host-csingle = $(HOSTCC) $(hostc_flags) -o $@ $< \ |
99 | $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F)) | |
767e581d | 100 | $(host-csingle): $(obj)/%: $(src)/%.c FORCE |
1da177e4 LT |
101 | $(call if_changed_dep,host-csingle) |
102 | ||
103 | # Link an executable based on list of .o files, all plain c | |
104 | # host-cmulti -> executable | |
105 | quiet_cmd_host-cmulti = HOSTLD $@ | |
106 | cmd_host-cmulti = $(HOSTCC) $(HOSTLDFLAGS) -o $@ \ | |
107 | $(addprefix $(obj)/,$($(@F)-objs)) \ | |
108 | $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F)) | |
97e3226e | 109 | $(host-cmulti): FORCE |
1da177e4 | 110 | $(call if_changed,host-cmulti) |
97e3226e | 111 | $(call multi_depend, $(host-cmulti), , -objs) |
1da177e4 LT |
112 | |
113 | # Create .o file from a single .c file | |
114 | # host-cobjs -> .o | |
115 | quiet_cmd_host-cobjs = HOSTCC $@ | |
116 | cmd_host-cobjs = $(HOSTCC) $(hostc_flags) -c -o $@ $< | |
767e581d | 117 | $(host-cobjs): $(obj)/%.o: $(src)/%.c FORCE |
1da177e4 LT |
118 | $(call if_changed_dep,host-cobjs) |
119 | ||
120 | # Link an executable based on list of .o files, a mixture of .c and .cc | |
121 | # host-cxxmulti -> executable | |
122 | quiet_cmd_host-cxxmulti = HOSTLD $@ | |
123 | cmd_host-cxxmulti = $(HOSTCXX) $(HOSTLDFLAGS) -o $@ \ | |
124 | $(foreach o,objs cxxobjs,\ | |
125 | $(addprefix $(obj)/,$($(@F)-$(o)))) \ | |
126 | $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F)) | |
97e3226e | 127 | $(host-cxxmulti): FORCE |
1da177e4 | 128 | $(call if_changed,host-cxxmulti) |
97e3226e | 129 | $(call multi_depend, $(host-cxxmulti), , -objs -cxxobjs) |
1da177e4 LT |
130 | |
131 | # Create .o file from a single .cc (C++) file | |
132 | quiet_cmd_host-cxxobjs = HOSTCXX $@ | |
133 | cmd_host-cxxobjs = $(HOSTCXX) $(hostcxx_flags) -c -o $@ $< | |
767e581d | 134 | $(host-cxxobjs): $(obj)/%.o: $(src)/%.cc FORCE |
1da177e4 LT |
135 | $(call if_changed_dep,host-cxxobjs) |
136 | ||
24403874 ER |
137 | # Compile .c file, create position independent .o file |
138 | # host-cshobjs -> .o | |
139 | quiet_cmd_host-cshobjs = HOSTCC -fPIC $@ | |
140 | cmd_host-cshobjs = $(HOSTCC) $(hostc_flags) -fPIC -c -o $@ $< | |
141 | $(host-cshobjs): $(obj)/%.o: $(src)/%.c FORCE | |
142 | $(call if_changed_dep,host-cshobjs) | |
143 | ||
144 | # Compile .c file, create position independent .o file | |
145 | # Note that plugin capable gcc versions can be either C or C++ based | |
146 | # therefore plugin source files have to be compilable in both C and C++ mode. | |
147 | # This is why a C++ compiler is invoked on a .c file. | |
148 | # host-cxxshobjs -> .o | |
149 | quiet_cmd_host-cxxshobjs = HOSTCXX -fPIC $@ | |
150 | cmd_host-cxxshobjs = $(HOSTCXX) $(hostcxx_flags) -fPIC -c -o $@ $< | |
151 | $(host-cxxshobjs): $(obj)/%.o: $(src)/%.c FORCE | |
152 | $(call if_changed_dep,host-cxxshobjs) | |
153 | ||
154 | # Link a shared library, based on position independent .o files | |
155 | # *.o -> .so shared library (host-cshlib) | |
156 | quiet_cmd_host-cshlib = HOSTLLD -shared $@ | |
157 | cmd_host-cshlib = $(HOSTCC) $(HOSTLDFLAGS) -shared -o $@ \ | |
158 | $(addprefix $(obj)/,$($(@F:.so=-objs))) \ | |
159 | $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F)) | |
160 | $(host-cshlib): FORCE | |
161 | $(call if_changed,host-cshlib) | |
162 | $(call multi_depend, $(host-cshlib), .so, -objs) | |
163 | ||
164 | # Link a shared library, based on position independent .o files | |
165 | # *.o -> .so shared library (host-cxxshlib) | |
166 | quiet_cmd_host-cxxshlib = HOSTLLD -shared $@ | |
167 | cmd_host-cxxshlib = $(HOSTCXX) $(HOSTLDFLAGS) -shared -o $@ \ | |
168 | $(addprefix $(obj)/,$($(@F:.so=-objs))) \ | |
169 | $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F)) | |
170 | $(host-cxxshlib): FORCE | |
171 | $(call if_changed,host-cxxshlib) | |
172 | $(call multi_depend, $(host-cxxshlib), .so, -objs) | |
173 | ||
1da177e4 | 174 | targets += $(host-csingle) $(host-cmulti) $(host-cobjs)\ |
24403874 | 175 | $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs) $(host-cxxshlib) $(host-cxxshobjs) |