]>
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 | ||
63d9c273 MT |
23 | # hostprogs-y := conf |
24 | # conf-objs := conf.o libkconfig.so | |
25 | # libkconfig-objs := expr.o type.o | |
26 | # Will create a shared library named libkconfig.so that consists of | |
27 | # expr.o and type.o (they are both compiled as C code and the object files | |
28 | # are made as position independent code). | |
29 | # conf.c is compiled as a C program, and conf.o is linked together with | |
30 | # libkconfig.so as the executable conf. | |
31 | # Note: Shared libraries consisting of C++ files are not supported | |
32 | ||
8f5cbd7e | 33 | __hostprogs := $(sort $(hostprogs-y) $(hostprogs-m)) |
63d9c273 MT |
34 | __hostlibs := $(sort $(hostlibs-y) $(hostlibs-m)) |
35 | __hostcxxlibs := $(sort $(hostcxxlibs-y) $(hostcxxlibs-m)) | |
1da177e4 | 36 | |
1da177e4 LT |
37 | # C code |
38 | # Executables compiled from a single .c file | |
edb950c1 MY |
39 | host-csingle := $(foreach m,$(__hostprogs), \ |
40 | $(if $($(m)-objs)$($(m)-cxxobjs),,$(m))) | |
1da177e4 LT |
41 | |
42 | # C executables linked based on several .o files | |
43 | host-cmulti := $(foreach m,$(__hostprogs),\ | |
44 | $(if $($(m)-cxxobjs),,$(if $($(m)-objs),$(m)))) | |
45 | ||
46 | # Object (.o) files compiled from .c files | |
47 | host-cobjs := $(sort $(foreach m,$(__hostprogs),$($(m)-objs))) | |
48 | ||
49 | # C++ code | |
d8d9efe2 | 50 | # C++ executables compiled from at least one .cc file |
1da177e4 LT |
51 | # and zero or more .c files |
52 | host-cxxmulti := $(foreach m,$(__hostprogs),$(if $($(m)-cxxobjs),$(m))) | |
53 | ||
54 | # C++ Object (.o) files compiled from .cc files | |
55 | host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs))) | |
56 | ||
63d9c273 MT |
57 | # Shared libaries (only .c supported) |
58 | # Shared libraries (.so) - all .so files referenced in "xxx-objs" | |
59 | host-cshlib := $(sort $(filter %.so, $(host-cobjs))) | |
60 | host-cshlib += $(sort $(filter %.so, $(__hostlibs))) | |
61 | host-cxxshlib := $(sort $(filter %.so, $(__hostcxxlibs))) | |
62 | # Remove .so files from "xxx-objs" | |
63 | host-cobjs := $(filter-out %.so,$(host-cobjs)) | |
64 | host-cxxobjs := $(filter-out %.so,$(host-cxxobjs)) | |
65 | ||
66 | # Object (.o) files used by the shared libaries | |
67 | host-cshobjs := $(sort $(foreach m,$(host-cshlib),$($(m:.so=-objs)))) | |
68 | host-cxxshobjs := $(sort $(foreach m,$(host-cxxshlib),$($(m:.so=-objs)))) | |
69 | ||
7b5b8203 | 70 | # output directory for programs/.o files |
1791ff71 MY |
71 | # hostprogs-y := tools/build may have been specified. |
72 | # Retrieve also directory of .o files from prog-objs or prog-cxxobjs notation | |
73 | host-objdirs := $(dir $(__hostprogs) $(host-cobjs) $(host-cxxobjs)) | |
7b5b8203 SR |
74 | |
75 | host-objdirs := $(strip $(sort $(filter-out ./,$(host-objdirs)))) | |
76 | ||
77 | ||
1da177e4 LT |
78 | __hostprogs := $(addprefix $(obj)/,$(__hostprogs)) |
79 | host-csingle := $(addprefix $(obj)/,$(host-csingle)) | |
80 | host-cmulti := $(addprefix $(obj)/,$(host-cmulti)) | |
81 | host-cobjs := $(addprefix $(obj)/,$(host-cobjs)) | |
82 | host-cxxmulti := $(addprefix $(obj)/,$(host-cxxmulti)) | |
83 | host-cxxobjs := $(addprefix $(obj)/,$(host-cxxobjs)) | |
63d9c273 MT |
84 | host-cshlib := $(addprefix $(obj)/,$(host-cshlib)) |
85 | host-cxxshlib := $(addprefix $(obj)/,$(host-cxxshlib)) | |
86 | host-cshobjs := $(addprefix $(obj)/,$(host-cshobjs)) | |
87 | host-cxxshobjs := $(addprefix $(obj)/,$(host-cxxshobjs)) | |
9870a93d PR |
88 | host-objdirs := $(addprefix $(obj)/,$(host-objdirs)) |
89 | ||
90 | obj-dirs += $(host-objdirs) | |
1da177e4 LT |
91 | |
92 | ##### | |
93 | # Handle options to gcc. Support building with separate output directory | |
94 | ||
5e8d780d SR |
95 | _hostc_flags = $(HOSTCFLAGS) $(HOST_EXTRACFLAGS) \ |
96 | $(HOSTCFLAGS_$(basetarget).o) | |
97 | _hostcxx_flags = $(HOSTCXXFLAGS) $(HOST_EXTRACXXFLAGS) \ | |
98 | $(HOSTCXXFLAGS_$(basetarget).o) | |
1da177e4 LT |
99 | |
100 | ifeq ($(KBUILD_SRC),) | |
101 | __hostc_flags = $(_hostc_flags) | |
102 | __hostcxx_flags = $(_hostcxx_flags) | |
103 | else | |
104 | __hostc_flags = -I$(obj) $(call flags,_hostc_flags) | |
105 | __hostcxx_flags = -I$(obj) $(call flags,_hostcxx_flags) | |
106 | endif | |
107 | ||
108 | hostc_flags = -Wp,-MD,$(depfile) $(__hostc_flags) | |
109 | hostcxx_flags = -Wp,-MD,$(depfile) $(__hostcxx_flags) | |
110 | ||
111 | ##### | |
112 | # Compile programs on the host | |
113 | ||
114 | # Create executable from a single .c file | |
115 | # host-csingle -> Executable | |
116 | quiet_cmd_host-csingle = HOSTCC $@ | |
e0af0d85 MU |
117 | cmd_host-csingle = $(HOSTCC) $(hostc_flags) -o $@ $< \ |
118 | $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F)) | |
767e581d | 119 | $(host-csingle): $(obj)/%: $(src)/%.c FORCE |
1da177e4 LT |
120 | $(call if_changed_dep,host-csingle) |
121 | ||
122 | # Link an executable based on list of .o files, all plain c | |
123 | # host-cmulti -> executable | |
124 | quiet_cmd_host-cmulti = HOSTLD $@ | |
125 | cmd_host-cmulti = $(HOSTCC) $(HOSTLDFLAGS) -o $@ \ | |
126 | $(addprefix $(obj)/,$($(@F)-objs)) \ | |
127 | $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F)) | |
97e3226e | 128 | $(host-cmulti): FORCE |
1da177e4 | 129 | $(call if_changed,host-cmulti) |
97e3226e | 130 | $(call multi_depend, $(host-cmulti), , -objs) |
1da177e4 LT |
131 | |
132 | # Create .o file from a single .c file | |
133 | # host-cobjs -> .o | |
134 | quiet_cmd_host-cobjs = HOSTCC $@ | |
135 | cmd_host-cobjs = $(HOSTCC) $(hostc_flags) -c -o $@ $< | |
767e581d | 136 | $(host-cobjs): $(obj)/%.o: $(src)/%.c FORCE |
1da177e4 LT |
137 | $(call if_changed_dep,host-cobjs) |
138 | ||
139 | # Link an executable based on list of .o files, a mixture of .c and .cc | |
140 | # host-cxxmulti -> executable | |
141 | quiet_cmd_host-cxxmulti = HOSTLD $@ | |
142 | cmd_host-cxxmulti = $(HOSTCXX) $(HOSTLDFLAGS) -o $@ \ | |
143 | $(foreach o,objs cxxobjs,\ | |
144 | $(addprefix $(obj)/,$($(@F)-$(o)))) \ | |
145 | $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F)) | |
97e3226e | 146 | $(host-cxxmulti): FORCE |
1da177e4 | 147 | $(call if_changed,host-cxxmulti) |
97e3226e | 148 | $(call multi_depend, $(host-cxxmulti), , -objs -cxxobjs) |
1da177e4 LT |
149 | |
150 | # Create .o file from a single .cc (C++) file | |
151 | quiet_cmd_host-cxxobjs = HOSTCXX $@ | |
152 | cmd_host-cxxobjs = $(HOSTCXX) $(hostcxx_flags) -c -o $@ $< | |
767e581d | 153 | $(host-cxxobjs): $(obj)/%.o: $(src)/%.cc FORCE |
1da177e4 LT |
154 | $(call if_changed_dep,host-cxxobjs) |
155 | ||
63d9c273 MT |
156 | # Compile .c file, create position independent .o file |
157 | # host-cshobjs -> .o | |
158 | quiet_cmd_host-cshobjs = HOSTCC -fPIC $@ | |
159 | cmd_host-cshobjs = $(HOSTCC) $(hostc_flags) -fPIC -c -o $@ $< | |
160 | $(host-cshobjs): $(obj)/%.o: $(src)/%.c FORCE | |
161 | $(call if_changed_dep,host-cshobjs) | |
162 | ||
163 | # Compile .c file, create position independent .o file | |
164 | # host-cxxshobjs -> .o | |
165 | quiet_cmd_host-cxxshobjs = HOSTCXX -fPIC $@ | |
166 | cmd_host-cxxshobjs = $(HOSTCXX) $(hostcxx_flags) -fPIC -c -o $@ $< | |
167 | $(host-cxxshobjs): $(obj)/%.o: $(src)/%.c FORCE | |
168 | $(call if_changed_dep,host-cxxshobjs) | |
169 | ||
170 | # Link a shared library, based on position independent .o files | |
171 | # *.o -> .so shared library (host-cshlib) | |
172 | quiet_cmd_host-cshlib = HOSTLLD -shared $@ | |
173 | cmd_host-cshlib = $(HOSTCC) $(HOSTLDFLAGS) -shared -o $@ \ | |
174 | $(addprefix $(obj)/,$($(@F:.so=-objs))) \ | |
175 | $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F)) | |
176 | $(host-cshlib): $(obj)/%: $(host-cshobjs) FORCE | |
177 | $(call if_changed,host-cshlib) | |
178 | ||
179 | # Link a shared library, based on position independent .o files | |
180 | # *.o -> .so shared library (host-cxxshlib) | |
181 | quiet_cmd_host-cxxshlib = HOSTLLD -shared $@ | |
182 | cmd_host-cxxshlib = $(HOSTCXX) $(HOSTLDFLAGS) -shared -o $@ \ | |
183 | $(addprefix $(obj)/,$($(@F:.so=-objs))) \ | |
184 | $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F)) | |
185 | $(host-cxxshlib): $(obj)/%: $(host-cxxshobjs) FORCE | |
186 | $(call if_changed,host-cxxshlib) | |
187 | ||
1da177e4 | 188 | targets += $(host-csingle) $(host-cmulti) $(host-cobjs)\ |
63d9c273 | 189 | $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs) $(host-cxxshlib) $(host-cxxshobjs) |