You can do it with mingw as well.
http://www.postgresql.org/docs/faqs.FAQ_MINGW.html
Tools for Building Binaries
The native Win32 port requires a 32-bit NT-based Microsoft operating system, like Windows NT 4, Windows 2000/2003, or Windows XP. (NT 4 is no longer supported since version 8.2) Earlier operating systems do not have sufficient infrastructure. Building the port also requires MinGW and Msys, which can be downloaded from http://www.mingw.org/. MinGW is a Unix-like build environment for Microsoft operating systems. Msys is a collection of unix tools required to run shell scripts like configure. Neither is required to run the resulting binaries; they are needed only for creating the binaries. Work is in progress to support building using Visual C++ in a future version.
Steps For Building Binaries
Download the nightly snapshot tarball from ftp://ftp.postgresql.org/pub/dev or checkout via CVS (you will need bison, flex, and perl installed to build from CVS)
Run configure (you might need to add the --without-zlib argument, depending on whether you have installed zlib on MinGW)
Run make install
Note: it is suggested that you run psql under CMD.EXE., as the Msys console has buffering issues.