First, make sure you have Mercurial installed on your machine, along with its requirements such as python.
Then, from the command line, you run
hg clone http://hg.netbeans.org/main/to get the full Platform and IDE sources. If you also want the contrib/ and misc/ repositories, it is best to first install the Forest extension for Mercurial, and then run
hg fclone http://hg.netbeans.org/main/ nb_all
To build, simply run Ant in the root of your NetBeans sources. The build will appear in $NB_SRC/nbbuild/netbeans/.