Makefile 10 KB

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