This wikipage is work in progress (broken formatting, and out of date)

STEP 0 preparation

   1 sudo debootstrap sid sid-chroot
   2 sudo pbuilder login --no-targz --buildplace sid-chroot
   3 sed -i ’s/^deb http/deb [arch=amd64] http/‘ /etc/apt/sources.list
   4 echo “deb-src http://ftp.us.debian.org/debian sid main” >> /etc/apt/sources.list
   5 dpkg --add-architecture mips64el
   6 apt-get update
   7 apt-get install binutils-mips64el-linux-gnuabi64 devscripts rdfind symlinks

STEP 1 build gcc stage1

apt-get build-dep gcc-4.9
apt-get purge libx32* libc6-i386 libc6-x32  # they conflicts with mips64el multilib packages

downgrade all packages from gcc-4.9 to 4.9.2-3 i.e. before with_deps_on_target_arch_pkgs was removed: download them from snapshot.debian.org

dget http://snapshot.debian.org/archive/debian/20141126T040641Z/pool/main/g/gcc-4.9/gcc-4.9_4.9.2-3.dsc
cd gcc-4.9-4.9.2

enable with_deps_on_target_arch_pkgs in debian/rules.defs

Patch some files

in debian/rules.defs,
Enable gccbase for stage1 and cross,

change

   1 ifneq ($(DEB_STAGE),stage1)
   2   # build a -base package.
   3   ifneq ($(DEB_CROSS),yes)
   4     with_gccbase := yes
   5   else
   6     ifneq ($(with_deps_on_target_arch_pkgs),yes)
   7       with_gccxbase := yes
   8     else
   9       with_gccbase := yes
  10     endif
  11   endif
  12 endif
  13 

to:

  with_gccbase := yes

In debian/rules.conf,
Enable gccbase for stage1,

After

   1 ifdef DEB_STAGE
   2   languages = c
   3   addons = cdev plugindev

add

   1     ifeq ($(with_gccbase),yes)
   2     addons += gccbase
   3     endif
   4 

Then run command

with_deps_on_target_arch_pkgs=yes DH_VERBOSE=1 WITH_SYSROOT=/ BACKPORT=false PKG_IGNORE_CURRENTLY_BUILDING=1 DEB_BUILD_OPTIONS=nostrip DEB_STAGE=stage1 dpkg-buildpackage --target-arch=mips64el -b -uc -us -d

We can get these deb files:

cpp-4.9-mips64el-linux-gnuabi64_4.9.2-3_amd64.deb
gcc-4.9-multilib-mips64el-linux-gnuabi64_4.9.2-3_amd64.deb
libgcc-4.9-dev_4.9.2-3_mips64el.deb
gcc-4.9-mips64el-linux-gnuabi64_4.9.2-3_amd64.deb
lib32gcc-4.9-dev_4.9.2-3_mips64el.deb
libn32gcc-4.9-dev_4.9.2-3_mips64el.deb
gcc-4.9-base_4.9.2-3_mips64el.deb

rm ../gcc-4.9-multilib*.deb
dpkg -i ../*.deb

STEP 2 build linux-libc-dev

apt-get source linux; cd linux-*
make -f debian/rules.gen binary-libc-dev_mips64el
dpkg -i ../linux-libc-dev*.deb

STEP 3 glibc stage1

apt-get source glibc; cd glibc-*

change debian/sysdeps/linux.mk

from

ifndef LINUX_SOURCE
  ifeq ($(DEB_HOST_GNU_TYPE),$(DEB_BUILD_GNU_TYPE))
    LINUX_HEADERS := /usr/include
  else
    LINUX_HEADERS := /usr/$(DEB_HOST_GNU_TYPE)/include
  endif
  LINUX_ARCH_HEADERS := /usr/include/$(DEB_HOST_MULTIARCH)
else
  LINUX_HEADERS := $(LINUX_SOURCE)/include
endif

to:

ifndef LINUX_SOURCE
  LINUX_HEADERS := /usr/include
  LINUX_ARCH_HEADERS := /usr/include/$(DEB_HOST_MULTIARCH)
else
  LINUX_HEADERS := $(LINUX_SOURCE)/include
endif

Then run

   1 DEB_STAGE=stage1 DEB_GCC_VERSION=-4.9 dpkg-buildpackage -B -amips64el -d
   2 dpkg —force-all -i ../*.deb

FIXME: libc6-dev depends on libc6, while for stage1, we have no libc6,

STEP 4 gcc stage2

with_deps_on_target_arch_pkgs=yes DH_VERBOSE=1 WITH_SYSROOT=/ BACKPORT=false PKG_IGNORE_CURRENTLY_BUILDING=1 DEB_BUILD_OPTIONS=nostrip DEB_STAGE=stage2 dpkg-buildpackage --target-arch=mips64el -b -uc -us -d

on the same source with stage1 gcc.