Fix ipkg compilation with ccache, thanks sn9
[openwrt.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:=$(call qstrip,$(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 ifeq ($(CONFIG_SSP_SUPPORT),y)
44 SSP:=--enable-ssp
45 else
46 SSP:=--disable-ssp
47 endif
48
49 EXTRA_TARGET=$(if $(CONFIG_EXTRA_TARGET_ARCH),--enable-biarch --enable-targets=$(call qstrip,$(CONFIG_EXTRA_TARGET_ARCH_NAME))-linux-uclibc)
50
51 define Stage1/Configure
52 $(SED) 's,TARGET_CROSS=.*,TARGET_CROSS=$(REAL_GNU_TARGET_NAME)-,' $(TOOLCHAIN_DIR)/info.mk
53 $(SED) 's,GCC_VERSION=.*,GCC_VERSION=$(PKG_VERSION),' $(TOOLCHAIN_DIR)/info.mk
54 mkdir -p $(BUILD_DIR1)
55 (cd $(BUILD_DIR1); rm -f config.cache; \
56 SHELL="$(BASH)" \
57 $(PKG_BUILD_DIR)/configure \
58 --prefix=$(TOOLCHAIN_DIR) \
59 --build=$(GNU_HOST_NAME) \
60 --host=$(GNU_HOST_NAME) \
61 --target=$(REAL_GNU_TARGET_NAME) \
62 --enable-languages=c \
63 --disable-shared \
64 --with-sysroot=$(BUILD_DIR_HOST)/uClibc_dev/ \
65 --disable-__cxa_atexit \
66 --enable-target-optspace \
67 --with-gnu-ld \
68 --disable-nls \
69 --disable-libmudflap \
70 --disable-multilib \
71 $(SSP) \
72 $(EXTRA_TARGET) \
73 $(SOFT_FLOAT_CONFIG_OPTION) \
74 $(call qstrip,$(CONFIG_EXTRA_GCC_CONFIG_OPTIONS)) \
75 );
76 endef
77 define Stage1/Compile
78 export SHELL="$(BASH)"; $(MAKE) -C $(BUILD_DIR1) all-gcc
79 endef
80 define Stage1/Install
81 export SHELL="$(BASH)"; $(MAKE) -C $(BUILD_DIR1) install-gcc
82 endef
83
84 define Stage2/Configure
85 mkdir -p $(BUILD_DIR2) $(TOOLCHAIN_DIR)/$(REAL_GNU_TARGET_NAME)
86 # Important! Required for limits.h to be fixed.
87 rm -rf $(TOOLCHAIN_DIR)/$(REAL_GNU_TARGET_NAME)/sys-include
88 ln -sf ../include $(TOOLCHAIN_DIR)/$(REAL_GNU_TARGET_NAME)/sys-include
89 rm -rf $(TOOLCHAIN_DIR)/$(REAL_GNU_TARGET_NAME)/lib
90 ln -sf ../lib $(TOOLCHAIN_DIR)/$(REAL_GNU_TARGET_NAME)/lib
91 (cd $(BUILD_DIR2); rm -f config.cache; \
92 SHELL="$(BASH)" \
93 $(PKG_BUILD_DIR)/configure \
94 --prefix=$(TOOLCHAIN_DIR) \
95 --build=$(GNU_HOST_NAME) \
96 --host=$(GNU_HOST_NAME) \
97 --target=$(REAL_GNU_TARGET_NAME) \
98 --enable-languages=$(TARGET_LANGUAGES) \
99 --enable-shared \
100 --disable-__cxa_atexit \
101 --enable-target-optspace \
102 --with-gnu-ld \
103 --disable-nls \
104 --disable-libmudflap \
105 --disable-multilib \
106 $(SSP) \
107 $(EXTRA_TARGET) \
108 $(SOFT_FLOAT_CONFIG_OPTION) \
109 $(call qstrip,$(CONFIG_EXTRA_GCC_CONFIG_OPTIONS)) \
110 );
111 endef
112
113 define Stage2/Compile
114 export SHELL="\$(BASH)"; \$(MAKE) -C \$(BUILD_DIR2) all
115 endef
116
117 define SetupExtraArch
118 for app in $(TOOLCHAIN_DIR)/bin/$(OPTIMIZE_FOR_CPU)*-{gcc,gcc-*,g++}; do \
119 [ -e $$$$app ] || continue; \
120 old_base=$$$$(basename $$$$app); \
121 new_base=$(call qstrip,$(CONFIG_EXTRA_TARGET_ARCH_NAME))-$$$${old_base##$(OPTIMIZE_FOR_CPU)-}; \
122 sed -e "s/@CC_BASE@/$$$$old_base/" \
123 -e 's/@EXTRA_ARCH_OPTS@/$(call qstrip,$(CONFIG_EXTRA_TARGET_ARCH_OPTS))/' \
124 ./files/alternate-arch-cc.in > \
125 $(TOOLCHAIN_DIR)/bin/$$$$new_base; \
126 chmod a+x $(TOOLCHAIN_DIR)/bin/$$$$new_base; \
127 done
128 endef
129
130 define Stage2/Install
131 $(MAKE) -C $(BUILD_DIR2) \
132 SHELL="$(BASH)" \
133 install
134 # Set up the symlinks to enable lying about target name.
135 set -e; \
136 (cd $(TOOLCHAIN_DIR); \
137 ln -sf $(REAL_GNU_TARGET_NAME) $(GNU_TARGET_NAME); \
138 cd bin; \
139 for app in $(REAL_GNU_TARGET_NAME)-* ; do \
140 ln -sf $$$${app} \
141 $(GNU_TARGET_NAME)$$$${app##$(REAL_GNU_TARGET_NAME)}; \
142 done; \
143 );
144 $(if $(CONFIG_EXTRA_TARGET_ARCH),$(call SetupExtraArch))
145 endef
146
147 define Build/Prepare
148 $(call Build/Prepare/Default)
149 $(SED) 's,\(version_string.. = "[0-9\.]*\).*\(";\),\1 (OpenWrt-2.0)\2,' $(PKG_BUILD_DIR)/gcc/version.c
150 $(SED) 's,\(bug_report_url.. = "\).*\(";\),\1<URL:https://dev.openwrt.org/>\2,' $(PKG_BUILD_DIR)/gcc/version.c
151 (cd $(PKG_BUILD_DIR)/libstdc++-v3; autoconf;);
152 $(SED) 's,gcc_no_link=yes,gcc_no_link=no,' $(PKG_BUILD_DIR)/libstdc++-v3/configure
153 endef
154
155 define Build/Configure
156 $(call Stage1/Configure)
157 endef
158
159 define Build/Compile
160 $(call Stage1/Compile)
161 $(if $(wildcard $(TOOLCHAIN_DIR)/bin/$(GNU_TARGET_NAME)-gcc),,$(call Stage1/Install))
162 endef
163
164 define Build/Install
165 $(call Stage2/Configure)
166 $(call Stage2/Compile)
167 $(call Stage2/Install)
168 endef
169
170 define Build/Clean
171 rm -rf \
172 $(PKG_BUILD_DIR) \
173 $(BUILD_DIR1) \
174 $(BUILD_DIR2) \
175 $(TOOLCHAIN_DIR)/$(REAL_GNU_TARGET_NAME) \
176 $(TOOLCHAIN_DIR)/bin/$(REAL_GNU_TARGET_NAME)-gc* \
177 $(TOOLCHAIN_DIR)/bin/$(REAL_GNU_TARGET_NAME)-c*
178 endef
179
180 $(eval $(call HostBuild))
This page took 0.050383 seconds and 5 git commands to generate.