#!/bin/sh
# Hello emacs, this is a -*- sh -*- script
#  Script for building a MinGW cross compiler on GNU/Linux
#
# by Paul Millar <paulm@astro.gla.ac.uk> based info from Pieter Thysebaert
#  -- This script is available under terms and conditions of BSD license. --
#
# some minor modifications done by Heiko Gerdau (hg@technosis.de)
# and Keith Marshall <keith.d.marshall@ntlworld.com>
#
# it is currently maintained by Michael Gerdau (mgd@technosis.de)
#

__me=$(basename "$0")

##
##  Parameters
##

#
#  Directories:--
#    PACKAGE_DIR is where we saved the downloaded tarballs;
#    BUILD_ROOT is a temporary location for the build, (will be created if it doesn't exist, will be removed when done unless do_clean=0 below);
#    PREFIX is the root of the compiler's installation tree.
#
PACKAGE_DIR=$HOME/ftp/mingw
BUILD_ROOT=$HOME/src/mingw
PREFIX=$HOME/mingw
#
#  Package Versions:--
#
GCC_VERSION="3.4.5-20060117-1"
BINUTILS_VERSION="2.16.91-20060119-1"
#BINUTILS_VERSION="2.17.50-20060824-1"
W32API_VERSION="3.7"
#RUNTIME_VERSION="3.10"
RUNTIME_VERSION="3.10-20060909-1"

EXTRACTGZ="tar xzf"
EXTRACTBZ2="tar xjf"
EXTGZ="-src.tar.gz"
EXTBZ2=".tar.bz2"

if [ -e $PACKAGE_DIR/gcc-core-${GCC_VERSION}${EXTBZ2} ]; then echo "$__me: Using tar.bz2"; EXT=${EXTBZ2}; EXTRACTCMD=${EXTRACTBZ2}; else echo "$__me: Using tar.gz"; EXT=${EXTGZ}; EXTRACTCMD=${EXTRACTGZ}; fi

#
#  What we're trying to build.
TARGET=${1:-i686-pc-mingw32}
#TARGET=${1:-i586-mingw32}

LOCAL_BUILD_DIR=BUILD
PREFIX_TARGET="$(echo $PREFIX/$TARGET)"

echo $__me: Building $TARGET

# whether we use options etc. used by Danny Smith to create the Win32 native compiler or our own
# note that bootstrapping does not work when building a crosscompiler which means that building
# a x-compiler with this switch enabled most likely won't work (in other words: it is mostly
# used for testing)
use_danny=0

# enforce setjmp/longjmp exception handling
# using DW2 EH is not compatible with the minwg.org stock version of the compiler as of 3.4.4 -- does only apply when using exceptions
enable_sjlj_exceptions=0

# shall our compiler generate localized msgs ?
enable_nls=1

# we need 2-passes to create the C++ libraries since bootstrap does not work when building a crosscompiler
# Danny's version is supposed to work single pass; our needs 2-passes to create the C++ libraries
if [ $use_danny -eq 1 ]; then pass_count=1; else pass_count=2; fi

# If you have distcc installed and wish to use it for creating the xcompiler, try:
# (something similar should be possible for icecream)
#export CC="distcc ${CC}"
#export DISTCC_LOG=~/distcc.log
#export DISTCC_HOSTS="localhost node2 node3 node4"
#MAKE_PROCESS_COUNT=8

#
# some remarks on specifying --host=<host>, --target=<target> and --build=<build>
# kindly provided by Keith Marshall:
# 1) build
#    this is *always* the platform on which you are running the build
#    process; since we are building on Linux, this is unequivocally going to
#    specify `linux', with the canonical form being `i686-pc-linux-gnu'.
#
# 2) host
#    this is a tricky one: it specifies the platform on which whatever we
#    are building is going to be run; for the cross-compiler itself, that's
#    also `i686-pc-linux-gnu', but when we get to the stage of building the
#    runtime support libraries to go with that cross-compiler, they must
#    contain code which will run on the `i686-pc-mingw32' host, so the `host'
#    specification should change to this, for the `runtime' and `w32api'
#    stages of the build.
#
# 3) target
#    this is probably the one which causes the most confusion; it is only
#    relevant when building a cross-compiler, and it specifies where the code
#    which is built by that cross-compiler itself will ultimately run; it
#    should not need to be specified at all, for the `runtime' or `w32api',
#    since these are already targetted to `i686-pc-mingw32' by a correct
#    `host' specification.

#
# Location (& versions) of various files.
# For latest versions, see
#      http://sourceforge.net/project/showfiles.php?group_id=2435
GCC=$PACKAGE_DIR/gcc-core-${GCC_VERSION}${EXT}
GPP=$PACKAGE_DIR/gcc-g++-${GCC_VERSION}${EXT}
GOBJ=$PACKAGE_DIR/gcc-objc-${GCC_VERSION}${EXT}
G77=$PACKAGE_DIR/gcc-g77-${GCC_VERSION}${EXT}
#G77=$PACKAGE_DIR/gcc-fortran-${GCC_VERSION}${EXT}
GADA=$PACKAGE_DIR/gcc-ada-${GCC_VERSION}${EXT}
GJAVA=$PACKAGE_DIR/gcc-java-${GCC_VERSION}${EXT}
TESTSUITE=$PACKAGE_DIR/gcc-testsuite-${GCC_VERSION}${EXT}
BINUTILS=$PACKAGE_DIR/binutils-${BINUTILS_VERSION}${EXTGZ}
W32API=$PACKAGE_DIR/w32api-${W32API_VERSION}${EXTGZ}
RUNTIME=$PACKAGE_DIR/mingw-runtime-${RUNTIME_VERSION}${EXTGZ}

# if you want to apply a patch to GCC give the path here
# usually we want a unified diff, e.g. created by (inside the modified gcc dir):
#   diff -u ../gcc-3.4.4-20050522-1.orig/gcc/Makefile.in gcc/Makefile.in >gcc-core-3.4.4-20050522-1-src-fix1.patch
# GCC_PATCH is a whitespace separated list of patchset to be applied with "-p0 -l"
# !!! it probably requires less maintainence to cd into the gcc-* srcdir and apply the patchset with "-p1 -l"
#GCC_PATCH="patchset1 patchset2 patchset3"
GCC_PATCH=
#GCC_PATCH=$PACKAGE_DIR/cross/gcc-3.4.5-patches/fix-fixincl.patch
#GCC_PATCH=$PACKAGE_DIR/gcc-core-3.4.5-20060117-1-src-includepathfix.patch
#GCC_PATCH=$PACKAGE_DIR/gcc-core-3.4.4-20050522-1-src-fix1.patch
#GCC_PATCH="$PACKAGE_DIR/gcc-core-3.4.4-20050522-1-src-fix1.patch $PACKAGE_DIR/mingw-responsefiles-3.4.4.patch $PACKAGE_DIR/mingw-responsefiles-3.4.4-2.patch"
# apply this patch to original GNU binutils-2.16.1.tar.bz2
#BINUTILS_PATCH=$PACKAGE_DIR/binutils-${BINUTILS_VERSION}.patch
BINUTILS_PATCH=
W32API_PATCH=
#RUNTIME_PATCH=$PACKAGE_DIR/mingw-runtime-${RUNTIME_VERSION}.patch
#RUNTIME_PATCH="$PACKAGE_DIR/mingw-runtime-${RUNTIME_VERSION}.math_patch $PACKAGE_DIR/mingw-runtime-${RUNTIME_VERSION}.configure_patch"
RUNTIME_PATCH=$PACKAGE_DIR/mingw-runtime-${RUNTIME_VERSION}.math_patch

##
##  Shouldn't need to alter anything from here on...
##
##  ...but if you need to by-pass certain stages,...
##  ...or enable/disable specific languages,...
##  ...here where you do it
##

do_clean=1
do_binutils=1
do_headers=1
do_gcc=1
lang_cpp=1
lang_objc=0
lang_fortran=1
lang_ada=0
lang_java=0
do_api=1
do_runtime=1
# enable this if you wish to execute the gcc testsuite
# testsuite either does not work for crosscompiling or at least needs more work to get it working
do_testsuite=0
strip_libs=1

# gcc 3.x uses f77, gcc 4.x uses fortran
__gcc_majorver=$(echo $GCC_VERSION | sed -e "s/^\([0-9]\).*/\1/")
if [ $__gcc_majorver -eq 3 ]; then
  lang_f77=$lang_fortran
  lang_fortran=0
fi

###########################################################################################
function run_error () {
    task=$1
    echo "###############################################"
    echo "$__me: $(date): step '$task' has Returncode $2"
    echo "you possibly will wish to check config.log for details"
    echo "setting do_clean=0 (i.e.keep all files from now on)"
    echo "hit CTRL-C to abort"
    echo "###############################################"
    do_clean=0
    read -p "<ENTER>"
    return 0
}
###########################################################################################

MAKE="make ${MAKE_PROCESS_COUNT:+-j $MAKE_PROCESS_COUNT}"
# add path with newly created tools to front of path -- we don't wish to use any possibly existing older tools elsewhere on the path
PATH=$PREFIX/bin:$PATH
VERSION=$(echo $GCC_VERSION | sed -e "s/^\([0-9\.]\+\).*/\1/")

#
# Clean slate
if [ $do_clean -eq 1 ]; then
  echo "$__me: $(date): Step do_clean"
  rm -rf $BUILD_ROOT
fi

[ ! -d $BUILD_ROOT ] && mkdir -pv $BUILD_ROOT

for (( ; $pass_count; pass_count=$pass_count-1 ))
do
echo "$__me: $(date): starting another pass: remaining passes: $pass_count (including this one)"
#
#  Build binutils package
if [ $do_binutils -eq 1 ]; then
  echo "$__me: $(date): Step do_binutils $BINUTILS"
  cd $BUILD_ROOT
  $EXTRACTGZ $BINUTILS
#  echo $EXTRACTBZ2 $BINUTILS
#  $EXTRACTBZ2 $BINUTILS
  confopts="--with-gcc --with-gnu-as --with-gnu-ld"     # these should be the default anyway, i.e. they might be omitted
#  confopts="$confopts --disable-shared"        # why wouldn't we want shared libraries ?
#  confopts="$confopts --disable-nls"           # why wouldn't we want compiler diagnostics in national language (otherwise it would be american english) ?
  #
  # To create the crossversion of binutils we need to define a couple of environment variables
  # see also comments in crosstool-0.42/crosstool.sh (or newer)
  # GCC_HOST will be set later
  #export GCC_HOST
  #
  # Which compiler to use
  CC_OLD=$CC
  AR_OLD=$AR
  NM_OLD=$NM
  export CC="gcc"
  export AR="ar"
  export NM="nm"
  # these are not required as of now (2006-Aug-25) but that might change in the future
  #export AS="as"
  #export DLLTOOL="dlltool"
  #export LD="ld"
  #export LIPO="lipo"
  #export RANLIB="ranlib"
  #export STRIP="strip"
  #export WINDRES="windres"
  #export OBJCOPY="objcopy"
  #export OBJDUMP="objdump"
  # @@@
  # @@@ possibly more to follow
  # @@@

  if [ "${BINUTILS_PATCH}" ]; then cd binutils-*; for PATCH in ${BINUTILS_PATCH}; do pwd; echo "$__me: $(date): applying: patch -p1 -l < $PATCH"; patch -p1 -l < $PATCH; done; cd ..; fi

  if [ -e $LOCAL_BUILD_DIR-binutils ]; then rm -rf $LOCAL_BUILD_DIR-binutils; fi
  mkdir $LOCAL_BUILD_DIR-binutils && cd $LOCAL_BUILD_DIR-binutils
  BUILD_HOST=$(../binutils-*/config.guess)
#  export GCC_HOST=$BUILD_HOST
  echo "$__me: $(date): Building binutils: config.guess suggests building host is '$BUILD_HOST'"
  if [ $use_danny -eq 1 ]; then
    # this is how Danny Smith configures the win32 binutils distribution (using msys/cygwin)
#    ../binutils-*/configure --prefix=$PREFIX --host=$TARGET --target=$TARGET --build=mingw32 --disable-nls --with-gcc --with-gnu-as --with-gnu-ld --disable-shared
    ../binutils-*/configure --prefix=$PREFIX --target=$TARGET $confopts
    __err=$?
    if [ $__err -ge 1 ]; then run_error "configure binutils" "$__err"; fi
    $MAKE CFLAGS="-O2 -mtune=i686 -D__USE_CRTIMP -fno-exceptions" LDFLAGS=-s
    __err=$?
    if [ $__err -ge 1 ]; then run_error "make binutils" "$__err"; fi
    cd ../binutils-*
    sed -e "s/..\/build/..\/$LOCAL_BUILD_DIR-binutils/" <libaddr2line.mak >libaddr2line_p.mak
    $MAKE -f libaddr2line_p.mak
    __err=$?
    if [ $__err -ge 1 ]; then run_error "make binutils libaddr2line_p" "$__err"; fi
    cd ../$LOCAL_BUILD_DIR-binutils
  else
    # this should be sufficient (as all other options provided by Danny seem to be the default anyway)
#    ../binutils-*/configure --prefix=$PREFIX --target=$TARGET
    echo "$__me: $(date): calling '../binutils-*/configure --prefix=$PREFIX --target=$TARGET $confopts'"
    ../binutils-*/configure --prefix=$PREFIX --target=$TARGET $confopts
    __err=$?
    if [ $__err -ge 1 ]; then run_error "configure binutils" "$__err"; fi
    # CFLAGS containing -mtune=i686 doesn't work when creating a crosscompiler, at least on SuSE 9.3
    $MAKE CFLAGS="-O2 -D__USE_CRTIMP -fno-exceptions" LDFLAGS=-s
    __err=$?
    if [ $__err -ge 1 ]; then run_error "make binutils" "$__err"; fi
  fi
  $MAKE install

  cd $BUILD_ROOT
  if [ $do_clean -eq 1 ]; then rm -rf binutils-* $LOCAL_BUILD_DIR-binutils; fi
  # don't do binutils upon second pass
  do_binutils=0
  export CC=$CC_OLD
  export AR=$AR_OLD
  export NM=$NM_OLD
fi

#
#  Install include directories so components can compile
if [ $do_headers -eq 1 ]; then
  echo "$__me: $(date): Step do_headers $W32API"
  cd $BUILD_ROOT

  mkdir -vp $PREFIX_TARGET/include

  $EXTRACTGZ $W32API
  if [ "${W32API_PATCH}" ]; then cd w32api-*; for PATCH in ${W32API_PATCH}; do pwd; echo "$__me: $(date): applying: patch -p1 -l < $PATCH"; patch -p1 -l < $PATCH; done; cd ..; fi
  cp -r w32api-*/include/* $PREFIX_TARGET/include
  if [ $do_clean -eq 1 ]; then rm -rf w32api-*; fi

  $EXTRACTGZ $RUNTIME
  if [ "${RUNTIME_PATCH}" ]; then cd mingw-runtime-*; for PATCH in ${RUNTIME_PATCH}; do pwd; echo "$__me: $(date): applying: patch -p1 -l < $PATCH"; patch -p1 -l < $PATCH; done; cd ..; fi
  cp -r mingw-runtime-*/include/* $PREFIX_TARGET/include
  if [ $do_clean -eq 1 ]; then rm -rf mingw-runtime-*; fi
  # we don't have to install headers twice
  do_headers=0
fi


#
#  Build and install cross-compiling gcc `c' compiler only
if [ $do_gcc -eq 1 ]; then
  if [ $pass_count -eq 1 ]; then echo "$__me: $(date): Step do_gcc $GCC (incl. all additional languages)"; else echo "$__me: $(date): Step do_gcc $GCC (lang=c only)"; fi
  cd $BUILD_ROOT
  echo $EXTRACTCMD $GCC
  $EXTRACTCMD $GCC
#  $EXTRACTCMD $TESTSUITE
  langs=c
  confopts="--with-gcc --with-gnu-ld --with-gnu-as"     # these never hurt...
  confopts="$confopts --enable-threads=win32"           # we always want threaded libraries (on systems that support them)
#  confopts="$confopts --disable-shared"                # why wouldn't we want shared libraries ?
  confopts="$confopts --disable-win32-registry" # don't look up installation paths in the Windows registry
  if [ $enable_nls             -eq 0 ]; then confopts="$confopts --disable-nls"; fi             # why wouldn't we want compiler diagnostics in national language (otherwise it would be american english) ?
  if [ $enable_sjlj_exceptions -eq 1 ]; then confopts="$confopts --enable-sjlj-exceptions"; fi
  # on all but the last pass we only build c and nothing else
  if [ $pass_count -eq 1 ]; then
#    if [ $lang_cpp     -eq 1 ]; then echo $EXTRACTCMD $GPP  ; $EXTRACTCMD $GPP  ; langs=$langs,c++; confopts="$confopts --enable-libstdcxx-debug"; fi
    if [ $lang_cpp     -eq 1 ]; then echo $EXTRACTCMD $GPP  ; $EXTRACTCMD $GPP  ; langs=$langs,c++; fi
    if [ $lang_f77     -eq 1 ]; then echo $EXTRACTCMD $G77  ; $EXTRACTCMD $G77  ; langs=$langs,f77; fi
    if [ $lang_fortran -eq 1 ]; then echo $EXTRACTCMD $G77  ; $EXTRACTCMD $G77  ; langs=$langs,fortran; fi
    if [ $lang_ada     -eq 1 ]; then echo $EXTRACTCMD $GADA ; $EXTRACTCMD $GADA ; langs=$langs,ada; fi
    if [ $lang_objc    -eq 1 ]; then echo $EXTRACTCMD $GOBJ ; $EXTRACTCMD $GOBJ ; langs=$langs,objc; fi
    if [ $lang_java    -eq 1 ]; then echo $EXTRACTCMD $GJAVA; $EXTRACTCMD $GJAVA; langs=$langs,java; confopts="$confopts --enable-libgcj --disable-java-awt --enable-java-gc=boehm --disable-libgcj-debug --enable-interpreter --without-x --enable-hash-synchronization"; fi
    if [ $do_testsuite -eq 1 ]; then echo $EXTRACTCMD $TESTSUITE; $EXTRACTCMD $TESTSUITE; fi
  fi
  echo $__me: Building gcc: langs=$langs confopts=$confopts
  cd gcc-*
#  if [ "${GCC_PATCH}" ]; then for PATCH in ${GCC_PATCH}; do pwd; echo "$__me: $(date): applying: patch -p0 -l < $PATCH"; patch -p0 -l < $PATCH; done; fi
  if [ "${GCC_PATCH}" ]; then for PATCH in ${GCC_PATCH}; do pwd; echo "$__me: $(date): applying: patch -p1 -l < $PATCH"; patch -p1 -l < $PATCH; done; fi
  cd ..

  if [ -e $LOCAL_BUILD_DIR-gcc ]; then rm -rf $LOCAL_BUILD_DIR-gcc; fi
  mkdir $LOCAL_BUILD_DIR-gcc && cd $LOCAL_BUILD_DIR-gcc
  BUILD_HOST=$(../gcc-*/config.guess)
  echo "$__me: $(date): Building gcc: config.guess suggests building host is '$BUILD_HOST'"
  if [ $use_danny -eq 1 ]; then
    # this is how Danny Smith configures the win32 binary distribution
#    ../gcc/configure --with-gcc --with-gnu-ld --with-gnu-as --host=mingw32 --target=mingw32  --prefix=/mingw --enable-threads --disable-nls --enable-languages=c,c++,f77,ada,objc,java --disable-win32-registry --disable-shared --enable-sjlj-exceptions --enable-libgcj --disable-java-awt --without-x --enable-java-gc=boehm --disable-libgcj-debug --enable-interpreter --enable-hash-synchronization --enable-libstdcxx-debug
    ../gcc-*/configure --with-gcc --with-gnu-ld --with-gnu-as --target=$TARGET --prefix=$PREFIX --enable-languages=$langs $confopts
    __err=$?
    if [ $__err -ge 1 ]; then run_error "configure gcc langs=$langs" "$__err"; fi
    $MAKE CFLAGS="-O2 -fomit-frame-pointer" CXXFLAGS="-mthreads -fno-omit-frame-pointer -O2" LDFLAGS=-s bootstrap
    __err=$?
    if [ $__err -ge 1 ]; then run_error "make gcc langs=$langs" "$__err"; fi
    if [ $lang_ada  -eq 1 ]; then
      echo "***"
      echo "*** about to make gnatlib_and_tools"
      echo "***"
      $MAKE -C gcc CFLAGS=-O2 LDFLAGS=-s gnatlib_and_tools
      echo "***"
      echo "*** done with make gnatlib_and_tools"
      echo "***"
      ls -l
    fi
  else
    # this used to be mgd's cmd for gcc 3.4.4 and gcc 3.4.5
    # if want to use pool allocator add: --enable-libstdcxx-allocator=pool to configure
    echo "$__me: $(date): calling '../gcc-*/configure --prefix=$PREFIX --target=$TARGET --enable-languages=$langs $confopts'"
##    ../gcc-*/configure --prefix=/home/mgd/mingw --target=i586-mingw32 --enable-languages=c --with-gcc --with-gnu-ld --with-gnu-as --enable-threads --disable-win32-registry --enable-shared
    ../gcc-*/configure --prefix=$PREFIX --target=$TARGET --enable-languages=$langs $confopts
    # here a test to see whether we can reduce executable size
#    ../gcc-*/configure --prefix=$PREFIX --target=$TARGET --enable-languages=$langs $confopts
    __err=$?
    if [ $__err -ge 1 ]; then run_error "configure gcc langs=$langs" "$__err"; fi
    # add LDFLAGS=-s to strip symbols from created libraries
    $MAKE CFLAGS="-O2 -fomit-frame-pointer $cflags" CXXFLAGS="-mthreads -fno-omit-frame-pointer -O2" LDFLAGS=-s
    __err=$?
    if [ $__err -ge 1 ]; then run_error "make gcc langs=$langs" "$__err"; fi
    # run tests only after we have really made our compiler (i.e. during the last pass)
    if [ $pass_count -eq 1 ]; then
      if [ $do_testsuite -eq 1 ]; then
        echo "$__me: $(date): Executing testsuite via '$MAKE check'..."
        $MAKE -k check
        if [ $lang_cpp     -eq 1 ]; then echo "$__me: $(date): Executing ABI check for libstdc++ testsuite via '$MAKE check'..."; $MAKE -k -C $TARGET/libstdc++-v3 check-abi; fi
      fi
    fi
  fi

  $MAKE install
  cd $BUILD_ROOT
  if [ $do_clean -eq 1 ]; then rm -rf gcc-* $LOCAL_BUILD_DIR-gcc; fi
fi


unset CC

#
#  Install Windows API
if [ $do_api -eq 1 ]; then
  echo "$__me: $(date): Step do_api $W32API"
  cd $BUILD_ROOT

  if [ ! -d w32api-* ]; then
      $EXTRACTGZ $W32API
      if [ "${W32API_PATCH}" ]; then cd w32api-*; for PATCH in ${W32API_PATCH}; do pwd; echo "$__me: $(date): applying: patch -p1 -l < $PATCH"; patch -p1 -l < $PATCH; done; cd ..; fi
  fi

  mkdir $LOCAL_BUILD_DIR-w32api && cd $LOCAL_BUILD_DIR-w32api

  BUILD_HOST=$(../w32api-*/config.guess)
  echo "$__me: $(date): Building w32api: config.guess suggest building host is '$BUILD_HOST' but since we are building the mingw runtime libs which are run under mingw this has to be $TARGET; however we should not need to specify target"
  echo "$__me: $(date): calling '../w32api-*/configure --prefix=$PREFIX_TARGET --host=$TARGET'"
  ../w32api-*/configure --prefix=$PREFIX_TARGET --host=$TARGET
  __err=$?
  if [ $__err -ge 1 ]; then run_error "configure w32api" "$__err"; fi
  $MAKE CFLAGS="-O2 -D__USE_CRTIMP -fno-exceptions" LDFLAGS=-s
  __err=$?
  if [ $__err -ge 1 ]; then run_error "make w32api" "$__err"; fi
  $MAKE install

  cd $BUILD_ROOT
  if [ $do_clean -eq 1 ]; then rm -rf w32api-* $LOCAL_BUILD_DIR-w32api; fi
  # creating the API libs twice doesn't make them "better"
  do_api=0
fi


#
#  Build and install the mingw-runtime
if [ $do_runtime -eq 1 ]; then
  echo "$__me: $(date): Step do_runtime $RUNTIME, $W32API"
  cd $BUILD_ROOT
  if [ ! -d runtime-* ]; then
      $EXTRACTGZ $RUNTIME
      if [ "${RUNTIME_PATCH}" ]; then cd mingw-runtime-*; for PATCH in ${RUNTIME_PATCH}; do pwd; echo "$__me: $(date): applying: patch -p1 -l < $PATCH"; patch -p1 -l < $PATCH; done; cd ..; fi
  fi
  # hack to convert from DOS to UNIX lineendings (needed for version 3.9 and possibly above)
  find mingw-runtime-* -type f -a -perm +111 -execdir dos2unix '{}' ";"
  find mingw-runtime-* -amin -2 -execdir chmod a+x '{}' ";"
  [ ! -d w32api-* ] && $EXTRACTGZ $W32API
  mv w32api-* w32api

  mkdir $LOCAL_BUILD_DIR-mingw-runtime && cd $LOCAL_BUILD_DIR-mingw-runtime

  BUILD_HOST=$(../mingw-runtime-*/config.guess)
  echo "$__me: $(date): Building mingw-runtime: config.guess suggest building host is '$BUILD_HOST' but since we are building the mingw runtime libs which are run under mingw this has to be $TARGET; however we should not need to specify target"
  CC_OLD=$CC
  export CC="$TARGET-gcc"
  echo "$__me: $(date): calling '../mingw-runtime-*/configure --prefix=$PREFIX_TARGET --host=$TARGET'"
  ../mingw-runtime-*/configure --prefix=$PREFIX_TARGET --host=$TARGET
  __err=$?
  if [ $__err -ge 1 ]; then mv config.log ../config-runtime.log; run_error "configure runtime" "$__err"; fi

  $MAKE CFLAGS="-O2 -D__USE_CRTIMP -fno-exceptions" LDFLAGS=-s
  __err=$?
  if [ $__err -ge 1 ]; then run_error "make runtime" "$__err"; fi
  $MAKE install
  export CC="$CC_OLD"

  cd $BUILD_ROOT
  if [ $do_clean -eq 1 ]; then rm -rf mingw-runtime-* w32api $LOCAL_BUILD_DIR-mingw-runtime; fi
  # no need to build the runtime libs twice
  do_runtime=0
fi

done

#
#  strip dbginfo from libs and objects if asked to do so
#  !!! the above process will create all libs and objects with dbginfo included. As a result any
#  !!! dbgversion of created libs, dlls and exes will contain the dbginfo for the compiler provided
#  !!! libs as well which increases their sizes considerably and we don't want that most of the time.
if [ $strip_libs -eq 1 ]; then
  echo "$__me: $(date): Step strip_libs"
  cd $PREFIX
  echo "$__me: $(date): Sizes with dbginfo:"
  ls -l ./$TARGET/lib ./lib/gcc/$TARGET/$VERSION/*.[oa] ./lib/libiberty.a
  tar cjhf libs-$TARGET-$GCC_VERSION-unstripped.tar.bz2 ./$TARGET/lib ./lib/gcc/$TARGET/$VERSION/*.[oa] ./lib/libiberty.a
  ./bin/$TARGET-strip -g ./$TARGET/lib/*.[oa] ./lib/gcc/$TARGET/$VERSION/*.[oa] ./lib/libiberty.a
  echo -e "\n$__me: $(date): Sizes without dbginfo:"
  ls -l ./$TARGET/lib ./lib/gcc/$TARGET/$VERSION/*.[oa] ./lib/libiberty.a

fi

#-- EOF

PHP Warning

lib/XmlElement.php:43 Warning[2]: get_class() expects parameter 1 to be object, string given (...repeated 9 times)

lib/XmlElement.php (In template 'navbar' < 'top' < 'body' < 'html'):43 Warning[2]: get_class() expects parameter 1 to be object, string given:

lib/XmlElement.php (In template 'navbar' < 'top' < 'body' < 'html'):43 Warning[2]: get_class() expects parameter 1 to be object, string given:

Valid XHTML 1.0! Valid CSS!
Page Execution took real: 0.072, user: 0.050, sys: 0.000 seconds , Memory: 2518488

lib/XmlElement.php (In template 'actionbar' < 'browse-footer'):43 Warning[2]: get_class() expects parameter 1 to be object, string given:

lib/XmlElement.php (In template 'actionbar' < 'browse-footer'):43 Warning[2]: get_class() expects parameter 1 to be object, string given: