Makefile 8.9 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 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-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. ifeq ($(ADK_x32),y)
  117. GCC_FINAL_CONFOPTS+= --with-abi=x32
  118. endif
  119. ifeq ($(ADK_64),y)
  120. GCC_FINAL_CONFOPTS+= --disable-biarch --disable-multilib
  121. endif
  122. endif
  123. ifeq ($(ADK_TARGET_ARCH_PPC),y)
  124. GCC_CONFOPTS+= --with-long-double-64 --enable-secureplt
  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_TARGET_ARCH_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_TARGET_ARCH_SH),y)
  156. (cd ${STAGING_TARGET_DIR}/ && ln -sf . m4)
  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. CC='$(HOST_CC)' \
  162. CXX='$(HOST_CXX)' \
  163. CFLAGS="-O0 -g0 -fomit-frame-pointer" \
  164. CXXFLAGS="-O0 -g0 -fomit-frame-pointer" \
  165. $(WRKBUILD)/configure \
  166. ${GCC_CONFOPTS} \
  167. --enable-languages=c \
  168. --disable-libssp \
  169. --disable-shared \
  170. --without-headers
  171. touch $@
  172. $(GCC_BUILD_DIR_MINIMAL)/.compiled: $(GCC_BUILD_DIR_MINIMAL)/.configured
  173. PATH='$(TARGET_PATH)' $(MAKE) ${GCC_MAKEOPTS} -C $(GCC_BUILD_DIR_MINIMAL) all-gcc
  174. touch $@
  175. $(WRKBUILD)/.headers: $(GCC_BUILD_DIR_MINIMAL)/.compiled
  176. PATH='$(TARGET_PATH)' $(MAKE) -C $(GCC_BUILD_DIR_MINIMAL) install-gcc
  177. touch $@
  178. $(GCC_BUILD_DIR_INITIAL)/.configured:
  179. mkdir -p $(GCC_BUILD_DIR_INITIAL)
  180. cd $(GCC_BUILD_DIR_INITIAL); \
  181. PATH='$(TARGET_PATH)' \
  182. CC='$(HOST_CC)' \
  183. CXX='$(HOST_CXX)' \
  184. CFLAGS="-O0 -g0 -fomit-frame-pointer" \
  185. CXXFLAGS="-O0 -g0 -fomit-frame-pointer" \
  186. $(WRKBUILD)/configure \
  187. ${GCC_CONFOPTS} \
  188. ${GCC_FINAL_CONFOPTS} \
  189. --enable-languages=c \
  190. --disable-shared \
  191. --disable-threads \
  192. --with-sysroot=$(STAGING_TARGET_DIR)
  193. touch $@
  194. $(GCC_BUILD_DIR_INITIAL)/.compiled: $(GCC_BUILD_DIR_INITIAL)/.configured
  195. PATH='$(TARGET_PATH)' $(MAKE) ${GCC_MAKEOPTS} -C $(GCC_BUILD_DIR_INITIAL) all-gcc all-target-libgcc
  196. touch $@
  197. $(WRKBUILD)/.configured: $(GCC_BUILD_DIR_INITIAL)/.compiled
  198. PATH='$(TARGET_PATH)' $(MAKE) -C $(GCC_BUILD_DIR_INITIAL) install-gcc install-target-libgcc
  199. touch $@
  200. $(GCC_BUILD_DIR_FINAL)/.configured:
  201. mkdir -p $(GCC_BUILD_DIR_FINAL)
  202. cd $(GCC_BUILD_DIR_FINAL); \
  203. PATH='$(TARGET_PATH)' \
  204. CC='$(HOST_CC)' \
  205. CXX='$(HOST_CXX)' \
  206. CFLAGS_FOR_TARGET='$(TARGET_CFLAGS)' \
  207. CXXFLAGS_FOR_TARGET='$(TARGET_CXXFLAGS)' \
  208. $(WRKBUILD)/configure \
  209. ${GCC_CONFOPTS} \
  210. ${GCC_FINAL_CONFOPTS} \
  211. --enable-cxx-flags='-fPIC' \
  212. --enable-languages=$(LANGUAGES) \
  213. --with-build-sysroot='$${prefix}/${STAGING_HOST2TARGET}' \
  214. --with-sysroot='$${prefix}/${STAGING_HOST2TARGET}'
  215. PATH='$(TARGET_PATH)' $(MAKE) -C $(GCC_BUILD_DIR_FINAL) configure-host
  216. touch $@
  217. $(WRKBUILD)/.compiled: $(GCC_BUILD_DIR_FINAL)/.configured
  218. cd $(GCC_BUILD_DIR_FINAL); \
  219. PATH='$(TARGET_PATH)' \
  220. $(MAKE) ${GCC_MAKEOPTS} all
  221. touch $@
  222. $(WRKBUILD)/.installed: $(WRKBUILD)/.compiled
  223. cd $(GCC_BUILD_DIR_FINAL); \
  224. PATH='$(TARGET_PATH)' \
  225. $(MAKE) install
  226. # remove duplicate tools, convert hardlinks to symlinks
  227. set -e; \
  228. cd $(TOOLCHAIN_DIR)/usr/$(GNU_TARGET_NAME)/bin; \
  229. for app in ar as c++ g++ gcc ld ld.gold ld.bfd nm objcopy objdump ranlib strip; do \
  230. ln -sf ../../bin/$(GNU_TARGET_NAME)-$${app} $${app}; \
  231. done;
  232. (cd $(TOOLCHAIN_DIR)/usr/bin && \
  233. ln -sf $(GNU_TARGET_NAME)-gcc $(GNU_TARGET_NAME)-gcc-${PKG_VERSION} && \
  234. ln -sf $(GNU_TARGET_NAME)-g++ $(GNU_TARGET_NAME)-g++-${PKG_VERSION} \
  235. )
  236. ifeq ($(ADK_TARGET_USE_GOLD),y)
  237. (cd $(TOOLCHAIN_DIR)/usr/bin && \
  238. ln -sf $(GNU_TARGET_NAME)-ld.gold $(GNU_TARGET_NAME)-ld)
  239. else
  240. ifeq (ADK_TOOLCHAIN_BINUTILS_2_20_1),)
  241. (cd $(TOOLCHAIN_DIR)/usr/bin && \
  242. ln -sf $(GNU_TARGET_NAME)-ld.bfd $(GNU_TARGET_NAME)-ld)
  243. endif
  244. endif
  245. cd $(STAGING_TARGET_DIR)/lib && \
  246. ln -sf libstdc++.so.6.0.$(LIBSTDCXXVER) libstdc++.so && \
  247. ln -sf libstdc++.so.6.0.$(LIBSTDCXXVER) libstdc++.so.6
  248. # cleanup unneeded docs
  249. rm -rf $(TOOLCHAIN_DIR)/usr/share
  250. ifeq ($(ADK_TARGET_ARCH_M68K),y)
  251. # create gcc wrapper for uClinux/m68k
  252. echo "#!/bin/sh" > $(TOOLCHAIN_DIR)/usr/bin/adk-uclinux-gcc
  253. echo "exec ${GNU_TARGET_NAME}-gcc \"\$$@\" -specs $(ADK_TOPDIR)/toolchain/gcc/m68k-uclinux-gcc.specs" >> $(TOOLCHAIN_DIR)/usr/bin/adk-uclinux-gcc
  254. chmod a+x $(TOOLCHAIN_DIR)/usr/bin/adk-uclinux-gcc
  255. endif
  256. ifeq ($(ADK_TARGET_ARCH_ARM),y)
  257. # create gcc wrapper for uClinux/arm
  258. echo "#!/bin/sh" > $(TOOLCHAIN_DIR)/usr/bin/adk-uclinux-gcc
  259. echo "exec ${GNU_TARGET_NAME}-gcc \"\$$@\" -specs $(ADK_TOPDIR)/toolchain/gcc/arm-uclinux-gcc.specs" >> $(TOOLCHAIN_DIR)/usr/bin/adk-uclinux-gcc
  260. chmod a+x $(TOOLCHAIN_DIR)/usr/bin/adk-uclinux-gcc
  261. endif
  262. touch $@
  263. include ${ADK_TOPDIR}/mk/toolchain.mk