Makefile 11 KB

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