Makefile 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  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_LINUX_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_LINUX_M68K)$(ADK_LINUX_SH)$(ADK_LINUX_X86_64)$(ADK_LINUX_X86),)
  65. GCC_FINAL_CONFOPTS+= --disable-biarch --disable-multilib
  66. endif
  67. ifeq ($(ADK_LINUX_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_LINUX_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_LINUX_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_LINUX_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)
  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_ARMV5TE),y)
  113. GCC_CONFOPTS+= --with-arch=armv5te
  114. endif
  115. ifeq ($(ADK_CPU_ARMV6),y)
  116. GCC_CONFOPTS+= --with-arch=armv6
  117. endif
  118. ifeq ($(ADK_CPU_ARMV7A),y)
  119. GCC_CONFOPTS+= --with-arch=armv7-a
  120. endif
  121. ifeq ($(ADK_CPU_ARM926EJ_S),y)
  122. GCC_CONFOPTS+= --with-arch=armv5te --with-tune=arm926ej-s
  123. endif
  124. ifeq ($(ADK_CPU_ARM1176JZF_S),y)
  125. GCC_CONFOPTS+= --with-arch=armv6 --with-tune=arm1176jzf-s
  126. endif
  127. ifeq ($(ADK_CPU_CORTEX_A9),y)
  128. GCC_CONFOPTS+= --with-arch=armv7-a --with-tune=cortex-a9
  129. endif
  130. ifeq ($(ADK_CPU_SPARC_V9),y)
  131. GCC_CONFOPTS+= --with-cpu=ultrasparc
  132. endif
  133. ifeq ($(ADK_CPU_ARC),y)
  134. GCC_CONFOPTS+= --with-cpu=arc700
  135. endif
  136. ifeq ($(ADK_CPU_CF_5208),y)
  137. GCC_CONFOPTS+= --enable-multilib --with-arch=cf --with-cpu=5208
  138. endif
  139. ifneq ($(ADK_TARGET_MIPS_ABI),)
  140. GCC_CONFOPTS+= --with-abi=${ADK_TARGET_MIPS_ABI}
  141. endif
  142. ifeq (${ADK_MAKE_PARALLEL},y)
  143. GCC_MAKEOPTS+= -j${ADK_MAKE_JOBS}
  144. endif
  145. ifeq ($(ADK_TARGET_UCLINUX),y)
  146. LANGUAGES:=c
  147. else
  148. LANGUAGES:=c,c++
  149. endif
  150. include ${ADK_TOPDIR}/mk/buildhlp.mk
  151. GCC_BUILD_DIR_MINIMAL:= $(WRKBUILD)-minimal
  152. GCC_BUILD_DIR_INITIAL:= $(WRKBUILD)-initial
  153. GCC_BUILD_DIR_FINAL:= $(WRKBUILD)-final
  154. $(GCC_BUILD_DIR_MINIMAL)/.configured:
  155. ifeq ($(ADK_LINUX_XTENSA),y)
  156. tar xf $(ADK_TOPDIR)/target/xtensa/overlay/xtensa_$(ADK_TARGET_XTENSA).tar \
  157. --strip-components=1 -C $(WRKSRC) gcc
  158. endif
  159. mkdir -p $(GCC_BUILD_DIR_MINIMAL)
  160. # these symlinks are very important, do not remove
  161. rm -rf $(TOOLCHAIN_DIR)/usr/$(GNU_TARGET_NAME)/sys-include
  162. mkdir -p $(TOOLCHAIN_DIR)/usr/$(GNU_TARGET_NAME)
  163. (cd $(TOOLCHAIN_DIR)/usr/$(GNU_TARGET_NAME); \
  164. ln -s ../$(STAGING_HOST2TARGET)/usr/include sys-include)
  165. rm -rf ${TOOLCHAIN_DIR}/usr/$(GNU_TARGET_NAME)/lib
  166. (cd $(TOOLCHAIN_DIR)/usr/$(GNU_TARGET_NAME); \
  167. ln -s ../$(STAGING_HOST2TARGET)/lib lib)
  168. ifeq ($(ADK_LINUX_SH),y)
  169. (cd ${STAGING_TARGET_DIR}/ && ln -sf . m4 && ln -sf . m4-nofpu)
  170. endif
  171. $(SED) '/k prot/agcc_cv_libc_provides_ssp=yes' $(WRKBUILD)/gcc/configure
  172. cd $(GCC_BUILD_DIR_MINIMAL); \
  173. PATH='$(TARGET_PATH)' \
  174. CFLAGS="-O0 -g0" \
  175. CXXFLAGS="-O0 -g0" \
  176. $(WRKBUILD)/configure \
  177. ${GCC_CONFOPTS} \
  178. --enable-languages=c \
  179. --disable-libssp \
  180. --disable-shared \
  181. --without-headers
  182. touch $@
  183. $(GCC_BUILD_DIR_MINIMAL)/.compiled: $(GCC_BUILD_DIR_MINIMAL)/.configured
  184. PATH='$(TARGET_PATH)' $(MAKE) ${GCC_MAKEOPTS} -C $(GCC_BUILD_DIR_MINIMAL) all-gcc
  185. touch $@
  186. $(WRKBUILD)/.headers: $(GCC_BUILD_DIR_MINIMAL)/.compiled
  187. PATH='$(TARGET_PATH)' $(MAKE) -C $(GCC_BUILD_DIR_MINIMAL) install-gcc
  188. touch $@
  189. $(GCC_BUILD_DIR_INITIAL)/.configured:
  190. mkdir -p $(GCC_BUILD_DIR_INITIAL)
  191. cd $(GCC_BUILD_DIR_INITIAL); \
  192. PATH='$(TARGET_PATH)' \
  193. CFLAGS="-O0 -g0" \
  194. CXXFLAGS="-O0 -g0" \
  195. $(WRKBUILD)/configure \
  196. ${GCC_CONFOPTS} \
  197. ${GCC_FINAL_CONFOPTS} \
  198. --enable-languages=c \
  199. --disable-shared \
  200. --disable-threads \
  201. --with-sysroot=$(STAGING_TARGET_DIR)
  202. touch $@
  203. $(GCC_BUILD_DIR_INITIAL)/.compiled: $(GCC_BUILD_DIR_INITIAL)/.configured
  204. PATH='$(TARGET_PATH)' $(MAKE) ${GCC_MAKEOPTS} -C $(GCC_BUILD_DIR_INITIAL) all-gcc all-target-libgcc
  205. touch $@
  206. $(WRKBUILD)/.configured: $(GCC_BUILD_DIR_INITIAL)/.compiled
  207. PATH='$(TARGET_PATH)' $(MAKE) -C $(GCC_BUILD_DIR_INITIAL) install-gcc install-target-libgcc
  208. touch $@
  209. $(GCC_BUILD_DIR_FINAL)/.configured:
  210. mkdir -p $(GCC_BUILD_DIR_FINAL)
  211. cd $(GCC_BUILD_DIR_FINAL); \
  212. PATH='$(TARGET_PATH)' \
  213. CFLAGS_FOR_TARGET='$(TARGET_CFLAGS)' \
  214. CXXFLAGS_FOR_TARGET='$(TARGET_CXXFLAGS)' \
  215. $(WRKBUILD)/configure \
  216. ${GCC_CONFOPTS} \
  217. ${GCC_FINAL_CONFOPTS} \
  218. --enable-languages=$(LANGUAGES) \
  219. --with-build-sysroot='$${prefix}/${STAGING_HOST2TARGET}' \
  220. --with-sysroot='$${prefix}/${STAGING_HOST2TARGET}'
  221. PATH='$(TARGET_PATH)' $(MAKE) -C $(GCC_BUILD_DIR_FINAL) configure-host
  222. touch $@
  223. $(WRKBUILD)/.compiled: $(GCC_BUILD_DIR_FINAL)/.configured
  224. cd $(GCC_BUILD_DIR_FINAL); \
  225. PATH='$(TARGET_PATH)' \
  226. $(MAKE) ${GCC_MAKEOPTS} all
  227. touch $@
  228. $(WRKBUILD)/.installed: $(WRKBUILD)/.compiled
  229. cd $(GCC_BUILD_DIR_FINAL); \
  230. PATH='$(TARGET_PATH)' \
  231. $(MAKE) install
  232. # remove duplicate tools, convert hardlinks to symlinks
  233. set -e; \
  234. cd $(TOOLCHAIN_DIR)/usr/$(GNU_TARGET_NAME)/bin; \
  235. for app in ar as c++ g++ gcc ld ld.gold ld.bfd nm objcopy objdump ranlib strip; do \
  236. ln -sf ../../bin/$(GNU_TARGET_NAME)-$${app} $${app}; \
  237. done;
  238. (cd $(TOOLCHAIN_DIR)/usr/bin && \
  239. ln -sf $(GNU_TARGET_NAME)-gcc $(GNU_TARGET_NAME)-gcc-${PKG_VERSION} && \
  240. ln -sf $(GNU_TARGET_NAME)-g++ $(GNU_TARGET_NAME)-g++-${PKG_VERSION} \
  241. )
  242. ifeq ($(ADK_TARGET_USE_GOLD),y)
  243. (cd $(TOOLCHAIN_DIR)/usr/bin && \
  244. ln -sf $(GNU_TARGET_NAME)-ld.gold $(GNU_TARGET_NAME)-ld)
  245. else
  246. ifeq (ADK_TOOLCHAIN_BINUTILS_2_20_1),)
  247. (cd $(TOOLCHAIN_DIR)/usr/bin && \
  248. ln -sf $(GNU_TARGET_NAME)-ld.bfd $(GNU_TARGET_NAME)-ld)
  249. endif
  250. endif
  251. cd $(STAGING_TARGET_DIR)/lib && \
  252. ln -sf libstdc++.so.6.0.$(LIBSTDCXXVER) libstdc++.so && \
  253. ln -sf libstdc++.so.6.0.$(LIBSTDCXXVER) libstdc++.so.6
  254. # cleanup unneeded docs
  255. rm -rf $(TOOLCHAIN_DIR)/usr/share
  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. touch $@
  261. include ${ADK_TOPDIR}/mk/toolchain.mk