Makerules 13 KB

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