Create a Cross Compiler for m32c architecture
Original Instructions by DJ Delorie's website:
http://www.delorie.com/electronics/rx-stick/#build-tools
Requirements:
binutils 2.17
gcc 4.1.2
newlib 1.14
gdb 6.5 (optional)
Procedure:
make a directory called cross_compile in your home directory and extract all the above to them such that the structure looks like:
cross_compile > binutils-2.17 (folder extracted by tarball)
> build-gcc > gcc-4.1.2 (folder extracted by tarball)(this hierarchy somehow enables libssp)
> newlib-1.14.0 (folder extracted by tarball)
> build-binutils
> build-newlib
cd build-binutils
../binutils-2.17/configure --prefix=/opt/myhat --target=m32c-elf
make
sudo make install
Errors faced:
While making binutils-2.17:
Error no.01.:
gcc -DHAVE_CONFIG_H -I. -I../../binutils-2.17/binutils -I. -D_GNU_SOURCE -I. -I../../binutils-2.17/binutils -I../bfd -I../../binutils-2.17/binutils/../bfd -I../../binutils-2.17/binutils/../include -I../../binutils-2.17/binutils/../intl -I../intl -DLOCALEDIR="\"/opt/myhat/share/locale\"" -Dbin_dummy_emulation=bin_vanilla_emulation -W -Wall -Wstrict-prototypes -Wmissing-prototypes -Werror -g -O2 -c ../../binutils-2.17/binutils/bucomm.c
cc1: warnings being treated as errors
../../binutils-2.17/binutils/bucomm.c: In function ‘make_tempname’:
../../binutils-2.17/binutils/bucomm.c:426: error: ignoring return value of ‘mktemp’, declared with attribute warn_unused_result
../../binutils-2.17/binutils/bucomm.c:433: error: ignoring return value of ‘mktemp’, declared with attribute warn_unused_result
make[4]: *** [bucomm.o] Error 1
make[4]: Leaving directory `/home/onkar/cross_compiler/build-binutils/binutils'
make[3]: *** [all-recursive] Error 1
make[3]: Leaving directory `/home/onkar/cross_compiler/build-binutils/binutils'
make[2]: *** [all] Error 2
make[2]: Leaving directory `/home/onkar/cross_compiler/build-binutils/binutils'
make[1]: *** [all-binutils] Error 2
make[1]: Leaving directory `/home/onkar/cross_compiler/build-binutils'
make: *** [all] Error 2
SOLUTION 01:
step1: gedit ./binutils/Makefile
step2: Find the word Werror (match-case) in the Makefile and delete the word/option
step3: Save file, exit and perform a make again which may lead you to error no. 02
Error No. 02.
gcc -DHAVE_CONFIG_H -I. -I../../binutils-2.17/gas -I. -D_GNU_SOURCE -I. -I../../binutils-2.17/gas -I../bfd -I../../binutils-2.17/gas/config -I../../binutils-2.17/gas/../include -I../../binutils-2.17/gas/.. -I../../binutils-2.17/gas/../bfd -I../../binutils-2.17/gas/../intl -I../intl -DLOCALEDIR="\"/opt/myhat/share/locale\"" -W -Wall -Wstrict-prototypes -Wmissing-prototypes -Werror -g -O2 -c ../../binutils-2.17/gas/app.c
cc1: warnings being treated as errors
../../binutils-2.17/gas/app.c: In function ‘do_scrub_chars’:
../../binutils-2.17/gas/app.c:566: error: array subscript is below array bounds
make[4]: *** [app.o] Error 1
make[4]: Leaving directory `/home/onkar/cross_compiler/build-binutils/gas'
make[3]: *** [all-recursive] Error 1
make[3]: Leaving directory `/home/onkar/cross_compiler/build-binutils/gas'
make[2]: *** [all] Error 2
make[2]: Leaving directory `/home/onkar/cross_compiler/build-binutils/gas'
make[1]: *** [all-gas] Error 2
make[1]: Leaving directory `/home/onkar/cross_compiler/build-binutils'
make: *** [all] Error 2
SOLUTION 02:
***** Repeat steps in SOLUTION 01 except for the Makefile in ./gas/
THESE WERE THE TWO ERRORS I FACED DURING MAKING BINUTILS.
Next move to partially making gcc-4.1.2
cd ..
cd ./build-gcc/gcc-4.1.2
./configure --prefix=/opt/myhat --target=m32c-elf --enable-languages=c --with-newlib
make -k
sudo make -k install
ERROR 02:
This make is meant to break since we haven't compiled newlib yet. For me, it breaks after
echo ./regex.o ./cplus-dem.o ./cp-demangle.o ./md5.o ./alloca.o ./argv.o ./choose-temp.o ./concat.o ./cp-demint.o ./dyn-string.o ./fdmatch.o ./fibheap.o ./floatformat.o ./fnmatch.o ./fopen_unlocked.o ./getopt.o ./getopt1.o ./getpwd.o ./getruntime.o ./hashtab.o ./hex.o ./lbasename.o ./lrealpath.o ./make-relative-prefix.o ./make-temp-file.o ./objalloc.o ./obstack.o ./partition.o ./pexecute.o ./physmem.o ./pex-common.o ./pex-one.o ./pex-unix.o ./safe-ctype.o ./sort.o ./spaces.o ./splay-tree.o ./strerror.o ./strsignal.o ./ternary.o ./unlink-if-ordinary.o ./xatexit.o ./xexit.o ./xmalloc.o ./xmemdup.o ./xstrdup.o ./xstrerror.o ./xstrndup.o > required-list
However you should still continue with sudo make -k install
Next, move to make newlib-1.14.0
cd ..
cd ./build-newlib
../newlib-1.14.0/configure --prefix=/opt/myhat --target=m32c-elf --enable-languages=c --with-newlib
make
make install
ERROR 03:
make[3]: Entering directory `/home/onkar/cross_compiler/build-newlib/etc'
/home/onkar/cross_compiler/newlib-1.14.0/missing makeinfo --split-size=5000000 --split-size=5000000 --no-split -I../../newlib-1.14.0/etc -o standards.info ../../newlib-1.14.0/etc/standards.texi
WARNING: `makeinfo' is missing on your system. You should only need it if
you modified a `.texi' or `.texinfo' file, or any other file
indirectly affecting the aspect of the manual. The spurious
call might also be the consequence of using a buggy `make' (AIX,
DU, IRIX). You might want to install the `Texinfo' package or
the `GNU make' package. Grab either from any GNU archive site.
make[3]: *** [standards.info] Error 1
make[3]: Leaving directory `/home/onkar/cross_compiler/build-newlib/etc'
make[2]: *** [info] Error 1
make[2]: Leaving directory `/home/onkar/cross_compiler/build-newlib/etc'
make[1]: *** [all-etc] Error 2
make[1]: Leaving directory `/home/onkar/cross_compiler/build-newlib'
make: *** [all] Error 2
To rectify this,
Step 01. gedit ./Makefile
Step 02. find the word MAKEINFO on line 259. It may have some other path to makeinfo in front of it. Replace it with the word makeinfo (provided makeinfo is installed on your linux distribution, if not, sudo apt-get install build-essential makeinfo texinfo)
Should look something like:
BISON = /home/onkar/cross_compiler/newlib-1.14.0/missing bison
YACC = /home/onkar/cross_compiler/newlib-1.14.0/missing bison -y
FLEX = /home/onkar/cross_compiler/newlib-1.14.0/missing flex
LEX = /home/onkar/cross_compiler/newlib-1.14.0/missing flex
M4 = m4
MAKEINFO = makeinfo
EXPECT = expect
RUNTEST = runtest
Step 03: Save and make again
Step 04: sudo make install
ERROR 04:
make[4]: Nothing to be done for `install-exec-am'.
/bin/sh ../../../newlib-1.14.0/newlib/../mkinstalldirs /usr/local/m32c-elf/lib
/usr/bin/install -c -m 644 libm.a /usr/local/m32c-elf/lib/libm.a
/usr/bin/install -c -m 644 libc.a /usr/local/m32c-elf/lib/libc.a
m32c-elf-ranlib /usr/local/m32c-elf/lib/libm.a
/bin/sh: m32c-elf-ranlib: not found
m32c-elf-ranlib /usr/local/m32c-elf/lib/libc.a
/bin/sh: m32c-elf-ranlib: not found
make[4]: *** [install-toollibLIBRARIES] Error 127
make[4]: Leaving directory `/home/onkar/cross_compiler/build-newlib/m32c-elf/newlib'
make[3]: *** [install-am] Error 2
make[3]: Leaving directory `/home/onkar/cross_compiler/build-newlib/m32c-elf/newlib'
make[2]: *** [install-recursive] Error 1
make[2]: Leaving directory `/home/onkar/cross_compiler/build-newlib/m32c-elf/newlib'
make[1]: *** [install-target-newlib] Error 2
make[1]: Leaving directory `/home/onkar/cross_compiler/build-newlib'
make: *** [install] Error 2
SOLUTION 04:
Step 01: gedit ./Makefile
Step 02 :Find in file m32c-elf-ranlib and append it as /opt/myhat/bin/m32c-elf-ranlib
Step 03: save and exit
Step 04: sudo make install
Next, we resume compiling gcc again
Step 01. cd ../build-gcc/gcc-4.1.2
Step 02. make
ERROR:
/usr/bin/install -c -m 644 ./libgcc.a /opt/myhat/lib/gcc/m32c-elf/4.1.2/
chmod 644 /opt/myhat/lib/gcc/m32c-elf/4.1.2/libgcc.a
m32c-elf-ranlib /opt/myhat/lib/gcc/m32c-elf/4.1.2/libgcc.a
make[3]: m32c-elf-ranlib: Command not found
make[3]: *** [install] Error 127
make[3]: Leaving directory `/home/onkar/cross_compiler/build-gcc/gcc-4.1.2/host-i686-pc-linux-gnu/gcc'
make[2]: *** [install-libgcc] Error 2
make[2]: Leaving directory `/home/onkar/cross_compiler/build-gcc/gcc-4.1.2/host-i686-pc-linux-gnu/gcc'
make[1]: *** [install-gcc] Error 2
make[1]: Leaving directory `/home/onkar/cross_compiler/build-gcc/gcc-4.1.2'
make: *** [install] Error 2
SOLUTION:
Step 01: cd host-i686-pc-linux-gnu/gcc/
Step 01: gedit ./Makefile
Step 01: find definition of RANLIB on line 237. Replace definition as either m32c-elf-ranlib or /opt/myhat/bin/m32c-elf-ranlib
Step 01: save and exit
Step 01: sudo make install
AND NOW YOU HAVE A CROSS COMPILER!!!!
CHECK /opt/myhat/bin TO FIND YOUR NEWLY BUILT CROSS COMPILER!