Makefile 12 KB

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