Makefile 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  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. --with-libelf=$(STAGING_HOST_DIR)/usr \
  27. --disable-__cxa_atexit \
  28. --with-system-zlib \
  29. --with-gnu-ld \
  30. --with-gnu-as \
  31. --disable-libsanitizer \
  32. --disable-install-libiberty \
  33. --disable-libitm \
  34. --disable-libmudflap \
  35. --disable-libgomp \
  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_LIB_NEWLIB),y)
  49. GCC_FINAL_CONFOPTS:= --with-newlib
  50. endif
  51. ifeq ($(ADK_TARGET_WITH_NPTL),y)
  52. GCC_FINAL_CONFOPTS:= --enable-tls --enable-threads --enable-libatomic
  53. GCC_TLS_CONFOPTS:= --enable-tls
  54. endif
  55. ifeq ($(ADK_TARGET_WITH_LT),y)
  56. GCC_FINAL_CONFOPTS:= --disable-tls --enable-threads --disable-libatomic
  57. GCC_TLS_CONFOPTS:= --disable-tls
  58. endif
  59. ifeq ($(ADK_TARGET_LIB_WITHOUT_THREADS)$(ADK_TARGET_WITHOUT_THREADS),y)
  60. GCC_FINAL_CONFOPTS:= --disable-tls --disable-threads --disable-libatomic
  61. GCC_TLS_CONFOPTS:= --disable-tls
  62. endif
  63. ifeq ($(ADK_TARGET_BINFMT_FLAT)$(ADK_TARGET_USE_STATIC_LIBS_ONLY)$(ADK_TARGET_BINFMT_DSBT),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_METAG),y)
  104. GCC_CONFOPTS+= --with-cpu=2.1 --enable-meta-default --disable-symvers
  105. endif
  106. ifeq ($(ADK_TARGET_CPU_CF),y)
  107. GCC_CONFOPTS+= --with-arch=cf --disable-multilib
  108. endif
  109. ifeq ($(ADK_TARGET_ARCH_NDS32),y)
  110. GCC_CONFOPTS+= --with-arch=v3
  111. endif
  112. ifeq ($(ADK_TARGET_ARCH_M68K)$(ADK_TARGET_ARCH_X86_64)$(ADK_TARGET_ARCH_X86),)
  113. GCC_FINAL_CONFOPTS+= --disable-biarch --disable-multilib
  114. endif
  115. ifeq ($(ADK_TARGET_ARCH_SH),y)
  116. ifeq ($(ADK_TARGET_LITTLE_ENDIAN),y)
  117. GCC_CONFOPTS+= --with-endian=little
  118. else
  119. GCC_CONFOPTS+= --with-endian=big
  120. endif
  121. ifeq ($(ADK_TARGET_CPU_SH_J2),y)
  122. GCC_CONFOPTS+= --enable-fdpic
  123. GCC_FINAL_CONFOPTS+= --with-multilib-list=mj2
  124. endif
  125. ifeq ($(ADK_TARGET_CPU_SH_SH2),y)
  126. GCC_FINAL_CONFOPTS+= --with-multilib-list=m2
  127. endif
  128. ifeq ($(ADK_TARGET_CPU_SH_SH2A),y)
  129. GCC_FINAL_CONFOPTS+= --with-multilib-list=m2a
  130. endif
  131. ifeq ($(ADK_TARGET_CPU_SH_SH3),y)
  132. GCC_FINAL_CONFOPTS+= --with-multilib-list=m3
  133. endif
  134. ifeq ($(ADK_TARGET_CPU_SH_SH4),y)
  135. GCC_FINAL_CONFOPTS+= --with-multilib-list=m4,m4-nofpu
  136. endif
  137. ifeq ($(ADK_TARGET_CPU_SH_SH4A),y)
  138. GCC_FINAL_CONFOPTS+= --with-multilib-list=m4a,m4a-nofpu
  139. endif
  140. endif
  141. ifeq ($(ADK_TARGET_ARCH_X86),y)
  142. ifeq ($(ADK_TARGET_KERNEL_64),y)
  143. GCC_FINAL_CONFOPTS+= --enable-biarch --enable-targets=all --disable-multilib
  144. else
  145. GCC_FINAL_CONFOPTS+= --disable-biarch --disable-multilib
  146. endif
  147. endif
  148. ifeq ($(ADK_TARGET_ARCH_X86_64),y)
  149. ifneq ($(ADK_TARGET_ABI_X32),)
  150. GCC_CONFOPTS+= --with-abi=x32 --enable-multilib
  151. else
  152. GCC_CONFOPTS+= --disable-biarch --disable-multilib
  153. endif
  154. endif
  155. ifeq ($(ADK_TARGET_ARCH_ALPHA),y)
  156. GCC_CONFOPTS+= --without-long-double-128
  157. endif
  158. ifeq ($(ADK_TARGET_ARCH_PPC),y)
  159. GCC_CONFOPTS+= --with-long-double-64 --enable-secureplt
  160. endif
  161. ifeq ($(ADK_TARGET_ARCH_PPC64),y)
  162. GCC_CONFOPTS+= --without-long-double-128 --with-abi=elfv2
  163. endif
  164. ifneq ($(ADK_TARGET_MIPS_ABI),)
  165. GCC_CONFOPTS+= --with-abi=${ADK_TARGET_MIPS_ABI}
  166. endif
  167. ifeq (${ADK_MAKE_PARALLEL},y)
  168. GCC_MAKEOPTS+= -j${ADK_MAKE_JOBS}
  169. endif
  170. USE_LANG:=c
  171. ifeq ($(ADK_TOOLCHAIN_WITH_CXX),y)
  172. USE_LANG+=c++
  173. endif
  174. ifeq ($(ADK_TOOLCHAIN_WITH_OBJC),y)
  175. USE_LANG+=objc
  176. endif
  177. ifeq ($(ADK_TOOLCHAIN_WITH_FORTRAN),y)
  178. USE_LANG+=fortran
  179. endif
  180. ifeq ($(ADK_TOOLCHAIN_WITH_GO),y)
  181. USE_LANG+=go
  182. endif
  183. LANGUAGES=$(shell echo ${USE_LANG} |tr ' ' ',')
  184. include ${ADK_TOPDIR}/mk/buildhlp.mk
  185. GCC_BUILD_DIR_INITIAL:= $(WRKBUILD)-initial
  186. GCC_BUILD_DIR_FINAL:= $(WRKBUILD)-final
  187. $(GCC_BUILD_DIR_INITIAL)/.configured:
  188. ifeq ($(ADK_TARGET_ARCH_XTENSA),y)
  189. tar xf $(ADK_TOPDIR)/target/xtensa/overlay/xtensa_$(ADK_TARGET_CPU_TYPE).tar \
  190. --strip-components=1 -C $(WRKSRC) gcc
  191. endif
  192. mkdir -p $(GCC_BUILD_DIR_INITIAL)
  193. # these symlinks are very important, do not remove
  194. rm -rf $(TOOLCHAIN_DIR)/usr/$(GNU_TARGET_NAME)/sys-include
  195. mkdir -p $(TOOLCHAIN_DIR)/usr/$(GNU_TARGET_NAME)
  196. (cd $(TOOLCHAIN_DIR)/usr/$(GNU_TARGET_NAME); \
  197. ln -s ../$(STAGING_HOST2TARGET)/usr/include sys-include)
  198. rm -rf ${TOOLCHAIN_DIR}/usr/$(GNU_TARGET_NAME)/lib
  199. (cd $(TOOLCHAIN_DIR)/usr/$(GNU_TARGET_NAME); \
  200. ln -s ../$(STAGING_HOST2TARGET)/usr/lib lib)
  201. ifeq ($(ADK_TARGET_ARCH_SH),y)
  202. ifeq ($(ADK_TARGET_CPU_SH_J2),y)
  203. (cd ${STAGING_TARGET_DIR}/ && ln -sf . mj2)
  204. endif
  205. ifeq ($(ADK_TARGET_CPU_SH_SH3),y)
  206. (cd ${STAGING_TARGET_DIR}/ && ln -sf . m3)
  207. endif
  208. ifeq ($(ADK_TARGET_CPU_SH_SH4),y)
  209. (cd ${STAGING_TARGET_DIR}/ && ln -sf . m4)
  210. endif
  211. ifeq ($(ADK_TARGET_CPU_SH_SH4A),y)
  212. (cd ${STAGING_TARGET_DIR}/ && ln -sf . m4a)
  213. endif
  214. endif
  215. $(SED) '/k prot/agcc_cv_libc_provides_ssp=yes' $(WRKBUILD)/gcc/configure
  216. cd $(GCC_BUILD_DIR_INITIAL); \
  217. PATH='$(TARGET_PATH)' \
  218. CC='$(HOST_CC)' \
  219. CXX='$(HOST_CXX)' \
  220. CFLAGS="-O0 -g0 -fomit-frame-pointer" \
  221. CXXFLAGS="-O0 -g0 -fomit-frame-pointer" \
  222. $(WRKBUILD)/configure \
  223. ${GCC_CONFOPTS} \
  224. ${GCC_TLS_CONFOPTS} \
  225. --enable-languages=c \
  226. --with-newlib \
  227. --disable-shared \
  228. --disable-threads \
  229. --disable-multilib \
  230. --without-headers
  231. touch $@
  232. $(GCC_BUILD_DIR_INITIAL)/.compiled: $(GCC_BUILD_DIR_INITIAL)/.configured
  233. ifeq ($(ADK_TOOLCHAIN_GCC_OLD),y)
  234. PATH='$(TARGET_PATH)' \
  235. $(MAKE) ${GCC_MAKEOPTS} -C $(GCC_BUILD_DIR_INITIAL) all-gcc
  236. else
  237. PATH='$(TARGET_PATH)' \
  238. $(MAKE) ${GCC_MAKEOPTS} -C $(GCC_BUILD_DIR_INITIAL) all-gcc all-target-libgcc
  239. endif
  240. touch $@
  241. $(WRKBUILD)/.configured: $(GCC_BUILD_DIR_INITIAL)/.compiled
  242. ifeq ($(ADK_TOOLCHAIN_GCC_OLD),y)
  243. PATH='$(TARGET_PATH)' \
  244. $(MAKE) -C $(GCC_BUILD_DIR_INITIAL) install-gcc
  245. else
  246. PATH='$(TARGET_PATH)' \
  247. $(MAKE) -C $(GCC_BUILD_DIR_INITIAL) install-gcc install-target-libgcc
  248. endif
  249. # required for newlib
  250. (cd $(TOOLCHAIN_DIR)/usr/bin && \
  251. ln -sf $(GNU_TARGET_NAME)-gcc $(GNU_TARGET_NAME)-cc \
  252. )
  253. touch $@
  254. $(WRKBUILD)/.compiled:
  255. mkdir -p $(GCC_BUILD_DIR_FINAL)
  256. cd $(GCC_BUILD_DIR_FINAL); \
  257. PATH='$(TARGET_PATH)' \
  258. CC='$(HOST_CC)' \
  259. CXX='$(HOST_CXX)' \
  260. CFLAGS_FOR_TARGET='$(TARGET_CFLAGS)' \
  261. CXXFLAGS_FOR_TARGET='$(TARGET_CXXFLAGS)' \
  262. $(WRKBUILD)/configure \
  263. ${GCC_CONFOPTS} \
  264. ${GCC_FINAL_CONFOPTS} \
  265. --enable-languages=$(LANGUAGES) \
  266. --with-build-sysroot='$${prefix}/${STAGING_HOST2TARGET}' \
  267. --with-sysroot='$${prefix}/${STAGING_HOST2TARGET}'
  268. PATH='$(TARGET_PATH)' $(MAKE) -C $(GCC_BUILD_DIR_FINAL) configure-host
  269. cd $(GCC_BUILD_DIR_FINAL); \
  270. PATH='$(TARGET_PATH)' \
  271. $(MAKE) ${GCC_MAKEOPTS} all
  272. touch $@
  273. $(WRKBUILD)/.installed: $(WRKBUILD)/.compiled
  274. cd $(GCC_BUILD_DIR_FINAL); \
  275. PATH='$(TARGET_PATH)' \
  276. $(MAKE) install
  277. # remove duplicate tools, convert hardlinks to symlinks
  278. set -e; \
  279. cd $(TOOLCHAIN_DIR)/usr/$(GNU_TARGET_NAME)/bin; \
  280. for app in ar as c++ g++ gcc ld ld.gold ld.bfd nm objcopy objdump ranlib strip; do \
  281. ln -sf ../../bin/$(GNU_TARGET_NAME)-$${app} $${app}; \
  282. done;
  283. (cd $(TOOLCHAIN_DIR)/usr/bin && \
  284. ln -sf $(GNU_TARGET_NAME)-gcc $(GNU_TARGET_NAME)-gcc-${PKG_VERSION} && \
  285. ln -sf $(GNU_TARGET_NAME)-g++ $(GNU_TARGET_NAME)-g++-${PKG_VERSION} \
  286. )
  287. touch $@
  288. $(WRKBUILD)/.final:
  289. ifeq ($(ADK_TARGET_CPU_CF),y)
  290. find $(STAGING_TARGET_DIR) -name libgcc.a -print | while read t; do $(GNU_TARGET_NAME)-ar dv "$t" _ctors.o; done
  291. endif
  292. # remove any libiberty.a, breaking package/binutils later
  293. -rm $(STAGING_TARGET_DIR)/usr/lib/libiberty.a
  294. # cleanup unneeded docs
  295. rm -rf $(TOOLCHAIN_DIR)/usr/share
  296. # cleanup unneeded libtool files
  297. -find $(STAGING_TARGET_DIR) $(STAGING_HOST_DIR) -name \*.la -exec rm {} \;
  298. # strip target libs and host tools for toolchain builds in non-Debug mode
  299. ifeq ($(ADK_DEBUG),)
  300. PATH="$(TARGET_PATH)" debug='0' prefix='${TARGET_CROSS}' ${BASH} ${SCRIPT_DIR}/rstrip.sh \
  301. $(STAGING_TARGET_DIR) $(TOOLCHAIN_DIR)/usr/lib/gcc/$(GNU_TARGET_NAME)
  302. debug='0' prefix=' ' ${BASH} ${SCRIPT_DIR}/rstrip.sh $(TOOLCHAIN_DIR)/usr/bin
  303. endif
  304. touch $@
  305. include ${ADK_TOPDIR}/mk/toolchain.mk