Makefile 11 KB

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