Makerules 7.5 KB

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