Makefile 11 KB

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