]>
Commit | Line | Data |
---|---|---|
9ef10914 | 1 | # |
56a78630 PM |
2 | # Licensed under LGPL v2.1, see the file COPYING.LIB in this tarball for details. |
3 | # | |
56a78630 | 4 | |
82334a1b | 5 | .SUFFIXES: .c .S .o .os .oS .so .a .s .i |
9ef10914 | 6 | |
1f124eb0 | 7 | PHONY := FORCE |
1ce54cfc | 8 | |
49d8a0e9 | 9 | .PHONY: dummy $(PHONY) subdirs \ |
99ef2719 | 10 | all $(clean_targets) \ |
1ce54cfc | 11 | config dist menuconfig oldconfig release \ |
49d8a0e9 | 12 | utils help |
1ce54cfc | 13 | |
a80fc77b | 14 | # order is important, the stripping uses STRIP_FLAGS for lib-so, but not for lib-a |
9ef10914 | 15 | ifeq ($(HAVE_SHARED),y) |
768f982c | 16 | .LIBPATTERNS: "lib%.so" |
b20ee706 | 17 | libs: $(lib-so-y) $(lib-a-y) |
a1dc829e | 18 | $(lib-so-y): | $(interp) |
9ef10914 | 19 | else |
768f982c | 20 | .LIBPATTERNS: "lib%.a" |
e1d59aed | 21 | ifeq ($(UCLIBC_FORMAT_SHARED_FLAT),y) |
808694e8 MF |
22 | libs: $(lib-gdb-y) |
23 | endif | |
b20ee706 | 24 | libs: $(lib-a-y) |
9ef10914 | 25 | endif |
ec80cbc1 | 26 | objs: all_objs |
5fe8fc1a | 27 | $(lib-so-y) $(lib-a-y): | $(top_builddir)lib |
9ef10914 | 28 | |
41537a77 BRF |
29 | # apply unconditional per-directory flags |
30 | define add_IS_IN_lib | |
31 | ifneq ($(strip $(2)),) | |
c846358a BRF |
32 | __add_IS_IN_lib := $(2) |
33 | __add_IS_IN_lib += $(2:.o=.i) $(2:.os=.i) $(2:.oS=.i) | |
34 | __add_IS_IN_lib += $(2:.o=.s) $(2:.os=.s) $(2:.oS=.s) | |
41537a77 BRF |
35 | $$(__add_IS_IN_lib): CFLAGS-for-library-members:=$(CFLAGS-$(1)) -DIN_LIB=$(word 1,$(subst /, ,$(1))) |
36 | endif | |
37 | endef | |
38 | $(eval $(call add_IS_IN_lib,rtld,$(ldso-y))) | |
39 | $(eval $(call add_IS_IN_lib,libc,$(libc-y) $(libc-static-y) $(libc-y:.o=.os) $(libc-shared-y) $(libc-nonshared-y))) | |
40 | $(eval $(call add_IS_IN_lib,libcrypt,$(libcrypt-a-y) $(libcrypt-so-y))) | |
41 | $(eval $(call add_IS_IN_lib,libdl,$(libdl-a-y) $(libdl-so-y))) | |
41537a77 | 42 | $(eval $(call add_IS_IN_lib,libm,$(libm-a-y) $(libm-so-y))) |
41537a77 BRF |
43 | $(eval $(call add_IS_IN_lib,libpthread/$(PTNAME),$(libpthread-a-y) $(libpthread-so-y) $(libpthread-nonshared-y))) |
44 | $(eval $(call add_IS_IN_lib,libpthread/$(PTNAME)_db,$(libthread_db-a-y) $(libthread_db-so-y))) | |
41537a77 BRF |
45 | $(eval $(call add_IS_IN_lib,librt,$(librt-a-y) $(librt-so-y))) |
46 | $(eval $(call add_IS_IN_lib,libutil,$(libutil-a-y) $(libutil-so-y))) | |
47 | $(eval $(call add_IS_IN_lib,libubacktrace,$(libubacktrace-a-y) $(libubacktrace-so-y))) | |
86387d4e | 48 | $(eval $(call add_IS_IN_lib,libuargp,$(libuargp-a-y) $(libuargp-so-y))) |
4fa7ed93 | 49 | $(eval $(call add_IS_IN_lib,libiconv,$(libiconv-a-y) $(libiconv-so-y))) |
b39b5151 | 50 | $(eval $(call add_IS_IN_lib,libintl,$(libintl-a-y) $(libintl-so-y))) |
41537a77 | 51 | |
63abaebc | 52 | shared_objs = $(libc-y:.o=.os) $(libc-shared-y) $(libc-nonshared-y) \ |
50aba30a | 53 | $(libcrypt-so-y) $(libdl-so-y) $(libm-so-y) \ |
63abaebc | 54 | $(libpthread-so-y) $(libpthread-nonshared-y) $(libthread_db-so-y) \ |
4fa7ed93 | 55 | $(librt-so-y) $(ldso-y) $(libutil-so-y) $(libubacktrace-so-y) \ |
b39b5151 | 56 | $(libuargp-so-y) $(libiconv-so-y) $(libintl-so-y) |
63abaebc BRF |
57 | |
58 | ar_objs = $(libc-y) $(libc-static-y) $(libcrypt-a-y) \ | |
50aba30a | 59 | $(libdl-a-y) $(libm-a-y) $(libpthread-a-y) $(libthread_db-a-y) \ |
4fa7ed93 | 60 | $(librt-a-y) $(libutil-a-y) $(libubacktrace-a-y) $(libuargp-a-y) \ |
b39b5151 | 61 | $(libiconv-a-y) $(libintl-a-y) |
ec80cbc1 PM |
62 | ifeq ($(DOPIC),y) |
63 | ar_objs := $(ar_objs:.o=.os) | |
64 | endif | |
63abaebc | 65 | flat_objs = $(lib-gdb-y) |
ec80cbc1 PM |
66 | |
67 | ifeq ($(HAVE_SHARED),y) | |
68 | all_objs: $(sort $(shared_objs) $(ar_objs)) | |
69 | else | |
70 | all_objs: $(ar_objs) | |
71 | endif | |
94c41e72 | 72 | $(shared_objs) $(ar_objs): | $(sub_headers) |
0a7b9d5d | 73 | |
dd44bf94 BRF |
74 | define objects_with_syms |
75 | $(foreach o,$(2),$(if $(shell $(NM) $(1) $(o) | grep .),$(o))) | |
76 | endef | |
77 | ||
0a7b9d5d | 78 | headers-y: $(headers-y) |
b5db14a3 | 79 | @true |
a80fc77b | 80 | |
9bf5af92 | 81 | MAKEFLAGS += --no-print-directory |
b5db14a3 | 82 | SHELL_SET_X := set +x |
49d8a0e9 BRF |
83 | define rel_srcdir |
84 | $(shell $(CONFIG_SHELL) $(top_srcdir)/extra/scripts/relative_path.sh $(@D) .) | |
85 | endef | |
26242d9e | 86 | ifneq ($(findstring s,$(MAKEFLAGS)),) |
b5db14a3 MF |
87 | export MAKE_IS_SILENT := y |
88 | SECHO := -@false | |
8c7a3d7c MF |
89 | DISP := sil |
90 | Q := @ | |
91 | else | |
b5db14a3 MF |
92 | export MAKE_IS_SILENT := n |
93 | SECHO := @echo | |
8c7a3d7c | 94 | ifneq ($(V)$(VERBOSE),) |
98d8242d | 95 | ifeq ($(V),2) |
9160ed20 BRF |
96 | DISP := bri# brief, like pur but with defines |
97 | Q := @ | |
98 | else | |
b5db14a3 | 99 | SHELL_SET_X := set -x |
8c7a3d7c | 100 | DISP := ver |
49d47f2b | 101 | Q := |
9160ed20 | 102 | endif |
8c7a3d7c MF |
103 | else |
104 | DISP := pur | |
105 | Q := @ | |
106 | endif | |
107 | endif | |
108 | ||
49d8a0e9 | 109 | show_objs = $(subst $(top_builddir),,$(subst ../,,$@)) |
9160ed20 BRF |
110 | define show_defs |
111 | $(filter -D%,$(1)) | |
112 | endef | |
113 | define show_ldflags | |
114 | $(subst $(comma), ,$(subst -Wl$(comma),,$(filter -Wl%,$(1)))) | |
115 | endef | |
f3adfd4d MF |
116 | |
117 | pur_disp_compile.c = echo " "CC $(show_objs) | |
6f538799 BRF |
118 | pur_disp_compile.i = echo " "CPP $(show_objs) |
119 | pur_disp_compile.s = echo " "CC-S $(show_objs) | |
30c6496f | 120 | pur_disp_compile.u = echo " "CC $(show_objs) |
f3adfd4d | 121 | pur_disp_compile.S = echo " "AS $(show_objs) |
8c7a3d7c | 122 | pur_disp_compile.m = $(pur_disp_compile.c) |
a0ebeb98 | 123 | pur_disp_compile.mi= echo " "CPP-m $(show_objs) |
f3adfd4d | 124 | pur_disp_compile-m = echo " "CC-m $(show_objs) |
2d534901 BRF |
125 | pur_disp_hcompile.u= echo " "HOSTCC $(show_objs) |
126 | pur_disp_hcompile.o= echo " "HOSTCC-o $(show_objs) | |
ad93127a | 127 | pur_disp_strip = echo " "STRIP $(STRIP_FLAGS) $@ |
686016a7 | 128 | pur_disp_t_strip = echo " "STRIP $(STRIP_FLAGS) $@ |
8c7a3d7c | 129 | pur_disp_ar = echo " "AR $(ARFLAGS) $@ |
0a7b9d5d | 130 | pur_disp_ld = echo " "LD $(1) |
49d8a0e9 BRF |
131 | pur_disp_ln = echo " "LN $(show_objs) |
132 | pur_disp_mkdir = echo " "MKDIR $(show_objs) | |
133 | pur_disp_gen = echo " "GEN $(show_objs) | |
b42f780c | 134 | pur_disp_install = echo " "INSTALL $(1) |
49d8a0e9 | 135 | pur_disp_unifdef = echo " "UNIFDEF $(show_objs) |
abdbaa89 | 136 | pur_disp_rm = echo " "CLEAN $(subst CLEAN_,,$(patsubst HEADERCLEAN_%,include \(%\),$@)) |
8c7a3d7c MF |
137 | |
138 | sil_disp_compile.c = true | |
6f538799 BRF |
139 | sil_disp_compile.i = true |
140 | sil_disp_compile.s = true | |
30c6496f | 141 | sil_disp_compile.u = true |
8c7a3d7c MF |
142 | sil_disp_compile.S = true |
143 | sil_disp_compile.m = true | |
a0ebeb98 | 144 | sil_disp_compile.mi= true |
8c7a3d7c | 145 | sil_disp_compile-m = true |
2d534901 BRF |
146 | sil_disp_hcompile.u= true |
147 | sil_disp_hcompile.o= true | |
8c7a3d7c | 148 | sil_disp_strip = true |
686016a7 | 149 | sil_disp_t_strip = true |
8c7a3d7c MF |
150 | sil_disp_ar = true |
151 | sil_disp_ld = true | |
f2420be7 BRF |
152 | sil_disp_ln = true |
153 | sil_disp_mkdir = true | |
154 | sil_disp_gen = true | |
b42f780c | 155 | sil_disp_install = true |
f2420be7 | 156 | sil_disp_unifdef = true |
b46830f8 | 157 | sil_disp_rm = true |
8c7a3d7c | 158 | |
9160ed20 BRF |
159 | bri_disp_compile.c = $(pur_disp_compile.c) $(call show_defs,$(cmd_compile.c)) |
160 | bri_disp_compile.i = $(pur_disp_compile.i) $(call show_defs,$(cmd_compile.i)) | |
161 | bri_disp_compile.s = $(pur_disp_compile.s) $(call show_defs,$(cmd_compile.s)) | |
162 | bri_disp_compile.u = $(pur_disp_compile.u) $(call show_defs,$(cmd_compile.u)) | |
163 | bri_disp_compile.S = $(pur_disp_compile.S) $(call show_defs,$(cmd_compile.S)) | |
164 | bri_disp_compile.m = $(pur_disp_compile.m) $(call show_defs,$(cmd_compile.m)) | |
165 | bri_disp_compile.mi = $(pur_disp_compile.mi) $(call show_defs,$(cmd_compile.mi)) | |
166 | bri_disp_compile-m = $(pur_disp_compile-m) $(call show_defs,$(cmd_compile-m)) | |
167 | bri_disp_hcompile.u = $(pur_disp_hcompile.u) $(call show_defs,$(cmd_hcompile.u)) | |
168 | bri_disp_hcompile.o = $(pur_disp_hcompile.o) $(call show_defs,$(cmd_hcompile.o)) | |
169 | bri_disp_strip = $(pur_disp_strip) | |
170 | bri_disp_t_strip = $(pur_disp_t_strip) | |
171 | bri_disp_ar = $(pur_disp_ar) | |
172 | bri_disp_ld = $(pur_disp_ld) $(call show_ldflags,$(cmd_ld)) | |
173 | bri_disp_ln = $(pur_disp_ln) | |
174 | bri_disp_mkdir = $(pur_disp_mkdir) | |
175 | bri_disp_gen = $(pur_disp_gen) | |
176 | bri_disp_install = $(pur_disp_install) | |
177 | bri_disp_unifdef = $(pur_disp_unifdef) | |
178 | bri_disp_rm = $(pur_disp_rm) | |
179 | ||
ba97a399 BRF |
180 | esc=$(subst ','\'',$(1)) |
181 | # ') | |
182 | ver_disp_compile.c = echo '$(call esc,$(cmd_compile.c))' | |
183 | ver_disp_compile.i = echo '$(call esc,$(cmd_compile.i))' | |
184 | ver_disp_compile.s = echo '$(call esc,$(cmd_compile.s))' | |
185 | ver_disp_compile.u = echo '$(call esc,$(cmd_compile.u))' | |
186 | ver_disp_compile.S = echo '$(call esc,$(cmd_compile.S))' | |
187 | ver_disp_compile.m = echo '$(call esc,$(cmd_compile.m))' | |
188 | ver_disp_compile.mi= echo '$(call esc,$(cmd_compile.mi))' | |
189 | ver_disp_compile-m = echo '$(call esc,$(cmd_compile-m))' | |
190 | ver_disp_hcompile.u= echo '$(call esc,$(cmd_hcompile.u))' | |
191 | ver_disp_hcompile.o= echo '$(call esc,$(cmd_hcompile.o))' | |
192 | ver_disp_strip = echo '$(call esc,$(cmd_strip))' | |
193 | ver_disp_t_strip = echo '$(call esc,$(cmd_t_strip))' | |
194 | ver_disp_ar = echo '$(call esc,$(cmd_ar))' | |
49d47f2b | 195 | ver_disp_ld = |
f2420be7 BRF |
196 | ver_disp_ln = |
197 | ver_disp_mkdir = | |
198 | ver_disp_gen = | |
b42f780c | 199 | ver_disp_install = |
ba97a399 | 200 | ver_disp_unifdef = echo '$(call esc,$(cmd_unifdef))' |
b74c3aa1 | 201 | ver_disp_rm = |
8c7a3d7c | 202 | |
f3adfd4d | 203 | disp_compile.c = $($(DISP)_disp_compile.c) |
6f538799 BRF |
204 | disp_compile.i = $($(DISP)_disp_compile.i) |
205 | disp_compile.s = $($(DISP)_disp_compile.s) | |
30c6496f | 206 | disp_compile.u = $($(DISP)_disp_compile.u) |
f3adfd4d MF |
207 | disp_compile.S = $($(DISP)_disp_compile.S) |
208 | disp_compile.m = $($(DISP)_disp_compile.m) | |
a0ebeb98 | 209 | disp_compile.mi= $($(DISP)_disp_compile.mi) |
f3adfd4d | 210 | disp_compile-m = $($(DISP)_disp_compile-m) |
2d534901 BRF |
211 | disp_hcompile.u= $($(DISP)_disp_hcompile.u) |
212 | disp_hcompile.o= $($(DISP)_disp_hcompile.o) | |
f3adfd4d | 213 | disp_strip = $($(DISP)_disp_strip) |
686016a7 | 214 | disp_t_strip = $($(DISP)_disp_t_strip) |
f3adfd4d MF |
215 | disp_ar = $($(DISP)_disp_ar) |
216 | disp_ld = $($(DISP)_disp_ld) | |
f2420be7 BRF |
217 | disp_ln = $($(DISP)_disp_ln) |
218 | disp_mkdir = $($(DISP)_disp_mkdir) | |
219 | disp_gen = $($(DISP)_disp_gen) | |
b42f780c | 220 | disp_install = $($(DISP)_disp_install) |
f2420be7 | 221 | disp_unifdef = $($(DISP)_disp_unifdef) |
b46830f8 | 222 | disp_rm = $($(DISP)_disp_rm) |
f3adfd4d | 223 | |
1f124eb0 | 224 | any-prereq = $(filter-out $(PHONY),$?) $(filter-out $(PHONY) $(wildcard $^),$^) |
6f538799 | 225 | |
1ce54cfc BRF |
226 | # ../foo/bar/baz.ext -> foo_bar_baz.ext |
227 | variablify = $(subst /,_,$(subst $(top_builddir),,$(1))) | |
228 | # strip the top_builddir off everything to make the *string* idempotent for -C | |
229 | dirify = $(subst $(top_builddir),,$(patsubst -L$(top_builddir)%,-L%,$(patsubst -I$(top_builddir)%,-I%,$(1)))) | |
230 | ||
6f538799 BRF |
231 | # True if not identical. Neither order nor whitespace nor identical flags |
232 | # matter. | |
1ce54cfc BRF |
233 | compare_flags = \ |
234 | $(strip $(filter-out $(call dirify,$(cmd_$(call variablify,$(1)))), \ | |
235 | $(call dirify,$(cmd_$(call variablify,$(@))))) \ | |
236 | $(filter-out $(call dirify,$(cmd_$(call variablify,$(@)))), \ | |
237 | $(call dirify,$(cmd_$(call variablify,$(1)))))) | |
6f538799 | 238 | |
e41fbf6d | 239 | # Rebuild if any prerequisite, the used CC or flags changed. |
6f538799 | 240 | # Previously used flags are stored in the corresponding .%.dep files |
1ce54cfc BRF |
241 | maybe_exec = \ |
242 | $(if $(strip $(compare_flags) $(any-prereq)), \ | |
6f538799 BRF |
243 | @set -e; \ |
244 | $(disp_$(1)); \ | |
245 | $(cmd_$(1)); \ | |
1ce54cfc BRF |
246 | echo 'cmd_$(call variablify,$@) := $(call dirify,$(cmd_$(call variablify,$1)))' >> $(dir $@).$(notdir $@).dep) |
247 | ||
02efec11 BRF |
248 | # collect flags of domulti prereqs |
249 | #collect_multi_flags = $(CFLAGS-$(notdir $(d))) $(CFLAGS-$(notdir $(patsubst %/,%,$(dir $(d))))) | |
250 | collect_multi_flags = $(CFLAGS-$(notdir $(patsubst %/,%,$(dir $(d))))) | |
6f538799 | 251 | |
41537a77 BRF |
252 | #sub_srcdir = $(word 1,$(filter-out lib extra locale libpthread,$(wordlist 1,2,$(subst /, ,$(subst $(top_srcdir),,$(dir $<)))))) |
253 | ||
c28c512d | 254 | CFLAGS_gen.dep = -MT $@ -MD -MP -MF $(dir $@).$(notdir $@).dep |
e41fbf6d | 255 | |
41537a77 BRF |
256 | cmd_compile.c = $(CC) -c $< -o $@ \ |
257 | $(filter-out $(CFLAGS-OMIT-$(notdir $<)), \ | |
258 | $(CFLAGS) \ | |
259 | $(CFLAGS-for-library-members) \ | |
1f124eb0 | 260 | $(CFLAGS-$(suffix $@)) \ |
41537a77 | 261 | $(CFLAGS-y-$(subst $(top_srcdir),,$(<D))) \ |
1f124eb0 BRF |
262 | $(CFLAGS-$(notdir $<)) \ |
263 | $(CFLAGS-$(notdir $@)) \ | |
41537a77 | 264 | ) \ |
1f124eb0 | 265 | $(CFLAGS_gen.dep) |
23b99061 | 266 | cmd_compile.i = $(cmd_compile.c:-c=-E -dD) $(UCLIBC_EXTRA_CPPFLAGS) |
6f538799 | 267 | cmd_compile.s = $(cmd_compile.c:-c=-S) |
31796465 | 268 | cmd_compile.u = $(CC) $^ $(DEPS-$(notdir $@)) -o $@ $(CFLAGS) $(CFLAGS-$(notdir $(^D))) $(CFLAGS-$(notdir $@)) $(CFLAGS_gen.dep) |
5c0c667f | 269 | cmd_compile.S = $(filter-out -std=%, $(cmd_compile.c)) -D__ASSEMBLER__ $(ASFLAGS) $(ARCH_ASFLAGS) $(ASFLAGS-$(suffix $@)) $(ASFLAGS-$(notdir $<)) $(ASFLAGS-$(notdir $@)) |
8c7a3d7c | 270 | cmd_compile.m = $(cmd_compile.c) -DL_$(patsubst %$(suffix $(notdir $@)),%,$(notdir $@)) |
23b99061 | 271 | cmd_compile.mi= $(cmd_compile.m:-c=-E -dD) $(UCLIBC_EXTRA_CPPFLAGS) |
6f538799 | 272 | |
02efec11 | 273 | cmd_compile-m = $(CC) $^ -c -o $@ $(CFLAGS) $(CFLAGS-$(suffix $@)) $(CFLAGS-$(notdir $(@D))) $(CFLAGS-$(notdir $@)) $(sort $(foreach d,$(^:$(top_srcdir)=),$(collect_multi_flags))) |
8c7a3d7c | 274 | cmd_strip = $(STRIPTOOL) $(STRIP_FLAGS) $^ |
cd84f06d | 275 | cmd_t_strip = $(STRIPTOOL) $(STRIP_FLAGS) $@ |
dd44bf94 | 276 | cmd_ar = $(AR) $(ARFLAGS) $@ $(call objects_with_syms,,$^) |
8c7a3d7c | 277 | |
f2420be7 BRF |
278 | define do_ln |
279 | @$(disp_ln) | |
280 | $(Q)$(LN) -fs | |
281 | endef | |
282 | ||
49d8a0e9 BRF |
283 | define do_mkdir |
284 | @$(disp_mkdir) | |
285 | $(Q)$(INSTALL) -d $@ | |
286 | endef | |
b46830f8 | 287 | |
b74c3aa1 BRF |
288 | define do_rm |
289 | @$(disp_rm) | |
290 | $(Q)$(RM) | |
291 | endef | |
b46830f8 | 292 | |
417e2c47 CA |
293 | define do_awk |
294 | @$(disp_gen) | |
295 | $(Q)$(AWK) -f | |
296 | endef | |
297 | ||
997d8efe AF |
298 | define do_sed |
299 | @$(disp_gen) | |
300 | $(Q)$(SED) | |
301 | endef | |
302 | ||
6f538799 BRF |
303 | compile.c = @$(call maybe_exec,compile.c) |
304 | compile.i = $(call maybe_exec,compile.i) | |
305 | compile.s = $(call maybe_exec,compile.s) | |
306 | compile.S = @$(call maybe_exec,compile.S) | |
307 | compile.m = @$(call maybe_exec,compile.m) | |
a0ebeb98 | 308 | compile.mi= $(call maybe_exec,compile.mi) |
0c2be5a1 | 309 | compile-m = @$(disp_compile-m) ; $(cmd_compile-m) && $(cmd_t_strip) |
f3adfd4d | 310 | do_strip = @$(disp_strip) ; $(cmd_strip) |
686016a7 | 311 | do_t_strip= @$(disp_t_strip) ; $(cmd_t_strip) |
f2420be7 | 312 | do_unifdef= @$(disp_unifdef) ; $(cmd_unifdef) |
b46830f8 BRF |
313 | hcompile.u= @$(disp_hcompile.u); $(cmd_hcompile.u) |
314 | hcompile.o= @$(disp_hcompile.o); $(cmd_hcompile.o) | |
a80fc77b | 315 | |
63abaebc | 316 | define do_ar |
63abaebc | 317 | @$(disp_ar) ; $(cmd_ar) |
6ef0e347 | 318 | @$(do_t_strip) |
63abaebc | 319 | endef |
3321ce75 | 320 | define compile.u |
30c6496f | 321 | @$(disp_compile.u) ; $(cmd_compile.u) |
65ebd664 | 322 | @$(disp_t_strip) |
3321ce75 | 323 | endef |
49d8a0e9 BRF |
324 | cmd_hcompile.u = $(HOSTCC) $(filter-out $(PHONY),$^) $(DEPS-$(notdir $@)) -o $@ $(BUILD_LDFLAGS) $(BUILD_LDFLAGS-$(notdir $(^D))) $(BUILD_LDFLAGS-$(notdir $@)) $(BUILD_CFLAGS) $(BUILD_CFLAGS-$(notdir $(^D))) $(BUILD_CFLAGS-$(notdir $@)) |
325 | cmd_hcompile.o = $(HOSTCC) $(filter-out $(PHONY),$<) $(DEPS-$(notdir $@)) -c -o $@ $(BUILD_CFLAGS) $(BUILD_CFLAGS-$(notdir $(^D))) $(BUILD_CFLAGS-$(notdir $@)) | |
3321ce75 | 326 | |
76d780f4 | 327 | define link.so |
76d780f4 PM |
328 | $(Q)$(RM) $@ $@.$(2) $(dir $@)$(1) |
329 | @$(disp_ld) | |
f4eebb61 BS |
330 | $(Q)$(CC) $(LDFLAGS-$(notdir $@)) $(LDFLAGS-y-$(@F)) \ |
331 | -Wl,-soname=$(notdir $@).$(2) \ | |
1df50b08 BRF |
332 | $(CFLAG_-nostdlib) $(CFLAG_-nostartfiles) \ |
333 | -o $(dir $@)$(1) $(START_FILE-$(notdir $@)) \ | |
51ce75b5 | 334 | -Wl,--whole-archive $(firstword $^) -Wl,--no-whole-archive \ |
76d780f4 PM |
335 | $(LIBS-$(notdir $@)) $(LIBGCC) $(END_FILE-$(notdir $@)) |
336 | $(Q)$(LN) -sf $(1) $@.$(2) | |
337 | $(Q)$(LN) -sf $(1) $@ | |
338 | endef | |
339 | ||
808694e8 MF |
340 | # CRT files needed by link-flat.so |
341 | LINK_FLAT_CRTS := $(top_builddir)lib/Scrt1.o $(top_builddir)lib/crti.o \ | |
342 | $(top_builddir)lib/crtn.o | |
343 | ||
344 | # Create a shared flat library from the archive named by the first dependency. | |
345 | # $@ names the shared library's .gdb file, not the flat file itself. | |
346 | # (This is because the .gdb suffix makes the ELF file more distinctive | |
347 | # than the suffixless flat file.) | |
348 | # | |
349 | # Argument 1 is the shared library file -- i.e. $(@:.gdb=) -- and argument 2 | |
350 | # is the shared library identifier. If it wasn't for $(disp_ld), we could | |
351 | # avoid passing $(@:.gdb=) as an argument and use $(@:.gdb=) instead of $(1). | |
e682ab41 BS |
352 | # |
353 | # This is so far only used for libc, for which we want to link the entire | |
354 | # libgcc into the shared object. | |
808694e8 | 355 | define link-flat.so |
808694e8 MF |
356 | $(Q)$(RM) $(1) $@ |
357 | @$(disp_ld) | |
a899b909 | 358 | $(Q)$(CC) $(LDFLAGS-$(notdir $@)) $(CFLAG_-nostdlib) -o $(1) \ |
e682ab41 | 359 | -Wl,-elf2flt -Wl,-shared-lib-id,$(2) $(top_builddir)lib/Scrt1.o \ |
51ce75b5 | 360 | $(top_builddir)/lib/crti.o -Wl,--whole-archive $(firstword $^) \ |
e682ab41 | 361 | $(LIBGCC) -Wl,--no-whole-archive $(LIBS-$(notdir $@)) $(LIBGCC) \ |
808694e8 MF |
362 | $(top_builddir)/lib/crtn.o |
363 | endef | |
364 | ||
a80fc77b | 365 | CFLAGS-.os+=$(PICFLAG) |
237277e9 | 366 | CFLAGS-.oS+=$(PICFLAG) -DSHARED |
a80fc77b | 367 | |
49d8a0e9 | 368 | $(top_builddir)%.o: $(top_srcdir)%.c FORCE ; $(compile.c) |
718dcdc3 BRF |
369 | $(top_builddir)%.os: $(top_srcdir)%.c FORCE | pregen; $(compile.c) |
370 | $(top_builddir)%.oS: $(top_srcdir)%.c FORCE | pregen; $(compile.c) | |
49d8a0e9 | 371 | $(top_builddir)%.o: $(top_srcdir)%.S FORCE ; $(compile.S) |
718dcdc3 BRF |
372 | $(top_builddir)%.os: $(top_srcdir)%.S FORCE | pregen; $(compile.S) |
373 | $(top_builddir)%.oS: $(top_srcdir)%.S FORCE | pregen; $(compile.S) | |
49d8a0e9 BRF |
374 | $(top_builddir)%.o: $(top_srcdir)%.s FORCE ; $(compile.S) |
375 | $(top_builddir)%.os: $(top_srcdir)%.s FORCE ; $(compile.S) | |
718dcdc3 BRF |
376 | $(top_builddir)%.oS: $(top_srcdir)%.s FORCE | pregen; $(compile.S) |
377 | $(top_builddir)%.i: $(top_srcdir)%.c FORCE | pregen; $(compile.i) | |
378 | $(top_builddir)%.i: $(top_srcdir)%.S FORCE | pregen; $(compile.i) | |
379 | $(top_builddir)%.s: $(top_srcdir)%.c FORCE | pregen; $(compile.s) | |
380 | $(top_builddir)%.s: $(top_srcdir)%.S FORCE | pregen; $(compile.s) | |
49d8a0e9 | 381 | $(top_builddir)%.dep: |
a80fc77b | 382 | |
9381d622 | 383 | $(top_builddir)lib/interp.c: | $(top_builddir)lib |
0ee65752 BRF |
384 | $(Q)echo "/* Force shared libraries to know about the correct library loader */" > [email protected] |
385 | $(Q)echo "#include <features.h>" >> [email protected] | |
3392f8b6 | 386 | $(Q)echo "const char __dl_ldso__[] attribute_hidden __attribute__ ((weak)) __attribute__ ((section " \ |
0ee65752 | 387 | "(\".interp\"))) =\""$(RUNTIME_PREFIX)$(MULTILIB_DIR)/$(UCLIBC_LDSO)"\";" >> [email protected] |
b7792601 | 388 | $(Q)$(SED) -i -e 's://:/:g' [email protected] |
0ee65752 | 389 | $(Q)mv [email protected] $@ |
72c0f6a2 | 390 | |
9381d622 | 391 | $(interp): $(top_builddir)lib/interp.c | $(sub_headers) |
72c0f6a2 | 392 | $(compile.c) |
72c0f6a2 PM |
393 | $(Q)$(STRIPTOOL) -x -R .note -R .comment $@ |
394 | ||
30a86497 | 395 | $(ldso): |
9381d622 | 396 | $(Q)cd $(top_builddir); $(MAKE) lib/$(patsubst %.$(ABI_VERSION),%,$(notdir $@)) |
cf5e4b82 | 397 | $(libc): |
9381d622 | 398 | $(Q)cd $(top_builddir); $(MAKE) lib/$(patsubst %.$(ABI_VERSION),%,$(notdir $@)) |
cf5e4b82 | 399 | |
28f1d458 | 400 | CRT := crt1 |
a80fc77b | 401 | |
e1d59aed | 402 | ifeq ($(HAVE_SHARED)$(UCLIBC_FORMAT_SHARED_FLAT),y) |
a80fc77b | 403 | CRTS=$(top_builddir)lib/$(CRT).o $(top_builddir)lib/S$(CRT).o |
237277e9 PM |
404 | else |
405 | CRTS=$(top_builddir)lib/$(CRT).o | |
406 | endif | |
a80fc77b | 407 | |
2c58afdb | 408 | ifeq ($(STATIC_PIE),y) |
409 | CRTS+=$(top_builddir)lib/r$(CRT).o | |
410 | endif | |
411 | ||
28f1d458 MF |
412 | ASFLAGS-$(CRT).o := -DL_$(CRT) |
413 | ASFLAGS-S$(CRT).o := $(PIEFLAG) -DL_S$(CRT) | |
2c58afdb | 414 | ASFLAGS-r$(CRT).o := $(PIEFLAG) -DL_r$(CRT) |
28f1d458 | 415 | $(CRTS): $(top_srcdir)libc/sysdeps/linux/$(TARGET_ARCH)/$(CRT).S |
28f1d458 | 416 | $(compile.S) |
f3adfd4d | 417 | $(Q)$(STRIPTOOL) -x -R .note -R .comment $@ |
a80fc77b | 418 | |
fe774e4e | 419 | ifeq ($(UCLIBC_CTOR_DTOR),y) |
a80fc77b | 420 | CTOR_TARGETS=$(top_builddir)lib/crti.o $(top_builddir)lib/crtn.o |
fe774e4e MF |
421 | else |
422 | CTOR_TARGETS:= | |
423 | endif | |
3328a7c9 BRF |
424 | ifeq ($(HAS_NO_THREADS)$(UCLIBC_HAS_THREADS_NATIVE),) |
425 | $(lib-so-y): $(CTOR_TARGETS) | |
426 | endif | |
a80fc77b | 427 | |
0e910924 BS |
428 | ifeq ($(UCLIBC_FORMAT_FDPIC_ELF),y) |
429 | CRTRELOC=$(top_builddir)lib/crtreloc.o | |
430 | $(CRTRELOC): $(top_builddir)lib/%.o : $(top_srcdir)libc/sysdeps/linux/$(TARGET_ARCH)/%.c | |
0e910924 BS |
431 | $(compile.c) |
432 | endif | |
433 | ||
fe774e4e | 434 | ifneq ($(wildcard $(top_srcdir)libc/sysdeps/linux/$(TARGET_ARCH)/initfini.c),) |
41d42afb | 435 | CFLAGS-initfini.s := -S -g0 $(PICFLAG) -fno-inline-functions -finhibit-size-directive |
335ec554 | 436 | $(top_builddir)lib/initfini.s: $(top_srcdir)libc/sysdeps/linux/$(TARGET_ARCH)/initfini.c | $(top_builddir)lib |
41d42afb | 437 | $(compile.c) |
fe774e4e | 438 | |
5fe8fc1a BRF |
439 | $(top_builddir)lib/defs.h: $(top_builddir)lib/initfini.s |
440 | $(do_sed) -n -e '/@TESTS_BEGIN/,/@TESTS_END/p' $< | \ | |
441 | $(AWK) -f $(top_srcdir)extra/scripts/defs.awk > [email protected] | |
fe774e4e MF |
442 | $(Q)mv [email protected] $@ |
443 | ||
444 | $(top_builddir)lib/crti.S: $(top_builddir)lib/initfini.s $(top_builddir)lib/defs.h | |
5fe8fc1a | 445 | $(do_sed) -n -e '1,/@HEADER_ENDS/p' \ |
49d47f2b BRF |
446 | -e '/@_.*_PROLOG_BEGINS/,/@_.*_PROLOG_ENDS/p' \ |
447 | -e '/@TRAILER_BEGINS/,$$p' $< > $@ | |
fe774e4e MF |
448 | |
449 | $(top_builddir)lib/crtn.S: $(top_builddir)lib/initfini.s | |
5fe8fc1a | 450 | $(do_sed) -n -e '1,/@HEADER_ENDS/p' \ |
49d47f2b BRF |
451 | -e '/@_.*_EPILOG_BEGINS/,/@_.*_EPILOG_ENDS/p' \ |
452 | -e '/@TRAILER_BEGINS/,$$p' $< > $@ | |
fe774e4e MF |
453 | |
454 | $(CTOR_TARGETS): $(top_builddir)lib/%.o : $(top_builddir)lib/%.S | |
a80fc77b PM |
455 | $(compile.S) $(PICFLAG) $(SSP_DISABLE_FLAGS) |
456 | else | |
fe774e4e | 457 | $(CTOR_TARGETS): $(top_builddir)lib/%.o : $(top_srcdir)libc/sysdeps/linux/$(TARGET_ARCH)/%.S |
fe774e4e | 458 | $(compile.S) $(PICFLAG) $(SSP_DISABLE_FLAGS) |
a80fc77b PM |
459 | endif |
460 | ||
d0bd553f | 461 | CRTS_COMPAT := |
b9b124c1 | 462 | |
673f4440 | 463 | startfiles = $(CRTS) $(CTOR_TARGETS) $(CRTS_COMPAT) $(CRTRELOC) |
5fe8fc1a | 464 | startfiles: $(startfiles) |
b60e6c91 | 465 | $(CRTS) $(CTOR_TARGETS) $(CRTS_COMPAT) $(CRTRELOC): | headers |
5fe8fc1a BRF |
466 | $(CRTS) $(CTOR_TARGETS) $(CRTS_COMPAT) $(CRTRELOC) \ |
467 | $(LINK_FLAT_CRTS) $(SHARED_START_FILES) $(SHARED_END_FILES): | $(top_builddir)lib | |
a80fc77b | 468 | |
237277e9 | 469 | $(top_builddir)lib/$(NONSHARED_LIBNAME): $(libc-nonshared-y) |
e8451264 | 470 | $(Q)$(RM) $@ |
e8451264 PM |
471 | $(do_ar) |
472 | ||
473 | $(top_builddir)lib/libpthread_nonshared.a: $(libpthread-nonshared-y) | |
e8451264 | 474 | $(Q)$(RM) $@ |
8c7a3d7c | 475 | $(do_ar) |
237277e9 | 476 | |
e211e88f BRF |
477 | files.dep := $(libc-a-y) $(libc-so-y) $(libc-nonshared-y) \ |
478 | $(libm-a-y) $(libm-so-y) \ | |
479 | $(libpthread-a-y) $(libpthread-so-y) $(libpthread-nonshared-y) \ | |
9381d622 | 480 | $(libthread_db-a-y) $(libthread_db-so-y) $(libpthread-generated-y) \ |
0e03ac5a BRF |
481 | $(START_FILE-libpthread.so) $(END_FILE-libpthread.so) \ |
482 | $(PTHREAD_INITFINI:.c=.s) \ | |
b433e2d9 | 483 | $(librt-a-y) $(librt-so-y) \ |
4fa7ed93 WB |
484 | $(libcrypt-a-y) $(libcrypt-so-y) \ |
485 | $(libutil-a-y) $(libutil-so-y) \ | |
d9f4c6bb | 486 | $(ldso-y) $(libdl-a-y) $(libdl-so-y) \ |
4fa7ed93 WB |
487 | $(libubacktrace-a-y) $(libubacktrace-so-y) \ |
488 | $(libuargp-so-y) $(libuargp-a-y) \ | |
b39b5151 WB |
489 | $(libiconv-so-y) $(libiconv-a-y) \ |
490 | $(libintl-so-y) $(libintl-a-y) | |
8040ad5d | 491 | .depends.dep := \ |
9381d622 | 492 | $(patsubst %.s,%.s.dep,$(filter %.s,$(files.dep))) \ |
809dbec5 BS |
493 | $(patsubst %.o,%.o.dep,$(filter %.o,$(files.dep))) \ |
494 | $(patsubst %.os,%.os.dep,$(filter %.os,$(files.dep))) \ | |
495 | $(patsubst %.oS,%.oS.dep,$(filter %.oS,$(files.dep))) | |
59051472 BRF |
496 | # Oh, and prepend a dot to the basename so i don't have to change my habit of |
497 | # calling 'size thefile.o*' | |
498 | .depends.dep := $(foreach f,$(.depends.dep),$(dir $(f)).$(notdir $(f))) | |
542bc8ee | 499 | .depends.dep := $(wildcard $(.depends.dep)) |
8040ad5d | 500 | |
6f538799 BRF |
501 | FORCE: |
502 | ||
237277e9 | 503 | clean: objclean-y headers_clean-y |
0096e0df | 504 | realclean: clean menuconfig-clean-y |
8040ad5d | 505 | $(Q)$(RM) $(.depends.dep) |
237277e9 | 506 | |
0a7b9d5d PM |
507 | objclean-y: $(objclean-y) |
508 | headers_clean-y: $(headers_clean-y) | |
ad93127a | 509 | |
5b83f5ff BRF |
510 | ifeq ($(filter $(noconfig_targets),$(MAKECMDGOALS)),) |
511 | ifneq ($(strip $(.depends.dep)),) | |
512 | .NOEXPORT: | |
513 | -include $(.depends.dep) | |
514 | endif | |
515 | endif | |
516 | ||
a1dc829e | 517 | # vi: ft=make : |