Makefile 9.8 KB

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