I suggest you take a look at the BLFS book online - it contains instructions to build all three of the packages you mentioned, although maybe not at their most current release, and things may have to be tweaked for your distro, since BLFS assumes an LFS system. Still, they should be useful as a starting point.
http://www.linuxfromscratch.org/blfs...3/BLFS-6.3.pdf
That's version 6.3 (the newest complete version), but you may want to see if there's another version on the Linux From Scratch site.