Makefile 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  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_CXXFLAGS:= $(filter-out -fstack-protector-all,$(TARGET_CXXFLAGS))
  9. endif
  10. GCC_CONFOPTS:= --prefix=$(TOOLCHAIN_DIR)/usr \
  11. --with-bugurl="http://www.openadk.org/" \
  12. --build=$(GNU_HOST_NAME) \
  13. --host=$(GNU_HOST_NAME) \
  14. --target=$(GNU_TARGET_NAME) \
  15. --with-gmp=$(STAGING_HOST_DIR)/usr \
  16. --with-mpfr=$(STAGING_HOST_DIR)/usr \
  17. --with-libelf=$(STAGING_HOST_DIR)/usr \
  18. --disable-__cxa_atexit \
  19. --with-gnu-ld \
  20. --with-gnu-as \
  21. --disable-libsanitizer \
  22. --disable-install-libiberty \
  23. --disable-libitm \
  24. --disable-libmudflap \
  25. --disable-libgomp \
  26. --disable-decimal-float \
  27. --disable-libstdcxx-pch \
  28. --disable-ppl-version-check \
  29. --disable-cloog-version-check \
  30. --disable-target-optspace \
  31. --with-system-zlib \
  32. --without-ppl \
  33. --without-cloog \
  34. --without-isl \
  35. --disable-nls
  36. GCC_FINAL_CONFOPTS:=
  37. ifneq ($(ADK_TARGET_WITH_NPTL),)
  38. GCC_CONFOPTS+= --enable-tls --enable-threads --enable-libatomic
  39. else
  40. GCC_CONFOPTS+= --disable-tls --disable-threads --disable-libatomic
  41. endif
  42. ifeq ($(ADK_TARGET_UCLINUX)$(ADK_TARGET_USE_STATIC_LIBS),y)
  43. GCC_FINAL_CONFOPTS+= --disable-shared
  44. else
  45. # uClibc/glibc uses libgcc_s.so.1 for pthread_cancel with dlopen
  46. ifeq (ADK_TARGET_LIB_MUSL),y)
  47. GCC_FINAL_CONFOPTS+= --enable-shared='libstdc++'
  48. else
  49. GCC_FINAL_CONFOPTS+= --enable-shared='libstdc++,libgcc'
  50. endif
  51. endif
  52. ifeq ($(ADK_LINUX_M68K)$(ADK_LINUX_SH)$(ADK_LINUX_X86_64)$(ADK_LINUX_X86),)
  53. GCC_FINAL_CONFOPTS+= --disable-biarch --disable-multilib
  54. endif
  55. ifeq ($(ADK_LINUX_SH),y)
  56. ifeq ($(ADK_little),y)
  57. GCC_CONFOPTS+= --with-endian=little
  58. else
  59. GCC_CONFOPTS+= --with-endian=big
  60. endif
  61. GCC_FINAL_CONFOPTS+= --enable-multilib --with-multilib-list=m4,m4-nofpu
  62. endif
  63. ifeq ($(ADK_LINUX_X86),y)
  64. ifeq ($(ADK_TARGET_KERNEL_64),y)
  65. GCC_FINAL_CONFOPTS+= --enable-biarch --enable-targets=all --disable-multilib
  66. else
  67. GCC_FINAL_CONFOPTS+= --disable-biarch --disable-multilib
  68. endif
  69. endif
  70. ifeq ($(ADK_LINUX_X86_64),y)
  71. ifeq ($(ADK_x32),y)
  72. GCC_FINAL_CONFOPTS+= --with-abi=x32
  73. endif
  74. ifeq ($(ADK_64),y)
  75. GCC_FINAL_CONFOPTS+= --disable-biarch --disable-multilib
  76. endif
  77. endif
  78. ifeq ($(ADK_TOOLCHAIN_WITH_SSP),y)
  79. GCC_FINAL_CONFOPTS+= --enable-libssp
  80. else
  81. GCC_FINAL_CONFOPTS+= --disable-libssp
  82. endif
  83. ifeq ($(ADK_TOOLCHAIN_WITH_LTO),y)
  84. GCC_CONFOPTS+= --enable-lto
  85. else
  86. GCC_CONFOPTS+= --disable-lto
  87. endif
  88. ifeq ($(ADK_LINUX_PPC),y)
  89. GCC_CONFOPTS+= --with-long-double-64 --enable-secureplt
  90. ifneq ($(ADK_TARGET_CPU_WITH_FPU),y)
  91. GCC_CONFOPTS+= --with-float=soft
  92. endif
  93. endif
  94. ifeq ($(ADK_TARGET_ARCH),arm)
  95. GCC_CONFOPTS+= --with-float=$(ADK_TARGET_FLOAT)
  96. ifneq ($(ADK_TARGET_FPU),)
  97. GCC_CONFOPTS+= --with-fpu=$(ADK_TARGET_FPU)
  98. endif
  99. endif
  100. ifeq ($(ADK_CPU_ARMV5TE),y)
  101. GCC_CONFOPTS+= --with-arch=armv5te
  102. endif
  103. ifeq ($(ADK_CPU_ARMV6),y)
  104. GCC_CONFOPTS+= --with-arch=armv6
  105. endif
  106. ifeq ($(ADK_CPU_ARMV7A),y)
  107. GCC_CONFOPTS+= --with-arch=armv7-a
  108. endif
  109. ifeq ($(ADK_CPU_ARM926EJ_S),y)
  110. GCC_CONFOPTS+= --with-arch=armv5te --with-tune=arm926ej-s
  111. endif
  112. ifeq ($(ADK_CPU_ARM1176JZF_S),y)
  113. GCC_CONFOPTS+= --with-arch=armv6 --with-tune=arm1176jzf-s
  114. endif
  115. ifeq ($(ADK_CPU_CORTEX_A9),y)
  116. GCC_CONFOPTS+= --with-arch=armv7-a --with-tune=cortex-a9
  117. endif
  118. ifeq ($(ADK_CPU_SPARC_V9),y)
  119. GCC_CONFOPTS+= --with-cpu=ultrasparc
  120. endif
  121. ifeq ($(ADK_CPU_ARC),y)
  122. GCC_CONFOPTS+= --with-cpu=arc700
  123. endif
  124. ifeq ($(ADK_CPU_CF_5208),y)
  125. GCC_CONFOPTS+= --enable-multilib --with-arch=cf --with-cpu=5208
  126. endif
  127. ifneq ($(ADK_TARGET_MIPS_ABI),)
  128. GCC_CONFOPTS+= --with-abi=${ADK_TARGET_MIPS_ABI}
  129. endif
  130. ifeq (${ADK_MAKE_PARALLEL},y)
  131. GCC_MAKEOPTS+= -j${ADK_MAKE_JOBS}
  132. endif
  133. ifeq ($(ADK_TARGET_UCLINUX),y)
  134. LANGUAGES:=c
  135. else
  136. LANGUAGES:=c,c++
  137. endif
  138. include ${ADK_TOPDIR}/mk/buildhlp.mk
  139. GCC_BUILD_DIR_MINIMAL:= $(WRKBUILD)-minimal
  140. GCC_BUILD_DIR_INITIAL:= $(WRKBUILD)-initial
  141. GCC_BUILD_DIR_FINAL:= $(WRKBUILD)-final
  142. $(GCC_BUILD_DIR_MINIMAL)/.configured:
  143. ifeq ($(ADK_LINUX_XTENSA),y)
  144. tar xf $(ADK_TOPDIR)/target/xtensa/overlay/xtensa_$(ADK_TARGET_XTENSA).tar \
  145. --strip-components=1 -C $(WRKSRC) gcc
  146. endif
  147. mkdir -p $(GCC_BUILD_DIR_MINIMAL)
  148. # these symlinks are very important, do not remove
  149. rm -rf $(TOOLCHAIN_DIR)/usr/$(GNU_TARGET_NAME)/sys-include
  150. mkdir -p $(TOOLCHAIN_DIR)/usr/$(GNU_TARGET_NAME)
  151. (cd $(TOOLCHAIN_DIR)/usr/$(GNU_TARGET_NAME); \
  152. ln -s ../$(STAGING_HOST2TARGET)/usr/include sys-include)
  153. rm -rf ${TOOLCHAIN_DIR}/usr/$(GNU_TARGET_NAME)/lib
  154. (cd $(TOOLCHAIN_DIR)/usr/$(GNU_TARGET_NAME); \
  155. ln -s ../$(STAGING_HOST2TARGET)/lib lib)
  156. ifeq ($(ADK_LINUX_SH),y)
  157. (cd ${STAGING_TARGET_DIR}/ && ln -sf . m4 && ln -sf . m4-nofpu)
  158. endif
  159. $(SED) '/k prot/agcc_cv_libc_provides_ssp=yes' $(WRKBUILD)/gcc/configure
  160. cd $(GCC_BUILD_DIR_MINIMAL); \
  161. PATH='$(TARGET_PATH)' \
  162. CFLAGS="-O0 -g0" \
  163. CXXFLAGS="-O0 -g0" \
  164. $(WRKBUILD)/configure \
  165. ${GCC_CONFOPTS} \
  166. --enable-languages=c \
  167. --disable-libssp \
  168. --disable-shared \
  169. --without-headers
  170. touch $@
  171. $(GCC_BUILD_DIR_MINIMAL)/.compiled: $(GCC_BUILD_DIR_MINIMAL)/.configured
  172. PATH='$(TARGET_PATH)' $(MAKE) ${GCC_MAKEOPTS} -C $(GCC_BUILD_DIR_MINIMAL) all-gcc
  173. touch $@
  174. $(WRKBUILD)/.headers: $(GCC_BUILD_DIR_MINIMAL)/.compiled
  175. PATH='$(TARGET_PATH)' $(MAKE) -C $(GCC_BUILD_DIR_MINIMAL) install-gcc
  176. touch $@
  177. $(GCC_BUILD_DIR_INITIAL)/.configured:
  178. mkdir -p $(GCC_BUILD_DIR_INITIAL)
  179. cd $(GCC_BUILD_DIR_INITIAL); \
  180. PATH='$(TARGET_PATH)' \
  181. CFLAGS="-O0 -g0" \
  182. CXXFLAGS="-O0 -g0" \
  183. $(WRKBUILD)/configure \
  184. ${GCC_CONFOPTS} \
  185. ${GCC_FINAL_CONFOPTS} \
  186. --enable-languages=c \
  187. --disable-shared \
  188. --disable-threads \
  189. --with-sysroot=$(STAGING_TARGET_DIR)
  190. touch $@
  191. $(GCC_BUILD_DIR_INITIAL)/.compiled: $(GCC_BUILD_DIR_INITIAL)/.configured
  192. PATH='$(TARGET_PATH)' $(MAKE) ${GCC_MAKEOPTS} -C $(GCC_BUILD_DIR_INITIAL) all-gcc all-target-libgcc
  193. touch $@
  194. $(WRKBUILD)/.configured: $(GCC_BUILD_DIR_INITIAL)/.compiled
  195. PATH='$(TARGET_PATH)' $(MAKE) -C $(GCC_BUILD_DIR_INITIAL) install-gcc install-target-libgcc
  196. touch $@
  197. $(GCC_BUILD_DIR_FINAL)/.configured:
  198. mkdir -p $(GCC_BUILD_DIR_FINAL)
  199. cd $(GCC_BUILD_DIR_FINAL); \
  200. PATH='$(TARGET_PATH)' \
  201. CFLAGS_FOR_TARGET='$(TARGET_CFLAGS)' \
  202. CXXFLAGS_FOR_TARGET='$(TARGET_CXXFLAGS)' \
  203. $(WRKBUILD)/configure \
  204. ${GCC_CONFOPTS} \
  205. ${GCC_FINAL_CONFOPTS} \
  206. --enable-languages=$(LANGUAGES) \
  207. --with-build-sysroot='$${prefix}/${STAGING_HOST2TARGET}' \
  208. --with-sysroot='$${prefix}/${STAGING_HOST2TARGET}'
  209. PATH='$(TARGET_PATH)' $(MAKE) -C $(GCC_BUILD_DIR_FINAL) configure-host
  210. touch $@
  211. $(WRKBUILD)/.compiled: $(GCC_BUILD_DIR_FINAL)/.configured
  212. cd $(GCC_BUILD_DIR_FINAL); \
  213. PATH='$(TARGET_PATH)' \
  214. $(MAKE) ${GCC_MAKEOPTS} all
  215. touch $@
  216. $(WRKBUILD)/.installed: $(WRKBUILD)/.compiled
  217. cd $(GCC_BUILD_DIR_FINAL); \
  218. PATH='$(TARGET_PATH)' \
  219. $(MAKE) install
  220. # remove duplicate tools, convert hardlinks to symlinks
  221. set -e; \
  222. cd $(TOOLCHAIN_DIR)/usr/$(GNU_TARGET_NAME)/bin; \
  223. for app in ar as c++ g++ gcc ld ld.gold ld.bfd nm objcopy objdump ranlib strip; do \
  224. ln -sf ../../bin/$(GNU_TARGET_NAME)-$${app} $${app}; \
  225. done;
  226. (cd $(TOOLCHAIN_DIR)/usr/bin && \
  227. ln -sf $(GNU_TARGET_NAME)-gcc $(GNU_TARGET_NAME)-gcc-${PKG_VERSION} && \
  228. ln -sf $(GNU_TARGET_NAME)-g++ $(GNU_TARGET_NAME)-g++-${PKG_VERSION} \
  229. )
  230. ifeq ($(ADK_TARGET_USE_GOLD),y)
  231. (cd $(TOOLCHAIN_DIR)/usr/bin && \
  232. ln -sf $(GNU_TARGET_NAME)-ld.gold $(GNU_TARGET_NAME)-ld)
  233. else
  234. (cd $(TOOLCHAIN_DIR)/usr/bin && \
  235. ln -sf $(GNU_TARGET_NAME)-ld.bfd $(GNU_TARGET_NAME)-ld)
  236. endif
  237. cd $(STAGING_TARGET_DIR)/lib && \
  238. ln -sf libstdc++.so.6.0.$(LIBSTDCXXVER) libstdc++.so && \
  239. ln -sf libstdc++.so.6.0.$(LIBSTDCXXVER) libstdc++.so.6
  240. # cleanup unneeded docs
  241. rm -rf $(TOOLCHAIN_DIR)/usr/share
  242. # create gcc wrapper for uClinux/m68k
  243. echo "#!/bin/sh" > $(TOOLCHAIN_DIR)/usr/bin/adk-uclinux-gcc
  244. echo "exec ${GNU_TARGET_NAME}-gcc \"\$$@\" -specs $(ADK_TOPDIR)/toolchain/gcc/m68k-uclinux-gcc.specs" >> $(TOOLCHAIN_DIR)/usr/bin/adk-uclinux-gcc
  245. chmod a+x $(TOOLCHAIN_DIR)/usr/bin/adk-uclinux-gcc
  246. touch $@
  247. include ${ADK_TOPDIR}/mk/toolchain.mk