Makerules 19 KB

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