57118bb119f32eba4c86f35eca32193768a2da02
[openwrt-10.03/.git] / toolchain / gcc / Makefile
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 # Copyright (C) 2005-2006 Felix Fietkau <nbd@openwrt.org>
6 #
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
21 include $(TOPDIR)/rules.mk
22
23 PKG_NAME:=gcc
24 PKG_VERSION:=$(strip $(subst ",, $(CONFIG_GCC_VERSION)))#"))
25
26 PATCH_DIR=./patches/$(PKG_VERSION)
27 PKG_SOURCE_URL:=ftp://ftp.fu-berlin.de/unix/languages/gcc/releases/gcc-$(PKG_VERSION) \
28         http://mirrors.rcn.net/pub/sourceware/gcc/releases/gcc-$(PKG_VERSION) \
29         ftp://ftp.gnu.org/gnu/gcc/releases/gcc-$(PKG_VERSION)
30 PKG_SOURCE:=gcc-$(PKG_VERSION).tar.bz2
31 STAGING_DIR_HOST:=$(TOOLCHAIN_DIR)
32 BUILD_DIR_HOST:=$(BUILD_DIR_TOOLCHAIN)
33
34 include $(INCLUDE_DIR)/host-build.mk
35
36 STAMP_BUILT:=$(TOOLCHAIN_DIR)/stamp/.gcc-initial_installed
37 BUILD_DIR1:=$(BUILD_DIR_HOST)/gcc-$(PKG_VERSION)-initial
38 BUILD_DIR2:=$(BUILD_DIR_HOST)/gcc-$(PKG_VERSION)-final
39
40 SEP:=,
41 TARGET_LANGUAGES:="c$(if $(CONFIG_INSTALL_LIBSTDCPP),$(SEP)c++)$(if $(CONFIG_INSTALL_LIBGCJ),$(SEP)java)"
42
43 define Stage1/Configure
44         $(SED) 's,TARGET_CROSS=.*,TARGET_CROSS=$(REAL_GNU_TARGET_NAME)-,' $(TOOLCHAIN_DIR)/info.mk
45         $(SED) 's,GCC_VERSION=.*,GCC_VERSION=$(PKG_VERSION),' $(TOOLCHAIN_DIR)/info.mk
46         mkdir -p $(BUILD_DIR1)
47         (cd $(BUILD_DIR1); rm -f config.cache; \
48                 SHELL="$(BASH)" \
49                 $(PKG_BUILD_DIR)/configure \
50                 --prefix=$(TOOLCHAIN_DIR) \
51                 --build=$(GNU_HOST_NAME) \
52                 --host=$(GNU_HOST_NAME) \
53                 --target=$(REAL_GNU_TARGET_NAME) \
54                 --enable-languages=c \
55                 --disable-shared \
56                 --with-sysroot=$(BUILD_DIR_HOST)/uClibc_dev/ \
57                 --disable-__cxa_atexit \
58                 --enable-target-optspace \
59                 --with-gnu-ld \
60                 --disable-nls \
61                 --disable-libmudflap \
62                 --disable-multilib \
63                 --disable-tls \
64                 $(SOFT_FLOAT_CONFIG_OPTION) \
65                 $(call qstrip,$(CONFIG_EXTRA_GCC_CONFIG_OPTIONS)) \
66         );
67 endef
68 define Stage1/Compile
69         export SHELL="$(BASH)"; $(MAKE) -C $(BUILD_DIR1) all-gcc
70 endef
71 define Stage1/Install
72         export SHELL="$(BASH)"; $(MAKE) -C $(BUILD_DIR1) install-gcc
73 endef
74
75 define Stage2/Configure
76         mkdir -p $(BUILD_DIR2)
77         # Important!  Required for limits.h to be fixed.
78         rm -rf $(TOOLCHAIN_DIR)/$(REAL_GNU_TARGET_NAME)/sys-include
79         ln -sf ../include $(TOOLCHAIN_DIR)/$(REAL_GNU_TARGET_NAME)/sys-include
80         rm -rf $(TOOLCHAIN_DIR)/$(REAL_GNU_TARGET_NAME)/lib
81         ln -sf ../lib $(TOOLCHAIN_DIR)/$(REAL_GNU_TARGET_NAME)/lib
82         (cd $(BUILD_DIR2); rm -f config.cache; \
83                 SHELL="$(BASH)" \
84                 $(PKG_BUILD_DIR)/configure \
85                 --prefix=$(TOOLCHAIN_DIR) \
86                 --build=$(GNU_HOST_NAME) \
87                 --host=$(GNU_HOST_NAME) \
88                 --target=$(REAL_GNU_TARGET_NAME) \
89                 --enable-languages=$(TARGET_LANGUAGES) \
90                 --enable-shared \
91                 --disable-__cxa_atexit \
92                 --enable-target-optspace \
93                 --with-gnu-ld \
94                 --disable-nls \
95                 --disable-libmudflap \
96                 --disable-multilib \
97                 --disable-tls \
98                 $(SOFT_FLOAT_CONFIG_OPTION) \
99                 $(call qstrip,$(CONFIG_EXTRA_GCC_CONFIG_OPTIONS)) \
100         );
101 endef
102
103 define Stage2/Compile
104         export SHELL="\$(BASH)"; \$(MAKE) -C \$(BUILD_DIR2) all
105 endef
106
107 define Stage2/Install
108         $(MAKE) -C $(BUILD_DIR2) \
109                 SHELL="$(BASH)" \
110                 install
111         # Set up the symlinks to enable lying about target name.
112         set -e; \
113         (cd $(TOOLCHAIN_DIR); \
114                 ln -sf $(REAL_GNU_TARGET_NAME) $(GNU_TARGET_NAME); \
115                 cd bin; \
116                 for app in $(REAL_GNU_TARGET_NAME)-* ; do \
117                         ln -sf $$$${app} \
118                         $(GNU_TARGET_NAME)$$$${app##$(REAL_GNU_TARGET_NAME)}; \
119                 done; \
120         );
121 endef
122
123 define Build/Prepare
124         $(call Build/Prepare/Default)
125         $(SED) 's,\(version_string.. = "[0-9\.]*\).*\(";\),\1 (OpenWrt-2.0)\2,' $(PKG_BUILD_DIR)/gcc/version.c
126         $(SED) 's,\(bug_report_url.. = "\).*\(";\),\1<URL:https://dev.openwrt.org/>\2,' $(PKG_BUILD_DIR)/gcc/version.c
127         (cd $(PKG_BUILD_DIR)/libstdc++-v3; autoconf;);
128         $(SED) 's,gcc_no_link=yes,gcc_no_link=no,' $(PKG_BUILD_DIR)/libstdc++-v3/configure
129 endef
130
131 define Build/Configure
132         $(call Stage1/Configure)
133 endef
134
135 define Build/Compile
136         $(call Stage1/Compile)
137         $(if $(wildcard $(TOOLCHAIN_DIR)/bin/$(GNU_TARGET_NAME)-gcc),,$(call Stage1/Install))
138 endef
139
140 define Build/Install
141         $(call Stage2/Configure)
142         $(call Stage2/Compile)
143         $(call Stage2/Install)
144 endef
145
146 define Build/Clean
147         rm -rf \
148                 $(PKG_BUILD_DIR) \
149                 $(BUILD_DIR1) \
150                 $(BUILD_DIR2) \
151                 $(TOOLCHAIN_DIR)/$(REAL_GNU_TARGET_NAME) \
152                 $(TOOLCHAIN_DIR)/bin/$(REAL_GNU_TARGET_NAME)-gc* \
153                 $(TOOLCHAIN_DIR)/bin/$(REAL_GNU_TARGET_NAME)-c*
154 endef
155
156 $(eval $(call HostBuild))