source: trunk/toolchain/make/target/gcc/gcc.mk @ 6384

Letzte Änderung dieser Datei seit 6384 war 6384, erstellt von er13 vor 8 Jahren

toolchain:

  • exclude kernel-headers from the download-toolchain
  • install the right ones at the build-time
  • refs #842, refs #348
Dateigröße: 11.1 KB
Zeile 
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) 2006 Daniel Eiband <eiband@online.de>
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
21GCC_VERSION:=$(TARGET_TOOLCHAIN_GCC_VERSION)
22GCC_SOURCE:=gcc-$(GCC_VERSION).tar.bz2
23GCC_SITE:=@GNU/gcc/gcc-$(GCC_VERSION)
24GCC_DIR:=$(TARGET_TOOLCHAIN_DIR)/gcc-$(GCC_VERSION)
25GCC_MAKE_DIR:=$(TOOLCHAIN_DIR)/make/target/gcc
26
27GCC_MD5_4.4.5 := 44b3192c4c584b9be5243d9e8e7e0ed1
28GCC_MD5_4.5.2 := d6559145853fbaaa0fd7556ed93bce9a
29GCC_MD5       := $(GCC_MD5_$(GCC_VERSION))
30
31GCC_INITIAL_PREREQ=
32GCC_STAGING_PREREQ=
33GCC_TARGET_PREREQ=
34
35GCC_BUILD_TARGET_LIBGCC:=y
36
37GCC_STAGING_PREREQ+=$(TARGET_TOOLCHAIN_STAGING_DIR)/usr/lib/libc.a
38
39GCC_COMMON_CONFIGURE_OPTIONS := \
40    --with-gnu-ld \
41    --disable-__cxa_atexit \
42    --enable-target-optspace \
43    --disable-libgomp \
44    --disable-libmudflap \
45    --disable-multilib \
46    --disable-tls \
47    --disable-fixed-point \
48    --with-float=soft --enable-cxx-flags=-msoft-float --disable-libssp \
49    $(DISABLE_NLS) \
50    $(DISABLE_LARGEFILE) \
51    $(QUIET)
52
53# enable non-PIC for mips* targets
54GCC_COMMON_CONFIGURE_OPTIONS += --with-mips-plt
55
56ifndef TARGET_TOOLCHAIN_NO_MPFR
57GCC_COMMON_CONFIGURE_OPTIONS += --disable-decimal-float
58
59GCC_INITIAL_PREREQ+=$(GMP_HOST_BINARY) $(MPFR_HOST_BINARY)
60GCC_TARGET_PREREQ+=$(GMP_TARGET_BINARY) $(MPFR_TARGET_BINARY)
61
62GCC_WITH_HOST_GMP=--with-gmp=$(GMP_HOST_DIR)
63GCC_WITH_HOST_MPFR=--with-mpfr=$(MPFR_HOST_DIR)
64
65ifeq ($(TARGET_TOOLCHAIN_GCC_MAJOR_VERSION),4.5)
66GCC_INITIAL_PREREQ+=$(MPC_HOST_BINARY)
67GCC_TARGET_PREREQ+=$(MPC_TARGET_BINARY)
68GCC_WITH_HOST_MPC=--with-mpc=$(MPC_HOST_DIR)
69endif
70
71endif
72
73GCC_EXTRA_MAKE_OPTIONS :=
74ifeq ($(strip $(FREETZ_STATIC_TOOLCHAIN)),y)
75GCC_EXTRA_MAKE_OPTIONS += "LDFLAGS=-static"
76endif
77
78
79GCC_LIB_SUBDIR=lib/gcc/$(REAL_GNU_TARGET_NAME)/$(GCC_VERSION)
80# This macro exists for the following reason:
81#   uClibc depends on some gcc internal headers located under $(GCC_LIB_SUBDIR).
82#   uClibc is compiled using gcc-initial, after that gcc-final (which depends on uClibc)
83#   is compiled and installed into the same location as gcc-initial. The causes the headers
84#   under $(GCC_LIB_SUBDIR) to be installed again, i.e. overwritten. The files are absolutely
85#   identical they however get new timestamp, which causes uClibc to be recompiled, which
86#   in turn causes gcc-final to be recompiled.
87#   We workaround the problem by explicitly setting the timestamp of the headers to some fixed value.
88# $1 - base dir (most of time $(TARGET_TOOLCHAIN_STAGING_DIR))
89# $2 (optional) - timestamp to be used
90define GCC_SET_HEADERS_TIMESTAMP
91$(if $(strip $(1)),\
92    if [ -d "$(strip $(1))/$(GCC_LIB_SUBDIR)" ] ; then \
93        find $(strip $(1))/$(GCC_LIB_SUBDIR) -name "*.h" -type f -exec touch -t $(if $(strip $(2)),$(strip $(2)),200001010000.00) \{\} \+; \
94    fi; \
95)
96endef
97
98gcc-source: $(DL_DIR)/$(GCC_SOURCE)
99ifneq ($(strip $(DL_DIR)/$(GCC_SOURCE)), $(strip $(DL_DIR)/$(GCC_KERNEL_SOURCE)))
100$(DL_DIR)/$(GCC_SOURCE): | $(DL_DIR)
101    $(DL_TOOL) $(DL_DIR) .config $(GCC_SOURCE) $(GCC_SITE) $(GCC_MD5)
102endif
103
104gcc-unpacked: $(GCC_DIR)/.unpacked
105$(GCC_DIR)/.unpacked: $(DL_DIR)/$(GCC_SOURCE) | $(TARGET_TOOLCHAIN_DIR)
106    $(RM) -r $(GCC_DIR)
107    tar -C $(TARGET_TOOLCHAIN_DIR) $(VERBOSE) -xjf $(DL_DIR)/$(GCC_SOURCE)
108    set -e; \
109    for i in $(GCC_MAKE_DIR)/$(GCC_VERSION)/*.patch; do \
110        $(PATCH_TOOL) $(GCC_DIR) $$i; \
111    done
112    for f in $$(find $(GCC_DIR) \( -name "configure" -o -name "config.rpath" \)); do $(call PKG_PREVENT_RPATH_HARDCODING1,$$f) done
113    touch $@
114
115##############################################################################
116#
117#   build the first pass gcc compiler
118#
119##############################################################################
120GCC_BUILD_DIR1:=$(TARGET_TOOLCHAIN_DIR)/gcc-$(GCC_VERSION)-initial
121
122$(GCC_BUILD_DIR1)/.configured: $(GCC_DIR)/.unpacked $(GCC_INITIAL_PREREQ) | target-toolchain-kernel-headers
123    mkdir -p $(GCC_BUILD_DIR1)
124    (cd $(GCC_BUILD_DIR1); $(RM) config.cache; \
125        PATH=$(TARGET_PATH) \
126        CC="$(TOOLCHAIN_HOSTCC)" \
127        CFLAGS="$(TOOLCHAIN_HOST_CFLAGS)" \
128        $(GCC_DIR)/configure \
129        --prefix=$(TARGET_TOOLCHAIN_PREFIX) \
130        --with-sysroot=$(TARGET_TOOLCHAIN_DEVEL_SYSROOT) \
131        --build=$(GNU_HOST_NAME) \
132        --host=$(GNU_HOST_NAME) \
133        --target=$(REAL_GNU_TARGET_NAME) \
134        --enable-languages=c \
135        --disable-shared \
136        --disable-threads \
137        $(GCC_WITH_HOST_GMP) \
138        $(GCC_WITH_HOST_MPFR) \
139        $(GCC_WITH_HOST_MPC) \
140        $(GCC_COMMON_CONFIGURE_OPTIONS) \
141    );
142    touch $@
143
144$(GCC_BUILD_DIR1)/.compiled: $(GCC_BUILD_DIR1)/.configured
145    PATH=$(TARGET_PATH) \
146        $(MAKE) $(GCC_EXTRA_MAKE_OPTIONS) -C $(GCC_BUILD_DIR1) \
147        all-gcc \
148        $(if $(GCC_BUILD_TARGET_LIBGCC),all-target-libgcc)
149    touch $@
150
151$(GCC_BUILD_DIR1)/.installed: $(GCC_BUILD_DIR1)/.compiled
152    PATH=$(TARGET_PATH) \
153        $(MAKE) -C $(GCC_BUILD_DIR1) \
154        install-gcc \
155        $(if $(GCC_BUILD_TARGET_LIBGCC),install-target-libgcc)
156    $(call GCC_INSTALL_COMMON,$(TARGET_TOOLCHAIN_STAGING_DIR)/usr,$(GCC_VERSION),$(REAL_GNU_TARGET_NAME),$(HOST_STRIP))
157    $(call GCC_SET_HEADERS_TIMESTAMP,$(TARGET_TOOLCHAIN_STAGING_DIR))
158    $(call REMOVE_DOC_NLS_DIRS,$(TARGET_TOOLCHAIN_STAGING_DIR))
159    touch $@
160
161gcc_initial: uclibc-configured binutils $(GCC_BUILD_DIR1)/.installed
162
163gcc_initial-uninstall: gcc-uninstall
164
165gcc_initial-clean: gcc_initial-uninstall
166    $(RM) -r $(GCC_BUILD_DIR1)
167
168gcc_initial-dirclean: gcc_initial-clean gcc-dirclean gcc_target-dirclean
169    $(RM) -r $(GCC_DIR)
170
171##############################################################################
172#
173# second pass compiler build. Build the compiler targeting
174# the newly built shared uClibc library.
175#
176##############################################################################
177GCC_BUILD_DIR2:=$(TARGET_TOOLCHAIN_DIR)/gcc-$(GCC_VERSION)-final
178
179$(GCC_BUILD_DIR2)/.configured: $(GCC_DIR)/.unpacked $(GCC_STAGING_PREREQ)
180    mkdir -p $(GCC_BUILD_DIR2)
181    # Important! Required for limits.h to be fixed.
182    ln -sf ../include $(TARGET_TOOLCHAIN_STAGING_DIR)/usr/$(REAL_GNU_TARGET_NAME)/sys-include
183    (cd $(GCC_BUILD_DIR2); $(RM) config.cache; \
184        PATH=$(TARGET_PATH) \
185        CC="$(TOOLCHAIN_HOSTCC)" \
186        CFLAGS="$(TOOLCHAIN_HOST_CFLAGS)" \
187        $(GCC_DIR)/configure \
188        --prefix=$(TARGET_TOOLCHAIN_PREFIX-gcc-final-phase) \
189        --with-sysroot=$(TARGET_TOOLCHAIN_SYSROOT) \
190        --build=$(GNU_HOST_NAME) \
191        --host=$(GNU_HOST_NAME) \
192        --target=$(REAL_GNU_TARGET_NAME) \
193        --enable-languages=c,c++ \
194        --enable-shared \
195        --enable-threads \
196        $(GCC_WITH_HOST_GMP) \
197        $(GCC_WITH_HOST_MPFR) \
198        $(GCC_WITH_HOST_MPC) \
199        $(GCC_COMMON_CONFIGURE_OPTIONS) \
200    );
201    touch $@
202
203$(GCC_BUILD_DIR2)/.compiled: $(GCC_BUILD_DIR2)/.configured
204    PATH=$(TARGET_PATH) $(MAKE) $(GCC_EXTRA_MAKE_OPTIONS) -C $(GCC_BUILD_DIR2) all
205    touch $@
206
207$(GCC_BUILD_DIR2)/.installed: $(GCC_BUILD_DIR2)/.compiled
208    PATH=$(TARGET_PATH) $(MAKE) -C $(GCC_BUILD_DIR2) install
209    $(call GCC_INSTALL_COMMON,$(TARGET_TOOLCHAIN_STAGING_DIR)/usr,$(GCC_VERSION),$(REAL_GNU_TARGET_NAME),$(HOST_STRIP))
210    $(call GCC_SET_HEADERS_TIMESTAMP,$(TARGET_TOOLCHAIN_STAGING_DIR))
211    $(call REMOVE_DOC_NLS_DIRS,$(TARGET_TOOLCHAIN_STAGING_DIR))
212    # Link some files to make mklibs happy
213    ln -sf ../usr/lib/gcc/$(REAL_GNU_TARGET_NAME)/$(TARGET_TOOLCHAIN_GCC_VERSION)/libgcc_pic.a $(TARGET_TOOLCHAIN_STAGING_DIR)/lib/libgcc_s_pic.a; \
214    ln -sf ../usr/lib/gcc/$(REAL_GNU_TARGET_NAME)/$(TARGET_TOOLCHAIN_GCC_VERSION)/libgcc.map $(TARGET_TOOLCHAIN_STAGING_DIR)/lib/libgcc_s_pic.map
215    # strip libraries
216    -(cd $(TARGET_TOOLCHAIN_STAGING_DIR)/usr/lib && $(TARGET_STRIP) libstdc++.so.*.*.* libgcc_s.so.1 >/dev/null 2>&1)
217    # set up the symlinks to enable lying about target name
218    ln -snf $(REAL_GNU_TARGET_NAME) $(TARGET_TOOLCHAIN_STAGING_DIR)/usr/$(GNU_TARGET_NAME)
219    $(call CREATE_TARGET_NAME_SYMLINKS,$(TARGET_TOOLCHAIN_STAGING_DIR)/usr,$(GCC_BINARIES_BIN),$(REAL_GNU_TARGET_NAME),$(GNU_TARGET_NAME))
220    touch $@
221
222gcc: uclibc-configured binutils gcc_initial uclibc \
223    $(GCC_BUILD_DIR2)/.installed $(TARGET_SPECIFIC_ROOT_DIR)/lib/libgcc_s.so.1
224
225gcc-uninstall:
226    $(RM) $(call TOOLCHAIN_BINARIES_LIST,$(TARGET_TOOLCHAIN_STAGING_DIR)/usr,$(GCC_BINARIES_BIN),$(REAL_GNU_TARGET_NAME))
227    $(RM) $(call TOOLCHAIN_BINARIES_LIST,$(TARGET_TOOLCHAIN_STAGING_DIR)/usr,$(GCC_BINARIES_BIN),$(GNU_TARGET_NAME))
228    $(RM) $(TARGET_TOOLCHAIN_STAGING_DIR)/usr/$(GNU_TARGET_NAME)
229    $(RM) -r $(TARGET_TOOLCHAIN_STAGING_DIR)/usr/{lib,libexec}/gcc
230
231gcc-clean: gcc-uninstall
232    $(RM) -r $(GCC_BUILD_DIR2)
233
234gcc-dirclean: gcc-clean
235
236.PHONY: gcc gcc_initial
237
238#############################################################
239#
240# Next build target gcc compiler
241#
242#############################################################
243GCC_BUILD_DIR3:=$(TARGET_TOOLCHAIN_DIR)/gcc-$(GCC_VERSION)-target
244
245$(GCC_BUILD_DIR3)/.configured: $(GCC_BUILD_DIR2)/.installed $(GCC_TARGET_PREREQ)
246    mkdir -p $(GCC_BUILD_DIR3)
247    (cd $(GCC_BUILD_DIR3); $(RM) config.cache; \
248        GCC="$(TARGET_CC)" \
249        CFLAGS_FOR_BUILD="-g -O2 $(TOOLCHAIN_HOST_CFLAGS)" \
250        $(TARGET_CONFIGURE_ENV) \
251        $(GCC_DIR)/configure \
252        --prefix=/usr \
253        --with-gxx-include-dir=/usr/include/c++ \
254        --build=$(GNU_HOST_NAME) \
255        --host=$(REAL_GNU_TARGET_NAME) \
256        --target=$(REAL_GNU_TARGET_NAME) \
257        --enable-languages=c,c++ \
258        --enable-shared \
259        --enable-threads \
260        $(GCC_COMMON_CONFIGURE_OPTIONS) \
261    );
262    touch $@
263
264$(GCC_BUILD_DIR3)/.compiled: $(GCC_BUILD_DIR3)/.configured
265    $(MAKE_ENV) $(MAKE) -C $(GCC_BUILD_DIR3) $(GCC_EXTRA_MAKE_OPTIONS) all
266    touch $@
267
268GCC_INCLUDE_DIR:=include-fixed
269
270$(TARGET_UTILS_DIR)/usr/bin/gcc: $(GCC_BUILD_DIR3)/.compiled
271    $(MAKE_ENV) $(MAKE1) -C $(GCC_BUILD_DIR3) DESTDIR=$(TARGET_UTILS_DIR) install
272    $(call GCC_INSTALL_COMMON,$(TARGET_UTILS_DIR)/usr,$(GCC_VERSION),$(REAL_GNU_TARGET_NAME),$(TARGET_STRIP))
273    $(call REMOVE_DOC_NLS_DIRS,$(TARGET_UTILS_DIR))
274    # strip libraries
275    -(cd $(TARGET_UTILS_DIR)/usr/lib && $(TARGET_STRIP) libstdc++.so.*.*.* libgcc_s.so.1 >/dev/null 2>&1)
276    # remove broken specs file (cross compile flag is set) and *.la* files
277    $(RM) $(TARGET_UTILS_DIR)/usr/$(GCC_LIB_SUBDIR)/specs $(TARGET_UTILS_DIR)/usr/lib/*.la*
278    # work around problem of missing syslimits.h
279    if [ ! -f $(TARGET_UTILS_DIR)/usr/$(GCC_LIB_SUBDIR)/$(GCC_INCLUDE_DIR)/syslimits.h ]; then \
280        echo "warning: working around missing syslimits.h"; \
281        cp -f $(TARGET_TOOLCHAIN_STAGING_DIR)/$(GCC_LIB_SUBDIR)/$(GCC_INCLUDE_DIR)/syslimits.h \
282            $(TARGET_UTILS_DIR)/usr/$(GCC_LIB_SUBDIR)/$(GCC_INCLUDE_DIR)/; \
283    fi
284    touch -c $@
285
286gcc_target: uclibc_target binutils_target $(TARGET_UTILS_DIR)/usr/bin/gcc
287
288gcc_target-uninstall:
289    $(RM) $(call TOOLCHAIN_BINARIES_LIST,$(TARGET_UTILS_DIR)/usr,$(GCC_BINARIES_BIN),$(REAL_GNU_TARGET_NAME))
290    $(RM) -r $(TARGET_UTILS_DIR)/usr/{lib,libexec}/gcc
291
292gcc_target-clean: gcc_target-uninstall
293    $(RM) -r $(GCC_BUILD_DIR3)
294
295gcc_target-dirclean: gcc_target-clean
Hinweis: Hilfe zum Repository-Browser finden Sie in TracBrowser.