Makefile 8.6 KB

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