Makefile 10 KB

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