Makerules 7.3 KB

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