Makerules 19 KB

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