gcc-uclibc-3.x.mk 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. # Makefile for to build a gcc/uClibc toolchain
  2. #
  3. # Copyright (C) 2002-2003 Erik Andersen <andersen@uclibc.org>
  4. # Copyright (C) 2004 Manuel Novoa III <mjn3@uclibc.org>
  5. #
  6. # This program is free software; you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation; either version 2 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. # General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program; if not, write to the Free Software
  18. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. ifneq ($(findstring 2.95,$(GCC_VERSION)),2.95)
  20. GCC_VERSION:=$(strip $(GCC_VERSION))
  21. #GCC_SITE:=ftp://ftp.gnu.org/gnu/gcc/releases/gcc-$(GCC_VERSION)
  22. GCC_SITE:=http://mirrors.rcn.net/pub/sourceware/gcc/releases/gcc-$(GCC_VERSION)
  23. #
  24. # snapshots....
  25. #GCC_VERSION:=3.3-20031013
  26. #GCC_SITE:=http://gcc.get-software.com/snapshots/$(GCC_VERSION)
  27. #
  28. GCC_SOURCE:=gcc-$(GCC_VERSION).tar.bz2
  29. GCC_DIR:=$(TOOL_BUILD_DIR)/gcc-$(GCC_VERSION)
  30. GCC_CAT:=bzcat
  31. GCC_STRIP_HOST_BINARIES:=true
  32. #############################################################
  33. #
  34. # Setup some initial stuff
  35. #
  36. #############################################################
  37. TARGET_LANGUAGES:=c
  38. ifeq ($(BR2_INSTALL_LIBSTDCPP),y)
  39. TARGET_LANGUAGES:=$(TARGET_LANGUAGES),c++
  40. endif
  41. ifeq ($(BR2_INSTALL_LIBGCJ),y)
  42. TARGET_LANGUAGES:=$(TARGET_LANGUAGES),java
  43. endif
  44. ifeq ($(BR2_INSTALL_OBJC),y)
  45. TARGET_LANGUAGES:=$(TARGET_LANGUAGES),objc
  46. endif
  47. #############################################################
  48. #
  49. # build the first pass gcc compiler
  50. #
  51. #############################################################
  52. GCC_BUILD_DIR1:=$(TOOL_BUILD_DIR)/gcc-$(GCC_VERSION)-initial
  53. $(DL_DIR)/$(GCC_SOURCE):
  54. mkdir -p $(DL_DIR)
  55. $(WGET) -P $(DL_DIR) $(GCC_SITE)/$(GCC_SOURCE)
  56. $(GCC_DIR)/.unpacked: $(DL_DIR)/$(GCC_SOURCE)
  57. mkdir -p $(TOOL_BUILD_DIR)
  58. $(GCC_CAT) $(DL_DIR)/$(GCC_SOURCE) | tar -C $(TOOL_BUILD_DIR) $(TAR_OPTIONS) -
  59. touch $(GCC_DIR)/.unpacked
  60. $(GCC_DIR)/.patched: $(GCC_DIR)/.unpacked
  61. # Apply any files named gcc-*.patch from the source directory to gcc
  62. toolchain/patch-kernel.sh $(GCC_DIR) toolchain/gcc/$(GCC_VERSION) \*.patch
  63. # Note: The soft float situation has improved considerably with gcc 3.4.x.
  64. # We can dispense with the custom spec files, as well as libfloat for the arm case.
  65. # However, we still need a patch for arm. There's a similar patch for gcc 3.3.x
  66. # which needs to be integrated so we can kill of libfloat for good, except for
  67. # anyone (?) who might still be using gcc 2.95. mjn3
  68. ifeq ($(BR2_SOFT_FLOAT),y)
  69. ifeq ("$(strip $(ARCH))","arm")
  70. toolchain/patch-kernel.sh $(GCC_DIR) toolchain/gcc/$(GCC_VERSION) arm-softfloat.patch.conditional
  71. endif
  72. ifeq ("$(strip $(ARCH))","armeb")
  73. toolchain/patch-kernel.sh $(GCC_DIR) toolchain/gcc/$(GCC_VERSION) arm-softfloat.patch.conditional
  74. endif
  75. # Not yet updated to 3.4.1.
  76. #ifeq ("$(strip $(ARCH))","i386")
  77. #toolchain/patch-kernel.sh $(GCC_DIR) toolchain/gcc i386-gcc-soft-float.patch
  78. #endif
  79. endif
  80. touch $(GCC_DIR)/.patched
  81. # The --without-headers option stopped working with gcc 3.0 and has never been
  82. # # fixed, so we need to actually have working C library header files prior to
  83. # # the step or libgcc will not build...
  84. $(GCC_BUILD_DIR1)/.configured: $(GCC_DIR)/.patched
  85. mkdir -p $(GCC_BUILD_DIR1)
  86. (cd $(GCC_BUILD_DIR1); PATH=$(TARGET_PATH) \
  87. $(GCC_DIR)/configure \
  88. --prefix=$(STAGING_DIR) \
  89. --build=$(GNU_HOST_NAME) \
  90. --host=$(GNU_HOST_NAME) \
  91. --target=$(REAL_GNU_TARGET_NAME) \
  92. --enable-languages=c \
  93. --disable-shared \
  94. --with-sysroot=$(TOOL_BUILD_DIR)/uClibc_dev/ \
  95. --disable-__cxa_atexit \
  96. --enable-target-optspace \
  97. --with-gnu-ld \
  98. $(DISABLE_NLS) \
  99. $(MULTILIB) \
  100. $(SOFT_FLOAT_CONFIG_OPTION) \
  101. $(GCC_WITH_CPU) $(GCC_WITH_ARCH) $(GCC_WITH_TUNE) \
  102. $(EXTRA_GCC_CONFIG_OPTIONS));
  103. touch $(GCC_BUILD_DIR1)/.configured
  104. $(GCC_BUILD_DIR1)/.compiled: $(GCC_BUILD_DIR1)/.configured
  105. PATH=$(TARGET_PATH) $(MAKE) -C $(GCC_BUILD_DIR1) all-gcc
  106. touch $(GCC_BUILD_DIR1)/.compiled
  107. $(STAGING_DIR)/bin/$(REAL_GNU_TARGET_NAME)-gcc: $(GCC_BUILD_DIR1)/.compiled
  108. PATH=$(TARGET_PATH) $(MAKE) -C $(GCC_BUILD_DIR1) install-gcc
  109. #rm -f $(STAGING_DIR)/bin/gccbug $(STAGING_DIR)/bin/gcov
  110. #rm -rf $(STAGING_DIR)/info $(STAGING_DIR)/man $(STAGING_DIR)/share/doc $(STAGING_DIR)/share/locale
  111. gcc_initial: uclibc-configured binutils $(STAGING_DIR)/bin/$(REAL_GNU_TARGET_NAME)-gcc
  112. gcc_initial-clean:
  113. rm -rf $(GCC_BUILD_DIR1)
  114. rm -f $(STAGING_DIR)/bin/$(REAL_GNU_TARGET_NAME)*
  115. gcc_initial-dirclean:
  116. rm -rf $(GCC_BUILD_DIR1)
  117. #############################################################
  118. #
  119. # second pass compiler build. Build the compiler targeting
  120. # the newly built shared uClibc library.
  121. #
  122. #############################################################
  123. #
  124. # Sigh... I had to rework things because using --with-gxx-include-dir
  125. # causes issues with include dir search order for g++. This seems to
  126. # have something to do with "path translations" and possibly doesn't
  127. # affect gcc-target. However, I haven't tested gcc-target yet so no
  128. # guarantees. mjn3
  129. GCC_BUILD_DIR2:=$(TOOL_BUILD_DIR)/gcc-$(GCC_VERSION)-final
  130. $(GCC_BUILD_DIR2)/.configured: $(GCC_DIR)/.patched $(STAGING_DIR)/lib/libc.a
  131. mkdir -p $(GCC_BUILD_DIR2)
  132. # Important! Required for limits.h to be fixed.
  133. ln -snf ../include $(STAGING_DIR)/$(REAL_GNU_TARGET_NAME)/sys-include
  134. (cd $(GCC_BUILD_DIR2); PATH=$(TARGET_PATH) \
  135. $(GCC_DIR)/configure \
  136. --prefix=$(STAGING_DIR) \
  137. --build=$(GNU_HOST_NAME) \
  138. --host=$(GNU_HOST_NAME) \
  139. --target=$(REAL_GNU_TARGET_NAME) \
  140. --enable-languages=$(TARGET_LANGUAGES) \
  141. --enable-shared \
  142. --disable-__cxa_atexit \
  143. --enable-target-optspace \
  144. --with-gnu-ld \
  145. $(DISABLE_NLS) \
  146. $(MULTILIB) \
  147. $(SOFT_FLOAT_CONFIG_OPTION) \
  148. $(GCC_WITH_CPU) $(GCC_WITH_ARCH) $(GCC_WITH_TUNE) \
  149. $(GCC_USE_SJLJ_EXCEPTIONS) \
  150. $(EXTRA_GCC_CONFIG_OPTIONS));
  151. touch $(GCC_BUILD_DIR2)/.configured
  152. $(GCC_BUILD_DIR2)/.compiled: $(GCC_BUILD_DIR2)/.configured
  153. PATH=$(TARGET_PATH) $(MAKE) -C $(GCC_BUILD_DIR2) all
  154. touch $(GCC_BUILD_DIR2)/.compiled
  155. $(GCC_BUILD_DIR2)/.installed: $(GCC_BUILD_DIR2)/.compiled
  156. PATH=$(TARGET_PATH) $(MAKE) -C $(GCC_BUILD_DIR2) install
  157. # Strip the host binaries
  158. ifeq ($(GCC_STRIP_HOST_BINARIES),true)
  159. -strip --strip-all -R .note -R .comment $(STAGING_DIR)/bin/*
  160. endif
  161. # Set up the symlinks to enable lying about target name.
  162. set -e; \
  163. (cd $(STAGING_DIR); \
  164. ln -snf $(REAL_GNU_TARGET_NAME) $(GNU_TARGET_NAME); \
  165. cd bin; \
  166. for app in $(REAL_GNU_TARGET_NAME)-* ; do \
  167. ln -snf $${app} \
  168. $(GNU_TARGET_NAME)$${app##$(REAL_GNU_TARGET_NAME)}; \
  169. done; \
  170. );
  171. #
  172. # Now for the ugly 3.3.x soft float hack...
  173. #
  174. ifeq ($(BR2_SOFT_FLOAT),y)
  175. ifeq ($(findstring 3.3.,$(GCC_VERSION)),3.3.)
  176. # Make sure we have a soft float specs file for this arch
  177. if [ ! -f toolchain/gcc/$(GCC_VERSION)/specs-$(ARCH)-soft-float ] ; then \
  178. echo soft float configured but no specs file for this arch ; \
  179. /bin/false ; \
  180. fi;
  181. # Replace specs file with one that defaults to soft float mode.
  182. if [ ! -f $(STAGING_DIR)/lib/gcc-lib/$(REAL_GNU_TARGET_NAME)/$(GCC_VERSION)/specs ] ; then \
  183. echo staging dir specs file is missing ; \
  184. /bin/false ; \
  185. fi;
  186. cp toolchain/gcc/$(GCC_VERSION)/specs-$(ARCH)-soft-float $(STAGING_DIR)/lib/gcc-lib/$(REAL_GNU_TARGET_NAME)/$(GCC_VERSION)/specs
  187. endif
  188. endif
  189. #
  190. # Ok... that's enough of that.
  191. #
  192. touch $(GCC_BUILD_DIR2)/.installed
  193. $(TARGET_DIR)/lib/libgcc_s.so.1: $(GCC_BUILD_DIR2)/.installed
  194. # These are in /lib, so...
  195. rm -rf $(TARGET_DIR)/usr/lib/libgcc_s.so*
  196. -$(STRIP) $(STAGING_DIR)/$(REAL_GNU_TARGET_NAME)/lib/libgcc_s.so.1
  197. -cp -a $(STAGING_DIR)/$(REAL_GNU_TARGET_NAME)/lib/libgcc_s* $(TARGET_DIR)/lib/
  198. ifeq ($(BR2_INSTALL_LIBSTDCPP),y)
  199. -cp -a $(STAGING_DIR)/lib/libstdc++.so* $(TARGET_DIR)/lib/
  200. endif
  201. ifeq ($(BR2_INSTALL_LIBGCJ),y)
  202. -cp -a $(STAGING_DIR)/lib/libgcj.so* $(TARGET_DIR)/lib/
  203. -cp -a $(STAGING_DIR)/lib/lib-org-w3c-dom.so* $(TARGET_DIR)/lib/
  204. -cp -a $(STAGING_DIR)/lib/lib-org-xml-sax.so* $(TARGET_DIR)/lib/
  205. -mkdir -p $(TARGET_DIR)/usr/lib/security
  206. -cp -a $(STAGING_DIR)/usr/lib/security/libgcj.security $(TARGET_DIR)/usr/lib/security/
  207. -cp -a $(STAGING_DIR)/usr/lib/security/classpath.security $(TARGET_DIR)/usr/lib/security/
  208. endif
  209. gcc: uclibc-configured binutils gcc_initial $(LIBFLOAT_TARGET) uclibc \
  210. $(TARGET_DIR)/lib/libgcc_s.so.1 $(GCC_BUILD_DIR2)/.installed $(GCC_TARGETS)
  211. gcc-source: $(DL_DIR)/$(GCC_SOURCE)
  212. gcc-clean:
  213. rm -rf $(GCC_BUILD_DIR2)
  214. rm -f $(STAGING_DIR)/bin/$(REAL_GNU_TARGET_NAME)*
  215. gcc-dirclean:
  216. rm -rf $(GCC_BUILD_DIR2)
  217. #############################################################
  218. #
  219. # Next build target gcc compiler
  220. #
  221. #############################################################
  222. GCC_BUILD_DIR3:=$(BUILD_DIR)/gcc-$(GCC_VERSION)-target
  223. $(GCC_BUILD_DIR3)/.configured: $(GCC_BUILD_DIR2)/.installed
  224. mkdir -p $(GCC_BUILD_DIR3)
  225. (cd $(GCC_BUILD_DIR3); PATH=$(TARGET_PATH) \
  226. $(GCC_DIR)/configure \
  227. --prefix=/usr \
  228. --build=$(GNU_HOST_NAME) \
  229. --host=$(REAL_GNU_TARGET_NAME) \
  230. --target=$(REAL_GNU_TARGET_NAME) \
  231. --enable-languages=$(TARGET_LANGUAGES) \
  232. --enable-shared \
  233. --with-gxx-include-dir=/usr/include/c++ \
  234. --disable-__cxa_atexit \
  235. --enable-target-optspace \
  236. --with-gnu-ld \
  237. $(DISABLE_NLS) \
  238. $(MULTILIB) \
  239. $(SOFT_FLOAT_CONFIG_OPTION) \
  240. $(GCC_WITH_CPU) $(GCC_WITH_ARCH) $(GCC_WITH_TUNE) \
  241. $(GCC_USE_SJLJ_EXCEPTIONS) \
  242. $(EXTRA_GCC_CONFIG_OPTIONS));
  243. touch $(GCC_BUILD_DIR3)/.configured
  244. $(GCC_BUILD_DIR3)/.compiled: $(GCC_BUILD_DIR3)/.configured
  245. PATH=$(TARGET_PATH) \
  246. $(MAKE) $(TARGET_GCC_ARGS) -C $(GCC_BUILD_DIR3) all
  247. touch $(GCC_BUILD_DIR3)/.compiled
  248. #
  249. # gcc-lib dir changes names to gcc with 3.4.mumble
  250. #
  251. ifeq ($(findstring 3.4.,$(GCC_VERSION)),3.4.)
  252. GCC_LIB_SUBDIR=lib/gcc/$(REAL_GNU_TARGET_NAME)/$(GCC_VERSION)
  253. else
  254. GCC_LIB_SUBDIR=lib/gcc-lib/$(REAL_GNU_TARGET_NAME)/$(GCC_VERSION)
  255. endif
  256. $(TARGET_DIR)/usr/bin/gcc: $(GCC_BUILD_DIR3)/.compiled
  257. PATH=$(TARGET_PATH) \
  258. $(MAKE) DESTDIR=$(TARGET_DIR) -C $(GCC_BUILD_DIR3) install
  259. # Remove broken specs file (cross compile flag is set).
  260. rm -f $(TARGET_DIR)/usr/$(GCC_LIB_SUBDIR)/specs
  261. #
  262. # Now for the ugly 3.3.x soft float hack...
  263. #
  264. ifeq ($(BR2_SOFT_FLOAT),y)
  265. ifeq ($(findstring 3.3.,$(GCC_VERSION)),3.3.)
  266. # Add a specs file that defaults to soft float mode.
  267. cp toolchain/gcc/$(GCC_VERSION)/specs-$(ARCH)-soft-float $(TARGET_DIR)/usr/lib/gcc-lib/$(REAL_GNU_TARGET_NAME)/$(GCC_VERSION)/specs
  268. # Make sure gcc does not think we are cross compiling
  269. $(SED) "s/^1/0/;" $(TARGET_DIR)/usr/lib/gcc-lib/$(REAL_GNU_TARGET_NAME)/$(GCC_VERSION)/specs
  270. endif
  271. endif
  272. #
  273. # Ok... that's enough of that.
  274. #
  275. -(cd $(TARGET_DIR)/bin; find -type f | xargs $(STRIP) > /dev/null 2>&1)
  276. -(cd $(TARGET_DIR)/usr/bin; find -type f | xargs $(STRIP) > /dev/null 2>&1)
  277. -(cd $(TARGET_DIR)/usr/$(GCC_LIB_SUBDIR); $(STRIP) cc1 cc1plus collect2 > /dev/null 2>&1)
  278. -(cd $(TARGET_DIR)/usr/lib; $(STRIP) libstdc++.so.*.*.* > /dev/null 2>&1)
  279. -(cd $(TARGET_DIR)/lib; $(STRIP) libgcc_s.so.*.*.* > /dev/null 2>&1)
  280. #
  281. rm -f $(TARGET_DIR)/usr/lib/*.la*
  282. #rm -rf $(TARGET_DIR)/share/locale $(TARGET_DIR)/usr/info \
  283. # $(TARGET_DIR)/usr/man $(TARGET_DIR)/usr/share/doc
  284. # Work around problem of missing syslimits.h
  285. @if [ ! -f $(TARGET_DIR)/usr/$(GCC_LIB_SUBDIR)/include/syslimits.h ] ; then \
  286. echo "warning: working around missing syslimits.h" ; \
  287. cp -f $(STAGING_DIR)/$(GCC_LIB_SUBDIR)/include/syslimits.h \
  288. $(TARGET_DIR)/usr/$(GCC_LIB_SUBDIR)/include/ ; \
  289. fi
  290. # These are in /lib, so...
  291. #rm -rf $(TARGET_DIR)/usr/lib/libgcc_s.so*
  292. #touch -c $(TARGET_DIR)/usr/bin/gcc
  293. gcc_target: uclibc_target binutils_target $(TARGET_DIR)/usr/bin/gcc
  294. gcc_target-clean:
  295. rm -rf $(GCC_BUILD_DIR3)
  296. rm -f $(TARGET_DIR)/usr/bin/$(REAL_GNU_TARGET_NAME)*
  297. gcc_target-dirclean:
  298. rm -rf $(GCC_BUILD_DIR3)
  299. endif