Makefile 8.9 KB

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