Script for building the toolchains for Linux and Mingw
------------------------------------------------------
The script builds four compilers, one native and three cross compilers.
The native compiler is built for build machine
(Optional - If the version is less than 2.95.3 for certain targets
 e.g. rx-elf )

Canadian cross method is used for building the compiler running on
mingw for target SH/H8/M16C.
The cross compilers are :
       1.      build-x-host compiler ( linux-x-mingw )
       2.      build-x-target compiler ( linux-x-rx )
       3.      host-x-target compiler ( mingw-x-rx )
               using above 2 compilers

Source code and Web sites:
--------------------------
Please download the sources from the following link,
http://www.kpitgnutools.com/sourceCode.php

Directory Structure:
--------------------
There are three top level directories needs to be created before starting
the toolchain building.
- <Source Directory>
- <Build Directory>
- <Prefix Directory>

1. All the sources required for toolchain building should be present in
   <Source Directory>
2. The building of the toolchain is done in <Build Directory>.
   During the build process, all the intermediate build files are kept in this
   directory. All the script files required for building the toolchain, the
   build script, timed_read, native-version, remove_cygwin_includes and
   assign_version should be placed in this directory only.
3. On successful building of the toolchain, the toolchain get installed in
   <Prefix Directory>


Setting up the user's Build Environment Variables in build script
-----------------------------------------------------------------
In order to describe the user's build environment to the build script, user
needs to modify the following build script variables.

a. CFLAGS, CXXFLAGS
   The flags specifying the mode in which the toolchain is to be build. Mode
   could be optimization (-O2) or debug (-g).
b. TIMELIMIT
   It is the time limit given to the user to respond to the questions prompted
   by build script during the toolchain building.
c. CPU
   The target CPU for which the user wants to build the toolchain.
   (sh/rx/h8300/m32c)
d. OBJ_FORMAT
   The object format of the output file the toolchain will be generating
   (i.e. elf/coff).
e. TOOLCHAIN_VERSION
   The version that user wants to assign to the toolchain. (e.g. v0501, v0701 etc.)
f. SOURCE_DIR_PATH
   The path of the <Source Directory>.
g. BUILD_DIR_PATH
   The path of the <Build Directory>.
h. PREFIX_DIR_PATH
   The path of the <Prefix Directory>.
i. PREFIX_DIR_PATH_ORIG
   The path where the native MingW and native RX ELF compilers are available.
j. BINUTILS_VERSION
   The version of the Binutils sources to be used.
k. GCC_VERSION
   The version of the GCC Sources to be used.
l. NEWLIB_VERSION
   The version of the Newlib Sources to be used.
m. BINUTILS_MINGW_NATIVE_VERSION
   The version of native MingW Binutils.
n. GCC_MINGW_NATIVE_VERSION
   The version of native MingW GCC.
o. MINGW_RUNTIME_VERSION
   The version of MingW RUNTIME .
   The RUNTIME is used to build the native compiler of the Windows.
p. W32API_VERSION
   The version of the W32API.
   W32API is used to build the native compiler of the Windows.
q. BINUTILS_RX_ELF_NATIVE_VERSION
   The version of native RX-ELF Binutils.
r. GCC_RX_ELF_NATIVE_VERSION
   The version of native RX-ELF GCC.
s. GCC_VERSION_INTERNAL
   This is the version string which can be used to override the default version
   string of the GCC compiler of the final toolchain to be build.
   e.g. 4.7-GNURX_v12.02
   (The version string is displayed on passing the  command line option
   "--version" to the compiler)
t. BINUTILS_VERSION_INTERNAL
   This is the version string which can be used to override the default version
   string of the binary utilities (ar, objcopy, size etc.) of the final toolchain
   to be build. e.g. 2.22-GNURX_v12.02
   (The version string is displayed on passing the  command line option
   "--version" to any of the binary utilities)
u. PREFIX_WGET_DIR_PATH
   Set the path of wget utility which is used to automatically download the
   sources if they are not present in the <Source Directory>.


The scripts necessary for toolchain building
--------------------------------------------
Along with the build script, four other scripts (timed_read, native-version,
remove_cygwin_includes and assign_version) are provided to use for toolchain
building. These scripts are necessary as those are called internally
by build script during the toolchain building. The purpose of each of these
scripts is given below
a. timed_read
   Counts down the timer from the value set by the build script varible
   "TIMELIMIT". This is the time length for which build script will wait for
   user's response to the questions prompted by it.
b. native-version
   This script compares user's native gcc version with version 2.95.3
   The GNURX ELF toolchain requires the native gcc version to be 2.95.3 or later.
c. remove_cygwin_includes
   Comments the cygwin includes from the newlib header files. This is required
   because, they generate lot of dependency scan errors in HEW.
d. assign-version
   It changes the version of the compiler and binary utilities to the version
   strings provided by user through build script. It assigns GCC_VERSION_INTERNAL
   as compiler's version and BINUTILS_VERSION_INTERNAL as binary utilities'
   version.


Procedure to build the Linux toolchain
--------------------------------------
1. Make sure that all the sources are properly extracted in the <Source Directory>.
2. Change build script to set the build enivronment variables.
3. Make sure that all the above mentioned build necessary scripts are present in
   the <Build Directory>.
4. Run the build script using the following command,
   $ sh <Build Script>

   The script prompts the following questions after starting its execution.
	a. Do you want to create the version files ([y]/n)?
	   - It calls the "assign_version" script to change the Binutils and
	   GCC versions to the version strings specified by the user through
	   build script.
	b. Do you want to change the Binutils version to
	   <BINUTILS_VERSION_INTERNAL> ([y]/n) ?
	   - Changes the version of the binary utilities according to the
	   version string set by build script variable BINUTILS_VERSION_INTERNAL.
	c. Do you want to change the Gcc version to <GCC_VERSION_INTERNAL>
	   ([y]/n) ?
	   - Changes the version of the GCC according to the version string set
	   by build script variable GCC_VERSION_INTERNAL.
	d. Do you want to create the makefile.in.diff patch file required for
	   mingw builds ([y]/n) ?
	   It creates a patch for protoize and unprotoize binary utilities.
	e. Do you want to remove the cygwin includes from newlib sources ([y]/n)?
	   - It removes the Cygwin includes from the newlib sources. This is
	   required to remove the scan dependency error from HEW.
	f. Do you want to reset the MAKEINFOFLAGS ([y]/n)?
	   - For resetting the MAKEINFOFLAGS from the Makefile.in file. This is to
	   be done only on the GNU/Linux where the makeinfo utility does not
	   support option --split-size.

5. After answering the above mentioned questions as per your requirements,
   it will proceed to build the toolchain. It first builds the Binutils, then
   core of the GCC compiler, then NEWLIB and finally builds the remaining GCC
   compiler. At each stage it ask user permission to proceed further. On crossing
   the default "TIMELIMIT" it assumes the user response as "YES" and proceeds
   further.
6. On successful completion of the building procedure, the toolchain will be
   installed in the following directory -
   <Prefix Directory>/gnu<CPU>_<TOOLCHAIN_VERSION>_<OBJ_FORMAT>-1
   e.g. /usr/share/gnurx_v12.02_elf-1


Procedure to build the MingW toolchain
--------------------------------------
1. The MingW toolchain can not be build directly without building the linux
   toolchain. Therefore the first step to build the MingW toolchain is to
   build the linux toolchain.

   However if you are building toolchain using cygwin, then you can directly
   build the Windows executables without building the linux toolchain. The first
   part of the build script which builds Linux toolchain on using Linux as
   building OS, builds the windows toolchain on cygwin. Therefore please ignore
   the statements where the script prompts Linux as its Build OS.
   e.g. "Do you want to Build Building the Linux - x -  <CPU-OBJ FORMAT>?"
   We recommend you to build MinW executables for windows for the following reason
   - Size of the executables is less in MingW compared to cygwin.
2. Once the linux toolchain is successfully built, the build script waits for
   user's permission to proceed to build the mingw toolchain.
3. Following the same stage sequence of toolchain building, it first builds the
   Binutils, then core of the GCC compiler, then NEWLIB and finally builds
   the remaining GCC compiler. At each stage it ask user permission to proceed
   further. On crossing the default "TIMELIMIT" it assumes the user response as
   "YES" and proceeds.
4. On successful completion of the build procedure, the toolchain will be
   installed in the following directory -
   <Prefix Directory>/mingwgnu<CPU>_<TOOLCHAIN_VERSION>_<OBJ_FORMAT>-1
   e.g. /usr/share/mingwgnurx_v12.02_elf-1
5. Please note that, the executables built by the MingW toolchain are the
   windows executables.


Note: The build variable values in the build script provided here, indicates
the build environment that we use at our end for successful building of the
Linux and Windows toolchains.
