Makerules 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  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. $(lib-so-y): $(interp)
  10. else
  11. .LIBPATTERNS: "lib%.a"
  12. ifeq ($(UCLIBC_FORMAT_SHARED_FLAT),y)
  13. libs: $(lib-gdb-y)
  14. endif
  15. libs: $(lib-a-y)
  16. endif
  17. objs: all_objs
  18. shared_objs = $(ldso-y) $(libc-y:.o=.os) $(libc-shared-y) $(libc-nonshared-y) $(libdl-so-y)
  19. shared_objs += $(libcrypt-so-y) $(libintl-so-y) $(libm-so-y) $(libnsl-so-y) $(libpthread-so-y) $(libpthread-nonshared-y)
  20. shared_objs += $(libthread_db-so-y) $(libresolv-so-y) $(librt-so-y) $(libutil-so-y)
  21. ar_objs = $(libc-y) $(libc-static-y) $(libdl-a-y) $(libcrypt-a-y) $(libintl-a-y) $(libm-a-y) $(libnsl-a-y)
  22. ar_objs += $(libpthread-a-y) $(libthread_db-a-y) $(libresolv-a-y) $(librt-a-y) $(libutil-a-y)
  23. ifeq ($(DOPIC),y)
  24. ar_objs := $(ar_objs:.o=.os)
  25. endif
  26. ifeq ($(HAVE_SHARED),y)
  27. all_objs: $(sort $(shared_objs) $(ar_objs))
  28. else
  29. all_objs: $(ar_objs)
  30. endif
  31. $(shared_objs) $(ar_objs): | $(sub_headers)
  32. headers-y: $(headers-y)
  33. @true
  34. MAKEFLAGS += --no-print-directory
  35. SHELL_SET_X := set +x
  36. ifneq ($(findstring s,$(MAKEFLAGS)),)
  37. export MAKE_IS_SILENT := y
  38. SECHO := -@false
  39. DISP := sil
  40. Q := @
  41. else
  42. export MAKE_IS_SILENT := n
  43. SECHO := @echo
  44. ifneq ($(V)$(VERBOSE),)
  45. SHELL_SET_X := set -x
  46. DISP := ver
  47. Q :=
  48. else
  49. DISP := pur
  50. Q := @
  51. endif
  52. endif
  53. show_objs = $(subst ../,,$@)
  54. pur_disp_compile.c = echo " "CC $(show_objs)
  55. pur_disp_compile.u = echo " "CC $(show_objs)
  56. pur_disp_compile.S = echo " "AS $(show_objs)
  57. pur_disp_compile.m = $(pur_disp_compile.c)
  58. pur_disp_compile-m = echo " "CC-m $(show_objs)
  59. pur_disp_strip = echo " "STRIP $(STRIP_FLAGS) $@
  60. pur_disp_t_strip = echo " "STRIP $(STRIP_FLAGS) $@
  61. pur_disp_ar = echo " "AR $(ARFLAGS) $@
  62. pur_disp_ld = echo " "LD $(1)
  63. sil_disp_compile.c = true
  64. sil_disp_compile.u = true
  65. sil_disp_compile.S = true
  66. sil_disp_compile.m = true
  67. sil_disp_compile-m = true
  68. sil_disp_strip = true
  69. sil_disp_t_strip = true
  70. sil_disp_ar = true
  71. sil_disp_ld = true
  72. ver_disp_compile.c = echo $(cmd_compile.c)
  73. ver_disp_compile.u = echo $(cmd_compile.u)
  74. ver_disp_compile.S = echo $(cmd_compile.S)
  75. ver_disp_compile.m = echo $(cmd_compile.m)
  76. ver_disp_compile-m = echo $(cmd_compile-m)
  77. ver_disp_strip = echo $(cmd_strip)
  78. ver_disp_t_strip = echo $(cmd_t_strip)
  79. ver_disp_ar = echo $(cmd_ar)
  80. ver_disp_ld =
  81. disp_compile.c = $($(DISP)_disp_compile.c)
  82. disp_compile.u = $($(DISP)_disp_compile.u)
  83. disp_compile.S = $($(DISP)_disp_compile.S)
  84. disp_compile.m = $($(DISP)_disp_compile.m)
  85. disp_compile-m = $($(DISP)_disp_compile-m)
  86. disp_strip = $($(DISP)_disp_strip)
  87. disp_t_strip = $($(DISP)_disp_t_strip)
  88. disp_ar = $($(DISP)_disp_ar)
  89. disp_ld = $($(DISP)_disp_ld)
  90. cmd_gen.dep = -MT $@ -MD -MF $(dir $@).$(notdir $@).dep
  91. cmd_compile.c = $(CC) -c $< -o $@ $(CFLAGS) $(ARCH_CFLAGS) $(CFLAGS-$(suffix $@)) $(filter-out $(CFLAGS-OMIT-$(notdir $<)),$(CFLAGS-$(notdir $(^D)))) $(CFLAGS-$(subst $(top_srcdir),,$(dir $<))) $(CFLAGS-$(notdir $<)) $(CFLAGS-$(notdir $@)) $(cmd_gen.dep)
  92. cmd_compile.u = $(CC) $^ $(DEPS-$(notdir $@)) -o $@ $(CFLAGS) $(CFLAGS-$(notdir $(^D))) $(CFLAGS-$(notdir $@)) $(cmd_gen.dep)
  93. cmd_compile.S = $(filter-out -std=gnu99, $(cmd_compile.c)) -D__ASSEMBLER__ $(ASFLAGS) $(ARCH_ASFLAGS) $(ASFLAGS-$(suffix $@)) $(ASFLAGS-$(notdir $<)) $(ASFLAGS-$(notdir $@))
  94. cmd_compile.m = $(cmd_compile.c) -DL_$(patsubst %$(suffix $(notdir $@)),%,$(notdir $@))
  95. cmd_compile-m = $(CC) $^ -c -o $@ $(CFLAGS) $(ARCH_CFLAGS) $(CFLAGS-$(suffix $@)) $(CFLAGS-$(notdir $(@D))) $(CFLAGS-$(notdir $@))
  96. cmd_strip = $(STRIPTOOL) $(STRIP_FLAGS) $^
  97. cmd_t_strip = $(STRIPTOOL) $(STRIP_FLAGS) $@
  98. cmd_ar = $(AR) $(ARFLAGS) $@ $^
  99. compile.c = @$(disp_compile.c) ; $(cmd_compile.c)
  100. compile.i = $(cmd_compile.c:-c=-E -dD)
  101. compile.s = $(cmd_compile.c:-c=-S)
  102. compile.S = @$(disp_compile.S) ; $(cmd_compile.S)
  103. compile.m = @$(disp_compile.m) ; $(cmd_compile.m)
  104. compile-m = @$(disp_compile-m) ; $(cmd_compile-m)
  105. do_strip = @$(disp_strip) ; $(cmd_strip)
  106. do_t_strip= @$(disp_t_strip) ; $(cmd_t_strip)
  107. do_ar = @$(disp_ar) ; $(cmd_ar)
  108. define compile.u
  109. @$(disp_compile.u) ; $(cmd_compile.u)
  110. @$(disp_t_strip)
  111. endef
  112. hcompile.u = $(HOSTCC) $^ $(DEPS-$(notdir $@)) -o $@ $(BUILD_LDFLAGS) $(BUILD_LDFLAGS-$(notdir $(^D))) $(BUILD_LDFLAGS-$(notdir $@)) $(BUILD_CFLAGS) $(BUILD_CFLAGS-$(notdir $(^D))) $(BUILD_CFLAGS-$(notdir $@))
  113. hcompile.o = $(HOSTCC) $^ $(DEPS-$(notdir $@)) -c -o $@ $(BUILD_CFLAGS) $(BUILD_CFLAGS-$(notdir $(^D))) $(BUILD_CFLAGS-$(notdir $@))
  114. define link.so
  115. $(Q)$(INSTALL) -d $(dir $@)
  116. $(Q)$(RM) $@ $@.$(2) $(dir $@)$(1)
  117. @$(disp_ld)
  118. $(Q)$(CC) $(LDFLAGS-$(notdir $@)) -Wl,-soname=$(notdir $@).$(2) \
  119. $(NOSTDLIB_CFLAGS) -o $(dir $@)$(1) $(START_FILE-$(notdir $@)) \
  120. -Wl,--whole-archive $(firstword $^) -Wl,--no-whole-archive \
  121. $(LIBS-$(notdir $@)) $(LIBGCC) $(END_FILE-$(notdir $@))
  122. $(Q)$(LN) -sf $(1) $@.$(2)
  123. $(Q)$(LN) -sf $(1) $@
  124. endef
  125. # CRT files needed by link-flat.so
  126. LINK_FLAT_CRTS := $(top_builddir)lib/Scrt1.o $(top_builddir)lib/crti.o \
  127. $(top_builddir)lib/crtn.o
  128. # Create a shared flat library from the archive named by the first dependency.
  129. # $@ names the shared library's .gdb file, not the flat file itself.
  130. # (This is because the .gdb suffix makes the ELF file more distinctive
  131. # than the suffixless flat file.)
  132. #
  133. # Argument 1 is the shared library file -- i.e. $(@:.gdb=) -- and argument 2
  134. # is the shared library identifier. If it wasn't for $(disp_ld), we could
  135. # avoid passing $(@:.gdb=) as an argument and use $(@:.gdb=) instead of $(1).
  136. #
  137. # This is so far only used for libc, for which we want to link the entire
  138. # libgcc into the shared object.
  139. define link-flat.so
  140. $(Q)$(INSTALL) -d $(dir $@)
  141. $(Q)$(RM) $(1) $@
  142. @$(disp_ld)
  143. $(Q)$(CC) $(LDFLAGS-$(notdir $@)) $(NOSTDLIB_CFLAGS) -o $(1) \
  144. -Wl,-elf2flt -Wl,-shared-lib-id,$(2) $(top_builddir)lib/Scrt1.o \
  145. $(top_builddir)/lib/crti.o -Wl,--whole-archive $(firstword $^) \
  146. $(LIBGCC) -Wl,--no-whole-archive $(LIBS-$(notdir $@)) $(LIBGCC) \
  147. $(top_builddir)/lib/crtn.o
  148. endef
  149. define linkm.so
  150. $(Q)$(INSTALL) -d $(dir $@)
  151. $(Q)$(RM) $@ $@.$(2) $(dir $@)$(1)
  152. @$(disp_ld)
  153. $(Q)$(CC) $(LDFLAGS-$(notdir $@)) -Wl,-soname=$(notdir $@).$(2) \
  154. $(NOSTDLIB_CFLAGS) -o $(dir $@)$(1) $(START_FILE-$(notdir $@)) \
  155. $^ \
  156. $(LIBS-$(notdir $@)) $(LIBGCC) $(END_FILE-$(notdir $@))
  157. $(Q)$(LN) -sf $(1) $@.$(2)
  158. $(Q)$(LN) -sf $(1) $@
  159. endef
  160. CFLAGS-.os+=$(PICFLAG)
  161. CFLAGS-.oS+=$(PICFLAG) -DSHARED
  162. %.o: %.c ; $(compile.c)
  163. %.os: %.c ; $(compile.c)
  164. %.oS: %.c ; $(compile.c)
  165. %.o: %.S ; $(compile.S)
  166. %.os: %.S ; $(compile.S)
  167. %.oS: %.S ; $(compile.S)
  168. %.o: %.s ; $(compile.S)
  169. %.os: %.s ; $(compile.S)
  170. %.oS: %.s ; $(compile.S)
  171. %.i: %.c ; $(compile.i)
  172. %.i: %.S ; $(compile.i)
  173. %.s: %.c ; $(compile.s)
  174. %.s: %.S ; $(compile.s)
  175. $(top_builddir)lib/interp.c: | $(sub_headers)
  176. $(Q)$(INSTALL) -d $(dir $@)
  177. $(Q)echo "/* Force shared libraries to know about the correct library loader */" > $@
  178. $(Q)echo "#include <features.h>" >> $@
  179. $(Q)echo "const char __dl_ldso__[] __attribute__ ((section " \
  180. "(\".interp\"))) =\""$(SHARED_LIB_LOADER_PREFIX)/$(UCLIBC_LDSO)"\";" >> $@
  181. $(interp): $(top_builddir)lib/interp.c
  182. $(compile.c)
  183. $(Q)$(STRIPTOOL) -x -R .note -R .comment $@
  184. $(ldso):
  185. @cd $(top_builddir); $(MAKE) lib/$(patsubst %.$(MAJOR_VERSION),%,$(notdir $@))
  186. $(libc):
  187. @cd $(top_builddir); $(MAKE) lib/$(patsubst %.$(MAJOR_VERSION),%,$(notdir $@))
  188. $(headers_dep): $(top_srcdir)extra/scripts/gen_bits_syscall_h.sh
  189. $(Q)cd $(top_builddir); $(MAKE) pregen
  190. CRT := crt1
  191. ifeq ($(HAVE_SHARED)$(UCLIBC_FORMAT_SHARED_FLAT),y)
  192. CRTS=$(top_builddir)lib/$(CRT).o $(top_builddir)lib/S$(CRT).o
  193. else
  194. CRTS=$(top_builddir)lib/$(CRT).o
  195. endif
  196. ASFLAGS-$(CRT).o := -DL_$(CRT)
  197. ASFLAGS-S$(CRT).o := $(PIEFLAG) -DL_S$(CRT)
  198. $(CRTS): $(top_srcdir)libc/sysdeps/linux/$(TARGET_ARCH)/$(CRT).S
  199. $(Q)$(INSTALL) -d $(dir $@)
  200. $(compile.S)
  201. $(Q)$(STRIPTOOL) -x -R .note -R .comment $@
  202. ifeq ($(UCLIBC_CTOR_DTOR),y)
  203. CTOR_TARGETS=$(top_builddir)lib/crti.o $(top_builddir)lib/crtn.o
  204. else
  205. CTOR_TARGETS:=
  206. endif
  207. ifeq ($(UCLIBC_FORMAT_FDPIC_ELF),y)
  208. CRTRELOC=$(top_builddir)lib/crtreloc.o
  209. $(CRTRELOC): $(top_builddir)lib/%.o : $(top_srcdir)libc/sysdeps/linux/$(TARGET_ARCH)/%.c
  210. $(Q)$(INSTALL) -d $(dir $@)
  211. $(compile.c)
  212. endif
  213. ifneq ($(wildcard $(top_srcdir)libc/sysdeps/linux/$(TARGET_ARCH)/initfini.c),)
  214. CFLAGS-initfini.s := -S -g0 $(PICFLAG) -fno-inline-functions -finhibit-size-directive
  215. $(top_builddir)lib/initfini.s: $(top_srcdir)libc/sysdeps/linux/$(TARGET_ARCH)/initfini.c
  216. $(compile.c)
  217. $(top_builddir)lib/defs.h: $(top_builddir)lib/initfini.s
  218. $(Q)sed -n -e '/@TESTS_BEGIN/,/@TESTS_END/p' $< | \
  219. gawk -f $(top_srcdir)extra/scripts/defs.awk > $@.tmp
  220. $(Q)mv $@.tmp $@
  221. $(top_builddir)lib/crti.S: $(top_builddir)lib/initfini.s $(top_builddir)lib/defs.h
  222. $(Q)sed -n -e '1,/@HEADER_ENDS/p' \
  223. -e '/@_.*_PROLOG_BEGINS/,/@_.*_PROLOG_ENDS/p' \
  224. -e '/@TRAILER_BEGINS/,$$p' $< > $@
  225. $(top_builddir)lib/crtn.S: $(top_builddir)lib/initfini.s
  226. $(Q)sed -n -e '1,/@HEADER_ENDS/p' \
  227. -e '/@_.*_EPILOG_BEGINS/,/@_.*_EPILOG_ENDS/p' \
  228. -e '/@TRAILER_BEGINS/,$$p' $< > $@
  229. $(CTOR_TARGETS): $(top_builddir)lib/%.o : $(top_builddir)lib/%.S
  230. $(Q)$(INSTALL) -d $(dir $@)
  231. $(compile.S) $(PICFLAG) $(SSP_DISABLE_FLAGS)
  232. else
  233. $(CTOR_TARGETS): $(top_builddir)lib/%.o : $(top_srcdir)libc/sysdeps/linux/$(TARGET_ARCH)/%.S
  234. $(Q)$(INSTALL) -d $(dir $@)
  235. $(compile.S) $(PICFLAG) $(SSP_DISABLE_FLAGS)
  236. endif
  237. #ifeq ($(TARGET_ARCH),nios)
  238. #CRTS_COMPAT := $(top_builddir)lib/crt0.o
  239. #$(CRTS_COMPAT):
  240. # ln -fs crt1.o $(top_builddir)lib/crt0.o
  241. #else
  242. CRTS_COMPAT :=
  243. #endif
  244. $(crt-y): $(CRTS) $(CTOR_TARGETS) $(CRTS_COMPAT) $(CRTRELOC)
  245. $(CRTS) $(CTOR_TARGETS) $(CRTS_COMPAT) $(CRTRELOC): | headers
  246. $(top_builddir)lib/$(NONSHARED_LIBNAME): $(libc-nonshared-y)
  247. $(Q)$(INSTALL) -d $(dir $@)
  248. $(Q)$(RM) $@
  249. $(do_strip)
  250. $(do_ar)
  251. $(top_builddir)lib/libpthread_nonshared.a: $(libpthread-nonshared-y)
  252. $(Q)$(INSTALL) -d $(dir $@)
  253. $(Q)$(RM) $@
  254. $(do_strip)
  255. $(do_ar)
  256. .depends.dep := \
  257. $(patsubst %.o,%.o.dep,$(filter %.o,$(libc-a-y) $(libc-so-y))) \
  258. $(patsubst %.os,%.os.dep,$(filter %.os,$(libc-a-y) $(libc-so-y))) \
  259. $(patsubst %.oS,%.oS.dep,$(filter %.oS,$(libc-a-y) $(libc-so-y)))
  260. # Oh, and prepend a dot to the basename so i don't have to change my habit of
  261. # calling 'size thefile.o*'
  262. .depends.dep := $(foreach f,$(.depends.dep),$(dir $(f)).$(notdir $(f)))
  263. ifdef .depends.dep
  264. -include $(.depends.dep)
  265. endif
  266. .PHONY: dummy create
  267. clean: objclean-y headers_clean-y
  268. realclean: clean
  269. $(Q)$(RM) $(.depends.dep)
  270. objclean-y: $(objclean-y)
  271. headers_clean-y: $(headers_clean-y)
  272. .PHONY: \
  273. all check clean realclean distclean test \
  274. config dist menuconfig oldconfig release \
  275. subdirs utils