Makerules 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  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 .E
  5. # order is important, the stripping uses STRIP_FLAGS for lib-so, but not for lib-a
  6. ifeq ($(HAVE_SHARED),y)
  7. .LIBPATTERNS: "lib%.so"
  8. libs: $(lib-so-y) $(lib-a-y)
  9. $(lib-so-y): $(interp)
  10. else
  11. .LIBPATTERNS: "lib%.a"
  12. libs: $(lib-a-y)
  13. endif
  14. objs: all_objs
  15. shared_objs = $(ldso-y) $(libc-y:.o=.os) $(libc-shared-y) $(libc-nonshared-y) $(libdl-so-y)
  16. shared_objs += $(libcrypt-so-y) $(libintl-so-y) $(libm-so-y) $(libnsl-so-y) $(libpthread-so-y) $(libpthread-nonshared-y)
  17. shared_objs += $(libthread_db-so-y) $(libresolv-so-y) $(librt-so-y) $(libutil-so-y)
  18. ar_objs = $(libc-y) $(libc-static-y) $(libdl-a-y) $(libcrypt-a-y) $(libintl-a-y) $(libm-a-y) $(libnsl-a-y)
  19. ar_objs += $(libpthread-a-y) $(libthread_db-a-y) $(libresolv-a-y) $(librt-a-y) $(libutil-a-y)
  20. ifeq ($(DOPIC),y)
  21. ar_objs := $(ar_objs:.o=.os)
  22. endif
  23. ifeq ($(HAVE_SHARED),y)
  24. all_objs: $(sort $(shared_objs) $(ar_objs))
  25. else
  26. all_objs: $(ar_objs)
  27. endif
  28. $(shared_objs) $(ar_objs): | $(sub_headers)
  29. headers-y: $(headers-y)
  30. @true
  31. MAKEFLAGS += --no-print-directory
  32. SHELL_SET_X := set +x
  33. ifneq ($(findstring s,$(MAKEFLAGS)),)
  34. export MAKE_IS_SILENT := y
  35. SECHO := -@false
  36. DISP := sil
  37. Q := @
  38. else
  39. export MAKE_IS_SILENT := n
  40. SECHO := @echo
  41. ifneq ($(V)$(VERBOSE),)
  42. SHELL_SET_X := set -x
  43. DISP := ver
  44. Q :=
  45. else
  46. DISP := pur
  47. Q := @
  48. endif
  49. endif
  50. show_objs = $(subst ../,,$@)
  51. pur_disp_compile.c = echo " "CC $(show_objs)
  52. pur_disp_compile.S = echo " "AS $(show_objs)
  53. pur_disp_compile.m = $(pur_disp_compile.c)
  54. pur_disp_compile-m = echo " "CC-m $(show_objs)
  55. pur_disp_strip = echo " "STRIP $(STRIP_FLAGS) $@
  56. pur_disp_t_strip = echo " "STRIP $(STRIP_FLAGS) $@
  57. pur_disp_ar = echo " "AR $(ARFLAGS) $@
  58. pur_disp_ld = echo " "LD $(1)
  59. sil_disp_compile.c = true
  60. sil_disp_compile.S = true
  61. sil_disp_compile.m = true
  62. sil_disp_compile-m = true
  63. sil_disp_strip = true
  64. sil_disp_t_strip = true
  65. sil_disp_ar = true
  66. sil_disp_ld = true
  67. ver_disp_compile.c = echo $(cmd_compile.c)
  68. ver_disp_compile.S = echo $(cmd_compile.S)
  69. ver_disp_compile.m = echo $(cmd_compile.m)
  70. ver_disp_compile-m = echo $(cmd_compile-m)
  71. ver_disp_strip = echo $(cmd_strip)
  72. ver_disp_t_strip = echo $(cmd_t_strip)
  73. ver_disp_ar = echo $(cmd_ar)
  74. ver_disp_ld =
  75. disp_compile.c = $($(DISP)_disp_compile.c)
  76. disp_compile.S = $($(DISP)_disp_compile.S)
  77. disp_compile.m = $($(DISP)_disp_compile.m)
  78. disp_compile-m = $($(DISP)_disp_compile-m)
  79. disp_strip = $($(DISP)_disp_strip)
  80. disp_t_strip = $($(DISP)_disp_t_strip)
  81. disp_ar = $($(DISP)_disp_ar)
  82. disp_ld = $($(DISP)_disp_ld)
  83. cmd_compile.c = $(CC) -c $< -o $@ $(CFLAGS) $(ARCH_CFLAGS) $(CFLAGS-$(suffix $@)) $(filter-out $(CFLAGS-OMIT-$(notdir $<)),$(CFLAGS-$(notdir $(^D)))) $(CFLAGS-$(subst $(top_srcdir),,$(dir $<))) $(CFLAGS-$(notdir $<)) $(CFLAGS-$(notdir $@))
  84. cmd_compile.S = $(cmd_compile.c) -D__ASSEMBLER__ $(ASFLAGS) $(ARCH_ASFLAGS) $(ASFLAGS-$(suffix $@)) $(ASFLAGS-$(notdir $<)) $(ASFLAGS-$(notdir $@))
  85. cmd_compile.m = $(cmd_compile.c) -DL_$(patsubst %$(suffix $(notdir $@)),%,$(notdir $@))
  86. cmd_compile-m = $(CC) $^ -c -o $@ $(CFLAGS) $(ARCH_CFLAGS) $(CFLAGS-$(suffix $@)) $(CFLAGS-$(notdir $(@D))) $(CFLAGS-$(notdir $@))
  87. cmd_strip = $(STRIPTOOL) $(STRIP_FLAGS) $^
  88. cmd_t_strip = $(STRIPTOOL) $(STRIP_FLAGS) $@
  89. cmd_ar = $(AR) $(ARFLAGS) $@ $^
  90. compile.c = @$(disp_compile.c) ; $(cmd_compile.c)
  91. compile.E = $(cmd_compile.c:-c=-E)
  92. compile.s = $(cmd_compile.c:-c=-S)
  93. compile.S = @$(disp_compile.S) ; $(cmd_compile.S)
  94. compile.m = @$(disp_compile.m) ; $(cmd_compile.m)
  95. compile-m = @$(disp_compile-m) ; $(cmd_compile-m)
  96. do_strip = @$(disp_strip) ; $(cmd_strip)
  97. do_t_strip= @$(disp_t_strip) ; $(cmd_t_strip)
  98. do_ar = @$(disp_ar) ; $(cmd_ar)
  99. define compile.u
  100. @$(disp_compile.c)
  101. $(Q)$(CC) $^ $(DEPS-$(notdir $@)) -o $@ $(CFLAGS) $(CFLAGS-$(notdir $(^D))) $(CFLAGS-$(notdir $@))
  102. @$(disp_strip)
  103. $(Q)$(STRIPTOOL) $(STRIP_FLAGS) $@
  104. endef
  105. hcompile.u = $(HOSTCC) $^ $(DEPS-$(notdir $@)) -o $@ $(BUILD_LDFLAGS) $(BUILD_LDFLAGS-$(notdir $(^D))) $(BUILD_LDFLAGS-$(notdir $@)) $(BUILD_CFLAGS) $(BUILD_CFLAGS-$(notdir $(^D))) $(BUILD_CFLAGS-$(notdir $@))
  106. hcompile.o = $(HOSTCC) $^ $(DEPS-$(notdir $@)) -c -o $@ $(BUILD_CFLAGS) $(BUILD_CFLAGS-$(notdir $(^D))) $(BUILD_CFLAGS-$(notdir $@))
  107. define link.so
  108. $(Q)$(INSTALL) -d $(dir $@)
  109. $(Q)$(RM) $@ $@.$(2) $(dir $@)$(1)
  110. @$(disp_ld)
  111. $(Q)$(LD) $(LDFLAGS-$(notdir $@)) -soname=$(notdir $@).$(2) \
  112. -o $(dir $@)$(1) $(START_FILE-$(notdir $@)) \
  113. --whole-archive $(firstword $^) --no-whole-archive \
  114. $(LIBS-$(notdir $@)) $(LIBGCC) $(END_FILE-$(notdir $@))
  115. $(Q)$(LN) -sf $(1) $@.$(2)
  116. $(Q)$(LN) -sf $(1) $@
  117. endef
  118. define linkm.so
  119. $(Q)$(INSTALL) -d $(dir $@)
  120. $(Q)$(RM) $@ $@.$(2) $(dir $@)$(1)
  121. @$(disp_ld)
  122. $(Q)$(LD) $(LDFLAGS-$(notdir $@)) -soname=$(notdir $@).$(2) \
  123. -o $(dir $@)$(1) $(START_FILE-$(notdir $@)) $^ \
  124. $(LIBS-$(notdir $@)) $(LIBGCC) $(END_FILE-$(notdir $@))
  125. $(Q)$(LN) -sf $(1) $@.$(2)
  126. $(Q)$(LN) -sf $(1) $@
  127. endef
  128. CFLAGS-.os+=$(PICFLAG)
  129. CFLAGS-.oS+=$(PICFLAG) -DSHARED
  130. %.o: %.c ; $(compile.c)
  131. %.os: %.c ; $(compile.c)
  132. %.oS: %.c ; $(compile.c)
  133. %.o: %.S ; $(compile.S)
  134. %.os: %.S ; $(compile.S)
  135. %.oS: %.S ; $(compile.S)
  136. %.o: %.s ; $(compile.S)
  137. %.os: %.s ; $(compile.S)
  138. %.oS: %.s ; $(compile.S)
  139. %.E: %.c ; $(compile.E)
  140. %.E: %.S ; $(compile.E)
  141. %.i: %.c ; $(compile.E)
  142. %.i: %.S ; $(compile.E)
  143. %.s: %.c ; $(compile.s)
  144. %.s: %.S ; $(compile.s)
  145. $(top_builddir)lib/interp.c: | $(sub_headers)
  146. $(Q)$(INSTALL) -d $(dir $@)
  147. $(Q)echo "/* Force shared libraries to know about the correct library loader */" > $@
  148. $(Q)echo "#include <features.h>" >> $@
  149. $(Q)echo "const char __dl_ldso__[] __attribute__ ((section " \
  150. "(\".interp\"))) =\""$(SHARED_LIB_LOADER_PREFIX)/$(UCLIBC_LDSO)"\";" >> $@
  151. $(interp): $(top_builddir)lib/interp.c
  152. $(compile.c)
  153. $(Q)$(STRIPTOOL) -x -R .note -R .comment $@
  154. $(ldso):
  155. @cd $(top_builddir); $(MAKE) lib/$(patsubst %.$(MAJOR_VERSION),%,$(notdir $@))
  156. $(libc):
  157. @cd $(top_builddir); $(MAKE) lib/$(patsubst %.$(MAJOR_VERSION),%,$(notdir $@))
  158. $(headers_dep):
  159. $(Q)cd $(top_builddir); $(MAKE) headers
  160. CRT := crt1
  161. ifeq ($(HAVE_SHARED),y)
  162. CRTS=$(top_builddir)lib/$(CRT).o $(top_builddir)lib/S$(CRT).o
  163. else
  164. CRTS=$(top_builddir)lib/$(CRT).o
  165. endif
  166. ASFLAGS-$(CRT).o := -DL_$(CRT)
  167. ASFLAGS-S$(CRT).o := $(PIEFLAG) -DL_S$(CRT)
  168. $(CRTS): $(top_srcdir)libc/sysdeps/linux/$(TARGET_ARCH)/$(CRT).S
  169. $(Q)$(INSTALL) -d $(dir $@)
  170. $(compile.S)
  171. $(Q)$(STRIPTOOL) -x -R .note -R .comment $@
  172. ifeq ($(UCLIBC_CTOR_DTOR),y)
  173. CTOR_TARGETS=$(top_builddir)lib/crti.o $(top_builddir)lib/crtn.o
  174. else
  175. CTOR_TARGETS:=
  176. endif
  177. ifneq ($(wildcard $(top_srcdir)libc/sysdeps/linux/$(TARGET_ARCH)/initfini.c),)
  178. CFLAGS-initfini.s := -S -g0 $(PICFLAG) -fno-inline-functions -finhibit-size-directive
  179. $(top_builddir)lib/initfini.s: $(top_srcdir)libc/sysdeps/linux/$(TARGET_ARCH)/initfini.c
  180. $(compile.c)
  181. $(top_builddir)lib/defs.h: $(top_builddir)lib/initfini.s
  182. $(Q)sed -n -e '/@TESTS_BEGIN/,/@TESTS_END/p' $< | \
  183. gawk -f $(top_srcdir)extra/scripts/defs.awk > $@.tmp
  184. $(Q)mv $@.tmp $@
  185. $(top_builddir)lib/crti.S: $(top_builddir)lib/initfini.s $(top_builddir)lib/defs.h
  186. $(Q)sed -n -e '1,/@HEADER_ENDS/p' \
  187. -e '/@_.*_PROLOG_BEGINS/,/@_.*_PROLOG_ENDS/p' \
  188. -e '/@TRAILER_BEGINS/,$$p' $< > $@
  189. $(top_builddir)lib/crtn.S: $(top_builddir)lib/initfini.s
  190. $(Q)sed -n -e '1,/@HEADER_ENDS/p' \
  191. -e '/@_.*_EPILOG_BEGINS/,/@_.*_EPILOG_ENDS/p' \
  192. -e '/@TRAILER_BEGINS/,$$p' $< > $@
  193. $(CTOR_TARGETS): $(top_builddir)lib/%.o : $(top_builddir)lib/%.S
  194. $(Q)$(INSTALL) -d $(dir $@)
  195. $(compile.S) $(PICFLAG) $(SSP_DISABLE_FLAGS)
  196. else
  197. $(CTOR_TARGETS): $(top_builddir)lib/%.o : $(top_srcdir)libc/sysdeps/linux/$(TARGET_ARCH)/%.S
  198. $(Q)$(INSTALL) -d $(dir $@)
  199. $(compile.S) $(PICFLAG) $(SSP_DISABLE_FLAGS)
  200. endif
  201. #ifeq ($(TARGET_ARCH),nios)
  202. #CRTS_COMPAT := $(top_builddir)lib/crt0.o
  203. #$(CRTS_COMPAT):
  204. # ln -fs crt1.o $(top_builddir)lib/crt0.o
  205. #else
  206. CRTS_COMPAT :=
  207. #endif
  208. $(crt-y): $(CRTS) $(CTOR_TARGETS) $(CRTS_COMPAT)
  209. $(CRTS) $(CTOR_TARGETS) $(CRTS_COMPAT): | headers
  210. $(top_builddir)lib/$(NONSHARED_LIBNAME): $(libc-nonshared-y)
  211. $(Q)$(INSTALL) -d $(dir $@)
  212. $(Q)$(RM) $@
  213. $(do_strip)
  214. $(do_ar)
  215. $(top_builddir)lib/libpthread_nonshared.a: $(libpthread-nonshared-y)
  216. $(Q)$(INSTALL) -d $(dir $@)
  217. $(Q)$(RM) $@
  218. $(do_strip)
  219. $(do_ar)
  220. .PHONY: dummy create
  221. clean: objclean-y headers_clean-y
  222. objclean-y: $(objclean-y)
  223. headers_clean-y: $(headers_clean-y)
  224. .PHONY: \
  225. all check clean distclean test \
  226. config dist menuconfig oldconfig release \
  227. subdirs utils