Makerules 5.9 KB

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