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