3 # This script builds and installs a gcc cross compiler.
5 # It has been used to build cross compilers from Linux to Cygwin,
6 # MinGW, and Solaris. It is unlikely that this script will work
7 # out-of-the-box. It is only intended as a template. You should read
8 # through it and understand what it does, and make changes as
9 # necessary. Feel free to add another targetType if you modify this
10 # script for another target.
12 # Notes from Anoq about the mingw target:
13 # I downloaded the following files from www.mingw.org:
14 # *) binutils-2.13.90-20030111-1-src.tar.gz which I unpacked to
15 # binutils-2.13.90-20030111-1-src.tar
16 # This script unpacks the .tar to binutils-2.13.90-20030111-1-src
17 # *) gcc-3.2.3-20030504-1-src.tar.gz which I unpacked to
18 # gcc-3.2.3-20030504-1-src.tar
19 # This script unpacks the .tar to gcc-3.2.3-20030504-1
20 # However when running make on gcc it complains about missing files
21 # stdlib.h and unistd.h
34 die
"usage: $name {cygwin|mingw|sun}"
52 # You may want to change the installation prefix, which is where the
53 # script will install the cross-compiler tools.
56 # You must have have the sources to binutils and gcc, and place the
57 # tarfiles in the current directory. You can find ftp sites to
58 # download binutils and gcc-core at gnu.org. You may need to change
59 # the version numbers below to match what you download.
60 binutils
='binutils-2.12'
62 gccTar
="gcc-core-$gccVers.tar"
64 # You may want to set the target.
67 target
='i386-pc-cygwin'
70 # For Cygwin, we also need the cygwin and w32api packages,
71 # which contain necessary header files and libraries. I got
72 # them by installing cygwin in a Windows machine (using #
73 # Cygwin's setup.exe program) and then getting the bzip'ed tar
74 # files out of their Cygwin packages dir. I had problems with
75 # cygwin-1.3.18-1, since its libcygwin.a contained a file,
76 # pseudo-reloc.o, with some strangeness that binutils didn't
78 cygwin
='cygwin-1.3.17-1'
82 target
='i386-pc-mingw32'
84 # These flags are from build-cross.sh from www.libsdl.org except:
85 # I added --disable-nls because of undefined references to dcgettext__
86 configureGCCFlags
='--with-headers=$prefix/$target/include --with-gnu-as --with-gnu-ld --without-newlib --disable-multilib --disable-nls'
87 makeGCCFlags
='LANGUAGES=c'
88 # For MinGW, we also need the mingw-runtime and w32api packages,
89 # which contain necessary header files and libraries. I got
90 # them from www.mingw.org.
91 mingw
='mingw-runtime-3.2'
95 target
='sparc-sun-solaris'
98 # For sun, we assume that you have already copied the includes
99 # and libraries from a Solaris machine to the host machine.
100 if ! [ -d "$prefix/$target/include" -a -d "$prefix/$target/lib" ]; then
101 die
"Must create $prefix/$target/{include,lib}."
103 # The GCC tools expect limits.h to be in sys-include, not include.
104 ( cd "$prefix/$target" &&
105 mkdir
-p sys-include
&&
106 mv include
/limits.h sys-include
)
111 if [ ! -r "$1" ]; then
112 die
"$1 does not exist"
116 echo 'Checking that needed files exist.'
119 case "$targetType" in
123 echo 'Copying include files and libraries needed by cross compiler.'
127 tar x
<..
/$cygwin.
tar
128 tar x
<..
/$w32api.
tar
129 mkdir
-p "$prefix/$target" ||
130 die
"Cannot create $prefix/$target."
131 (cd usr
&& tar c include lib
) |
(cd "$prefix/$target/" && tar x
)
136 echo 'Copying include files and libraries needed by cross compiler.'
141 tar x
<..
/$w32api.
tar
142 mkdir
-p "$prefix/$target" ||
143 die
"Cannot create $prefix/$target."
144 (tar c include lib
) |
(cd "$prefix/$target/" && tar x
)
150 echo 'Building binutils.'
152 if [ ! -d "$binutils" ]; then
155 mkdir
-p build-binutils
157 "../$binutils/configure" "--prefix=$prefix" "--target=$target" \
158 >"$root/configure-binutils-log" 2>&1 ||
159 die
"Configure of binutils failed."
160 make all
install >"$root/build-binutils-log" 2>&1 ||
161 die
"Build of binutils failed."
168 eval "../gcc-$gccVers/configure" -v $configureGCCFlags \
169 --enable-languages=c \
172 >"$root/configure-gcc-log" 2>&1 ||
173 die
"Configure of gcc failed."
174 eval make $makeGCCFlags all
install >"$root/build-gcc-log" 2>&1 ||
175 die
"Build of gcc failed."