fix static linking for FDPIC toolchains
[uclibc-ng.git] / Makerules
blobd7086006a985b51111a312421df171761ba78228
2 # Licensed under LGPL v2.1, see the file COPYING.LIB in this tarball for details.
5 .SUFFIXES: .c .S .o .os .oS .so .a .s .i
7 PHONY := FORCE
9 .PHONY: dummy $(PHONY) subdirs \
10         all $(clean_targets) \
11         config dist menuconfig oldconfig release \
12         utils help
14 # order is important, the stripping uses STRIP_FLAGS for lib-so, but not for lib-a
15 ifeq ($(HAVE_SHARED),y)
16 .LIBPATTERNS: "lib%.so"
17 libs: $(lib-so-y) $(lib-a-y)
18 $(lib-so-y): | $(interp)
19 else
20 .LIBPATTERNS: "lib%.a"
21 ifeq ($(UCLIBC_FORMAT_SHARED_FLAT),y)
22 libs: $(lib-gdb-y)
23 endif
24 libs: $(lib-a-y)
25 endif
26 objs: all_objs
27 $(lib-so-y) $(lib-a-y): | $(top_builddir)lib
29 # apply unconditional per-directory flags
30 define add_IS_IN_lib
31 ifneq ($(strip $(2)),)
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)
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)))
42 $(eval $(call add_IS_IN_lib,libm,$(libm-a-y) $(libm-so-y)))
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)))
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)))
48 $(eval $(call add_IS_IN_lib,libuargp,$(libuargp-a-y) $(libuargp-so-y)))
50 shared_objs = $(libc-y:.o=.os) $(libc-shared-y) $(libc-nonshared-y) \
51         $(libcrypt-so-y) $(libdl-so-y) $(libm-so-y) \
52         $(libpthread-so-y) $(libpthread-nonshared-y) $(libthread_db-so-y) \
53         $(librt-so-y) $(ldso-y) $(libutil-so-y) $(libubacktrace-so-y) $(libuargp-so-y)
55 ar_objs =  $(libc-y) $(libc-static-y) $(libcrypt-a-y) \
56         $(libdl-a-y) $(libm-a-y) $(libpthread-a-y) $(libthread_db-a-y) \
57         $(librt-a-y) $(libutil-a-y) $(libubacktrace-a-y) $(libuargp-a-y)
58 ifeq ($(DOPIC),y)
59 ar_objs := $(ar_objs:.o=.os)
60 endif
61 flat_objs = $(lib-gdb-y)
63 ifeq ($(HAVE_SHARED),y)
64 all_objs: $(sort $(shared_objs) $(ar_objs))
65 else
66 all_objs: $(ar_objs)
67 endif
68 $(shared_objs) $(ar_objs): | $(sub_headers)
70 define objects_with_syms
71         $(foreach o,$(2),$(if $(shell $(NM) $(1) $(o) | grep .),$(o)))
72 endef
74 headers-y: $(headers-y)
75         @true
77 MAKEFLAGS += --no-print-directory
78 SHELL_SET_X := set +x
79 define rel_srcdir
80         $(shell $(CONFIG_SHELL) $(top_srcdir)/extra/scripts/relative_path.sh $(@D) .)
81 endef
82 ifneq ($(findstring s,$(MAKEFLAGS)),)
83 export MAKE_IS_SILENT := y
84 SECHO := -@false
85 DISP := sil
86 Q := @
87 else
88 export MAKE_IS_SILENT := n
89 SECHO := @echo
90 ifneq ($(V)$(VERBOSE),)
91 ifeq ($(V),2)
92 DISP := bri# brief, like pur but with defines
93 Q := @
94 else
95 SHELL_SET_X := set -x
96 DISP := ver
97 Q :=
98 endif
99 else
100 DISP := pur
101 Q := @
102 endif
103 endif
105 show_objs = $(subst $(top_builddir),,$(subst ../,,$@))
106 define show_defs
107         $(filter -D%,$(1))
108 endef
109 define show_ldflags
110         $(subst $(comma), ,$(subst -Wl$(comma),,$(filter -Wl%,$(1))))
111 endef
113 pur_disp_compile.c = echo "  "CC $(show_objs)
114 pur_disp_compile.i = echo "  "CPP $(show_objs)
115 pur_disp_compile.s = echo "  "CC-S $(show_objs)
116 pur_disp_compile.u = echo "  "CC $(show_objs)
117 pur_disp_compile.S = echo "  "AS $(show_objs)
118 pur_disp_compile.m = $(pur_disp_compile.c)
119 pur_disp_compile.mi= echo "  "CPP-m $(show_objs)
120 pur_disp_compile-m = echo "  "CC-m $(show_objs)
121 pur_disp_hcompile.u= echo "  "HOSTCC $(show_objs)
122 pur_disp_hcompile.o= echo "  "HOSTCC-o $(show_objs)
123 pur_disp_strip     = echo "  "STRIP $(STRIP_FLAGS) $@
124 pur_disp_t_strip   = echo "  "STRIP $(STRIP_FLAGS) $@
125 pur_disp_ar        = echo "  "AR $(ARFLAGS) $@
126 pur_disp_ld        = echo "  "LD $(1)
127 pur_disp_ln        = echo "  "LN $(show_objs)
128 pur_disp_mkdir     = echo "  "MKDIR $(show_objs)
129 pur_disp_gen       = echo "  "GEN $(show_objs)
130 pur_disp_install   = echo "  "INSTALL $(1)
131 pur_disp_unifdef   = echo "  "UNIFDEF $(show_objs)
132 pur_disp_rm        = echo "  "CLEAN $(subst CLEAN_,,$(patsubst HEADERCLEAN_%,include \(%\),$@))
134 sil_disp_compile.c = true
135 sil_disp_compile.i = true
136 sil_disp_compile.s = true
137 sil_disp_compile.u = true
138 sil_disp_compile.S = true
139 sil_disp_compile.m = true
140 sil_disp_compile.mi= true
141 sil_disp_compile-m = true
142 sil_disp_hcompile.u= true
143 sil_disp_hcompile.o= true
144 sil_disp_strip     = true
145 sil_disp_t_strip   = true
146 sil_disp_ar        = true
147 sil_disp_ld        = true
148 sil_disp_ln        = true
149 sil_disp_mkdir     = true
150 sil_disp_gen       = true
151 sil_disp_install   = true
152 sil_disp_unifdef   = true
153 sil_disp_rm        = true
155 bri_disp_compile.c = $(pur_disp_compile.c) $(call show_defs,$(cmd_compile.c))
156 bri_disp_compile.i = $(pur_disp_compile.i) $(call show_defs,$(cmd_compile.i))
157 bri_disp_compile.s = $(pur_disp_compile.s) $(call show_defs,$(cmd_compile.s))
158 bri_disp_compile.u = $(pur_disp_compile.u) $(call show_defs,$(cmd_compile.u))
159 bri_disp_compile.S = $(pur_disp_compile.S) $(call show_defs,$(cmd_compile.S))
160 bri_disp_compile.m = $(pur_disp_compile.m) $(call show_defs,$(cmd_compile.m))
161 bri_disp_compile.mi = $(pur_disp_compile.mi) $(call show_defs,$(cmd_compile.mi))
162 bri_disp_compile-m = $(pur_disp_compile-m) $(call show_defs,$(cmd_compile-m))
163 bri_disp_hcompile.u = $(pur_disp_hcompile.u) $(call show_defs,$(cmd_hcompile.u))
164 bri_disp_hcompile.o = $(pur_disp_hcompile.o) $(call show_defs,$(cmd_hcompile.o))
165 bri_disp_strip = $(pur_disp_strip)
166 bri_disp_t_strip = $(pur_disp_t_strip)
167 bri_disp_ar = $(pur_disp_ar)
168 bri_disp_ld = $(pur_disp_ld) $(call show_ldflags,$(cmd_ld))
169 bri_disp_ln = $(pur_disp_ln)
170 bri_disp_mkdir = $(pur_disp_mkdir)
171 bri_disp_gen = $(pur_disp_gen)
172 bri_disp_install = $(pur_disp_install)
173 bri_disp_unifdef = $(pur_disp_unifdef)
174 bri_disp_rm = $(pur_disp_rm)
176 esc=$(subst ','\'',$(1))
177 # ')
178 ver_disp_compile.c = echo '$(call esc,$(cmd_compile.c))'
179 ver_disp_compile.i = echo '$(call esc,$(cmd_compile.i))'
180 ver_disp_compile.s = echo '$(call esc,$(cmd_compile.s))'
181 ver_disp_compile.u = echo '$(call esc,$(cmd_compile.u))'
182 ver_disp_compile.S = echo '$(call esc,$(cmd_compile.S))'
183 ver_disp_compile.m = echo '$(call esc,$(cmd_compile.m))'
184 ver_disp_compile.mi= echo '$(call esc,$(cmd_compile.mi))'
185 ver_disp_compile-m = echo '$(call esc,$(cmd_compile-m))'
186 ver_disp_hcompile.u= echo '$(call esc,$(cmd_hcompile.u))'
187 ver_disp_hcompile.o= echo '$(call esc,$(cmd_hcompile.o))'
188 ver_disp_strip     = echo '$(call esc,$(cmd_strip))'
189 ver_disp_t_strip   = echo '$(call esc,$(cmd_t_strip))'
190 ver_disp_ar        = echo '$(call esc,$(cmd_ar))'
191 ver_disp_ld        =
192 ver_disp_ln        =
193 ver_disp_mkdir     =
194 ver_disp_gen       =
195 ver_disp_install   =
196 ver_disp_unifdef   = echo '$(call esc,$(cmd_unifdef))'
197 ver_disp_rm        =
199 disp_compile.c = $($(DISP)_disp_compile.c)
200 disp_compile.i = $($(DISP)_disp_compile.i)
201 disp_compile.s = $($(DISP)_disp_compile.s)
202 disp_compile.u = $($(DISP)_disp_compile.u)
203 disp_compile.S = $($(DISP)_disp_compile.S)
204 disp_compile.m = $($(DISP)_disp_compile.m)
205 disp_compile.mi= $($(DISP)_disp_compile.mi)
206 disp_compile-m = $($(DISP)_disp_compile-m)
207 disp_hcompile.u= $($(DISP)_disp_hcompile.u)
208 disp_hcompile.o= $($(DISP)_disp_hcompile.o)
209 disp_strip     = $($(DISP)_disp_strip)
210 disp_t_strip   = $($(DISP)_disp_t_strip)
211 disp_ar        = $($(DISP)_disp_ar)
212 disp_ld        = $($(DISP)_disp_ld)
213 disp_ln        = $($(DISP)_disp_ln)
214 disp_mkdir     = $($(DISP)_disp_mkdir)
215 disp_gen       = $($(DISP)_disp_gen)
216 disp_install   = $($(DISP)_disp_install)
217 disp_unifdef   = $($(DISP)_disp_unifdef)
218 disp_rm        = $($(DISP)_disp_rm)
220 any-prereq = $(filter-out $(PHONY),$?) $(filter-out $(PHONY) $(wildcard $^),$^)
222 # ../foo/bar/baz.ext -> foo_bar_baz.ext
223 variablify = $(subst /,_,$(subst $(top_builddir),,$(1)))
224 # strip the top_builddir off everything to make the *string* idempotent for -C
225 dirify = $(subst $(top_builddir),,$(patsubst -L$(top_builddir)%,-L%,$(patsubst -I$(top_builddir)%,-I%,$(1))))
227 # True if not identical. Neither order nor whitespace nor identical flags
228 # matter.
229 compare_flags = \
230         $(strip $(filter-out $(call dirify,$(cmd_$(call variablify,$(1)))), \
231                                 $(call dirify,$(cmd_$(call variablify,$(@))))) \
232                 $(filter-out $(call dirify,$(cmd_$(call variablify,$(@)))), \
233                                 $(call dirify,$(cmd_$(call variablify,$(1))))))
235 # Rebuild if any prerequisite, the used CC or flags changed.
236 # Previously used flags are stored in the corresponding .%.dep files
237 maybe_exec = \
238                 $(if $(strip $(compare_flags) $(any-prereq)), \
239                 @set -e; \
240                 $(disp_$(1)); \
241                 $(cmd_$(1)); \
242                 echo 'cmd_$(call variablify,$@) := $(call dirify,$(cmd_$(call variablify,$1)))' >> $(dir $@).$(notdir $@).dep)
244 # collect flags of domulti prereqs
245 #collect_multi_flags = $(CFLAGS-$(notdir $(d))) $(CFLAGS-$(notdir $(patsubst %/,%,$(dir $(d)))))
246 collect_multi_flags = $(CFLAGS-$(notdir $(patsubst %/,%,$(dir $(d)))))
248 #sub_srcdir = $(word 1,$(filter-out lib extra locale libpthread,$(wordlist 1,2,$(subst /, ,$(subst $(top_srcdir),,$(dir $<))))))
250 CFLAGS_gen.dep = -MT $@ -MD -MP -MF $(dir $@).$(notdir $@).dep
252 cmd_compile.c = $(CC) -c $< -o $@ \
253     $(filter-out $(CFLAGS-OMIT-$(notdir $<)), \
254         $(CFLAGS) \
255         $(CFLAGS-for-library-members) \
256         $(CFLAGS-$(suffix $@)) \
257         $(CFLAGS-y-$(subst $(top_srcdir),,$(<D))) \
258         $(CFLAGS-$(notdir $<)) \
259         $(CFLAGS-$(notdir $@)) \
260     ) \
261         $(CFLAGS_gen.dep)
262 cmd_compile.i = $(cmd_compile.c:-c=-E -dD) $(UCLIBC_EXTRA_CPPFLAGS)
263 cmd_compile.s = $(cmd_compile.c:-c=-S)
264 cmd_compile.u = $(CC) $^ $(DEPS-$(notdir $@)) -o $@ $(CFLAGS) $(CFLAGS-$(notdir $(^D))) $(CFLAGS-$(notdir $@)) $(CFLAGS_gen.dep)
265 cmd_compile.S = $(filter-out -std=%, $(cmd_compile.c)) -D__ASSEMBLER__ $(ASFLAGS) $(ARCH_ASFLAGS) $(ASFLAGS-$(suffix $@)) $(ASFLAGS-$(notdir $<)) $(ASFLAGS-$(notdir $@))
266 cmd_compile.m = $(cmd_compile.c) -DL_$(patsubst %$(suffix $(notdir $@)),%,$(notdir $@))
267 cmd_compile.mi= $(cmd_compile.m:-c=-E -dD) $(UCLIBC_EXTRA_CPPFLAGS)
269 cmd_compile-m = $(CC) $^ -c -o $@ $(CFLAGS) $(CFLAGS-$(suffix $@)) $(CFLAGS-$(notdir $(@D))) $(CFLAGS-$(notdir $@)) $(sort $(foreach d,$(^:$(top_srcdir)=),$(collect_multi_flags)))
270 cmd_strip     = $(STRIPTOOL) $(STRIP_FLAGS) $^
271 cmd_t_strip   = $(STRIPTOOL) $(STRIP_FLAGS) $@
272 cmd_ar        = $(AR) $(ARFLAGS) $@ $(call objects_with_syms,,$^)
274 define do_ln
275         @$(disp_ln)
276         $(Q)$(LN) -fs
277 endef
279 define do_mkdir
280         @$(disp_mkdir)
281         $(Q)$(INSTALL) -d $@
282 endef
284 define do_rm
285         @$(disp_rm)
286         $(Q)$(RM)
287 endef
289 define do_awk
290         @$(disp_gen)
291         $(Q)$(AWK) -f
292 endef
294 define do_sed
295         @$(disp_gen)
296         $(Q)$(SED)
297 endef
299 compile.c = @$(call maybe_exec,compile.c)
300 compile.i =  $(call maybe_exec,compile.i)
301 compile.s =  $(call maybe_exec,compile.s)
302 compile.S = @$(call maybe_exec,compile.S)
303 compile.m = @$(call maybe_exec,compile.m)
304 compile.mi=  $(call maybe_exec,compile.mi)
305 compile-m = @$(disp_compile-m) ; $(cmd_compile-m) && $(cmd_t_strip)
306 do_strip  = @$(disp_strip)     ; $(cmd_strip)
307 do_t_strip= @$(disp_t_strip)   ; $(cmd_t_strip)
308 do_unifdef= @$(disp_unifdef)   ; $(cmd_unifdef)
309 hcompile.u= @$(disp_hcompile.u); $(cmd_hcompile.u)
310 hcompile.o= @$(disp_hcompile.o); $(cmd_hcompile.o)
312 define do_ar
313         @$(disp_ar) ; $(cmd_ar)
314         @$(do_t_strip)
315 endef
316 define compile.u
317         @$(disp_compile.u) ; $(cmd_compile.u)
318         @$(disp_t_strip)
319 endef
320 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 $@))
321 cmd_hcompile.o = $(HOSTCC) $(filter-out $(PHONY),$<) $(DEPS-$(notdir $@)) -c -o $@ $(BUILD_CFLAGS) $(BUILD_CFLAGS-$(notdir $(^D))) $(BUILD_CFLAGS-$(notdir $@))
323 define link.so
324         $(Q)$(RM) $@ $@.$(2) $(dir $@)$(1)
325         @$(disp_ld)
326         $(Q)$(CC) $(LDFLAGS-$(notdir $@)) $(LDFLAGS-y-$(@F)) \
327                 -Wl,-soname=$(notdir $@).$(2) \
328                 $(CFLAG_-nostdlib) $(CFLAG_-nostartfiles) \
329                 -o $(dir $@)$(1) $(START_FILE-$(notdir $@)) \
330                 -Wl,--whole-archive $(firstword $^) -Wl,--no-whole-archive \
331                 $(LIBS-$(notdir $@)) $(LIBGCC) $(END_FILE-$(notdir $@))
332         $(Q)$(LN) -sf $(1) $@.$(2)
333         $(Q)$(LN) -sf $(1) $@
334 endef
336 # CRT files needed by link-flat.so
337 LINK_FLAT_CRTS := $(top_builddir)lib/Scrt1.o $(top_builddir)lib/crti.o \
338         $(top_builddir)lib/crtn.o
340 # Create a shared flat library from the archive named by the first dependency.
341 # $@ names the shared library's .gdb file, not the flat file itself.
342 # (This is because the .gdb suffix makes the ELF file more distinctive
343 # than the suffixless flat file.)
345 # Argument 1 is the shared library file -- i.e. $(@:.gdb=) -- and argument 2
346 # is the shared library identifier.  If it wasn't for $(disp_ld), we could
347 # avoid passing $(@:.gdb=) as an argument and use $(@:.gdb=) instead of $(1).
349 # This is so far only used for libc, for which we want to link the entire
350 # libgcc into the shared object.
351 define link-flat.so
352         $(Q)$(RM) $(1) $@
353         @$(disp_ld)
354         $(Q)$(CC) $(LDFLAGS-$(notdir $@)) $(CFLAG_-nostdlib) -o $(1) \
355                 -Wl,-elf2flt -Wl,-shared-lib-id,$(2) $(top_builddir)lib/Scrt1.o \
356                 $(top_builddir)/lib/crti.o -Wl,--whole-archive $(firstword $^) \
357                 $(LIBGCC) -Wl,--no-whole-archive $(LIBS-$(notdir $@)) $(LIBGCC) \
358                 $(top_builddir)/lib/crtn.o
359 endef
361 CFLAGS-.os+=$(PICFLAG)
362 CFLAGS-.oS+=$(PICFLAG) -DSHARED
364 $(top_builddir)%.o:  $(top_srcdir)%.c FORCE ; $(compile.c)
365 $(top_builddir)%.os: $(top_srcdir)%.c FORCE | pregen; $(compile.c)
366 $(top_builddir)%.oS: $(top_srcdir)%.c FORCE | pregen; $(compile.c)
367 $(top_builddir)%.o:  $(top_srcdir)%.S FORCE ; $(compile.S)
368 $(top_builddir)%.os: $(top_srcdir)%.S FORCE | pregen; $(compile.S)
369 $(top_builddir)%.oS: $(top_srcdir)%.S FORCE | pregen; $(compile.S)
370 $(top_builddir)%.o:  $(top_srcdir)%.s FORCE ; $(compile.S)
371 $(top_builddir)%.os: $(top_srcdir)%.s FORCE ; $(compile.S)
372 $(top_builddir)%.oS: $(top_srcdir)%.s FORCE | pregen; $(compile.S)
373 $(top_builddir)%.i:  $(top_srcdir)%.c FORCE | pregen; $(compile.i)
374 $(top_builddir)%.i:  $(top_srcdir)%.S FORCE | pregen; $(compile.i)
375 $(top_builddir)%.s:  $(top_srcdir)%.c FORCE | pregen; $(compile.s)
376 $(top_builddir)%.s:  $(top_srcdir)%.S FORCE | pregen; $(compile.s)
377 $(top_builddir)%.dep:
379 $(top_builddir)lib/interp.c: | $(top_builddir)lib
380         $(Q)echo "/* Force shared libraries to know about the correct library loader */" > $@.tmp
381         $(Q)echo "#include <features.h>" >> $@.tmp
382         $(Q)echo "const char __dl_ldso__[] attribute_hidden __attribute__ ((weak)) __attribute__ ((section " \
383                 "(\".interp\"))) =\""$(RUNTIME_PREFIX)$(MULTILIB_DIR)/$(UCLIBC_LDSO)"\";" >> $@.tmp
384         $(Q)$(SED) -i -e 's://:/:g' $@.tmp
385         $(Q)mv $@.tmp $@
387 $(interp): $(top_builddir)lib/interp.c | $(sub_headers)
388         $(compile.c)
389         $(Q)$(STRIPTOOL) -x -R .note -R .comment $@
391 $(ldso):
392         $(Q)cd $(top_builddir); $(MAKE) lib/$(patsubst %.$(ABI_VERSION),%,$(notdir $@))
393 $(libc):
394         $(Q)cd $(top_builddir); $(MAKE) lib/$(patsubst %.$(ABI_VERSION),%,$(notdir $@))
396 CRT := crt1
398 ifeq ($(HAVE_SHARED)$(UCLIBC_FORMAT_SHARED_FLAT),y)
399 CRTS=$(top_builddir)lib/$(CRT).o $(top_builddir)lib/S$(CRT).o
400 else
401 CRTS=$(top_builddir)lib/$(CRT).o
402 endif
404 ASFLAGS-$(CRT).o := -DL_$(CRT)
405 ASFLAGS-S$(CRT).o := $(PIEFLAG) -DL_S$(CRT)
406 $(CRTS): $(top_srcdir)libc/sysdeps/linux/$(TARGET_ARCH)/$(CRT).S
407         $(compile.S)
408         $(Q)$(STRIPTOOL) -x -R .note -R .comment $@
410 ifeq ($(UCLIBC_CTOR_DTOR),y)
411 CTOR_TARGETS=$(top_builddir)lib/crti.o $(top_builddir)lib/crtn.o
412 else
413 CTOR_TARGETS:=
414 endif
415 ifeq ($(HAS_NO_THREADS)$(UCLIBC_HAS_THREADS_NATIVE),)
416 $(lib-so-y): $(CTOR_TARGETS)
417 endif
419 ifeq ($(UCLIBC_FORMAT_FDPIC_ELF),y)
420 CRTRELOC=$(top_builddir)lib/crtreloc.o
421 $(CRTRELOC): $(top_builddir)lib/%.o : $(top_srcdir)libc/sysdeps/linux/$(TARGET_ARCH)/%.c
422         $(compile.c)
423 endif
425 ifneq ($(wildcard $(top_srcdir)libc/sysdeps/linux/$(TARGET_ARCH)/initfini.c),)
426 CFLAGS-initfini.s := -S -g0 $(PICFLAG) -fno-inline-functions -finhibit-size-directive
427 $(top_builddir)lib/initfini.s: $(top_srcdir)libc/sysdeps/linux/$(TARGET_ARCH)/initfini.c | $(top_builddir)lib
428         $(compile.c)
430 $(top_builddir)lib/defs.h: $(top_builddir)lib/initfini.s
431         $(do_sed) -n -e '/@TESTS_BEGIN/,/@TESTS_END/p' $< | \
432                 $(AWK) -f $(top_srcdir)extra/scripts/defs.awk > $@.tmp
433         $(Q)mv $@.tmp $@
435 $(top_builddir)lib/crti.S: $(top_builddir)lib/initfini.s $(top_builddir)lib/defs.h
436         $(do_sed) -n -e '1,/@HEADER_ENDS/p' \
437                 -e '/@_.*_PROLOG_BEGINS/,/@_.*_PROLOG_ENDS/p' \
438                 -e '/@TRAILER_BEGINS/,$$p' $< > $@
440 $(top_builddir)lib/crtn.S: $(top_builddir)lib/initfini.s
441         $(do_sed) -n -e '1,/@HEADER_ENDS/p' \
442                 -e '/@_.*_EPILOG_BEGINS/,/@_.*_EPILOG_ENDS/p' \
443                 -e '/@TRAILER_BEGINS/,$$p' $< > $@
445 $(CTOR_TARGETS): $(top_builddir)lib/%.o : $(top_builddir)lib/%.S
446         $(compile.S) $(PICFLAG) $(SSP_DISABLE_FLAGS)
447 else
448 $(CTOR_TARGETS): $(top_builddir)lib/%.o : $(top_srcdir)libc/sysdeps/linux/$(TARGET_ARCH)/%.S
449         $(compile.S) $(PICFLAG) $(SSP_DISABLE_FLAGS)
450 endif
452 CRTS_COMPAT :=
454 startfiles = $(CRTS) $(CTOR_TARGETS) $(CRTS_COMPAT) $(CRTRELOC)
455 startfiles: $(startfiles)
456 $(CRTS) $(CTOR_TARGETS) $(CRTS_COMPAT) $(CRTRELOC): | headers
457 $(CRTS) $(CTOR_TARGETS) $(CRTS_COMPAT) $(CRTRELOC) \
458         $(LINK_FLAT_CRTS) $(SHARED_START_FILES) $(SHARED_END_FILES): | $(top_builddir)lib
460 $(top_builddir)lib/$(NONSHARED_LIBNAME): $(libc-nonshared-y)
461         $(Q)$(RM) $@
462         $(do_ar)
464 $(top_builddir)lib/libpthread_nonshared.a: $(libpthread-nonshared-y)
465         $(Q)$(RM) $@
466         $(do_ar)
468 files.dep := $(libc-a-y) $(libc-so-y) $(libc-nonshared-y) \
469         $(libm-a-y) $(libm-so-y) \
470         $(libpthread-a-y) $(libpthread-so-y) $(libpthread-nonshared-y) \
471         $(libthread_db-a-y) $(libthread_db-so-y) $(libpthread-generated-y) \
472         $(START_FILE-libpthread.so) $(END_FILE-libpthread.so) \
473         $(PTHREAD_INITFINI:.c=.s) \
474         $(librt-a-y) $(librt-so-y) \
475         $(libcrypt-a-y) $(libcrypt-so-y) $(libutil-a-y) $(libutil-so-y) \
476         $(ldso-y) $(libdl-a-y) $(libdl-so-y) \
477         $(libubacktrace-a-y) $(libubacktrace-so-y) $(libuargp-so-y) $(libuargp-a-y)
478 .depends.dep := \
479         $(patsubst %.s,%.s.dep,$(filter %.s,$(files.dep))) \
480         $(patsubst %.o,%.o.dep,$(filter %.o,$(files.dep))) \
481         $(patsubst %.os,%.os.dep,$(filter %.os,$(files.dep))) \
482         $(patsubst %.oS,%.oS.dep,$(filter %.oS,$(files.dep)))
483 # Oh, and prepend a dot to the basename so i don't have to change my habit of
484 # calling 'size thefile.o*'
485 .depends.dep := $(foreach f,$(.depends.dep),$(dir $(f)).$(notdir $(f)))
486 .depends.dep := $(wildcard $(.depends.dep))
488 FORCE:
490 clean: objclean-y headers_clean-y
491 realclean: clean menuconfig-clean-y
492         $(Q)$(RM) $(.depends.dep)
494 objclean-y: $(objclean-y)
495 headers_clean-y: $(headers_clean-y)
497 ifeq ($(filter $(noconfig_targets),$(MAKECMDGOALS)),)
498 ifneq ($(strip $(.depends.dep)),)
499 .NOEXPORT:
500 -include $(.depends.dep)
501 endif
502 endif
504 # vi: ft=make :