Makerules 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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-y: $(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) -L$(top_builddir)lib $(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 ($(COMPAT_ATEXIT),y)
  118. echo "GROUP ( $(NONSHARED_LIBNAME) $(SHARED_MAJORNAME) $(ASNEEDED) )" >> $@
  119. else
  120. echo "GROUP ( $(SHARED_MAJORNAME) $(NONSHARED_LIBNAME) $(ASNEEDED) )" >> $@
  121. endif
  122. endif
  123. $($(LIB_NAME)_OUT)/$(LIB_NAME)_m.o $($(LIB_NAME)_OUT)/$(LIB_NAME)_m.os: $($(LIB_NAME)-multi-y)
  124. $(compile-m)
  125. # local testing only until libc is multi-capable
  126. libc_m.os: $(libc-multi-y)
  127. $(compile-m)
  128. ifneq ($(DOMULTI),n)
  129. $($(LIB_NAME)_OUT)/$(LIB_NAME)_so.a: $($(LIB_NAME)_OUT)/$(LIB_NAME)_m.os $($(LIB_NAME)-nomulti-y:.o=.os) $($(LIB_NAME)-shared-y)
  130. $(RM) $@
  131. ifneq ($(strip $(STRIP_FLAGS)),)
  132. $(STRIPTOOL) $(STRIP_FLAGS) $^
  133. else
  134. $(STRIPTOOL) -x -R .note -R .comment $^
  135. endif
  136. $(AR) $(ARFLAGS) $@ $^
  137. ifeq ($(DOPIC),y)
  138. $(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)
  139. else
  140. $(top_builddir)lib/$(LIB_NAME).a: $($(LIB_NAME)_OUT)/$(LIB_NAME)_m.o $($(LIB_NAME)-nomulti-y) $($(LIB_NAME)-static-y)
  141. endif
  142. $(INSTALL) -d $(dir $@)
  143. $(RM) $@
  144. $(STRIPTOOL) -x -R .note -R .comment $^
  145. $(AR) $(ARFLAGS) $@ $^
  146. else # DOMULTI
  147. $($(LIB_NAME)_OUT)/$(LIB_NAME)_so.a: $($(LIB_NAME)-SHARED_OBJS)
  148. $(RM) $@
  149. ifneq ($(strip $(STRIP_FLAGS)),)
  150. $(STRIPTOOL) $(STRIP_FLAGS) $^
  151. else
  152. $(STRIPTOOL) -x -R .note -R .comment $^
  153. endif
  154. $(AR) $(ARFLAGS) $@ $^
  155. ifeq ($(DOPIC),y)
  156. $(top_builddir)lib/$(LIB_NAME).a: $($(LIB_NAME)-ARCHIVE_OBJS:.o=.os)
  157. else
  158. $(top_builddir)lib/$(LIB_NAME).a: $($(LIB_NAME)-ARCHIVE_OBJS)
  159. endif
  160. $(INSTALL) -d $(dir $@)
  161. $(RM) $@
  162. $(STRIPTOOL) -x -R .note -R .comment $^
  163. $(AR) $(ARFLAGS) $@ $^
  164. endif # DOMULTI
  165. $(LIB_NAME)_clean:
  166. rm -f $($(LIB_NAME)_OUT)/*.{o,os,a}