Makerules 6.2 KB

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