1
0

Makefile 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  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. --with-system-zlib \
  31. --without-ppl \
  32. --without-cloog \
  33. --without-isl \
  34. --disable-nls
  35. GCC_FINAL_CONFOPTS:=
  36. ifneq ($(ADK_TARGET_WITH_NPTL),)
  37. GCC_CONFOPTS+= --enable-tls --enable-threads --enable-libatomic
  38. else
  39. GCC_CONFOPTS+= --disable-tls --disable-threads --disable-libatomic
  40. endif
  41. ifneq ($(ADK_LINUX_AARCH64)$(ADK_LINUX_ALPHA)$(ADK_LINUX_BFIN)$(ADK_LINUX_XTENSA)$(ADK_LINUX_M68K),y)
  42. GCC_FINAL_CONFOPTS+= --enable-cxx-flags='$(TARGET_CXXFLAGS)'
  43. endif
  44. ifeq ($(ADK_TARGET_UCLINUX),y)
  45. GCC_FINAL_CONFOPTS+= --disable-shared
  46. else
  47. # uClibc/glibc uses libgcc_s.so.1 for pthread_cancel with dlopen
  48. ifeq (ADK_TARGET_LIB_MUSL),y)
  49. GCC_FINAL_CONFOPTS+= --enable-shared='libstdc++'
  50. else
  51. GCC_FINAL_CONFOPTS+= --enable-shared='libstdc++,libgcc'
  52. endif
  53. endif
  54. ifeq ($(ADK_LINUX_M68K)$(ADK_LINUX_SH)$(ADK_LINUX_X86_64)$(ADK_LINUX_X86),)
  55. GCC_FINAL_CONFOPTS+= --disable-biarch --disable-multilib
  56. endif
  57. ifeq ($(ADK_LINUX_SH),y)
  58. ifeq ($(ADK_little),y)
  59. GCC_CONFOPTS+= --with-endian=little
  60. else
  61. GCC_CONFOPTS+= --with-endian=big
  62. endif
  63. GCC_FINAL_CONFOPTS+= --enable-multilib --with-multilib-list=m4,m4-nofpu
  64. endif
  65. ifeq ($(ADK_LINUX_X86),y)
  66. ifeq ($(ADK_TARGET_KERNEL_64),y)
  67. GCC_FINAL_CONFOPTS+= --enable-biarch --enable-targets=all --disable-multilib
  68. else
  69. GCC_FINAL_CONFOPTS+= --disable-biarch --disable-multilib
  70. endif
  71. endif
  72. ifeq ($(ADK_LINUX_X86_64),y)
  73. ifeq ($(ADK_x32),y)
  74. GCC_FINAL_CONFOPTS+= --with-abi=x32
  75. endif
  76. ifeq ($(ADK_64),y)
  77. GCC_FINAL_CONFOPTS+= --disable-biarch --disable-multilib
  78. endif
  79. endif
  80. ifeq ($(ADK_TOOLCHAIN_WITH_SSP),y)
  81. GCC_FINAL_CONFOPTS+= --enable-libssp
  82. else
  83. GCC_FINAL_CONFOPTS+= --disable-libssp
  84. endif
  85. ifeq ($(ADK_TOOLCHAIN_WITH_LTO),y)
  86. GCC_CONFOPTS+= --enable-lto
  87. else
  88. GCC_CONFOPTS+= --disable-lto
  89. endif
  90. ifeq ($(ADK_LINUX_PPC),y)
  91. GCC_CONFOPTS+= --with-long-double-64 --enable-secureplt
  92. ifneq ($(ADK_TARGET_CPU_WITH_FPU),y)
  93. GCC_CONFOPTS+= --with-float=soft
  94. endif
  95. endif
  96. ifeq ($(ADK_TARGET_ARCH),arm)
  97. GCC_CONFOPTS+= --with-float=$(ADK_TARGET_FLOAT)
  98. ifneq ($(ADK_TARGET_FPU),)
  99. GCC_CONFOPTS+= --with-fpu=$(ADK_TARGET_FPU)
  100. endif
  101. endif
  102. ifeq ($(ADK_CPU_ARMV5TE),y)
  103. GCC_CONFOPTS+= --with-arch=armv5te
  104. endif
  105. ifeq ($(ADK_CPU_ARMV6),y)
  106. GCC_CONFOPTS+= --with-arch=armv6
  107. endif
  108. ifeq ($(ADK_CPU_ARMV7A),y)
  109. GCC_CONFOPTS+= --with-arch=armv7-a
  110. endif
  111. ifeq ($(ADK_CPU_ARM926EJ_S),y)
  112. GCC_CONFOPTS+= --with-arch=armv5te --with-tune=arm926ej-s
  113. endif
  114. ifeq ($(ADK_CPU_ARM1176JZF_S),y)
  115. GCC_CONFOPTS+= --with-arch=armv6 --with-tune=arm1176jzf-s
  116. endif
  117. ifeq ($(ADK_CPU_CORTEX_A9),y)
  118. GCC_CONFOPTS+= --with-arch=armv7-a --with-tune=cortex-a9
  119. endif
  120. ifeq ($(ADK_CPU_SPARC_V9),y)
  121. GCC_CONFOPTS+= --with-cpu=ultrasparc
  122. endif
  123. ifeq ($(ADK_CPU_CF_5208),y)
  124. GCC_CONFOPTS+= --enable-multilib --with-arch=cf --with-cpu=5208
  125. endif
  126. ifneq ($(ADK_TARGET_MIPS_ABI),)
  127. GCC_CONFOPTS+= --with-abi=${ADK_TARGET_MIPS_ABI}
  128. endif
  129. ifeq (${ADK_MAKE_PARALLEL},y)
  130. GCC_MAKEOPTS+= -j${ADK_MAKE_JOBS}
  131. endif
  132. ifeq ($(ADK_TARGET_UCLINUX),y)
  133. LANGUAGES:=c
  134. else
  135. LANGUAGES:=c,c++
  136. endif
  137. include ${ADK_TOPDIR}/mk/buildhlp.mk
  138. GCC_BUILD_DIR_MINIMAL:= $(WRKBUILD)-minimal
  139. GCC_BUILD_DIR_INITIAL:= $(WRKBUILD)-initial
  140. GCC_BUILD_DIR_FINAL:= $(WRKBUILD)-final
  141. $(GCC_BUILD_DIR_MINIMAL)/.configured:
  142. ifeq ($(ADK_LINUX_XTENSA),y)
  143. tar xf $(ADK_TOPDIR)/target/xtensa/overlay/xtensa_$(ADK_TARGET_XTENSA).tar \
  144. --strip-components=1 -C $(WRKSRC) gcc
  145. endif
  146. mkdir -p $(GCC_BUILD_DIR_MINIMAL)
  147. # these symlinks are very important, do not remove
  148. rm -rf $(TOOLCHAIN_DIR)/usr/$(GNU_TARGET_NAME)/sys-include
  149. mkdir -p $(TOOLCHAIN_DIR)/usr/$(GNU_TARGET_NAME)
  150. (cd $(TOOLCHAIN_DIR)/usr/$(GNU_TARGET_NAME); \
  151. ln -s ../$(STAGING_HOST2TARGET)/usr/include sys-include)
  152. rm -rf ${TOOLCHAIN_DIR}/usr/$(GNU_TARGET_NAME)/lib
  153. (cd $(TOOLCHAIN_DIR)/usr/$(GNU_TARGET_NAME); \
  154. ln -s ../$(STAGING_HOST2TARGET)/lib lib)
  155. ifeq ($(ADK_LINUX_SH),y)
  156. (cd ${STAGING_TARGET_DIR}/ && ln -sf . m4 && ln -sf . m4-nofpu)
  157. endif
  158. $(SED) '/k prot/agcc_cv_libc_provides_ssp=yes' $(WRKBUILD)/gcc/configure
  159. cd $(GCC_BUILD_DIR_MINIMAL); \
  160. PATH='$(TARGET_PATH)' \
  161. CFLAGS="-O0 -g0" \
  162. CXXFLAGS="-O0 -g0" \
  163. $(WRKBUILD)/configure \
  164. ${GCC_CONFOPTS} \
  165. --enable-languages=c \
  166. --disable-libssp \
  167. --disable-shared \
  168. --without-headers
  169. touch $@
  170. $(GCC_BUILD_DIR_MINIMAL)/.compiled: $(GCC_BUILD_DIR_MINIMAL)/.configured
  171. PATH='$(TARGET_PATH)' $(MAKE) ${GCC_MAKEOPTS} -C $(GCC_BUILD_DIR_MINIMAL) all-gcc
  172. touch $@
  173. $(WRKBUILD)/.headers: $(GCC_BUILD_DIR_MINIMAL)/.compiled
  174. PATH='$(TARGET_PATH)' $(MAKE) -C $(GCC_BUILD_DIR_MINIMAL) install-gcc
  175. touch $@
  176. $(GCC_BUILD_DIR_INITIAL)/.configured:
  177. mkdir -p $(GCC_BUILD_DIR_INITIAL)
  178. cd $(GCC_BUILD_DIR_INITIAL); \
  179. PATH='$(TARGET_PATH)' \
  180. CFLAGS="-O0 -g0" \
  181. CXXFLAGS="-O0 -g0" \
  182. $(WRKBUILD)/configure \
  183. ${GCC_CONFOPTS} \
  184. ${GCC_FINAL_CONFOPTS} \
  185. --enable-languages=c \
  186. --disable-shared \
  187. --disable-threads \
  188. --with-sysroot=$(STAGING_TARGET_DIR)
  189. touch $@
  190. $(GCC_BUILD_DIR_INITIAL)/.compiled: $(GCC_BUILD_DIR_INITIAL)/.configured
  191. PATH='$(TARGET_PATH)' $(MAKE) ${GCC_MAKEOPTS} -C $(GCC_BUILD_DIR_INITIAL) all-gcc all-target-libgcc
  192. touch $@
  193. $(WRKBUILD)/.configured: $(GCC_BUILD_DIR_INITIAL)/.compiled
  194. PATH='$(TARGET_PATH)' $(MAKE) -C $(GCC_BUILD_DIR_INITIAL) install-gcc install-target-libgcc
  195. touch $@
  196. $(GCC_BUILD_DIR_FINAL)/.configured:
  197. mkdir -p $(GCC_BUILD_DIR_FINAL)
  198. cd $(GCC_BUILD_DIR_FINAL); \
  199. PATH='$(TARGET_PATH)' \
  200. $(WRKBUILD)/configure \
  201. ${GCC_CONFOPTS} \
  202. ${GCC_FINAL_CONFOPTS} \
  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. (cd $(TOOLCHAIN_DIR)/usr/bin && \
  232. ln -sf $(GNU_TARGET_NAME)-ld.bfd $(GNU_TARGET_NAME)-ld)
  233. endif
  234. cd $(STAGING_TARGET_DIR)/lib && \
  235. ln -sf libstdc++.so.6.0.$(LIBSTDCXXVER) libstdc++.so && \
  236. ln -sf libstdc++.so.6.0.$(LIBSTDCXXVER) libstdc++.so.6
  237. # cleanup unneeded docs
  238. rm -rf $(TOOLCHAIN_DIR)/usr/share
  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. touch $@
  244. include ${ADK_TOPDIR}/mk/toolchain.mk