Makefile 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  1. # This file is part of the OpenADK project. OpenADK is copyrighted
  2. # material, please see the LICENCE file in the top-level directory.
  3. include $(ADK_TOPDIR)/rules.mk
  4. include ../rules.mk
  5. include Makefile.inc
  6. # disable SSP for libstdc++
  7. ifeq ($(ADK_TARGET_LIB_MUSL),y)
  8. TARGET_CFLAGS:= $(filter-out -fstack-protector-all,$(TARGET_CFLAGS))
  9. TARGET_CXXFLAGS:= $(filter-out -fstack-protector-all,$(TARGET_CXXFLAGS))
  10. endif
  11. # disable lto for gcc
  12. TARGET_CFLAGS:= $(filter-out -flto,$(TARGET_CFLAGS))
  13. TARGET_CXXFLAGS:= $(filter-out -flto,$(TARGET_CXXFLAGS))
  14. # for uClinux, we need to filter out some flags
  15. ifeq ($(ADK_TARGET_UCLINUX),y)
  16. TARGET_CFLAGS:= $(filter-out -msep-data,$(TARGET_CFLAGS))
  17. TARGET_CXXFLAGS:= $(filter-out -msep-data,$(TARGET_CXXFLAGS))
  18. endif
  19. ifeq ($(ADK_TARGET_USE_STATIC_AND_SHARED_LIBS),y)
  20. TARGET_CFLAGS:= $(filter-out -static,$(TARGET_CFLAGS))
  21. TARGET_CXXFLAGS:= $(filter-out -static,$(TARGET_CXXFLAGS))
  22. endif
  23. GCC_CONFOPTS:= --prefix=$(TOOLCHAIN_DIR)/usr \
  24. --with-bugurl="$(ADK_VENDOR_URL)" \
  25. --build=$(GNU_HOST_NAME) \
  26. --host=$(GNU_HOST_NAME) \
  27. --target=$(GNU_TARGET_NAME) \
  28. --with-gmp=$(STAGING_HOST_DIR)/usr \
  29. --with-mpfr=$(STAGING_HOST_DIR)/usr \
  30. --enable-__cxa_atexit \
  31. --with-system-zlib \
  32. --with-gnu-ld \
  33. --with-gnu-as \
  34. --disable-libsanitizer \
  35. --disable-install-libiberty \
  36. --disable-libitm \
  37. --disable-libmudflap \
  38. --disable-libgomp \
  39. --disable-libcc1 \
  40. --disable-libmpx \
  41. --disable-libcilkrts \
  42. --disable-libquadmath \
  43. --disable-libquadmath-support \
  44. --disable-decimal-float \
  45. --disable-libstdcxx-pch \
  46. --disable-ppl-version-check \
  47. --disable-cloog-version-check \
  48. --without-ppl \
  49. --without-cloog \
  50. --without-isl \
  51. --disable-werror \
  52. --disable-nls \
  53. --enable-obsolete
  54. ifeq ($(ADK_TARGET_OS_LINUX),y)
  55. ifeq ($(ADK_TARGET_LIB_UCLIBC_NG),y)
  56. ifeq ($(ADK_TARGET_WITH_NPTL),y)
  57. GCC_FINAL_CONFOPTS:= --enable-tls --enable-threads --enable-libatomic
  58. GCC_TLS_CONFOPTS:= --enable-tls
  59. endif
  60. ifeq ($(ADK_TARGET_WITH_LT),y)
  61. GCC_FINAL_CONFOPTS:= --disable-tls --enable-threads --disable-libatomic
  62. GCC_TLS_CONFOPTS:= --disable-tls
  63. endif
  64. ifeq ($(ADK_TARGET_LIB_WITHOUT_THREADS)$(ADK_TARGET_WITHOUT_THREADS),y)
  65. GCC_FINAL_CONFOPTS:= --disable-tls --disable-threads --disable-libatomic
  66. GCC_TLS_CONFOPTS:= --disable-tls
  67. endif
  68. else
  69. GCC_FINAL_CONFOPTS:= --enable-tls --enable-threads --enable-libatomic
  70. GCC_TLS_CONFOPTS:= --enable-tls
  71. endif
  72. endif
  73. ifeq ($(ADK_TARGET_OS_BAREMETAL),y)
  74. GCC_FINAL_CONFOPTS:= --disable-libatomic
  75. endif
  76. ifeq ($(ADK_TARGET_LIB_NEWLIB),y)
  77. GCC_FINAL_CONFOPTS+= --with-newlib
  78. endif
  79. ifeq ($(ADK_TARGET_USE_STATIC_LIBS_ONLY),y)
  80. GCC_FINAL_CONFOPTS+= --disable-shared
  81. else
  82. GCC_FINAL_CONFOPTS+= --enable-shared --enable-cxx-flags='-fPIC'
  83. endif
  84. ifeq ($(ADK_TOOLCHAIN_WITH_SSP),y)
  85. GCC_FINAL_CONFOPTS+= --enable-libssp
  86. else
  87. GCC_FINAL_CONFOPTS+= --disable-libssp
  88. endif
  89. ifeq ($(ADK_TOOLCHAIN_WITH_LTO),y)
  90. GCC_CONFOPTS+= --enable-lto
  91. else
  92. GCC_CONFOPTS+= --disable-lto
  93. endif
  94. #
  95. # architecture specific
  96. #
  97. ifneq ($(ADK_TARGET_GCC_CPU),)
  98. GCC_CONFOPTS+= --with-cpu=$(ADK_TARGET_GCC_CPU)
  99. endif
  100. ifneq ($(ADK_TARGET_GCC_ARCH),)
  101. GCC_CONFOPTS+= --with-arch=$(ADK_TARGET_GCC_ARCH)
  102. endif
  103. ifneq ($(ADK_TARGET_FLOAT),)
  104. GCC_CONFOPTS+= --with-float=$(ADK_TARGET_FLOAT)
  105. endif
  106. ifneq ($(ADK_TARGET_FPU),)
  107. GCC_CONFOPTS+= --with-fpu=$(ADK_TARGET_FPU)
  108. endif
  109. ifneq ($(ADK_TARGET_INSTRUCTION_SET),)
  110. GCC_CONFOPTS+= --with-mode=$(ADK_TARGET_INSTRUCTION_SET)
  111. endif
  112. ifneq ($(ADK_TARGET_NAN_MODE),)
  113. GCC_CONFOPTS+= --with-nan=$(ADK_TARGET_NAN_MODE)
  114. endif
  115. # .symver is broken for Blackfin, simple C++ apps fail to link
  116. ifeq ($(ADK_TARGET_ARCH_BFIN),y)
  117. GCC_CONFOPTS+= --disable-symvers
  118. endif
  119. ifeq ($(ADK_TARGET_ARCH_CSKY),y)
  120. GCC_CONFOPTS+= --with-cskyabi=abiv2 --disable-multilib
  121. ifeq ($(ADK_TARGET_LITTLE_ENDIAN),y)
  122. GCC_CONFOPTS+= --with-endian=little
  123. else
  124. GCC_CONFOPTS+= --with-endian=big
  125. endif
  126. endif
  127. ifeq ($(ADK_TARGET_ARCH_METAG),y)
  128. GCC_CONFOPTS+= --with-cpu=2.1 --enable-meta-default --disable-symvers
  129. endif
  130. ifeq ($(ADK_TARGET_CPU_CF),y)
  131. GCC_CONFOPTS+= --with-arch=cf --disable-multilib
  132. endif
  133. ifeq ($(ADK_TARGET_ARCH_NDS32),y)
  134. GCC_CONFOPTS+= --with-arch=v3
  135. endif
  136. ifeq ($(ADK_TARGET_ARCH_M68K)$(ADK_TARGET_ARCH_X86_64)$(ADK_TARGET_ARCH_X86),)
  137. GCC_FINAL_CONFOPTS+= --disable-biarch --disable-multilib
  138. endif
  139. ifeq ($(ADK_TARGET_ARCH_SH),y)
  140. ifeq ($(ADK_TARGET_LITTLE_ENDIAN),y)
  141. GCC_CONFOPTS+= --with-endian=little
  142. else
  143. GCC_CONFOPTS+= --with-endian=big
  144. endif
  145. ifeq ($(ADK_TARGET_BINFMT_FDPIC),y)
  146. GCC_CONFOPTS+= --enable-fdpic
  147. endif
  148. ifeq ($(ADK_TARGET_CPU_SH_J2),y)
  149. GCC_CONFOPTS+= --with-multilib-list=mj2
  150. endif
  151. ifeq ($(ADK_TARGET_CPU_SH_SH2),y)
  152. GCC_CONFOPTS+= --with-multilib-list=m2
  153. endif
  154. ifeq ($(ADK_TARGET_CPU_SH_SH2A),y)
  155. GCC_CONFOPTS+= --with-multilib-list=m2a,m2a-nofpu
  156. endif
  157. ifeq ($(ADK_TARGET_CPU_SH_SH3),y)
  158. GCC_CONFOPTS+= --with-multilib-list=m3
  159. endif
  160. ifeq ($(ADK_TARGET_CPU_SH_SH4),y)
  161. GCC_CONFOPTS+= --with-multilib-list=m4,m4-nofpu
  162. endif
  163. ifeq ($(ADK_TARGET_CPU_SH_SH4A),y)
  164. GCC_CONFOPTS+= --with-multilib-list=m4a,m4a-nofpu
  165. endif
  166. endif
  167. ifeq ($(ADK_TARGET_ARCH_X86),y)
  168. ifeq ($(ADK_TARGET_KERNEL_64),y)
  169. GCC_FINAL_CONFOPTS+= --enable-biarch --enable-targets=all --disable-multilib
  170. else
  171. GCC_FINAL_CONFOPTS+= --disable-biarch --disable-multilib
  172. endif
  173. endif
  174. ifeq ($(ADK_TARGET_ARCH_X86_64),y)
  175. ifneq ($(ADK_TARGET_ABI_X32),)
  176. GCC_CONFOPTS+= --with-abi=x32 --enable-multilib
  177. else
  178. GCC_CONFOPTS+= --disable-biarch --disable-multilib
  179. endif
  180. endif
  181. ifeq ($(ADK_TARGET_ARCH_ALPHA),y)
  182. GCC_CONFOPTS+= --without-long-double-128
  183. endif
  184. ifeq ($(ADK_TARGET_ARCH_PPC),y)
  185. GCC_CONFOPTS+= --with-long-double-64 --enable-secureplt
  186. endif
  187. ifeq ($(ADK_TARGET_ARCH_PPC64),y)
  188. ifeq ($(ADK_TARGET_LIB_GLIBC),y)
  189. GCC_CONFOPTS+= --with-long-double-128 --with-abi=elfv2
  190. else
  191. GCC_CONFOPTS+= --without-long-double-128 --with-abi=elfv2
  192. endif
  193. endif
  194. ifeq ($(ADK_TARGET_ARCH_S390),y)
  195. GCC_CONFOPTS+= --with-long-double-128
  196. endif
  197. ifneq ($(ADK_TARGET_ABI_MIPS64),)
  198. GCC_CONFOPTS+= --with-abi=${ADK_TARGET_ABI_MIPS64}
  199. endif
  200. ifneq ($(ADK_TARGET_ABI_RISCV),)
  201. GCC_CONFOPTS+= --with-abi=${ADK_TARGET_ABI_RISCV}
  202. endif
  203. ifeq (${ADK_MAKE_PARALLEL},y)
  204. GCC_MAKEOPTS+= -j${ADK_MAKE_JOBS}
  205. endif
  206. USE_LANG:=c
  207. ifeq ($(ADK_TOOLCHAIN_WITH_CXX),y)
  208. USE_LANG+=c++
  209. endif
  210. ifeq ($(ADK_TOOLCHAIN_WITH_OBJC),y)
  211. USE_LANG+=objc
  212. endif
  213. ifeq ($(ADK_TOOLCHAIN_WITH_FORTRAN),y)
  214. USE_LANG+=fortran
  215. endif
  216. ifeq ($(ADK_TOOLCHAIN_WITH_GO),y)
  217. USE_LANG+=go
  218. endif
  219. LANGUAGES=$(shell echo ${USE_LANG} |tr ' ' ',')
  220. include ${ADK_TOPDIR}/mk/buildhlp.mk
  221. GCC_BUILD_DIR_INITIAL:= $(WRKBUILD)-initial
  222. GCC_BUILD_DIR_FINAL:= $(WRKBUILD)-final
  223. $(GCC_BUILD_DIR_INITIAL)/.configured:
  224. ifeq ($(ADK_TARGET_ARCH_XTENSA),y)
  225. tar xf $(ADK_TOPDIR)/target/xtensa/overlay/xtensa_$(ADK_TARGET_CPU_TYPE).tar \
  226. --strip-components=1 -C $(WRKSRC) gcc
  227. endif
  228. mkdir -p $(GCC_BUILD_DIR_INITIAL)
  229. # these symlinks are very important, do not remove
  230. rm -rf $(TOOLCHAIN_DIR)/usr/$(GNU_TARGET_NAME)/sys-include
  231. mkdir -p $(TOOLCHAIN_DIR)/usr/$(GNU_TARGET_NAME)
  232. (cd $(TOOLCHAIN_DIR)/usr/$(GNU_TARGET_NAME); \
  233. ln -s ../$(STAGING_HOST2TARGET)/usr/include sys-include)
  234. rm -rf ${TOOLCHAIN_DIR}/usr/$(GNU_TARGET_NAME)/lib
  235. (cd $(TOOLCHAIN_DIR)/usr/$(GNU_TARGET_NAME); \
  236. ln -s ../$(STAGING_HOST2TARGET)/usr/lib lib)
  237. ifeq ($(ADK_TARGET_ARCH_SH),y)
  238. ifeq ($(ADK_TARGET_CPU_SH_SH2),y)
  239. (cd ${STAGING_TARGET_DIR}/ && ln -sf . m2)
  240. endif
  241. ifeq ($(ADK_TARGET_CPU_SH_SH2A),y)
  242. (cd ${STAGING_TARGET_DIR}/ && ln -sf . m2a)
  243. endif
  244. ifeq ($(ADK_TARGET_CPU_SH_SH3),y)
  245. (cd ${STAGING_TARGET_DIR}/ && ln -sf . m3)
  246. endif
  247. ifeq ($(ADK_TARGET_CPU_SH_SH4),y)
  248. (cd ${STAGING_TARGET_DIR}/ && ln -sf . m4)
  249. endif
  250. ifeq ($(ADK_TARGET_CPU_SH_SH4A),y)
  251. (cd ${STAGING_TARGET_DIR}/ && ln -sf . m4a)
  252. endif
  253. endif
  254. $(SED) '/k prot/agcc_cv_libc_provides_ssp=yes' $(WRKBUILD)/gcc/configure
  255. cd $(GCC_BUILD_DIR_INITIAL); \
  256. PATH='$(TARGET_PATH)' \
  257. CC='$(HOST_CC)' \
  258. CXX='$(HOST_CXX)' \
  259. CFLAGS="-O0 -g0 -fomit-frame-pointer" \
  260. CXXFLAGS="-O0 -g0 -fomit-frame-pointer" \
  261. $(WRKBUILD)/configure \
  262. ${GCC_CONFOPTS} \
  263. ${GCC_TLS_CONFOPTS} \
  264. --enable-languages=c \
  265. --with-newlib \
  266. --disable-shared \
  267. --disable-threads \
  268. --disable-multilib \
  269. --without-headers
  270. touch $@
  271. $(GCC_BUILD_DIR_INITIAL)/.compiled: $(GCC_BUILD_DIR_INITIAL)/.configured
  272. ifeq ($(ADK_TOOLCHAIN_GCC_METAG),y)
  273. PATH='$(TARGET_PATH)' \
  274. $(MAKE) ${GCC_MAKEOPTS} -C $(GCC_BUILD_DIR_INITIAL) all-gcc
  275. else
  276. PATH='$(TARGET_PATH)' \
  277. $(MAKE) ${GCC_MAKEOPTS} -C $(GCC_BUILD_DIR_INITIAL) all-gcc all-target-libgcc
  278. endif
  279. touch $@
  280. $(WRKBUILD)/.configured: $(GCC_BUILD_DIR_INITIAL)/.compiled
  281. ifeq ($(ADK_TOOLCHAIN_GCC_METAG),y)
  282. PATH='$(TARGET_PATH)' \
  283. $(MAKE) -C $(GCC_BUILD_DIR_INITIAL) install-gcc
  284. else
  285. PATH='$(TARGET_PATH)' \
  286. $(MAKE) -C $(GCC_BUILD_DIR_INITIAL) install-gcc install-target-libgcc
  287. endif
  288. # required for newlib
  289. (cd $(TOOLCHAIN_DIR)/usr/bin && \
  290. ln -sf $(GNU_TARGET_NAME)-gcc $(GNU_TARGET_NAME)-cc \
  291. )
  292. touch $@
  293. $(WRKBUILD)/.compiled:
  294. mkdir -p $(GCC_BUILD_DIR_FINAL)
  295. cd $(GCC_BUILD_DIR_FINAL); \
  296. PATH='$(TARGET_PATH)' \
  297. CC='$(HOST_CC)' \
  298. CXX='$(HOST_CXX)' \
  299. CFLAGS_FOR_TARGET='$(TARGET_CFLAGS)' \
  300. CXXFLAGS_FOR_TARGET='$(TARGET_CXXFLAGS)' \
  301. $(WRKBUILD)/configure \
  302. ${GCC_CONFOPTS} \
  303. ${GCC_FINAL_CONFOPTS} \
  304. --enable-languages=$(LANGUAGES) \
  305. --with-build-sysroot='$${prefix}/${STAGING_HOST2TARGET}' \
  306. --with-sysroot='$${prefix}/${STAGING_HOST2TARGET}'
  307. PATH='$(TARGET_PATH)' $(MAKE) -C $(GCC_BUILD_DIR_FINAL) configure-host
  308. cd $(GCC_BUILD_DIR_FINAL); \
  309. PATH='$(TARGET_PATH)' \
  310. $(MAKE) ${GCC_MAKEOPTS} all
  311. touch $@
  312. $(WRKBUILD)/.installed: $(WRKBUILD)/.compiled
  313. cd $(GCC_BUILD_DIR_FINAL); \
  314. PATH='$(TARGET_PATH)' \
  315. $(MAKE) install
  316. # remove duplicate tools, convert hardlinks to symlinks
  317. set -e; \
  318. cd $(TOOLCHAIN_DIR)/usr/$(GNU_TARGET_NAME)/bin; \
  319. for app in ar as c++ g++ gcc ld ld.gold ld.bfd nm objcopy objdump ranlib strip; do \
  320. ln -sf ../../bin/$(GNU_TARGET_NAME)-$${app} $${app}; \
  321. done;
  322. (cd $(TOOLCHAIN_DIR)/usr/bin && \
  323. ln -sf $(GNU_TARGET_NAME)-gcc $(GNU_TARGET_NAME)-gcc-${PKG_VERSION} && \
  324. ln -sf $(GNU_TARGET_NAME)-g++ $(GNU_TARGET_NAME)-g++-${PKG_VERSION} \
  325. )
  326. touch $@
  327. $(WRKBUILD)/.final:
  328. ifeq ($(ADK_TARGET_CPU_CF),y)
  329. find $(STAGING_TARGET_DIR) -name libgcc.a -print | while read t; do $(GNU_TARGET_NAME)-ar dv "$t" _ctors.o; done
  330. endif
  331. # cleanup unneeded docs
  332. rm -rf $(TOOLCHAIN_DIR)/usr/share
  333. # cleanup unneeded libtool files
  334. -find $(STAGING_TARGET_DIR) $(STAGING_HOST_DIR) -name \*.la -exec rm {} \;
  335. # strip target libs and host tools for toolchain builds in non-Debug mode
  336. ifeq ($(ADK_DEBUG),)
  337. PATH="$(TARGET_PATH)" debug='0' prefix='${TARGET_CROSS}' ${BASH} ${SCRIPT_DIR}/rstrip.sh \
  338. $(STAGING_TARGET_DIR) $(TOOLCHAIN_DIR)/usr/lib/gcc/$(GNU_TARGET_NAME)
  339. debug='0' prefix=' ' ${BASH} ${SCRIPT_DIR}/rstrip.sh $(TOOLCHAIN_DIR)/usr/bin
  340. endif
  341. touch $@
  342. include ${ADK_TOPDIR}/mk/toolchain.mk