├── .gitignore ├── README ├── build-binutils.sh ├── build-canadian.sh ├── build-elf.sh ├── build-gcc-bootstrap.sh ├── build-gcc-final.sh ├── build-libstdc++.sh ├── build-newlib.sh ├── build.sh ├── createinstaller.sh ├── download.sh ├── extract-source.sh ├── patch.sh └── patches ├── binutils └── 2.16.1a │ └── gprof-objc-fix.patch └── gcc ├── 3.4.6 └── collect2.c.patch ├── 4.0.0 └── collect2.patch ├── 4.9.1 └── 0010-color.patch └── 6.2.0 └── 960-fix-ubsan-defref.patch /.gitignore: -------------------------------------------------------------------------------- 1 | # Temporary directories 2 | download 3 | source 4 | build 5 | toolchain* 6 | installerpackage 7 | 8 | # Vim 9 | *.vim 10 | *.swp 11 | *.swo 12 | *.swn 13 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | | SEGA SATURN HITACHI SUPERH SH-2 GCC C COMPILER | 2 | 3 | |OVERVIEW| 4 | This is an optimised version of the GCC C compiler for Hitachi SuperH SH-2 5 | microprocessors. 6 | 7 | |BUILDING| 8 | Currently, only GNU/Linux and Windows are actively supported as build targets. 9 | Other operating systems may work with modification to the build files. If you 10 | have made changes to build on a non-supported operating system, please use 11 | GitHub to make a pull request. All new build platforms are very much 12 | appreciated. 13 | 14 | Mac OS X is supported by way of Misty De Meo. 15 | 16 | In order to successfully build GCC, the following environment variables need 17 | to be defined: 18 | export SRCDIR=$(pwd)/source 19 | export BUILDDIR=$(pwd)/build 20 | export TARGETMACH=sh-elf 21 | export BUILDMACH=x86_64-pc-linux-gnu 22 | export HOSTMACH=x86_64-pc-linux-gnu 23 | export INSTALLDIR=$(pwd)/toolchain 24 | export SYSROOTDIR=$INSTALLDIR/sysroot 25 | export ROOTDIR=$(pwd) 26 | export DOWNLOADDIR=$(pwd)/download 27 | export PROGRAM_PREFIX=saturn-sh2- 28 | 29 | PROGRAM_PREFIX is the prefix used before the tool's name, such as: 30 | saturn-sh2-gcc, where gcc is the program, with saturn-sh2- being the prefix. 31 | BUILDMACH is the development machine the compiler will run on. 32 | 33 | The HOSTMACH is the system architecture the compiler will run on, while the 34 | TARGETMARCH is the architecture the program or library created from the Saturn 35 | SH-2 compilerwill run on. 36 | 37 | BUILDMACH is used for cross-compiling, set it to the current machine's build 38 | architecture, and the HOSTMACH to the platform the generated compiler will run 39 | on. When not cross-compiling, set both HOSTMACH and BUILDMACH to the same 40 | value. 41 | 42 | Depending on the operating system the compiler is built on, additional tools 43 | may be required. For cross-compiling for Windows, MinGW-w64 (i686 or x86_64) 44 | will be required on GNU/Linux systems. 45 | 46 | There are no Windows batch files for compilation of the compiler on a native 47 | Windows install. MSYS with MinGW-w64 or Cygwin may work, though they have not 48 | been tested. 49 | 50 | SKIP_DOWNLOAD can be set to any string to skip the call to `download.sh`, for 51 | example if the dependency tarballs have already been downloaded using something 52 | else. 53 | 54 | 55 | After the environment variables are set, run build-elf.sh. 56 | -------------------------------------------------------------------------------- /build-binutils.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | 4 | [ -d $BUILDDIR/binutils ] && rm -rf $BUILDDIR/binutils 5 | 6 | mkdir -p $BUILDDIR/binutils 7 | cd $BUILDDIR/binutils 8 | 9 | export CFLAGS=${BINUTILS_CFLAGS} 10 | export CXXFLAGS="-s" 11 | 12 | $SRCDIR/binutils-${BINUTILSVER}/configure \ 13 | --disable-werror --host=$HOSTMACH --build=$BUILDMACH --target=$TARGETMACH \ 14 | --prefix=$INSTALLDIR --with-sysroot=$SYSROOTDIR \ 15 | --program-prefix=${PROGRAM_PREFIX} --disable-nls --enable-languages=c 16 | 17 | make -j${NCPU} 18 | make install -j${NCPU} 19 | -------------------------------------------------------------------------------- /build-canadian.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [[ "$HOSTMACH" == "$BUILDMACH" ]]; then 4 | echo "Build and host are the same. Building a cross compiler for one host/build architecture" 5 | ./build.sh 6 | exit $? 7 | fi 8 | 9 | if [ -z $INSTALLDIR_BUILD_TARGET ]; then 10 | INSTALLDIR_BUILD_TARGET=${INSTALLDIR}_build_target 11 | fi 12 | 13 | if [ -z $NCPU ]; then 14 | # Mac OS X 15 | if $(command -v sysctl >/dev/null 2>&1); then 16 | export NCPU=`sysctl -n hw.ncpu` 17 | # coreutils 18 | elif $(command -v nproc >/dev/null 2>&1); then 19 | export NCPU=`nproc` 20 | # fallback to non-parallel build if we still have no idea 21 | else 22 | export NCPU=1 23 | fi 24 | fi 25 | 26 | [ -d $INSTALLDIR ] && rm -rf $INSTALLDIR 27 | [ -d ${INSTALLDIR_BUILD_TARGET} ] && rm -rf ${INSTALLDIR_BUILD_TARGET} 28 | 29 | HOSTORIG=$HOSTMACH 30 | PREFIXORIG=$PROGRAM_PREFIX 31 | 32 | if [ -z $SKIP_DOWNLOAD ]; then 33 | ./download.sh 34 | 35 | if [ $? -ne 0 ]; then 36 | echo "Failed to retrieve the files necessary for building GCC" 37 | exit 1 38 | fi 39 | fi 40 | 41 | ./extract-source.sh 42 | 43 | if [ $? -ne 0 ]; then 44 | echo "Failed to extract the source files" 45 | exit 1 46 | fi 47 | 48 | ./patch.sh 49 | 50 | if [ $? -ne 0 ]; then 51 | echo "Failed to patch packages" 52 | exit 1 53 | fi 54 | 55 | # Build the cross compiler for the build 56 | # NOT IMPLEMENTED 57 | 58 | # Build the cross compiler for the target 59 | export HOSTMACH=$BUILDMACH 60 | export PROGRAM_PREFIX=${TARGETMACH}- 61 | CURRENT_COMPILER="${TARGETMACH} running on ${HOSTMACH}" 62 | #export PROGRAM_PREFIX=${PREFIXORIG} 63 | 64 | ./build-binutils.sh 65 | if [ $? -ne 0 ]; then 66 | echo "Failed to build binutils for ${CURRENT_COMPILER}" 67 | exit 1 68 | fi 69 | 70 | ./build-gcc-bootstrap.sh 71 | if [ $? -ne 0 ]; then 72 | echo "Failed to build GCC bootstrap for ${CURRENT_COMPILER}" 73 | exit 1 74 | fi 75 | 76 | ./build-newlib.sh 77 | if [ $? -ne 0 ]; then 78 | echo "Failed to build newlib for ${CURRENT_COMPILER}" 79 | exit 1 80 | fi 81 | 82 | ./build-gcc-final.sh 83 | 84 | if [ $? -ne 0 ]; then 85 | echo "Failed to build final GCC for ${CURRENT_COMPILER}" 86 | exit 1 87 | fi 88 | export PROGRAM_PREFIX=$PREFIXORIG 89 | 90 | mv ${INSTALLDIR} ${INSTALLDIR_BUILD_TARGET} 91 | 92 | export PATH=${INSTALLDIR_BUILD_TARGET}/bin:$PATH 93 | 94 | # Build the cross compiler for the target using the host to build 95 | export HOSTMACH=$HOSTORIG 96 | 97 | CURRENT_COMPILER="${TARGETMACH} running on ${HOSTMACH}" 98 | 99 | ./build-binutils.sh 100 | if [ $? -ne 0 ]; then 101 | echo "Failed to build binutils for ${CURRENT_COMPILER}" 102 | exit 1 103 | fi 104 | 105 | ./build-gcc-bootstrap.sh 106 | if [ $? -ne 0 ]; then 107 | echo "Failed to build GCC bootstrap for ${CURRENT_COMPILER}" 108 | exit 1 109 | fi 110 | 111 | export PROGRAM_PREFIX=${TARGETMACH}- 112 | ./build-newlib.sh 113 | if [ $? -ne 0 ]; then 114 | echo "Failed to build newlib for ${CURRENT_COMPILER}" 115 | exit 1 116 | fi 117 | export PROGRAM_PREFIX=$PREFIXORIG 118 | 119 | ./build-gcc-final.sh 120 | if [ $? -ne 0 ]; then 121 | echo "Failed to build final GCC for ${CURRENT_COMPILER}" 122 | exit 1 123 | else 124 | echo "Successfully built GCC for ${CURRENT_COMPILER}" 125 | fi 126 | 127 | -------------------------------------------------------------------------------- /build-elf.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | export BINUTILSVER=2.27 3 | export BINUTILSREV= 4 | export GCCVER=6.2.0 5 | export GCCREV= 6 | export NEWLIBVER=2.4.0 7 | export NEWLIBREV= 8 | export MPCVER=1.0.3 9 | export MPCREV= 10 | export MPFRVER=3.1.5 11 | export MPFRREV= 12 | export GMPVER=6.1.1 13 | export GMPREV= 14 | 15 | export OBJFORMAT=ELF 16 | 17 | export TARGETMACH=sh-elf 18 | 19 | if [ -z ${PROGRAM_PREFIX} ]; then 20 | export PROGRAM_PREFIX=saturn-sh2-elf- 21 | else 22 | export PROGRAM_PREFIX=${PROGRAM_PREFIX}elf- 23 | fi 24 | 25 | export BINUTILS_CFLAGS="-s" 26 | export GCC_BOOTSTRAP_FLAGS="--with-cpu=m2" 27 | export GCC_FINAL_FLAGS="--with-cpu=m2 --with-sysroot=$SYSROOTDIR" 28 | 29 | ./build.sh 30 | 31 | if [ $? -ne 0 ]; then 32 | echo "Failed to build the ELF toolchain" 33 | exit 1 34 | fi 35 | 36 | if [[ "${CREATEINSTALLER}" == "YES" ]]; then 37 | ./createinstaller.sh 38 | fi 39 | -------------------------------------------------------------------------------- /build-gcc-bootstrap.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | 4 | [ -d $BUILDDIR/gcc-bootstrap ] && rm -rf $BUILDDIR/gcc-bootstrap 5 | 6 | mkdir -p $BUILDDIR/gcc-bootstrap 7 | cd $BUILDDIR/gcc-bootstrap 8 | 9 | export PATH=$INSTALLDIR/bin:$PATH 10 | export CFLAGS="-s" 11 | export CXXFLAGS="-s" 12 | 13 | `realpath --relative-to=./ ${SRCDIR}/gcc-${GCCVER}`/configure \ 14 | --build=$BUILDMACH --host=$HOSTMACH --target=$TARGETMACH \ 15 | --prefix=$INSTALLDIR --without-headers --enable-bootstrap \ 16 | --enable-languages=c,c++ --disable-threads --disable-libmudflap \ 17 | --with-gnu-ld --with-gnu-as --with-gcc --disable-libssp --disable-libgomp \ 18 | --disable-nls --disable-shared --program-prefix=${PROGRAM_PREFIX} \ 19 | --with-newlib --disable-multilib --disable-libgcj \ 20 | --without-included-gettext --disable-libstdcxx \ 21 | ${GCC_BOOTSTRAP_FLAGS} 22 | 23 | #if [[ "${HOSTMACH}" != "${BUILDMACH}" ]]; then 24 | # # There should be a check for if gcc/auto-build.h exists 25 | # cp ./gcc/auto-host.h ./gcc/auto-build.h 26 | # mkdir gcc 27 | # cp $ROOTDIR/auto-host.h ./gcc/auto-build.h 28 | #fi 29 | 30 | make all-gcc -j${NCPU} 31 | make install-gcc -j${NCPU} 32 | 33 | make all-target-libgcc -j${NCPU} 34 | make install-target-libgcc -j${NCPU} 35 | 36 | -------------------------------------------------------------------------------- /build-gcc-final.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | 4 | [ -d $BUILDDIR/gcc-final ] && rm -rf $BUILDDIR/gcc-final 5 | 6 | mkdir $BUILDDIR/gcc-final 7 | cd $BUILDDIR/gcc-final 8 | 9 | #echo "libc_cv_forced_unwind=yes" > config.cache 10 | #echo "libc_ctors_header=yes" >> config.cache 11 | #echo "libc_cv_c_cleanup=yes" >> config.cache 12 | 13 | export CFLAGS="-s" 14 | export CXXFLAGS="-s" 15 | 16 | export PATH=$INSTALLDIR/bin:$PATH 17 | 18 | `realpath --relative-to=./ ${SRCDIR}/gcc-${GCCVER}`/configure \ 19 | --build=$BUILDMACH --target=$TARGETMACH --host=$HOSTMACH \ 20 | --prefix=$INSTALLDIR --enable-languages=c,c++ \ 21 | --with-gnu-as --with-gnu-ld --disable-shared --disable-threads \ 22 | --disable-multilib --disable-libmudflap --disable-libssp --enable-lto \ 23 | --disable-nls --with-newlib \ 24 | --program-prefix=${PROGRAM_PREFIX} ${GCC_FINAL_FLAGS} 25 | 26 | make -j${NCPU} 27 | make install -j${NCPU} 28 | 29 | -------------------------------------------------------------------------------- /build-libstdc++.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | 4 | [ -d $BUILDDIR/libstdc++ ] && rm -rf $BUILDDIR/libstdc++ 5 | 6 | mkdir -p $BUILDDIR/libstdc++ 7 | cd $BUILDDIR/libstdc++ 8 | 9 | export PATH=$INSTALLDIR/bin:$PATH 10 | export CROSS=${PROGRAM_PREFIX} 11 | export CC=${CROSS}gcc 12 | export CXX=${CROSS}g++ 13 | export CPP=${CROSS}cpp 14 | 15 | $SRCDIR/gcc-${GCCVER}/libstdc++-v3/configure \ 16 | --host=${TARGETMACH} --build=${BUILDMACH} --target=${TARGETMACH} --with-cross-host=${HOSTMACH} \ 17 | --prefix=${INSTALLDIR} --disable-nls --disable-multilib --disable-libstdcxx-threads \ 18 | --with-newlib --disable-libstdcxx-pch 19 | 20 | make 21 | #-j${NCPU} 22 | make install -j${NCPU} 23 | 24 | -------------------------------------------------------------------------------- /build-newlib.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | 4 | [ -d $BUILDDIR/newlib ] && rm -rf $BUILDDIR/newlib 5 | 6 | mkdir -p $BUILDDIR/newlib 7 | cd $BUILDDIR/newlib 8 | 9 | export PATH=$INSTALLDIR/bin:$PATH 10 | export CROSS=${PROGRAM_PREFIX} 11 | export CC_FOR_TARGET=${CROSS}gcc 12 | export LD_FOR_TARGET=${CROSS}ld 13 | export AS_FOR_TARGET=${CROSS}as 14 | export AR_FOR_TARGET=${CROSS}ar 15 | export RANLIB_FOR_TARGET=${CROSS}ranlib 16 | 17 | export newlib_cflags="${newlib_cflags} -DPREFER_SIZE_OVER_SPEED -D__OPTIMIZE_SIZE__" 18 | 19 | $SRCDIR/newlib-${NEWLIBVER}/configure --prefix=$INSTALLDIR \ 20 | --target=$TARGETMACH --build=$BUILDMACH --host=$HOSTMACH \ 21 | --enable-newlib-nano-malloc --enable-target-optspace 22 | 23 | make all -j${NCPU} 24 | make install -j${NCPU} 25 | -------------------------------------------------------------------------------- /build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | function print_environment_variable_usage 4 | { 5 | PRINT_USAGE="ALL" 6 | if [ -n "$1" ]; then 7 | PRINT_USAGE="$1" 8 | fi 9 | 10 | printf "\nEnvironment variable usage\n" 11 | printf "%s\n\n" "--------------------------" 12 | 13 | if [ "${PRINT_USAGE}" == "ALL" ] || [ "${PRINT_USAGE}" == "ROOTDIR" ]; then 14 | printf "ROOTDIR - The directory for the root of the build process\n" 15 | fi 16 | 17 | if [ "${PRINT_USAGE}" == "ALL" ] || [ "${PRINT_USAGE}" == "DOWNLOADDIR" ]; then 18 | printf "DOWNLOADDIR - The directory that contains the various required archive\n" 19 | printf " packages\n" 20 | fi 21 | 22 | if [ "${PRINT_USAGE}" == "ALL" ] || [ "${PRINT_USAGE}" == "SRCDIR" ]; then 23 | printf "SRCDIR - The directory that contains the extracted source files for\n" 24 | printf " each program used in the build process.\n" 25 | fi 26 | 27 | if [ "${PRINT_USAGE}" == "ALL" ] || [ "${PRINT_USAGE}" == "BUILDDIR" ]; then 28 | printf "BUILDDIR - The directory that contains the built program files\n" 29 | fi 30 | 31 | if [ "${PRINT_USAGE}" == "ALL" ] || [ "${PRINT_USAGE}" == "INSTALLDIR" ]; then 32 | printf "INSTALLDIR - The directory that contains all of the built program files\n" 33 | fi 34 | 35 | if [ "${PRINT_USAGE}" == "ALL" ] || [ "${PRINT_USAGE}" == "SYSROOTDIR" ]; then 36 | printf "SYSROOTDIR - The directory where the sysroot directory lives (typically,\n" 37 | printf " this should be set to \${INSTALLDIR}/sysroot)\n" 38 | fi 39 | 40 | if [ "${PRINT_USAGE}" == "ALL" ] || [ "${PRINT_USAGE}" == "TARGETMACH" ]; then 41 | printf "TARGETMACH - The architecture that the compiler is targetting\n" 42 | fi 43 | 44 | if [ "${PRINT_USAGE}" == "ALL" ] || [ "${PRINT_USAGE}" == "BUILDMACH" ]; then 45 | printf "BUILDMACH - The current machine's architecture for building the programs\n" 46 | fi 47 | 48 | if [ "${PRINT_USAGE}" == "ALL" ] || [ "${PRINT_USAGE}" == "HOSTMACH" ]; then 49 | printf "HOSTMACH - The architecture that the programs will run on\n" 50 | fi 51 | 52 | if [ "${PRINT_USAGE}" == "ALL" ] || [ "${PRINT_USAGE}" == "PROGRAM_PREFIX" ]; then 53 | printf "PROGRAM_PREFIX - The prefix used before the tool's name, such as:\n" 54 | printf " saturn-sh2-gcc, where gcc is the program, with saturn-sh2-\n" 55 | printf " being the prefix\n" 56 | fi 57 | } 58 | 59 | if [ -z ${ROOTDIR} ]; then 60 | printf "The environment variable \${ROOTDIR} was not set\n" 61 | print_environment_variable_usage "ROOTDIR" 62 | exit -1 63 | fi 64 | 65 | if [ -z ${DOWNLOADDIR} ]; then 66 | printf "The environment variable \${DOWNLOADDIR} was not set\n" 67 | print_environment_variable_usage "DOWNLOADDIR" 68 | exit -1 69 | fi 70 | 71 | if [ -z ${SRCDIR} ]; then 72 | printf "The environment variable \${SRCDIR} was not set\n" 73 | print_environment_variable_usage "SRCDIR" 74 | exit -1 75 | fi 76 | 77 | if [ -z ${BUILDDIR} ]; then 78 | printf "The environment variable \${BUILDDIR} was not set\n" 79 | print_environment_variable_usage "BUILDDIR" 80 | exit -1 81 | fi 82 | 83 | if [ -z ${INSTALLDIR} ]; then 84 | printf "The environment variable \${INSTALLDIR} was not set\n" 85 | print_environment_variable_usage "INSTALLDIR" 86 | exit -1 87 | fi 88 | 89 | if [ -z ${SYSROOTDIR} ]; then 90 | printf "The environment variable \${SYSROOTDIR} was not set\n" 91 | print_environment_variable_usage "SYSROOTDIR" 92 | exit -1 93 | fi 94 | 95 | if [ -z ${TARGETMACH} ]; then 96 | printf "The environment variable \${TARGETMACH} was not set\n" 97 | print_environment_variable_usage "TARGETMACH" 98 | exit -1 99 | fi 100 | 101 | if [ -z ${BUILDMACH} ]; then 102 | printf "The environment variable \${BUILDMACH} was not set\n" 103 | print_environment_variable_usage "BUILDMACH" 104 | exit -1 105 | fi 106 | 107 | if [ -z ${HOSTMACH} ]; then 108 | printf "The environment variable \${HOSTMACH} was not set\n" 109 | print_environment_variable_usage "HOSTMACH" 110 | exit -1 111 | fi 112 | 113 | if [ -z ${PROGRAM_PREFIX} ]; then 114 | printf "The environment variable \${PROGRAM_PREFIX} was not set\n" 115 | print_environment_variable_usage "PROGRAM_PREFIX" 116 | exit -1 117 | fi 118 | 119 | if [[ "$HOSTMACH" != "$BUILDMACH" ]]; then 120 | echo "Build and host are not the same. Building a Canadian-cross compiler" 121 | ./build-canadian.sh 122 | exit $? 123 | fi 124 | 125 | if [ -z $NCPU ]; then 126 | # Mac OS X 127 | if $(command -v sysctl >/dev/null 2>&1); then 128 | export NCPU=`sysctl -n hw.ncpu` 129 | # coreutils 130 | elif $(command -v nproc >/dev/null 2>&1); then 131 | export NCPU=`nproc` 132 | # fallback to non-parallel build if we still have no idea 133 | else 134 | export NCPU=1 135 | fi 136 | fi 137 | 138 | [ -d $INSTALLDIR ] && rm -rf $INSTALLDIR 139 | 140 | if [ -z $SKIP_DOWNLOAD]; then 141 | ./download.sh 142 | 143 | if [ $? -ne 0 ]; then 144 | echo "Failed to retrieve the files necessary for building GCC" 145 | exit 1 146 | fi 147 | fi 148 | 149 | ./extract-source.sh 150 | 151 | if [ $? -ne 0 ]; then 152 | echo "Failed to extract the source files necessary for building GCC" 153 | exit 1 154 | fi 155 | 156 | ./patch.sh 157 | 158 | if [ $? -ne 0 ]; then 159 | echo "Failed to patch packages" 160 | exit 1 161 | fi 162 | 163 | ./build-binutils.sh 164 | 165 | if [ $? -ne 0 ]; then 166 | echo "Failed building binutils" 167 | exit 1 168 | fi 169 | 170 | ./build-gcc-bootstrap.sh 171 | 172 | if [ $? -ne 0 ]; then 173 | echo "Failed building the bootstrap phase of GCC" 174 | exit 1 175 | fi 176 | 177 | ./build-newlib.sh 178 | 179 | if [ $? -ne 0 ]; then 180 | echo "Failed building newlib" 181 | exit 1 182 | fi 183 | 184 | ./build-libstdc++.sh 185 | 186 | if [ $? -ne 0 ]; then 187 | echo "Failed building libstdc++" 188 | exit 1 189 | fi 190 | 191 | ./build-gcc-final.sh 192 | 193 | if [ $? -ne 0 ]; then 194 | echo "Failed building the final version of GCC" 195 | exit 1 196 | fi 197 | 198 | -------------------------------------------------------------------------------- /createinstaller.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | 4 | export TAG_NAME=`git describe --tags | sed -e 's/_[0-9].*//'` 5 | export VERSION_NUM=`git describe --match "${TAG_NAME}_[0-9]*" HEAD | sed -e 's/-g.*//' -e "s/${TAG_NAME}_//"` 6 | export MAJOR_BUILD_NUM=`echo $VERSION_NUM | sed 's/-[^.]*$//' | sed -r 's/.[^.]*$//' | sed -r 's/.[^.]*$//'` 7 | export MINOR_BUILD_NUM=`echo $VERSION_NUM | sed 's/-[^.]*$//' | sed -r 's/.[^.]*$//' | sed -r 's/.[.]*//'` 8 | export REVISION_BUILD_NUM=`echo $VERSION_NUM | sed 's/-[^.]*$//' | sed -r 's/.*(.[0-9].)//'` 9 | export BUILD_NUM=`echo $VERSION_NUM | sed -e 's/[0-9].[0-9].[0-9]//' -e 's/-//'` 10 | 11 | if [ -z $TAG_NAME ]; then 12 | TAG_NAME=unknown 13 | fi 14 | 15 | if [ -z $MAJOR_BUILD_NUM ]; then 16 | MAJOR_BUILD_NUM=0 17 | fi 18 | 19 | if [ -z $MINOR_BUILD_NUM ]; then 20 | MINOR_BUILD_NUM=0 21 | fi 22 | 23 | if [ -z $REVISION_BUILD_NUM ]; then 24 | REVISION_BUILD_NUM=0 25 | fi 26 | 27 | if [ -z $BUILD_NUM ]; then 28 | BUILD_NUM=0 29 | fi 30 | 31 | mkdir -p $ROOTDIR/installerpackage/{org.opengamedevelopers.sega.saturn.sdk.gcc/{data,meta},config} 32 | 33 | cat > $ROOTDIR/installerpackage/org.opengamedevelopers.sega.saturn.sdk.gcc/meta/package.xml << __EOF__ 34 | 35 | 36 | SEGA Saturn SDK GCC ${GCCVER} 37 | GCC ${GCCVER} optimised for the SEGA Saturn Hitachi SH-2 [${OBJFORMAT}]. Host compiler: $HOSTMACH 38 | ${MAJOR_BUILD_NUM}.${MINOR_BUILD_NUM}.${REVISION_BUILD_NUM}.${BUILD_NUM} 39 | org.opengamedevelopers.sega.saturn.sdk.gcc 40 | `git log --pretty=format:"%ci" -1 | sed -e 's/ [^ ]*$//g'` 41 | 42 | 43 | 44 | 45 | __EOF__ 46 | 47 | wget -c -O $ROOTDIR/installerpackage/org.opengamedevelopers.sega.saturn.sdk.gcc/meta/gplv3.txt https://www.gnu.org/licenses/gpl-3.0.txt 48 | 49 | printf "Packaging $INSTALLDIR ... " 50 | $QTIFWDIR/bin/archivegen $ROOTDIR/installerpackage/org.opengamedevelopers.sega.saturn.sdk.gcc/data/directory.7z $INSTALLDIR 51 | if [ $? -ne "0" ]; then 52 | printf "FAILED\n" 53 | exit 1 54 | fi 55 | 56 | printf "OK\n" 57 | 58 | rm -rf $ROOTDIR/installerpackage/gcc 59 | 60 | $QTIFWDIR/bin/repogen -p $ROOTDIR/installerpackage -i org.opengamedevelopers.sega.saturn.sdk.gcc $ROOTDIR/installerpackage/gcc 61 | 62 | -------------------------------------------------------------------------------- /download.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | if [ ! -d $DOWNLOADDIR ]; then 3 | mkdir -p $DOWNLOADDIR 4 | fi 5 | 6 | cd $DOWNLOADDIR 7 | 8 | if test "`curl -V`"; then 9 | FETCH="curl -f -L -O -C -" 10 | elif test "`wget -V`"; then 11 | FETCH="wget -c" 12 | else 13 | echo "Could not find either curl or wget, please install either one to continue" 14 | exit 1 15 | fi 16 | 17 | if test "`parallel -V`"; then 18 | PARALLEL="TRUE" 19 | else 20 | PARALLEL="FALSE" 21 | fi 22 | 23 | if [[ "$PARALLEL" == "FALSE" ]]; then 24 | $FETCH https://ftp.gnu.org/gnu/gnu-keyring.gpg 25 | 26 | $FETCH https://ftp.gnu.org/gnu/binutils/binutils-${BINUTILSVER}${BINUTILSREV}.tar.bz2.sig 27 | $FETCH https://ftp.gnu.org/gnu/gcc/gcc-${GCCVER}${GCCREV}/gcc-${GCCVER}${GCCREV}.tar.bz2.sig 28 | 29 | $FETCH https://ftp.gnu.org/gnu/binutils/binutils-${BINUTILSVER}${BINUTILSREV}.tar.bz2 30 | $FETCH https://ftp.gnu.org/gnu/gcc/gcc-${GCCVER}${GCCREV}/gcc-${GCCVER}${GCCREV}.tar.bz2 31 | $FETCH https://sourceware.org/pub/newlib/newlib-${NEWLIBVER}${NEWLIBREV}.tar.gz 32 | if [ -n "${MPCVER}" ]; then 33 | $FETCH https://ftp.gnu.org/gnu/mpc/mpc-${MPCVER}${MPCREV}.tar.gz.sig 34 | $FETCH https://ftp.gnu.org/gnu/mpc/mpc-${MPCVER}${MPCREV}.tar.gz 35 | fi 36 | if [ -n "${MPFRVER}" ]; then 37 | $FETCH https://ftp.gnu.org/gnu/mpfr/mpfr-${MPFRVER}${MPFRREV}.tar.bz2.sig 38 | $FETCH https://ftp.gnu.org/gnu/mpfr/mpfr-${MPFRVER}${MPFRREV}.tar.bz2 39 | fi 40 | if [ -n "${GMPVER}" ]; then 41 | $FETCH https://gmplib.org/download/gmp/gmp-${GMPVER}${GMPREV}.tar.bz2.sig 42 | $FETCH https://gmplib.org/download/gmp/gmp-${GMPVER}${GMPREV}.tar.bz2 43 | fi 44 | else 45 | echo "https://ftp.gnu.org/gnu/gnu-keyring.gpg" > downloadlist.txt 46 | echo "https://ftp.gnu.org/gnu/binutils/binutils-${BINUTILSVER}${BINUTILSREV}.tar.bz2.sig" >> downloadlist.txt 47 | echo "https://ftp.gnu.org/gnu/gcc/gcc-${GCCVER}${GCCREV}/gcc-${GCCVER}${GCCREV}.tar.bz2.sig" >> downloadlist.txt 48 | echo "https://ftp.gnu.org/gnu/binutils/binutils-${BINUTILSVER}${BINUTILSREV}.tar.bz2" >> downloadlist.txt 49 | echo "https://ftp.gnu.org/gnu/gcc/gcc-${GCCVER}${GCCREV}/gcc-${GCCVER}${GCCREV}.tar.bz2" >> downloadlist.txt 50 | echo "ftp://sourceware.org/pub/newlib/newlib-${NEWLIBVER}${NEWLIBREV}.tar.gz" >> downloadlist.txt 51 | 52 | if [ -n "${MPCVER}" ]; then 53 | echo "https://ftp.gnu.org/gnu/mpc/mpc-${MPCVER}${MPCREV}.tar.gz.sig" >> downloadlist.txt 54 | echo "https://ftp.gnu.org/gnu/mpc/mpc-${MPCVER}${MPCREV}.tar.gz" >> downloadlist.txt 55 | fi 56 | 57 | if [ -n "${MPFRVER}" ]; then 58 | echo "https://ftp.gnu.org/gnu/mpfr/mpfr-${MPFRVER}${MPFRREV}.tar.bz2.sig" >> downloadlist.txt 59 | echo "https://ftp.gnu.org/gnu/mpfr/mpfr-${MPFRVER}${MPFRREV}.tar.bz2" >> downloadlist.txt 60 | fi 61 | 62 | if [ -n "${GMPVER}" ]; then 63 | echo "https://gmplib.org/download/gmp/gmp-${GMPVER}${GMPREV}.tar.bz2.sig" >> downloadlist.txt 64 | echo "https://gmplib.org/download/gmp/gmp-${GMPVER}${GMPREV}.tar.bz2" >> downloadlist.txt 65 | fi 66 | 67 | cat downloadlist.txt | parallel -j 10 --progress --gnu $FETCH 68 | fi 69 | 70 | # GPG return status 71 | # 1 == bad signature 72 | # 2 == no file 73 | gpg --verify --keyring ./gnu-keyring.gpg binutils-${BINUTILSVER}${BINUTILSREV}.tar.bz2.sig 74 | if [ $? -ne 0 ]; then 75 | if [ $? -ne 0 ]; then 76 | echo "Failed to verify GPG signature for binutils" 77 | exit 1 78 | fi 79 | fi 80 | 81 | gpg --verify --keyring ./gnu-keyring.gpg gcc-${GCCVER}${GCCREV}.tar.bz2.sig 82 | if [ $? -ne 0 ]; then 83 | if [ $? -ne 0 ]; then 84 | echo "Failed to verify GPG signautre for gcc" 85 | exit 1 86 | fi 87 | fi 88 | 89 | if [ -n "${MPCVER}" ]; then 90 | gpg --verify --keyring ./gnu-keyring.gpg mpc-${MPCVER}${MPCREV}.tar.gz.sig 91 | if [ $? -ne 0 ]; then 92 | if [ $? -ne 0 ]; then 93 | echo "Failed to verify GPG signautre for mpc" 94 | exit 1 95 | fi 96 | fi 97 | fi 98 | 99 | if [ -n "${MPFRVER}" ]; then 100 | gpg --verify --keyring ./gnu-keyring.gpg mpfr-${MPFRVER}${MPFRREV}.tar.bz2.sig 101 | if [ $? -ne 0 ]; then 102 | if [ $? -ne 0 ]; then 103 | echo "Failed to verify GPG signautre for mpfr" 104 | exit 1 105 | fi 106 | fi 107 | fi 108 | 109 | -------------------------------------------------------------------------------- /extract-source.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo "Extracting source files..." 4 | 5 | if [ ! -d $SRCDIR ]; then 6 | mkdir -p $SRCDIR 7 | fi 8 | 9 | cd $SRCDIR 10 | 11 | if [ ! -d binutils-${BINUTILSVER} ]; then 12 | tar xvjpf $DOWNLOADDIR/binutils-${BINUTILSVER}${BINUTILSREV}.tar.bz2 13 | if [ $? -ne 0 ]; then 14 | rm -rf binutils-${BINUTILSVER} 15 | exit 1 16 | fi 17 | cd $SRCDIR 18 | fi 19 | 20 | if [ ! -d gcc-${GCCVER} ]; then 21 | tar xvjpf $DOWNLOADDIR/gcc-${GCCVER}${GCCREV}.tar.bz2 22 | if [ $? -ne 0 ]; then 23 | rm -rf gcc-${GCCVER} 24 | exit 1 25 | fi 26 | fi 27 | 28 | if [ ! -d newlib-${NEWLIBVER} ]; then 29 | tar xvzpf $DOWNLOADDIR/newlib-${NEWLIBVER}${NEWLIBREV}.tar.gz 30 | if [ $? -ne 0 ]; then 31 | rm -rf newlib-${NEWLIBVER} 32 | exit 1 33 | fi 34 | fi 35 | 36 | if [ -n "${MPCVER}" ]; then 37 | if [ ! -d mpc-${MPCVER} ]; then 38 | tar xvpf $DOWNLOADDIR/mpc-${MPCVER}${MPCREV}.tar.gz 39 | if [ $? -ne 0 ]; then 40 | rm -rf mpc-${MPCVER} 41 | exit 1 42 | fi 43 | fi 44 | cp -rv mpc-${MPCVER} gcc-${GCCVER}/mpc 45 | fi 46 | 47 | if [ -n "${MPFRVER}" ]; then 48 | if [ ! -d mpfr-${MPFRVER} ]; then 49 | tar xvjpf $DOWNLOADDIR/mpfr-${MPFRVER}${MPFRREV}.tar.bz2 50 | if [ $? -ne 0 ]; then 51 | rm -rf mpfr-${MPFRVER} 52 | exit 1 53 | fi 54 | fi 55 | cp -rv mpfr-${MPFRVER} gcc-${GCCVER}/mpfr 56 | fi 57 | 58 | if [ -n "${GMPVER}" ]; then 59 | if [ ! -d gmp-${GMPVER} ]; then 60 | tar xvjpf $DOWNLOADDIR/gmp-${GMPVER}${GMPREV}.tar.bz2 61 | if [ $? -ne 0 ]; then 62 | rm -rf gmp-${GMPVER} 63 | exit 1 64 | fi 65 | fi 66 | cp -rv gmp-${GMPVER} gcc-${GCCVER}/gmp 67 | fi 68 | 69 | echo "Done" 70 | -------------------------------------------------------------------------------- /patch.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [ -d $ROOTDIR/patches/binutils/${BINUTILSVER}${BINUTILSREV} ]; then 4 | cd $SRCDIR 5 | for file in $ROOTDIR/patches/binutils/${BINUTILSVER}${BINUTILSREV}/*.patch; do 6 | patch -Np1 -i $file 7 | if [ $? -eq 0 ]; then 8 | echo "Patched ${file}" 9 | elif [ $? -eq 1 ]; then 10 | echo "Already applied patch ${file}" 11 | else 12 | echo "Failed to apply patch ${file}" 13 | exit 1 14 | fi 15 | done 16 | fi 17 | 18 | if [ -d $ROOTDIR/patches/gcc/${GCCVER}${GCCREV} ]; then 19 | cd $SRCDIR 20 | for file in $ROOTDIR/patches/gcc/${GCCVER}${GCCREV}/*.patch; do 21 | patch -Np1 -i $file 22 | if [ $? -eq 0 ]; then 23 | echo "Patched ${file}" 24 | elif [ $? -eq 1 ]; then 25 | echo "Already applied patch ${file}" 26 | else 27 | echo "Failed to apply patch ${file}" 28 | exit 1 29 | fi 30 | done 31 | fi 32 | 33 | exit 0 34 | -------------------------------------------------------------------------------- /patches/binutils/2.16.1a/gprof-objc-fix.patch: -------------------------------------------------------------------------------- 1 | --- a/binutils-2.16.1/gprof/Makefile.in 2004-11-30 17:20:48.000000000 +0000 2 | +++ b/binutils-2.16.1/gprof/Makefile.in 2014-06-10 16:36:49.528576822 +0100 3 | @@ -263,7 +263,7 @@ 4 | $(MAKE) $(AM_MAKEFLAGS) all-recursive 5 | 6 | .SUFFIXES: 7 | -.SUFFIXES: .m .c .dvi .html .info .lo .o .obj .pdf .ps .texi 8 | +.SUFFIXES: .c .dvi .html .info .lo .o .obj .pdf .ps .texi 9 | am--refresh: 10 | @: 11 | $(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps) 12 | -------------------------------------------------------------------------------- /patches/gcc/3.4.6/collect2.c.patch: -------------------------------------------------------------------------------- 1 | --- a/gcc-3.4.6/gcc/collect2.c 2005-01-10 15:25:23.000000000 +0000 2 | +++ b/gcc-3.4.6/gcc/collect2.c 2014-06-10 16:49:08.314622023 +0100 3 | @@ -1534,7 +1534,7 @@ 4 | if (redir) 5 | { 6 | /* Open response file. */ 7 | - redir_handle = open (redir, O_WRONLY | O_TRUNC | O_CREAT); 8 | + redir_handle = open (redir, O_WRONLY | O_TRUNC | O_CREAT, 0666); 9 | 10 | /* Duplicate the stdout and stderr file handles 11 | so they can be restored later. */ 12 | -------------------------------------------------------------------------------- /patches/gcc/4.0.0/collect2.patch: -------------------------------------------------------------------------------- 1 | --- a/gcc-4.0.0/gcc/collect2.c 2005-01-18 11:36:01.000000000 +0000 2 | +++ b/gcc-4.0.0/gcc/collect2.c 2014-06-22 19:37:01.153187105 +0100 3 | @@ -1574,7 +1574,7 @@ 4 | if (redir) 5 | { 6 | /* Open response file. */ 7 | - redir_handle = open (redir, O_WRONLY | O_TRUNC | O_CREAT); 8 | + redir_handle = open (redir, O_WRONLY | O_TRUNC | O_CREAT, 0666); 9 | 10 | /* Duplicate the stdout and stderr file handles 11 | so they can be restored later. */ 12 | -------------------------------------------------------------------------------- /patches/gcc/4.9.1/0010-color.patch: -------------------------------------------------------------------------------- 1 | --- a/gcc-4.9.1/gcc/diagnostic-color.c 2 | +++ b/gcc-4.9.1/gcc/diagnostic-color.c 3 | @@ -263,14 +263,6 @@ 4 | return true; 5 | } 6 | 7 | -#if defined(_WIN32) 8 | -bool 9 | -colorize_init (diagnostic_color_rule_t) 10 | -{ 11 | - return false; 12 | -} 13 | -#else 14 | - 15 | /* Return true if we should use color when in auto mode, false otherwise. */ 16 | static bool 17 | should_colorize (void) 18 | @@ -298,4 +290,3 @@ 19 | gcc_unreachable (); 20 | } 21 | } 22 | -#endif 23 | -------------------------------------------------------------------------------- /patches/gcc/6.2.0/960-fix-ubsan-defref.patch: -------------------------------------------------------------------------------- 1 | --- a/gcc-6.2.0/gcc/ubsan.c 2 | +++ b/gcc-6.2.0/gcc/ubsan.c 3 | @@ -1471,7 +1471,7 @@ ubsan_use_new_style_p (location_t loc) 4 | 5 | expanded_location xloc = expand_location (loc); 6 | if (xloc.file == NULL || strncmp (xloc.file, "\1", 2) == 0 7 | - || xloc.file == '\0' || xloc.file[0] == '\xff' 8 | + || xloc.file[0] == '\0' || xloc.file[0] == '\xff' 9 | || xloc.file[1] == '\xff') 10 | return false; 11 | 12 | --------------------------------------------------------------------------------