Makefile 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  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. ifeq ($(ADK_TOOLCHAIN_WITH_GO),y)
  20. TARGET_CFLAGS+= -lpthread
  21. TARGET_CXXFLAGS+= -lpthread
  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-werror \
  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. GCC_TLS_CONFOPTS:= --enable-tls
  58. endif
  59. ifeq ($(ADK_TARGET_WITH_LT),y)
  60. GCC_FINAL_CONFOPTS:= --disable-tls --enable-threads --disable-libatomic
  61. GCC_TLS_CONFOPTS:= --disable-tls
  62. endif
  63. ifeq ($(ADK_TARGET_LIB_WITHOUT_THREADS)$(ADK_TARGET_WITHOUT_THREADS),y)
  64. GCC_FINAL_CONFOPTS:= --disable-tls --disable-threads --disable-libatomic
  65. GCC_TLS_CONFOPTS:= --disable-tls
  66. endif
  67. ifeq ($(ADK_TARGET_BINFMT_FLAT)$(ADK_TARGET_USE_STATIC_LIBS)$(ADK_TARGET_BINFMT_DSBT),y)
  68. GCC_FINAL_CONFOPTS+= --disable-shared
  69. else
  70. # uClibc/glibc uses libgcc_s.so.1 for pthread_cancel with dlopen
  71. GCC_FINAL_CONFOPTS+= --enable-shared='libstdc++,libgcc' --enable-cxx-flags='-fPIC'
  72. endif
  73. ifeq ($(ADK_TOOLCHAIN_WITH_SSP),y)
  74. GCC_FINAL_CONFOPTS+= --enable-libssp
  75. else
  76. GCC_FINAL_CONFOPTS+= --disable-libssp
  77. endif
  78. ifeq ($(ADK_TOOLCHAIN_WITH_LTO),y)
  79. GCC_CONFOPTS+= --enable-lto
  80. else
  81. GCC_CONFOPTS+= --disable-lto
  82. endif
  83. #
  84. # architecture specific
  85. #
  86. ifneq ($(ADK_TARGET_GCC_CPU),)
  87. GCC_CONFOPTS+= --with-cpu=$(ADK_TARGET_GCC_CPU)
  88. endif
  89. ifneq ($(ADK_TARGET_GCC_ARCH),)
  90. GCC_CONFOPTS+= --with-arch=$(ADK_TARGET_GCC_ARCH)
  91. endif
  92. ifneq ($(ADK_TARGET_FLOAT),)
  93. GCC_CONFOPTS+= --with-float=$(ADK_TARGET_FLOAT)
  94. endif
  95. ifneq ($(ADK_TARGET_FPU),)
  96. GCC_CONFOPTS+= --with-fpu=$(ADK_TARGET_FPU)
  97. endif
  98. ifeq ($(ADK_TARGET_ARCH_ARM_WITH_THUMB),y)
  99. GCC_CONFOPTS+= --with-mode=thumb
  100. endif
  101. ifeq ($(ADK_TARGET_ARCH_METAG),y)
  102. GCC_CONFOPTS+= --with-cpu=2.1 --enable-meta-default --disable-symvers
  103. endif
  104. ifeq ($(ADK_TARGET_CPU_CF),y)
  105. GCC_CONFOPTS+= --enable-multilib --with-arch=cf
  106. endif
  107. ifeq ($(ADK_TARGET_ARCH_NDS32),y)
  108. GCC_CONFOPTS+= --with-arch=v3
  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_CONFOPTS+= --with-abi=x32 --enable-multilib
  145. else
  146. GCC_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_PPC64),y)
  156. GCC_CONFOPTS+= --without-long-double-128 --with-abi=elfv2
  157. endif
  158. ifeq ($(ADK_TARGET_ARCH_FRV),y)
  159. GCC_CONFOPTS+= --enable-sjlj-exceptions
  160. endif
  161. ifneq ($(ADK_TARGET_MIPS_ABI),)
  162. GCC_CONFOPTS+= --with-abi=${ADK_TARGET_MIPS_ABI}
  163. endif
  164. ifeq (${ADK_MAKE_PARALLEL},y)
  165. GCC_MAKEOPTS+= -j${ADK_MAKE_JOBS}
  166. endif
  167. USE_LANG:=c
  168. ifeq ($(ADK_TOOLCHAIN_WITH_CXX),y)
  169. USE_LANG+=c++
  170. endif
  171. ifeq ($(ADK_TOOLCHAIN_WITH_OBJC),y)
  172. USE_LANG+=objc
  173. endif
  174. ifeq ($(ADK_TOOLCHAIN_WITH_FORTRAN),y)
  175. USE_LANG+=fortran
  176. endif
  177. ifeq ($(ADK_TOOLCHAIN_WITH_GO),y)
  178. USE_LANG+=go
  179. endif
  180. LANGUAGES=$(shell echo ${USE_LANG} |tr ' ' ',')
  181. include ${ADK_TOPDIR}/mk/buildhlp.mk
  182. GCC_BUILD_DIR_INITIAL:= $(WRKBUILD)-initial
  183. GCC_BUILD_DIR_FINAL:= $(WRKBUILD)-final
  184. $(GCC_BUILD_DIR_INITIAL)/.configured:
  185. ifeq ($(ADK_TARGET_ARCH_XTENSA),y)
  186. tar xf $(ADK_TOPDIR)/target/xtensa/overlay/xtensa_$(ADK_TARGET_CPU_TYPE).tar \
  187. --strip-components=1 -C $(WRKSRC) gcc
  188. endif
  189. mkdir -p $(GCC_BUILD_DIR_INITIAL)
  190. # these symlinks are very important, do not remove
  191. rm -rf $(TOOLCHAIN_DIR)/usr/$(GNU_TARGET_NAME)/sys-include
  192. mkdir -p $(TOOLCHAIN_DIR)/usr/$(GNU_TARGET_NAME)
  193. (cd $(TOOLCHAIN_DIR)/usr/$(GNU_TARGET_NAME); \
  194. ln -s ../$(STAGING_HOST2TARGET)/usr/include sys-include)
  195. rm -rf ${TOOLCHAIN_DIR}/usr/$(GNU_TARGET_NAME)/lib
  196. (cd $(TOOLCHAIN_DIR)/usr/$(GNU_TARGET_NAME); \
  197. ln -s ../$(STAGING_HOST2TARGET)/usr/lib lib)
  198. ifeq ($(ADK_TARGET_ARCH_SH),y)
  199. ifeq ($(ADK_TARGET_CPU_SH_SH3),y)
  200. (cd ${STAGING_TARGET_DIR}/ && ln -sf . m3)
  201. endif
  202. ifeq ($(ADK_TARGET_CPU_SH_SH4),y)
  203. (cd ${STAGING_TARGET_DIR}/ && ln -sf . m4)
  204. endif
  205. ifeq ($(ADK_TARGET_CPU_SH_SH4A),y)
  206. (cd ${STAGING_TARGET_DIR}/ && ln -sf . m4a)
  207. endif
  208. endif
  209. ifeq ($(ADK_TARGET_ARCH_ARC),y)
  210. $(SED) 's/crtbeginS.o libgmon.a crtg.o/crtbeginS.o crtg.o/' \
  211. $(WRKBUILD)/libgcc/config.host
  212. endif
  213. $(SED) '/k prot/agcc_cv_libc_provides_ssp=yes' $(WRKBUILD)/gcc/configure
  214. cd $(GCC_BUILD_DIR_INITIAL); \
  215. PATH='$(TARGET_PATH)' \
  216. CC='$(HOST_CC)' \
  217. CXX='$(HOST_CXX)' \
  218. CFLAGS="-O0 -g0 -fomit-frame-pointer" \
  219. CXXFLAGS="-O0 -g0 -fomit-frame-pointer" \
  220. $(WRKBUILD)/configure \
  221. ${GCC_CONFOPTS} \
  222. ${GCC_TLS_CONFOPTS} \
  223. --enable-languages=c \
  224. --with-newlib \
  225. --disable-shared \
  226. --disable-threads \
  227. --disable-multilib \
  228. --without-headers
  229. touch $@
  230. $(GCC_BUILD_DIR_INITIAL)/.compiled: $(GCC_BUILD_DIR_INITIAL)/.configured
  231. ifeq ($(ADK_TOOLCHAIN_GCC_OLD),y)
  232. PATH='$(TARGET_PATH)' \
  233. $(MAKE) ${GCC_MAKEOPTS} -C $(GCC_BUILD_DIR_INITIAL) all-gcc
  234. else
  235. PATH='$(TARGET_PATH)' \
  236. $(MAKE) ${GCC_MAKEOPTS} -C $(GCC_BUILD_DIR_INITIAL) all-gcc all-target-libgcc
  237. endif
  238. touch $@
  239. $(WRKBUILD)/.configured: $(GCC_BUILD_DIR_INITIAL)/.compiled
  240. ifeq ($(ADK_TOOLCHAIN_GCC_OLD),y)
  241. PATH='$(TARGET_PATH)' \
  242. $(MAKE) -C $(GCC_BUILD_DIR_INITIAL) install-gcc
  243. else
  244. PATH='$(TARGET_PATH)' \
  245. $(MAKE) -C $(GCC_BUILD_DIR_INITIAL) install-gcc install-target-libgcc
  246. endif
  247. # required for newlib
  248. (cd $(TOOLCHAIN_DIR)/usr/bin && \
  249. ln -sf $(GNU_TARGET_NAME)-gcc $(GNU_TARGET_NAME)-cc \
  250. )
  251. touch $@
  252. $(WRKBUILD)/.compiled:
  253. mkdir -p $(GCC_BUILD_DIR_FINAL)
  254. cd $(GCC_BUILD_DIR_FINAL); \
  255. PATH='$(TARGET_PATH)' \
  256. CC='$(HOST_CC)' \
  257. CXX='$(HOST_CXX)' \
  258. CFLAGS_FOR_TARGET='$(TARGET_CFLAGS)' \
  259. CXXFLAGS_FOR_TARGET='$(TARGET_CXXFLAGS)' \
  260. $(WRKBUILD)/configure \
  261. ${GCC_CONFOPTS} \
  262. ${GCC_FINAL_CONFOPTS} \
  263. --enable-languages=$(LANGUAGES) \
  264. --with-build-sysroot='$${prefix}/${STAGING_HOST2TARGET}' \
  265. --with-sysroot='$${prefix}/${STAGING_HOST2TARGET}'
  266. PATH='$(TARGET_PATH)' $(MAKE) -C $(GCC_BUILD_DIR_FINAL) configure-host
  267. cd $(GCC_BUILD_DIR_FINAL); \
  268. PATH='$(TARGET_PATH)' \
  269. $(MAKE) ${GCC_MAKEOPTS} all
  270. touch $@
  271. $(WRKBUILD)/.installed: $(WRKBUILD)/.compiled
  272. cd $(GCC_BUILD_DIR_FINAL); \
  273. PATH='$(TARGET_PATH)' \
  274. $(MAKE) install
  275. # remove duplicate tools, convert hardlinks to symlinks
  276. set -e; \
  277. cd $(TOOLCHAIN_DIR)/usr/$(GNU_TARGET_NAME)/bin; \
  278. for app in ar as c++ g++ gcc ld ld.gold ld.bfd nm objcopy objdump ranlib strip; do \
  279. ln -sf ../../bin/$(GNU_TARGET_NAME)-$${app} $${app}; \
  280. done;
  281. (cd $(TOOLCHAIN_DIR)/usr/bin && \
  282. ln -sf $(GNU_TARGET_NAME)-gcc $(GNU_TARGET_NAME)-gcc-${PKG_VERSION} && \
  283. ln -sf $(GNU_TARGET_NAME)-g++ $(GNU_TARGET_NAME)-g++-${PKG_VERSION} \
  284. )
  285. touch $@
  286. $(WRKBUILD)/.final:
  287. ifeq ($(ADK_TARGET_CPU_CF),y)
  288. find $(STAGING_TARGET_DIR) -name libgcc.a -print | while read t; do $(GNU_TARGET_NAME)-ar dv "$t" _ctors.o; done
  289. endif
  290. # remove any libiberty.a, breaking package/binutils later
  291. -rm $(STAGING_TARGET_DIR)/usr/lib/libiberty.a
  292. # cleanup unneeded docs
  293. rm -rf $(TOOLCHAIN_DIR)/usr/share
  294. # cleanup unneeded libtool files
  295. -find $(STAGING_TARGET_DIR) $(STAGING_HOST_DIR) -name \*.la -exec rm {} \;
  296. # strip target libs and host tools for toolchain builds in non-Debug mode
  297. ifeq ($(ADK_DEBUG),)
  298. PATH="$(TARGET_PATH)" debug='0' prefix='${TARGET_CROSS}' ${BASH} ${SCRIPT_DIR}/rstrip.sh \
  299. $(STAGING_TARGET_DIR) $(TOOLCHAIN_DIR)/usr/lib/gcc/$(GNU_TARGET_NAME)
  300. debug='0' prefix=' ' ${BASH} ${SCRIPT_DIR}/rstrip.sh $(TOOLCHAIN_DIR)/usr/bin
  301. endif
  302. touch $@
  303. include ${ADK_TOPDIR}/mk/toolchain.mk