Download the gcc 4.9 sources in some subdirectory, say gcc-4.9.
cd gcc-4.9
apt-get source gcc-4.9
Then
cd gcc-4.9-4.9.0/debian
Then put debian under version control. I use mercurial. This is an
optional step, but is useful if something goes wrong.
Clone this Mercurial repository containing a patch against the Debian packaging files repository. You can clone it in the debian directory. I.e.
gcc-4.9/gcc-4.9-4.9.0/debian$ hg clone https://bitbucket.org/faheem/gcc-4.9-debian-mq
gcc-4.9/gcc-4.9-4.9.0/debian$ patch -p1 < gcc-4.9-debian-mq/debian
patching file control
patching file rules.defs
patching file source/format
Now you can attempt a build. You'll need a few packages installed,
like build-essential, fakeroot and devscripts.
debuild -uc -us
This will probably fail if you don't have the necessary build
dependencies. So, install them; debuild will tell you what is
missing. With the patch you should be able to successfully resolve all
dependencies on wheezy.
NOTES: This patch may not continue to work for further updates of
gcc-4.9. For reference, here is the version I am patching
against. This is the first Debian package following the gcc 4.9 release on
2014-04-22.
Therefore, I'm including some notes about how the patch was generated,
so others can do this themselves. Please read through this. In
particular, note (5) may concern you even if you are not planning to
make your own patch.
debuild will complain about build dependencies not being
installed. Even after they are installed, debuild will complain about
the versions not being sufficiently recent. So, the simplest thing to
do is to remove the version numbers mentioned.
This is only strictly necessary if you are putting debian under
version control. For reasons I won't go into here, format 1 makes the
build fail if debian is under version control.
UPDATE: Finally got around to building i386 debs for gcc 4.9 (in an i386 chroot using schroot (see)), and installed those in tandem with the amd64 ones, because of the aforementioned multilib constraint. I'm still testing, but both g++ 4.7 and g++-4.9 compile the code I tested it with. The installation of gcc 4.9 debs isn't completely straightforward, because some of the common libraries for 4.7 and 4.9 need to be upgraded too, like libstdc++6.