Makefile 9.6 KB

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