Tools/portbuild for details. Note that this is still a major work in progress. I probably forgot something but I need to go to sleep. At least it works here (most of the time :).