Makefile 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  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. endif
  57. ifeq ($(ADK_TARGET_WITH_LT),y)
  58. GCC_FINAL_CONFOPTS:= --disable-tls --enable-threads --disable-libatomic
  59. endif
  60. ifeq ($(ADK_TARGET_LIB_WITHOUT_THREADS)$(ADK_TARGET_WITHOUT_THREADS),y)
  61. GCC_FINAL_CONFOPTS:= --disable-tls --disable-threads --disable-libatomic
  62. endif
  63. ifeq ($(ADK_TARGET_BINFMT_FLAT)$(ADK_TARGET_USE_STATIC_LIBS)$(ADK_TARGET_BINFMT_DSBT),y)
  64. GCC_FINAL_CONFOPTS+= --disable-shared
  65. else
  66. # uClibc/glibc uses libgcc_s.so.1 for pthread_cancel with dlopen
  67. ifeq (ADK_TARGET_LIB_MUSL),y)
  68. GCC_FINAL_CONFOPTS+= --enable-shared='libstdc++'
  69. else
  70. GCC_FINAL_CONFOPTS+= --enable-shared='libstdc++,libgcc'
  71. endif
  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_CPU_CF),y)
  105. GCC_CONFOPTS+= --enable-multilib --with-arch=cf
  106. endif
  107. ifeq ($(ADK_TARGET_ARCH_M68K)$(ADK_TARGET_ARCH_X86_64)$(ADK_TARGET_ARCH_X86),)
  108. GCC_FINAL_CONFOPTS+= --disable-biarch --disable-multilib
  109. endif
  110. ifeq ($(ADK_TARGET_ARCH_SH),y)
  111. ifeq ($(ADK_TARGET_LITTLE_ENDIAN),y)
  112. GCC_CONFOPTS+= --with-endian=little
  113. else
  114. GCC_CONFOPTS+= --with-endian=big
  115. endif
  116. ifeq ($(ADK_CPU_SH2),y)
  117. GCC_FINAL_CONFOPTS+= --with-multilib-list=m2
  118. endif
  119. ifeq ($(ADK_CPU_SH2A),y)
  120. GCC_FINAL_CONFOPTS+= --with-multilib-list=m2a
  121. endif
  122. ifeq ($(ADK_CPU_SH3),y)
  123. GCC_FINAL_CONFOPTS+= --with-multilib-list=m3
  124. endif
  125. ifeq ($(ADK_CPU_SH4),y)
  126. GCC_FINAL_CONFOPTS+= --with-multilib-list=m4,m4-nofpu
  127. endif
  128. ifeq ($(ADK_CPU_SH4A),y)
  129. GCC_FINAL_CONFOPTS+= --with-multilib-list=m4a,m4a-nofpu
  130. endif
  131. endif
  132. ifeq ($(ADK_TARGET_ARCH_X86),y)
  133. ifeq ($(ADK_TARGET_KERNEL_64),y)
  134. GCC_FINAL_CONFOPTS+= --enable-biarch --enable-targets=all --disable-multilib
  135. else
  136. GCC_FINAL_CONFOPTS+= --disable-biarch --disable-multilib
  137. endif
  138. endif
  139. ifeq ($(ADK_TARGET_ARCH_X86_64),y)
  140. ifneq ($(ADK_TARGET_ABI_X32),)
  141. GCC_FINAL_CONFOPTS+= --with-abi=x32
  142. else
  143. GCC_FINAL_CONFOPTS+= --disable-biarch --disable-multilib
  144. endif
  145. endif
  146. ifeq ($(ADK_TARGET_ARCH_ALPHA),y)
  147. GCC_CONFOPTS+= --without-long-double-128
  148. endif
  149. ifeq ($(ADK_TARGET_ARCH_PPC),y)
  150. GCC_CONFOPTS+= --with-long-double-64 --enable-secureplt
  151. endif
  152. ifneq ($(ADK_TARGET_MIPS_ABI),)
  153. GCC_CONFOPTS+= --with-abi=${ADK_TARGET_MIPS_ABI}
  154. endif
  155. ifeq (${ADK_MAKE_PARALLEL},y)
  156. GCC_MAKEOPTS+= -j${ADK_MAKE_JOBS}
  157. endif
  158. ifeq ($(ADK_TARGET_WITHOUT_CXX),y)
  159. LANGUAGES:=c
  160. else
  161. LANGUAGES:=c,c++
  162. endif
  163. include ${ADK_TOPDIR}/mk/buildhlp.mk
  164. GCC_BUILD_DIR_INITIAL:= $(WRKBUILD)-initial
  165. GCC_BUILD_DIR_FINAL:= $(WRKBUILD)-final
  166. $(GCC_BUILD_DIR_INITIAL)/.configured:
  167. ifeq ($(ADK_TARGET_ARCH_XTENSA),y)
  168. tar xf $(ADK_TOPDIR)/target/xtensa/overlay/xtensa_$(ADK_TARGET_XTENSA).tar \
  169. --strip-components=1 -C $(WRKSRC) gcc
  170. endif
  171. mkdir -p $(GCC_BUILD_DIR_INITIAL)
  172. # these symlinks are very important, do not remove
  173. rm -rf $(TOOLCHAIN_DIR)/usr/$(GNU_TARGET_NAME)/sys-include
  174. mkdir -p $(TOOLCHAIN_DIR)/usr/$(GNU_TARGET_NAME)
  175. (cd $(TOOLCHAIN_DIR)/usr/$(GNU_TARGET_NAME); \
  176. ln -s ../$(STAGING_HOST2TARGET)/usr/include sys-include)
  177. rm -rf ${TOOLCHAIN_DIR}/usr/$(GNU_TARGET_NAME)/lib
  178. (cd $(TOOLCHAIN_DIR)/usr/$(GNU_TARGET_NAME); \
  179. ln -s ../$(STAGING_HOST2TARGET)/usr/lib lib)
  180. ifeq ($(ADK_TARGET_ARCH_SH),y)
  181. ifeq ($(ADK_CPU_SH3),y)
  182. (cd ${STAGING_TARGET_DIR}/ && ln -sf . m3)
  183. endif
  184. ifeq ($(ADK_CPU_SH4),y)
  185. (cd ${STAGING_TARGET_DIR}/ && ln -sf . m4)
  186. endif
  187. ifeq ($(ADK_CPU_SH4A),y)
  188. (cd ${STAGING_TARGET_DIR}/ && ln -sf . m4a)
  189. endif
  190. endif
  191. ifeq ($(ADK_TARGET_ARCH_ARC),y)
  192. $(SED) 's/crtbeginS.o libgmon.a crtg.o/crtbeginS.o crtg.o/' \
  193. $(WRKBUILD)/libgcc/config.host
  194. endif
  195. $(SED) '/k prot/agcc_cv_libc_provides_ssp=yes' $(WRKBUILD)/gcc/configure
  196. cd $(GCC_BUILD_DIR_INITIAL); \
  197. PATH='$(TARGET_PATH)' \
  198. CC='$(HOST_CC)' \
  199. CXX='$(HOST_CXX)' \
  200. CFLAGS="-O0 -g0 -fomit-frame-pointer" \
  201. CXXFLAGS="-O0 -g0 -fomit-frame-pointer" \
  202. $(WRKBUILD)/configure \
  203. ${GCC_CONFOPTS} \
  204. --enable-languages=c \
  205. --with-newlib \
  206. --enable-tls \
  207. --disable-shared \
  208. --disable-threads \
  209. --disable-multilib \
  210. --without-headers
  211. touch $@
  212. $(GCC_BUILD_DIR_INITIAL)/.compiled: $(GCC_BUILD_DIR_INITIAL)/.configured
  213. ifeq ($(ADK_TOOLCHAIN_GCC_OLD),y)
  214. PATH='$(TARGET_PATH)' \
  215. $(MAKE) ${GCC_MAKEOPTS} -C $(GCC_BUILD_DIR_INITIAL) all-gcc
  216. else
  217. PATH='$(TARGET_PATH)' \
  218. $(MAKE) ${GCC_MAKEOPTS} -C $(GCC_BUILD_DIR_INITIAL) all-gcc all-target-libgcc
  219. endif
  220. touch $@
  221. $(WRKBUILD)/.configured: $(GCC_BUILD_DIR_INITIAL)/.compiled
  222. ifeq ($(ADK_TOOLCHAIN_GCC_OLD),y)
  223. PATH='$(TARGET_PATH)' \
  224. $(MAKE) -C $(GCC_BUILD_DIR_INITIAL) install-gcc
  225. else
  226. PATH='$(TARGET_PATH)' \
  227. $(MAKE) -C $(GCC_BUILD_DIR_INITIAL) install-gcc install-target-libgcc
  228. endif
  229. # required for newlib
  230. (cd $(TOOLCHAIN_DIR)/usr/bin && \
  231. ln -sf $(GNU_TARGET_NAME)-gcc $(GNU_TARGET_NAME)-cc \
  232. )
  233. ifeq ($(ADK_TARGET_ARCH_M68K),y)
  234. # create gcc wrapper for uClinux/m68k
  235. echo "#!/bin/sh" > $(TOOLCHAIN_DIR)/usr/bin/adk-uclinux-gcc
  236. echo "exec ${GNU_TARGET_NAME}-gcc \"\$$@\" -specs $(ADK_TOPDIR)/toolchain/gcc/m68k-uclinux-gcc.specs" >> $(TOOLCHAIN_DIR)/usr/bin/adk-uclinux-gcc
  237. chmod a+x $(TOOLCHAIN_DIR)/usr/bin/adk-uclinux-gcc
  238. endif
  239. touch $@
  240. $(WRKBUILD)/.compiled:
  241. mkdir -p $(GCC_BUILD_DIR_FINAL)
  242. cd $(GCC_BUILD_DIR_FINAL); \
  243. PATH='$(TARGET_PATH)' \
  244. CC='$(HOST_CC)' \
  245. CXX='$(HOST_CXX)' \
  246. CFLAGS_FOR_TARGET='$(TARGET_CFLAGS)' \
  247. CXXFLAGS_FOR_TARGET='$(TARGET_CXXFLAGS)' \
  248. $(WRKBUILD)/configure \
  249. ${GCC_CONFOPTS} \
  250. ${GCC_FINAL_CONFOPTS} \
  251. --enable-cxx-flags='-fPIC' \
  252. --enable-languages=$(LANGUAGES) \
  253. --with-build-sysroot='$${prefix}/${STAGING_HOST2TARGET}' \
  254. --with-sysroot='$${prefix}/${STAGING_HOST2TARGET}'
  255. PATH='$(TARGET_PATH)' $(MAKE) -C $(GCC_BUILD_DIR_FINAL) configure-host
  256. cd $(GCC_BUILD_DIR_FINAL); \
  257. PATH='$(TARGET_PATH)' \
  258. $(MAKE) ${GCC_MAKEOPTS} all
  259. touch $@
  260. $(WRKBUILD)/.installed: $(WRKBUILD)/.compiled
  261. cd $(GCC_BUILD_DIR_FINAL); \
  262. PATH='$(TARGET_PATH)' \
  263. $(MAKE) install
  264. # remove duplicate tools, convert hardlinks to symlinks
  265. set -e; \
  266. cd $(TOOLCHAIN_DIR)/usr/$(GNU_TARGET_NAME)/bin; \
  267. for app in ar as c++ g++ gcc ld ld.gold ld.bfd nm objcopy objdump ranlib strip; do \
  268. ln -sf ../../bin/$(GNU_TARGET_NAME)-$${app} $${app}; \
  269. done;
  270. (cd $(TOOLCHAIN_DIR)/usr/bin && \
  271. ln -sf $(GNU_TARGET_NAME)-gcc $(GNU_TARGET_NAME)-gcc-${PKG_VERSION} && \
  272. ln -sf $(GNU_TARGET_NAME)-g++ $(GNU_TARGET_NAME)-g++-${PKG_VERSION} \
  273. )
  274. touch $@
  275. $(WRKBUILD)/.final:
  276. # remove any libiberty.a, breaking package/binutils later
  277. -rm $(STAGING_TARGET_DIR)/usr/lib/libiberty.a
  278. # cleanup unneeded docs
  279. rm -rf $(TOOLCHAIN_DIR)/usr/share
  280. # cleanup unneeded libtool files
  281. -find $(STAGING_TARGET_DIR) $(STAGING_HOST_DIR) -name \*.la -exec rm {} \;
  282. # strip target libs and host tools for toolchain builds
  283. PATH="$(TARGET_PATH)" debug='0' prefix='${TARGET_CROSS}' ${BASH} ${SCRIPT_DIR}/rstrip.sh \
  284. $(STAGING_TARGET_DIR) $(TOOLCHAIN_DIR)/usr/lib/gcc/$(GNU_TARGET_NAME)
  285. debug='0' prefix=' ' ${BASH} ${SCRIPT_DIR}/rstrip.sh $(TOOLCHAIN_DIR)/usr/bin
  286. touch $@
  287. include ${ADK_TOPDIR}/mk/toolchain.mk