Makefile 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. OUTPUT = $(CURDIR)/output
  2. BINUTILS_SRCDIR = BINUTILS_SRCDIR_not_set
  3. GCC_SRCDIR = GCC_SRCDIR_not_set
  4. MUSL_SRCDIR = MUSL_SRCDIR_not_set
  5. GCC_CONFIG_FOR_TARGET =
  6. COMMON_CONFIG =
  7. GCC_CONFIG =
  8. TOOLCHAIN_CONFIG =
  9. XGCC_DIR = ../obj_gcc/gcc
  10. XGCC = $(XGCC_DIR)/xgcc -B $(XGCC_DIR)
  11. -include config.mak
  12. ifneq ($(findstring fdpic,$(TARGET)),)
  13. GCC_CONFIG_FOR_TARGET += --enable-fdpic
  14. endif
  15. ifneq ($(filter x86_64%x32,$(TARGET)),)
  16. GCC_CONFIG_FOR_TARGET += --with-abi=x32
  17. endif
  18. ifneq ($(findstring powerpc64,$(TARGET)),)
  19. GCC_CONFIG_FOR_TARGET += --with-abi=elfv2
  20. endif
  21. ifneq ($(findstring mips64,$(TARGET))$(findstring mipsisa64,$(TARGET)),)
  22. ifneq ($(findstring n32,$(TARGET)),)
  23. GCC_CONFIG_FOR_TARGET += --with-abi=n32
  24. else
  25. GCC_CONFIG_FOR_TARGET += --with-abi=64
  26. endif
  27. endif
  28. ifneq ($(findstring s390x,$(TARGET)),)
  29. GCC_CONFIG_FOR_TARGET += --with-long-double-128
  30. endif
  31. ifneq ($(filter %sf,$(TARGET)),)
  32. GCC_CONFIG_FOR_TARGET += --with-float=soft
  33. endif
  34. ifneq ($(filter %hf,$(TARGET)),)
  35. GCC_CONFIG_FOR_TARGET += --with-float=hard
  36. endif
  37. ifneq ($(LIBTOOL),)
  38. LIBTOOL_ARG = LIBTOOL=$(LIBTOOL)
  39. endif
  40. MAKE += MULTILIB_OSDIRNAMES=
  41. MAKE += INFO_DEPS= infodir=
  42. MAKE += ac_cv_prog_lex_root=lex.yy
  43. MAKE += MAKEINFO=false
  44. FULL_BINUTILS_CONFIG = \
  45. --disable-separate-code \
  46. $(COMMON_CONFIG) $(BINUTILS_CONFIG) $(TOOLCHAIN_CONFIG) \
  47. --disable-werror \
  48. --target=$(TARGET) --prefix= \
  49. --libdir=/lib --disable-multilib \
  50. --with-sysroot=$(SYSROOT) \
  51. --enable-deterministic-archives
  52. FULL_GCC_CONFIG = --enable-languages=c,c++ \
  53. $(GCC_CONFIG_FOR_TARGET) \
  54. $(COMMON_CONFIG) $(GCC_CONFIG) $(TOOLCHAIN_CONFIG) \
  55. --disable-bootstrap \
  56. --disable-assembly \
  57. --disable-werror \
  58. --target=$(TARGET) --prefix= \
  59. --libdir=/lib --disable-multilib \
  60. --with-sysroot=$(SYSROOT) \
  61. --enable-tls \
  62. --disable-libmudflap --disable-libsanitizer \
  63. --disable-gnu-indirect-function \
  64. --disable-libmpx \
  65. --enable-initfini-array \
  66. --enable-libstdcxx-time=rt
  67. FULL_MUSL_CONFIG = $(MUSL_CONFIG) \
  68. --prefix= --host=$(TARGET)
  69. ifneq ($(NATIVE),)
  70. HOST:=$(TARGET)
  71. endif
  72. ifeq ($(BUILD),)
  73. GUESS = $(shell cd $(GCC_SRCDIR) && ./config.guess)
  74. TARGET_CANON = $(shell cd $(GCC_SRCDIR) && ./config.sub $(TARGET))
  75. BUILD = $(GUESS)$(if $(subst $(TARGET_CANON),,$(GUESS)),,xx)
  76. endif
  77. ifeq ($(HOST),)
  78. SYSROOT = /$(TARGET)
  79. FULL_BINUTILS_CONFIG += --build=$(BUILD) --host=$(BUILD)
  80. FULL_GCC_CONFIG += --with-build-sysroot=$(CURDIR)/obj_sysroot \
  81. AR_FOR_TARGET=$(PWD)/obj_binutils/binutils/ar \
  82. AS_FOR_TARGET=$(PWD)/obj_binutils/gas/as-new \
  83. LD_FOR_TARGET=$(PWD)/obj_binutils/ld/ld-new \
  84. NM_FOR_TARGET=$(PWD)/obj_binutils/binutils/nm-new \
  85. OBJCOPY_FOR_TARGET=$(PWD)/obj_binutils/binutils/objcopy \
  86. OBJDUMP_FOR_TARGET=$(PWD)/obj_binutils/binutils/objdump \
  87. RANLIB_FOR_TARGET=$(PWD)/obj_binutils/binutils/ranlib \
  88. READELF_FOR_TARGET=$(PWD)/obj_binutils/binutils/readelf \
  89. STRIP_FOR_TARGET=$(PWD)/obj_binutils/binutils/strip-new \
  90. --build=$(BUILD) --host=$(BUILD) \
  91. # end
  92. FULL_MUSL_CONFIG += CC="$(XGCC)" LIBCC="../obj_gcc/$(TARGET)/libgcc/libgcc.a"
  93. MUSL_VARS = AR=../obj_binutils/binutils/ar RANLIB=../obj_binutils/binutils/ranlib
  94. obj_musl/.lc_configured: | obj_gcc/gcc/.lc_built
  95. obj_musl/.lc_built: | obj_gcc/$(TARGET)/libgcc/libgcc.a
  96. obj_gcc/gcc/.lc_built: | obj_sysroot/usr obj_sysroot/lib32 obj_sysroot/lib64 obj_sysroot/include
  97. obj_gcc/.lc_built: | obj_sysroot/.lc_libs obj_sysroot/.lc_headers
  98. obj_gcc/.lc_configured: obj_binutils/.lc_built
  99. else
  100. SYSROOT = /
  101. FULL_BINUTILS_CONFIG += --build=$(BUILD) --host=$(HOST)
  102. FULL_GCC_CONFIG += --build=$(BUILD) --host=$(HOST)
  103. MUSL_VARS =
  104. endif
  105. ifeq ($(TARGET),)
  106. all:
  107. @echo TARGET must be set.
  108. @exit 1
  109. install: all
  110. else
  111. all: musl gcc binutils
  112. install: install-musl install-gcc install-binutils
  113. musl: obj_musl/.lc_built
  114. toolchain: gcc binutils
  115. install-toolchain: install-gcc install-binutils
  116. gcc: obj_gcc/.lc_built
  117. binutils: obj_binutils/.lc_built
  118. .PHONY: all musl toolchain install-musl install-toolchain clean
  119. src_binutils: | $(BINUTILS_SRCDIR)
  120. ln -sf $(BINUTILS_SRCDIR) $@
  121. src_gcc_base: | $(GCC_SRCDIR)
  122. ln -sf $(GCC_SRCDIR) $@
  123. src_musl: | $(MUSL_SRCDIR)
  124. ln -sf $(MUSL_SRCDIR) $@
  125. ifneq ($(GMP_SRCDIR),)
  126. src_gcc: src_gmp
  127. src_gmp: | $(GMP_SRCDIR)
  128. ln -sf "$(GMP_SRCDIR)" $@
  129. endif
  130. ifneq ($(MPC_SRCDIR),)
  131. src_gcc: src_mpc
  132. src_mpc: | $(MPC_SRCDIR)
  133. ln -sf "$(MPC_SRCDIR)" $@
  134. endif
  135. ifneq ($(MPFR_SRCDIR),)
  136. src_gcc: src_mpfr
  137. src_mpfr: | $(MPFR_SRCDIR)
  138. ln -sf "$(MPFR_SRCDIR)" $@
  139. endif
  140. ifneq ($(ISL_SRCDIR),)
  141. src_gcc: src_isl
  142. src_isl: | $(ISL_SRCDIR)
  143. ln -sf "$(ISL_SRCDIR)" $@
  144. endif
  145. src_gcc: src_gcc_base
  146. rm -rf $@ [email protected]
  147. mkdir [email protected]
  148. cd [email protected] && ln -sf ../src_gcc_base/* .
  149. $(if $(GMP_SRCDIR),cd [email protected] && ln -sf ../src_gmp gmp)
  150. $(if $(MPC_SRCDIR),cd [email protected] && ln -sf ../src_mpc mpc)
  151. $(if $(MPFR_SRCDIR),cd [email protected] && ln -sf ../src_mpfr mpfr)
  152. $(if $(ISL_SRCDIR),cd [email protected] && ln -sf ../src_isl isl)
  153. mv [email protected] $@
  154. obj_%:
  155. mkdir -p $@
  156. obj_sysroot/include:
  157. mkdir -p $@
  158. obj_sysroot/usr: | obj_sysroot
  159. ln -sf . $@
  160. obj_sysroot/lib32: | obj_sysroot
  161. ln -sf lib $@
  162. obj_sysroot/lib64: | obj_sysroot
  163. ln -sf lib $@
  164. obj_binutils/.lc_configured: | obj_binutils src_binutils
  165. cd obj_binutils && ../src_binutils/configure $(FULL_BINUTILS_CONFIG)
  166. touch $@
  167. obj_binutils/.lc_built: | obj_binutils/.lc_configured
  168. cd obj_binutils && $(MAKE) MAKE="$(MAKE) $(LIBTOOL_ARG)" all
  169. touch $@
  170. obj_gcc/.lc_configured: | obj_gcc src_gcc
  171. cd obj_gcc && ../src_gcc/configure $(FULL_GCC_CONFIG)
  172. touch $@
  173. obj_gcc/gcc/.lc_built: | obj_gcc/.lc_configured
  174. cd obj_gcc && $(MAKE) MAKE="$(MAKE) $(LIBTOOL_ARG)" all-gcc
  175. touch $@
  176. obj_musl/.lc_configured: | obj_musl src_musl
  177. cd obj_musl && ../src_musl/configure $(FULL_MUSL_CONFIG)
  178. touch $@
  179. obj_sysroot/.lc_headers: | obj_musl/.lc_configured obj_sysroot
  180. cd obj_musl && $(MAKE) DESTDIR=$(CURDIR)/obj_sysroot install-headers
  181. touch $@
  182. obj_gcc/$(TARGET)/libgcc/libgcc.a: | obj_sysroot/.lc_headers
  183. cd obj_gcc && $(MAKE) MAKE="$(MAKE) enable_shared=no $(LIBTOOL_ARG)" all-target-libgcc
  184. obj_musl/.lc_built: | obj_musl/.lc_configured
  185. cd obj_musl && $(MAKE) $(MUSL_VARS)
  186. touch $@
  187. obj_sysroot/.lc_libs: | obj_musl/.lc_built
  188. cd obj_musl && $(MAKE) $(MUSL_VARS) DESTDIR=$(CURDIR)/obj_sysroot install
  189. touch $@
  190. obj_gcc/.lc_built: | obj_gcc/.lc_configured obj_gcc/gcc/.lc_built
  191. cd obj_gcc && $(MAKE) MAKE="$(MAKE) $(LIBTOOL_ARG)"
  192. touch $@
  193. install-musl: | obj_musl/.lc_built
  194. cd obj_musl && $(MAKE) $(MUSL_VARS) DESTDIR=$(DESTDIR)$(OUTPUT)$(SYSROOT) install
  195. install-binutils: | obj_binutils/.lc_built
  196. cd obj_binutils && $(MAKE) MAKE="$(MAKE) $(LIBTOOL_ARG)" DESTDIR=$(DESTDIR)$(OUTPUT) install
  197. install-gcc: | obj_gcc/.lc_built
  198. cd obj_gcc && $(MAKE) MAKE="$(MAKE) $(LIBTOOL_ARG)" DESTDIR=$(DESTDIR)$(OUTPUT) install
  199. ln -sf $(TARGET)-gcc $(DESTDIR)$(OUTPUT)/bin/$(TARGET)-cc
  200. ifneq ($(LINUX_SRCDIR),)
  201. TARGET_ARCH = $(firstword $(subst -, ,$(TARGET)))
  202. TARGET_ARCH_MANGLED = $(patsubst i%86,x86,$(patsubst aarch64%,arm64%,$(TARGET_ARCH)))
  203. LINUX_ARCH_LIST = $(sort $(notdir $(wildcard $(LINUX_SRCDIR)/arch/*)))
  204. LINUX_ARCH = $(lastword $(foreach a,$(LINUX_ARCH_LIST),$(if $(filter $(a)%,$(TARGET_ARCH_MANGLED)),$(a))))
  205. ifneq ($(LINUX_ARCH),)
  206. all: kernel-headers
  207. install: install-kernel-headers
  208. kernel-headers: | obj_kernel_headers/.lc_built
  209. src_kernel_headers: | $(LINUX_SRCDIR)
  210. ln -sf "$(LINUX_SRCDIR)" $@
  211. obj_kernel_headers/.lc_built: | src_kernel_headers
  212. mkdir -p $(CURDIR)/obj_kernel_headers/staged
  213. cd src_kernel_headers && $(MAKE) ARCH=$(LINUX_ARCH) O=$(CURDIR)/obj_kernel_headers INSTALL_HDR_PATH=$(CURDIR)/obj_kernel_headers/staged headers_install
  214. find obj_kernel_headers/staged/include '(' -name .install -o -name ..install.cmd ')' -exec rm {} +
  215. touch $@
  216. install-kernel-headers: | obj_kernel_headers/.lc_built
  217. mkdir -p $(DESTDIR)$(OUTPUT)$(SYSROOT)/include
  218. cp -R obj_kernel_headers/staged/include/* $(DESTDIR)$(OUTPUT)$(SYSROOT)/include
  219. endif
  220. endif
  221. endif
  222. clean:
  223. rm -rf src_* obj_*