Makerules 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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. pur_show_objs = $(subst ../,,$@)
  28. pur_disp_compile.c = echo " "CC $(pur_show_objs)
  29. pur_disp_compile.S = echo " "AS $(pur_show_objs)
  30. pur_disp_compile.m = $(pur_disp_compile.c)
  31. pur_disp_compile-m = echo " "CC-m $(pur_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. cmd_compile.c = $(CC) -c $< -o $@ $(CPPFLAGS) $(CFLAGS) $(ARCH_CFLAGS) $(CFLAGS-$(suffix $@)) $(CFLAGS-$(notdir $@)) $(CFLAGS-$(notdir $<))
  50. cmd_compile.S = $(cmd_compile.c) $(S_CPPFLAGS) $(ASFLAGS) $(ARCH_ASFLAGS) $(ASFLAGS-$(suffix $@)) $(ASFLAGS-$(notdir $@)) $(ASFLAGS-$(notdir $<))
  51. cmd_compile.m = $(cmd_compile.c) -DL_$(patsubst %$(suffix $(notdir $@)),%,$(notdir $@))
  52. cmd_compile-m = $(CC) $^ -c -o $@ $(CPPFLAGS) $(CFLAGS) $(ARCH_CFLAGS) $(CFLAGS-$(suffix $@)) $(CFLAGS-$(notdir $@)) $(CFLAGS-$(notdir $<)) $(CFLAGS-multi-y)
  53. cmd_strip = $(STRIPTOOL) $(STRIP_FLAGS) $^
  54. cmd_ar = $(AR) $(ARFLAGS) $@ $^
  55. compile.c = @$($(DISP)_disp_compile.c) ; $(cmd_compile.c)
  56. compile.S = @$($(DISP)_disp_compile.S) ; $(cmd_compile.S)
  57. compile.m = @$($(DISP)_disp_compile.m) ; $(cmd_compile.m)
  58. compile-m = @$($(DISP)_disp_compile-m) ; $(cmd_compile-m)
  59. do_strip = @$($(DISP)_disp_strip) ; $(cmd_strip)
  60. do_ar = @$($(DISP)_disp_ar) ; $(cmd_ar)
  61. disp_ld = $($(DISP)_disp_ld)
  62. CFLAGS-.os+=$(PICFLAG)
  63. CFLAGS-.oS+=$(PICFLAG) -DSHARED
  64. %.o: %.c
  65. $(compile.c)
  66. %.os: %.c
  67. $(compile.c)
  68. %.oS: %.c
  69. $(compile.c)
  70. %.o: %.S
  71. $(compile.S)
  72. %.os: %.S
  73. $(compile.S)
  74. #ifeq ($(HAVE_ELF),y)
  75. CRT=crt1
  76. #else
  77. #CRT=crt0
  78. #endif
  79. ifeq ($(HAVE_SHARED),y)
  80. CRTS=$(top_builddir)lib/$(CRT).o $(top_builddir)lib/S$(CRT).o
  81. else
  82. CRTS=$(top_builddir)lib/$(CRT).o
  83. endif
  84. $(top_builddir)lib/$(CRT).o: $(top_srcdir)libc/sysdeps/linux/$(TARGET_ARCH)/$(CRT).S
  85. $(Q)$(INSTALL) -d $(dir $@)
  86. $(compile.S) -DL_$(patsubst %$(suffix $(notdir $@)),%,$(notdir $@))
  87. $(STRIPTOOL) -x -R .note -R .comment $@
  88. $(top_builddir)lib/S$(CRT).o: $(top_srcdir)libc/sysdeps/linux/$(TARGET_ARCH)/$(CRT).S
  89. $(Q)$(INSTALL) -d $(dir $@)
  90. $(compile.S) $(PIEFLAG) -DL_$(patsubst %$(suffix $(notdir $@)),%,$(notdir $@))
  91. $(STRIPTOOL) -x -R .note -R .comment $@
  92. CTOR_TARGETS=$(top_builddir)lib/crti.o $(top_builddir)lib/crtn.o
  93. ifeq ($(UCLIBC_CTOR_DTOR),y)
  94. $(top_builddir)lib/crti.o: $(top_srcdir)libc/sysdeps/linux/$(TARGET_ARCH)/crti.S
  95. $(Q)$(INSTALL) -d $(dir $@)
  96. $(compile.S) $(PICFLAG) $(SSP_DISABLE_FLAGS)
  97. $(top_builddir)lib/crtn.o: $(top_srcdir)libc/sysdeps/linux/$(TARGET_ARCH)/crtn.S
  98. $(Q)$(INSTALL) -d $(dir $@)
  99. $(compile.S) $(PICFLAG) $(SSP_DISABLE_FLAGS)
  100. else
  101. $(CTOR_TARGETS):
  102. $(Q)$(INSTALL) -d $(top_builddir)lib
  103. $(do_ar)
  104. endif
  105. crt-y: $(crt-y)
  106. $(crt-y): $(CRTS) $(CTOR_TARGETS)
  107. other-y: $(other-y)
  108. headers-y: $(headers-y)
  109. objclean-y: $(objclean-y)
  110. headers_clean-y: $(headers_clean-y)
  111. $(top_builddir)lib/$(NONSHARED_LIBNAME): $(libc-nonshared-y)
  112. $(Q)$(INSTALL) -d $(dir $@)
  113. $(do_ar)
  114. .PHONY: dummy create
  115. clean: objclean-y headers_clean-y
  116. ifeq ($(strip $(LIB_NAME)),)
  117. LIB_NAME=libc
  118. endif
  119. ifeq ($(strip $($(LIB_NAME)_FULL_NAME)),)
  120. $(LIB_NAME)_FULL_NAME:=$(LIB_NAME)-$(MAJOR_VERSION).$(MINOR_VERSION).$(SUBLEVEL).so
  121. endif
  122. $(LIB_NAME)-SHARED_OBJS=$($(LIB_NAME)-so-y) $($(LIB_NAME)-shared-y)
  123. ifeq ($(HAVE_SHARED),y)
  124. shared: $($(LIB_NAME)-SHARED_OBJS)
  125. else
  126. shared:
  127. endif
  128. $(LIB_NAME)-ARCHIVE_OBJS=$($(LIB_NAME)-a-y) $($(LIB_NAME)-static-y)
  129. ifeq ($(DOPIC),y)
  130. objs: shared $($(LIB_NAME)-ARCHIVE_OBJS:.o=.os) $(crt-y) $(other-y)
  131. else
  132. objs: shared $($(LIB_NAME)-ARCHIVE_OBJS) $(crt-y) $(other-y)
  133. endif
  134. libc=$(top_builddir)lib/libc.so
  135. interp=$(top_builddir)libc/misc/internals/interp.os
  136. ifeq ($(strip $(EXTRA_LINK_LIBS)),)
  137. #EXTRA_LINK_LIBS:=$(interp) -L$(top_builddir)lib -lc $(LDADD_LIBFLOAT) $(LIBGCC)
  138. EXTRA_LINK_LIBS:=$(interp) -L$(top_builddir)lib $(libc) $(LDADD_LIBFLOAT) $(LIBGCC)
  139. endif
  140. ifneq ($(strip $(LIB_NAME)),libc)
  141. ifneq ($(strip $(LIB_NAME)),ld-uClibc)
  142. $(top_builddir)lib/$(LIB_NAME).so: $($(LIB_NAME)_OUT)/$(LIB_NAME)_so.a $(interp) $(libc)
  143. else
  144. $(top_builddir)lib/$(LIB_NAME).so: $($(LIB_NAME)_OUT)/$(LIB_NAME)_so.a
  145. endif
  146. else
  147. $(top_builddir)lib/$(LIB_NAME).so: $($(LIB_NAME)_OUT)/$(LIB_NAME)_so.a $(interp)
  148. endif
  149. $(Q)$(INSTALL) -d $(dir $@)
  150. $(Q)$(RM) $@ $@.$(MAJOR_VERSION) $(top_builddir)lib/$($(LIB_NAME)_FULL_NAME)
  151. @$(disp_ld)
  152. $(Q)$(LD) $(LDFLAGS) $(EXTRA_LINK_OPTS) -soname=$(notdir $@).$(MAJOR_VERSION) \
  153. -o $(top_builddir)lib/$($(LIB_NAME)_FULL_NAME) $(SHARED_START_FILES) \
  154. --whole-archive $(firstword $^) --no-whole-archive \
  155. $(EXTRA_LINK_LIBS) $(SHARED_END_FILES)
  156. $(Q)$(LN) -sf $($(LIB_NAME)_FULL_NAME) $@.$(MAJOR_VERSION)
  157. ifneq ($(strip $(LIB_NAME)),libc)
  158. ifneq ($(strip $(LIB_NAME)),ld-uClibc)
  159. $(Q)$(LN) -sf $($(LIB_NAME)_FULL_NAME) $@
  160. endif
  161. else
  162. $(Q)echo "/* GNU ld script" > $@
  163. $(Q)echo " * Use the shared library, but some functions are only in" >> $@
  164. $(Q)echo " * the static library, so try that secondarily. */" >> $@
  165. ifeq ($(COMPAT_ATEXIT),y)
  166. $(Q)echo "GROUP ( $(NONSHARED_LIBNAME) $(SHARED_MAJORNAME) $(ASNEEDED) )" >> $@
  167. else
  168. $(Q)echo "GROUP ( $(SHARED_MAJORNAME) $(NONSHARED_LIBNAME) $(ASNEEDED) )" >> $@
  169. endif
  170. endif
  171. $($(LIB_NAME)_OUT)/$(LIB_NAME)_m.o $($(LIB_NAME)_OUT)/$(LIB_NAME)_m.os: $($(LIB_NAME)-multi-y)
  172. $(compile-m)
  173. # local testing only until libc is multi-capable
  174. libc_m.os: $(libc-multi-y)
  175. $(compile-m)
  176. ifneq ($(DOMULTI),n)
  177. $($(LIB_NAME)_OUT)/$(LIB_NAME)_so.a: $($(LIB_NAME)_OUT)/$(LIB_NAME)_m.os $($(LIB_NAME)-nomulti-y:.o=.os) $($(LIB_NAME)-shared-y)
  178. $(Q)$(RM) $@
  179. $(do_strip)
  180. $(do_ar)
  181. ifeq ($(DOPIC),y)
  182. $(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)
  183. else
  184. $(top_builddir)lib/$(LIB_NAME).a: $($(LIB_NAME)_OUT)/$(LIB_NAME)_m.o $($(LIB_NAME)-nomulti-y) $($(LIB_NAME)-static-y)
  185. endif
  186. $(Q)$(INSTALL) -d $(dir $@)
  187. $(Q)$(RM) $@
  188. $(do_strip)
  189. $(do_ar)
  190. else # DOMULTI
  191. $($(LIB_NAME)_OUT)/$(LIB_NAME)_so.a: $($(LIB_NAME)-SHARED_OBJS)
  192. $(Q)$(RM) $@
  193. $(do_strip)
  194. $(do_ar)
  195. ifeq ($(DOPIC),y)
  196. $(top_builddir)lib/$(LIB_NAME).a: $($(LIB_NAME)-ARCHIVE_OBJS:.o=.os)
  197. else
  198. $(top_builddir)lib/$(LIB_NAME).a: $($(LIB_NAME)-ARCHIVE_OBJS)
  199. endif
  200. $(Q)$(INSTALL) -d $(dir $@)
  201. $(Q)$(RM) $@
  202. $(do_strip)
  203. $(do_ar)
  204. endif # DOMULTI
  205. $(LIB_NAME)_clean:
  206. $(RM) $($(LIB_NAME)_OUT)/*.{o,os,a}