Makefile 8.7 KB

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