1 ###############################################################################
3 # IPFire.org - A linux based firewall #
4 # Copyright (C) 2007, 2008, 2009 Michael Tremer & Christian Schmidt #
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 3 of the License, or #
9 # (at your option) any later version. #
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 #
14 # GNU General Public License for more details. #
16 # You should have received a copy of the GNU General Public License #
17 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
19 ###############################################################################
21 ###############################################################################
23 ###############################################################################
31 THISAPP = $(PKG_NAME)-$(VER)
32 DL_FILE = $(THISAPP).tar.bz2
33 DIR_APP = $(DIR_SRC)/$(THISAPP)
35 ifeq "$(STAGE)" "base"
36 OBJECT = $(DIR_INFO)/$(STAGE_ORDER)_$(STAGE)/$(THISAPP)
38 OBJECT = $(DIR_INFO)/$(STAGE_ORDER)_$(STAGE)/$(THISAPP)-pass$(PASS)
42 GROUP = Development/Compilers
47 URL = http://gcc.gnu.org/
48 LICENSE = GPLv3+ and GPLv2+ with exceptions
49 SHORT_DESC = Various compilers (C, C++, Objective-C, Java, ...).
52 The gcc package contains the GNU Compiler Collection. \
53 You'll need this package in order to compile C code.
59 GMP = $(shell grep ^VER $(DIR_LFS)/gmp | awk '{ print $$3 }')
60 MPFR = $(shell grep ^VER $(DIR_LFS)/mpfr | awk '{ print $$3 }')
62 ifeq "$(MACHINE)" "i586"
63 CONFIGURE_ARGS = --disable-decimal-float
66 ###############################################################################
68 ###############################################################################
70 objects = $(DL_FILE) \
71 gmp-$(GMP).tar.bz2 mpfr-$(MPFR).tar.bz2 \
72 $(THISAPP)-fstack_protector-1.patch \
73 $(THISAPP)-fortify_source-2.patch \
74 $(THISAPP)-fpie-1.patch \
75 $(THISAPP)-branch-startfiles-1.patch \
76 $(THISAPP)-asprintf_fix.patch
91 ###############################################################################
92 # Installation Details
93 ###############################################################################
97 @rm -rf $(DIR_APP) $(DIR_SRC)/gcc-build && cd $(DIR_SRC) && $(EXTRACTOR) $(DIR_DL)/$(DL_FILE)
98 -mkdir -v $(DIR_SRC)/gcc-build
100 # First, unpack gmp and mpfr.
101 # We use the build-"magic" of the gcc build system that we compile libgmp and
102 # libmpfr right (with -fPIC and so on).
103 cd $(DIR_APP) && $(EXTRACTOR) $(DIR_DL)/gmp-$(GMP).tar.bz2
104 cd $(DIR_APP) && ln -svf gmp-* gmp
105 cd $(DIR_APP) && $(EXTRACTOR) $(DIR_DL)/mpfr-$(MPFR).tar.bz2
106 cd $(DIR_APP) && ln -svf mpfr-* mpfr
108 ifeq "$(STAGE)" "toolchain"
110 ## Enable -fPIC by default
111 cd $(DIR_APP) && sed 's/^\(#define CC1_SPEC.*\)\("\)$$/\1 %{fno-pic|fpic|fPIC:;:-fPIC}\2/' \
112 -i gcc/config/i386/linux.h
114 # libssp has no use with new versions of Glibc. Glibc completely replaces all
115 # functions in libssp, linking to libssp will cause conflicts with libc, so
116 # libssp is a waste of space... so --disable-libssp.
118 cd $(DIR_SRC)/gcc-build && \
119 CC="gcc -B/usr/bin/" \
120 ../$(THISAPP)/configure \
122 --target=$(IFS_TARGET) \
123 --with-cpu=$(MACHINE) \
124 --with-arch=$(MACHINE) \
125 --prefix=$(TOOLS_DIR) \
126 --with-local-prefix=$(TOOLS_DIR) \
127 --libexecdir=$(TOOLS_DIR)/lib \
128 --enable-languages=c \
135 cd $(DIR_SRC)/gcc-build && make $(PARALLELISMFLAGS)
136 cd $(DIR_SRC)/gcc-build && make install
138 ln -fvs gcc $(TOOLS_DIR)/bin/cc
142 # Enable hardening by default:
143 cd $(DIR_APP) && patch -Np1 -i $(DIR_PATCHES)/$(THISAPP)-fortify_source-2.patch
144 cd $(DIR_APP) && patch -Np1 -i $(DIR_PATCHES)/$(THISAPP)-fstack_protector-1.patch
146 # This fpie patch also warns about DT_TEXTREL in shared objects (libraries and
147 # PIE's), and makes linker warnings fatal. Disable --fatal-warnings with
148 # -Wl,--no-fatal-warnings.
149 cd $(DIR_APP) && patch -Np1 -i $(DIR_PATCHES)/$(THISAPP)-fpie-1.patch
150 cd $(DIR_APP) && patch -Np1 -i $(DIR_PATCHES)/$(THISAPP)-branch-startfiles-1.patch
152 # This patch fixes a conflict between libiberty's asprintf() and Glibc's, when
153 # -D_FORTIFY_SOURCE=2 is used:
154 cd $(DIR_APP) && patch -Np0 -i $(DIR_PATCHES)/$(THISAPP)-asprintf_fix.patch
156 cd $(DIR_APP) && sed 's@\./fixinc\.sh@-c true@' -i gcc/Makefile.in
157 cd $(DIR_APP) && sed 's/^XCFLAGS =$$/& -fomit-frame-pointer/' -i gcc/Makefile.in
159 for file in $$(find gcc/config -name linux64.h -o -name linux.h); do \
160 cp -uv $$file{,.orig}; \
161 sed -e 's@/lib\(64\)\?\(32\)\?/ld@$(TOOLS_DIR)&@g' \
162 -e 's@/usr@$(TOOLS_DIR)@g' $$file.orig > $$file; \
163 echo -e "\n#undef STANDARD_INCLUDE_DIR\n#define STANDARD_INCLUDE_DIR 0" >> $$file; \
167 # Libgomp uses -Werror regardless of --disable-werror, and this will cause a
168 # build failure when -D_FORTIFY_SOURCE=2 causes build time warnings:
169 cd $(DIR_APP) && sed -e "s/-Werror//" -i libgomp/configure
171 # We need to do another bootstrap, so that everything in $(TOOLS_DIR) is hardened.
172 cd $(DIR_SRC)/gcc-build && \
173 ../$(THISAPP)/configure \
175 --target=$(IFS_TARGET) \
176 --with-cpu=$(MACHINE) \
177 --with-arch=$(MACHINE) \
178 --prefix=$(TOOLS_DIR) \
179 --with-local-prefix=$(TOOLS_DIR) \
180 --libexecdir=$(TOOLS_DIR)/lib \
181 --enable-clocale=gnu \
183 --enable-threads=posix \
184 --enable-__cxa_atexit \
185 --enable-languages=c,c++ \
186 --disable-libstdcxx-pch \
187 --disable-bootstrap \
192 cd $(DIR_SRC)/gcc-build && make $(PARALLELISMFLAGS)
193 cd $(DIR_SRC)/gcc-build && make install
197 ifeq "$(STAGE)" "base"
198 cd $(DIR_APP) && patch -Np1 -i $(DIR_PATCHES)/$(THISAPP)-fortify_source-2.patch
199 cd $(DIR_APP) && patch -Np1 -i $(DIR_PATCHES)/$(THISAPP)-fstack_protector-1.patch
200 cd $(DIR_APP) && patch -Np1 -i $(DIR_PATCHES)/$(THISAPP)-fpie-1.patch
201 cd $(DIR_APP) && sed -i 's/install_to_$$(INSTALL_DEST) //' libiberty/Makefile.in
202 cd $(DIR_APP) && sed -i 's/^XCFLAGS =$$/& -fomit-frame-pointer/' gcc/Makefile.in
203 cd $(DIR_APP) && sed -i 's@\./fixinc\.sh@-c true@' gcc/Makefile.in
205 # Libgomp uses -Werror regardless of --disable-werror, and this will cause a
206 # build failure when -D_FORTIFY_SOURCE=2 causes build time warnings:
207 cd $(DIR_APP) && sed -e "s/-Werror//" -i libgomp/configure
209 cd $(DIR_SRC)/gcc-build && \
210 ../$(THISAPP)/configure \
212 --target=$(IFS_TARGET) \
213 --with-cpu=$(MACHINE) \
214 --with-arch=$(MACHINE) \
216 --libexecdir=/usr/lib \
218 --enable-threads=posix \
219 --enable-__cxa_atexit \
220 --enable-clocale=gnu \
221 --enable-languages=c,c++ \
222 --disable-bootstrap \
226 cd $(DIR_SRC)/gcc-build && make $(PARALLELISMFLAGS)
227 cd $(DIR_SRC)/gcc-build && make install
229 ln -sfv ../usr/bin/cpp /lib
230 ln -sfv gcc /usr/bin/cc
233 @rm -rf $(DIR_APP) $(DIR_SRC)/gcc-build