Makerules 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  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. # 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. else
  10. .LIBPATTERNS: "lib%.a"
  11. libs: lib-a-y
  12. endif
  13. lib-a-y: $(lib-a-y)
  14. lib-so-y: $(lib-so-y)
  15. ifneq ($(findstring s,$(MAKEFLAGS)),)
  16. DISP := sil
  17. Q := @
  18. else
  19. ifneq ($(V)$(VERBOSE),)
  20. DISP := ver
  21. Q :=
  22. else
  23. DISP := pur
  24. Q := @
  25. endif
  26. endif
  27. show_objs = $(subst ../,,$@)
  28. pur_disp_compile.c = echo " "CC $(show_objs)
  29. pur_disp_compile.S = echo " "AS $(show_objs)
  30. pur_disp_compile.m = $(pur_disp_compile.c)
  31. pur_disp_compile-m = echo " "CC-m $(show_objs)
  32. pur_disp_strip = echo " "STRIP $(STRIP_FLAGS) $@:*
  33. pur_disp_ar = echo " "AR $(ARFLAGS) $@
  34. pur_disp_ld = echo " "LD $($(LIB_NAME)_FULL_NAME)
  35. sil_disp_compile.c = true
  36. sil_disp_compile.S = true
  37. sil_disp_compile.m = true
  38. sil_disp_compile-m = true
  39. sil_disp_strip = true
  40. sil_disp_ar = true
  41. sil_disp_ld = true
  42. ver_disp_compile.c = echo $(cmd_compile.c)
  43. ver_disp_compile.S = echo $(cmd_compile.S)
  44. ver_disp_compile.m = echo $(cmd_compile.m)
  45. ver_disp_compile-m = echo $(cmd_compile-m)
  46. ver_disp_strip = echo $(cmd_strip)
  47. ver_disp_ar = echo $(cmd_ar)
  48. ver_disp_ld =
  49. disp_compile.c = $($(DISP)_disp_compile.c)
  50. disp_compile.S = $($(DISP)_disp_compile.S)
  51. disp_compile.m = $($(DISP)_disp_compile.m)
  52. disp_compile-m = $($(DISP)_disp_compile-m)
  53. disp_strip = $($(DISP)_disp_strip)
  54. disp_ar = $($(DISP)_disp_ar)
  55. disp_ld = $($(DISP)_disp_ld)
  56. cmd_compile.c = $(CC) -c $< -o $@ $(CFLAGS) $(ARCH_CFLAGS) $(CFLAGS-$(suffix $@)) $(CFLAGS-$(notdir $(^D))) $(CFLAGS-$(subst $(top_srcdir),,$(dir $<))) $(CFLAGS-$(notdir $<)) $(CFLAGS-$(notdir $@))
  57. cmd_compile.S = $(cmd_compile.c) $(ASFLAGS) $(ARCH_ASFLAGS) $(ASFLAGS-$(suffix $@)) $(ASFLAGS-$(notdir $<)) $(ASFLAGS-$(notdir $@))
  58. cmd_compile.m = $(cmd_compile.c) -DL_$(patsubst %$(suffix $(notdir $@)),%,$(notdir $@))
  59. cmd_compile-m = $(CC) $^ -c -o $@ $(CFLAGS) $(ARCH_CFLAGS) $(CFLAGS-$(suffix $@)) $(CFLAGS-$(notdir $@)) $(CFLAGS-multi-y)
  60. cmd_strip = $(STRIPTOOL) $(STRIP_FLAGS) $^
  61. cmd_ar = $(AR) $(ARFLAGS) $@ $^
  62. compile.c = @$(disp_compile.c) ; $(cmd_compile.c)
  63. compile.E = $(cmd_compile.c:-c=-E)
  64. compile.S = @$(disp_compile.S) ; $(cmd_compile.S)
  65. compile.m = @$(disp_compile.m) ; $(cmd_compile.m)
  66. compile-m = @$(disp_compile-m) ; $(cmd_compile-m)
  67. do_strip = @$(disp_strip) ; $(cmd_strip)
  68. do_ar = @$(disp_ar) ; $(cmd_ar)
  69. define link.so
  70. $(Q)$(INSTALL) -d $(dir $@)
  71. $(Q)$(RM) $@ $@.$(2) $(dir $@)$(1)
  72. @$(disp_ld)
  73. $(Q)$(LD) $(LDFLAGS-$(notdir $@)) -soname=$(notdir $@).$(2) \
  74. -o $(dir $@)$(1) $(START_FILE-$(notdir $@)) \
  75. --whole-archive $(firstword $^) --no-whole-archive \
  76. $(LIBS-$(notdir $@)) $(LIBGCC) $(END_FILE-$(notdir $@))
  77. $(Q)$(LN) -sf $(1) $@.$(2)
  78. $(Q)$(LN) -sf $(1) $@
  79. endef
  80. CFLAGS-.os+=$(PICFLAG)
  81. CFLAGS-.oS+=$(PICFLAG) -DSHARED
  82. %.o: %.c ; $(compile.c)
  83. %.os: %.c ; $(compile.c)
  84. %.oS: %.c ; $(compile.c)
  85. %.o: %.S ; $(compile.S)
  86. %.os: %.S ; $(compile.S)
  87. %.o: %.s ; $(compile.S)
  88. %.os: %.s ; $(compile.S)
  89. %.E: %.c ; $(compile.E)
  90. %.E: %.S ; $(compile.E)
  91. #ifeq ($(HAVE_ELF),y)
  92. CRT=crt1
  93. #else
  94. #CRT=crt0
  95. #endif
  96. ifeq ($(HAVE_SHARED),y)
  97. CRTS=$(top_builddir)lib/$(CRT).o $(top_builddir)lib/S$(CRT).o
  98. else
  99. CRTS=$(top_builddir)lib/$(CRT).o
  100. endif
  101. $(top_builddir)lib/$(CRT).o: $(top_srcdir)libc/sysdeps/linux/$(TARGET_ARCH)/$(CRT).S
  102. $(Q)$(INSTALL) -d $(dir $@)
  103. $(compile.S) -DL_$(patsubst %$(suffix $(notdir $@)),%,$(notdir $@))
  104. @$(disp_strip) $(show_objs)
  105. $(Q)$(STRIPTOOL) -x -R .note -R .comment $@
  106. $(top_builddir)lib/S$(CRT).o: $(top_srcdir)libc/sysdeps/linux/$(TARGET_ARCH)/$(CRT).S
  107. $(Q)$(INSTALL) -d $(dir $@)
  108. $(compile.S) $(PIEFLAG) -DL_$(patsubst %$(suffix $(notdir $@)),%,$(notdir $@))
  109. @$(disp_strip) $(show_objs)
  110. $(Q)$(STRIPTOOL) -x -R .note -R .comment $@
  111. CTOR_TARGETS=$(top_builddir)lib/crti.o $(top_builddir)lib/crtn.o
  112. ifeq ($(UCLIBC_CTOR_DTOR),y)
  113. $(top_builddir)lib/crti.o: $(top_srcdir)libc/sysdeps/linux/$(TARGET_ARCH)/crti.S
  114. $(Q)$(INSTALL) -d $(dir $@)
  115. $(compile.S) $(PICFLAG) $(SSP_DISABLE_FLAGS)
  116. $(top_builddir)lib/crtn.o: $(top_srcdir)libc/sysdeps/linux/$(TARGET_ARCH)/crtn.S
  117. $(Q)$(INSTALL) -d $(dir $@)
  118. $(compile.S) $(PICFLAG) $(SSP_DISABLE_FLAGS)
  119. else
  120. $(CTOR_TARGETS):
  121. $(Q)$(INSTALL) -d $(top_builddir)lib
  122. $(do_ar)
  123. endif
  124. crt-y: $(crt-y)
  125. $(crt-y): $(CRTS) $(CTOR_TARGETS)
  126. other-y: $(other-y)
  127. headers-y: $(headers-y)
  128. objclean-y: $(objclean-y)
  129. headers_clean-y: $(headers_clean-y)
  130. $(top_builddir)lib/$(NONSHARED_LIBNAME): $(libc-nonshared-y)
  131. $(Q)$(INSTALL) -d $(dir $@)
  132. $(do_ar)
  133. .PHONY: dummy create
  134. clean: objclean-y headers_clean-y
  135. ifeq ($(strip $(LIB_NAME)),)
  136. LIB_NAME=libc
  137. endif
  138. ifeq ($(strip $($(LIB_NAME)_FULL_NAME)),)
  139. $(LIB_NAME)_FULL_NAME:=$(LIB_NAME)-$(MAJOR_VERSION).$(MINOR_VERSION).$(SUBLEVEL).so
  140. endif
  141. $(LIB_NAME)-SHARED_OBJS=$($(LIB_NAME)-so-y) $($(LIB_NAME)-shared-y)
  142. ifeq ($(HAVE_SHARED),y)
  143. shared: $($(LIB_NAME)-SHARED_OBJS)
  144. else
  145. shared:
  146. endif
  147. $(LIB_NAME)-ARCHIVE_OBJS=$($(LIB_NAME)-a-y) $($(LIB_NAME)-static-y)
  148. ifeq ($(DOPIC),y)
  149. objs: shared $($(LIB_NAME)-ARCHIVE_OBJS:.o=.os) $(crt-y) $(other-y)
  150. else
  151. objs: shared $($(LIB_NAME)-ARCHIVE_OBJS) $(crt-y) $(other-y)
  152. endif
  153. libc=$(top_builddir)lib/libc.so
  154. interp=$(top_builddir)libc/misc/internals/interp.os
  155. ifeq ($(strip $(EXTRA_LINK_LIBS)),)
  156. #EXTRA_LINK_LIBS:=$(interp) -L$(top_builddir)lib -lc $(LDADD_LIBFLOAT) $(LIBGCC)
  157. EXTRA_LINK_LIBS:=$(interp) -L$(top_builddir)lib $(libc) $(LDADD_LIBFLOAT) $(LIBGCC)
  158. endif
  159. ifneq ($(strip $(LIB_NAME)),libc)
  160. ifneq ($(strip $(LIB_NAME)),ld-uClibc)
  161. $(top_builddir)lib/$(LIB_NAME).so: $($(LIB_NAME)_OUT)/$(LIB_NAME)_so.a $(interp) $(libc)
  162. else
  163. $(top_builddir)lib/$(LIB_NAME).so: $($(LIB_NAME)_OUT)/$(LIB_NAME)_so.a
  164. endif
  165. else
  166. $(top_builddir)lib/$(LIB_NAME).so: $($(LIB_NAME)_OUT)/$(LIB_NAME)_so.a $(interp)
  167. endif
  168. $(Q)$(INSTALL) -d $(dir $@)
  169. $(Q)$(RM) $@ $@.$(MAJOR_VERSION) $(top_builddir)lib/$($(LIB_NAME)_FULL_NAME)
  170. @$(disp_ld)
  171. $(Q)$(LD) $(LDFLAGS) $(EXTRA_LINK_OPTS) -soname=$(notdir $@).$(MAJOR_VERSION) \
  172. -o $(top_builddir)lib/$($(LIB_NAME)_FULL_NAME) $(SHARED_START_FILES) \
  173. --whole-archive $(firstword $^) --no-whole-archive \
  174. $(EXTRA_LINK_LIBS) $(SHARED_END_FILES)
  175. $(Q)$(LN) -sf $($(LIB_NAME)_FULL_NAME) $@.$(MAJOR_VERSION)
  176. ifneq ($(strip $(LIB_NAME)),libc)
  177. ifneq ($(strip $(LIB_NAME)),ld-uClibc)
  178. $(Q)$(LN) -sf $($(LIB_NAME)_FULL_NAME) $@
  179. endif
  180. else
  181. $(Q)echo "/* GNU ld script" > $@
  182. $(Q)echo " * Use the shared library, but some functions are only in" >> $@
  183. $(Q)echo " * the static library, so try that secondarily. */" >> $@
  184. ifeq ($(COMPAT_ATEXIT),y)
  185. $(Q)echo "GROUP ( $(NONSHARED_LIBNAME) $(SHARED_MAJORNAME) $(ASNEEDED) )" >> $@
  186. else
  187. $(Q)echo "GROUP ( $(SHARED_MAJORNAME) $(NONSHARED_LIBNAME) $(ASNEEDED) )" >> $@
  188. endif
  189. endif
  190. $($(LIB_NAME)_OUT)/$(LIB_NAME)_m.o $($(LIB_NAME)_OUT)/$(LIB_NAME)_m.os: $($(LIB_NAME)-multi-y)
  191. $(compile-m)
  192. # local testing only until libc is multi-capable
  193. libc_m.os: $(libc-multi-y)
  194. $(compile-m)
  195. ifneq ($(DOMULTI),n)
  196. $($(LIB_NAME)_OUT)/$(LIB_NAME)_so.a: $($(LIB_NAME)_OUT)/$(LIB_NAME)_m.os $($(LIB_NAME)-nomulti-y:.o=.os) $($(LIB_NAME)-shared-y)
  197. $(Q)$(RM) $@
  198. $(do_strip)
  199. $(do_ar)
  200. ifeq ($(DOPIC),y)
  201. $(top_builddir)lib/$(LIB_NAME).a: $($(LIB_NAME)_OUT)/$(LIB_NAME)_m.os $($(LIB_NAME)-nomulti-y:.o=.os) $($(LIB_NAME)-static-y:.o=.os)
  202. else
  203. $(top_builddir)lib/$(LIB_NAME).a: $($(LIB_NAME)_OUT)/$(LIB_NAME)_m.o $($(LIB_NAME)-nomulti-y) $($(LIB_NAME)-static-y)
  204. endif
  205. $(Q)$(INSTALL) -d $(dir $@)
  206. $(Q)$(RM) $@
  207. $(do_strip)
  208. $(do_ar)
  209. else # DOMULTI
  210. $($(LIB_NAME)_OUT)/$(LIB_NAME)_so.a: $($(LIB_NAME)-SHARED_OBJS)
  211. $(Q)$(RM) $@
  212. $(do_strip)
  213. $(do_ar)
  214. ifeq ($(DOPIC),y)
  215. $(top_builddir)lib/$(LIB_NAME).a: $($(LIB_NAME)-ARCHIVE_OBJS:.o=.os)
  216. else
  217. $(top_builddir)lib/$(LIB_NAME).a: $($(LIB_NAME)-ARCHIVE_OBJS)
  218. endif
  219. $(Q)$(INSTALL) -d $(dir $@)
  220. $(Q)$(RM) $@
  221. $(do_strip)
  222. $(do_ar)
  223. endif # DOMULTI
  224. $(LIB_NAME)_clean:
  225. $(RM) $($(LIB_NAME)_OUT)/*.{o,os,a}