Makerules 13 KB

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