Makefile 9.1 KB

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