Makefile 8.6 KB

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