2 # Copyright (c) 2013 Vojtech Horky
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions
9 # - Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
11 # - Redistributions in binary form must reproduce the above copyright
12 # notice, this list of conditions and the following disclaimer in the
13 # documentation and/or other materials provided with the distribution.
14 # - The name of the author may not be used to endorse or promote products
15 # derived from this software without specific prior written permission.
17 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 mirror_="ftp://ftp.fu-berlin.de/unix/languages/gcc"
32 shipsources="$mirror_/releases/$shipname-$shipversion/$shipname-$shipversion.tar.bz2 gcc.template includes.patch libiberty.patch pex-helenos.c"
33 shiptugs="libgmp libmpfr libmpc libisl zlib"
37 run tar xjf ${shipname}-${shipversion}.tar.bz2
40 msg "Patching sources..."
41 # Missing include diretives
42 patch -p0 <includes.patch
43 # Prevent name clashes in getopt.c and fnmatch.c
44 patch -p0 <libiberty.patch
46 run sed 's/\(static search_line_fast_type search_line_fast\);/\1 = search_line_acc_char;/' \
47 -i "${shipname}-${shipversion}/libcpp/lex.c"
48 run sed '/fopen/s#w+b#wb+#' -i "${shipname}-${shipversion}/gcc/toplev.c"
50 # HelenOS does not have its own unwind.h. Luckily,
51 # we may use the one provided by GCC itself.
52 msg "Fixing unwind.h..."
54 run cp ${shipname}-${shipversion}/gcc/unwind-generic.h include/unwind.h
56 # There is a name clash on the REVISION macro from config.h
57 # Luckily, we do not need the one from HelenOS and thus simply removing
58 # it from the original config.h shall be okay
59 msg "Purging HelenOS config.h, declaring compiler flags..."
60 sed -e '/REVISION/d' -e '/PROCESSOR/d' "$HSCT_CACHE_DIR/include/system_config.h" >include/helenos_config.h
61 fixed_cflags="`echo $HSCT_CFLAGS | sed 's#-imacros[ \t]\+[^ \t]*/system_config\.h#-imacros '$PWD'/include/helenos_config.h#'`"
63 # We shall define this macro somewhere, this is not the first
64 # harbour we are defining this macro in
65 extra_ppflags="-DCHAR_BIT=8"
67 # Other preprocessor flags due to bad guesses by configure
68 extra_ppflags="$extra_ppflags -DHAVE_SYS_STAT_H -Dinhibit_libc"
69 extra_ppflags="$extra_ppflags -I$HSCT_INCLUDE_DIR -I`pwd`/include"
72 # Do not use HelenOS libc due to file names clashes
73 extra_ldflags="-L$HSCT_LIB_DIR"
75 msg "Creating GCC wrapper..."
77 # This is kind of stupid because we do not have separate
78 # preprocessor flags in HelenOS. That is why C flags are empty
80 -DCROSS_CC="$HSCT_CC" \
81 -DPPFLAGS="$extra_ppflags $extra_cflags $fixed_cflags" \
83 -DLDFLAGS="$extra_ldflags $HSCT_LDFLAGS_FOR_CC" \
84 gcc.template >bin/patched-gcc
85 cc="`pwd`/bin/patched-gcc"
88 # We need to trick configure into thinking that we are actually
89 # cross-compiling even if it does not think so.
90 msg "Fixing cross-compilation guesses..."
91 find -name configure | while read fname; do
92 run sed 's/^cross_compiling=no/cross_compiling=yes/' -i "$fname"
95 # We really do not need to fix any includes
96 run sed 's/STMP_FIXINC=stmp-fixinc/STMP_FIXINC=/' -i "${shipname}-${shipversion}/gcc/configure"
98 # PEX is used to wrap different means to launch an external program
99 # We do not implement the fork() system call, we need to fix it to
100 # use the task_spawn() API.
101 # As the msdos version is not needed at all, we replace it with our
102 # own at various places to ensure the HelenOS version is built
104 msg "Providing our pex implementation..."
105 run cp pex-helenos.c "${shipname}-${shipversion}/libiberty/"
107 -e 's/@pexecute@/pex-helenos/' \
108 -e 's/pex-msdos/pex-helenos/g' \
109 -i "${shipname}-${shipversion}/libiberty/Makefile.in"
111 # Somewhere during the compilation C++ compiler is required
112 cxx=`echo "$HSCT_CC" | sed 's/gcc$/g++/'`
114 # Prevent building documentation
115 # (there is a problem with newer version of texinfo?)
116 sed 's/^BUILD_INFO[ \t]*=.*/BUILD_INFO = /g' -i ${shipname}-${shipversion}/gcc/Makefile.in
120 # Out-of-source build is recommended for GCC
124 # Although we are forcing the cross-compilation, sometimes
125 # it is apparently not enough. This is an ungly hack until we
126 # patch the sources with some *-helenos-* target.
127 self_target=`../${shipname}-${shipversion}/config.guess`
128 if [ "$self_target" = "$HSCT_GNU_TARGET" ]; then
129 # Only works for building ia32 on i686
130 self_target=`echo "$self_target" | sed 's/686/386/'`
133 # This is extremely crippled version but it at least compiles
134 run ../${shipname}-${shipversion}/configure \
135 --build=$self_target \
136 --host=$HSCT_GNU_TARGET \
137 --target=$HSCT_GNU_TARGET \
141 --disable-libmudflap \
147 --enable-languages=c \
153 --disable-libquadmath \
154 --enable-decimal-float=dpd \
156 --disable-multiarch \
157 --disable-libstdcxx-pch \
158 --disable-libunwind-exceptions \
166 OBJCOPY="$HSCT_OBJCOPY" \
167 RANLIB="$HSCT_RANLIB" \
168 STRIP="$HSCT_STRIP" \
169 OBJDUMP="$HSCT_OBJDUMP" \
173 run make all-gcc -j$shipfunnels
178 run make install-gcc "DESTDIR=$PWD/PKG"
180 # Copy the executables
181 run mkdir -p "$HSCT_MY_DIR/app/"
182 for app in gcc cpp gcov; do
183 run cp PKG/usr/local/bin/$app "$HSCT_MY_DIR/app/"
185 run cp PKG/usr/local/libexec/gcc/*/4.6.3/cc1 "$HSCT_MY_DIR/app/"