Makefile 11 KB

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