Headers and libraries also archived
[harbours.git] / gcc / HARBOUR
blob02de2070f8d377965e6b3e3a1703b110b9740db6
2 # Copyright (c) 2013 Vojtech Horky
3 # All rights reserved.
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions
7 # are met:
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.
29 shipname=gcc
30 shipversion=4.6.3
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"
34 shipfunnels=4
36 build() {
37         run tar xjf ${shipname}-${shipversion}.tar.bz2
38         
39         
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"
49         
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..."
53         run mkdir -p include
54         run cp ${shipname}-${shipversion}/gcc/unwind-generic.h include/unwind.h
55         
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#'`"
62         
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"
66         
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"
70         
71         extra_cflags=""
72         # Do not use HelenOS libc due to file names clashes
73         extra_ldflags="-L$HSCT_LIB_DIR"
74         
75         msg "Creating GCC wrapper..."
76         run mkdir -p bin
77         # This is kind of stupid because we do not have separate
78         # preprocessor flags in HelenOS. That is why C flags are empty          
79         m4 \
80                 -DCROSS_CC="$HSCT_CC" \
81                 -DPPFLAGS="$extra_ppflags $extra_cflags $fixed_cflags" \
82                 -DCFLAGS="" \
83                 -DLDFLAGS="$extra_ldflags $HSCT_LDFLAGS_FOR_CC" \
84                 gcc.template >bin/patched-gcc
85         cc="`pwd`/bin/patched-gcc"
86         run chmod +x "$cc"
87         
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"
93         done
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"
97         
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
103         # correctly.
104         msg "Providing our pex implementation..."
105         run cp pex-helenos.c "${shipname}-${shipversion}/libiberty/"
106         run sed \
107                 -e 's/@pexecute@/pex-helenos/' \
108                 -e 's/pex-msdos/pex-helenos/g' \
109                 -i "${shipname}-${shipversion}/libiberty/Makefile.in"
110         
111         # Somewhere during the compilation C++ compiler is required
112         cxx=`echo "$HSCT_CC" | sed 's/gcc$/g++/'`
113         
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
117         
118         msg "Building..."
119         
120         # Out-of-source build is recommended for GCC
121         run mkdir -p build
122         cd build
123         
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/'`
131         fi
132         
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 \
138                 --without-ppl \
139                 --without-cloog \
140                 --disable-mudflap \
141                 --disable-libmudflap \
142                 --disable-libgomp \
143                 --disable-gomp \
144                 --with-system-zlib \
145                 --without-headers \
146                 --disable-shared \
147                 --enable-languages=c \
148                 --disable-checking \
149                 --disable-lto \
150                 --disable-threads \
151                 --disable-nls \
152                 --disable-libssp \
153                 --disable-libquadmath \
154                 --enable-decimal-float=dpd \
155                 --disable-multilib \
156                 --disable-multiarch \
157                 --disable-libstdcxx-pch \
158                 --disable-libunwind-exceptions \
159                 --with-gnu-as \
160                 --with-gnu-ld \
161                 CC="$cc" \
162                 LD="$cc" \
163                 AR="$HSCT_AR" \
164                 AS="$HSCT_AS" \
165                 NM="$HSCT_NM" \
166                 OBJCOPY="$HSCT_OBJCOPY" \
167                 RANLIB="$HSCT_RANLIB" \
168                 STRIP="$HSCT_STRIP" \
169                 OBJDUMP="$HSCT_OBJDUMP" \
170                 CXX="$cxx" \
171                 CC_FOR_TARGET="$cc"
173         run make all-gcc -j$shipfunnels
176 package() {
177         cd build
178         run make install-gcc "DESTDIR=$PWD/PKG"
179         
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/"
184         done
185         run cp PKG/usr/local/libexec/gcc/*/4.6.3/cc1 "$HSCT_MY_DIR/app/"