Makefile 8.8 KB

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