Makerules 7.3 KB

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