Makerules 18 KB

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