[PC-BSD Dev] Automated PBI creation

Hi Guys,
I have been working on hacking the FreeBSD ports tree to allow easy PBI
creation via a "pbi" target. The idea goes something like this:
cd /usr/ports/audio/amarok; make pbi;
simple enough ?
I have gotten quite far with this. Currently the pbi target pulls only
dependencies that are listed as dependencies (and its dependencies...
and so on) and makes packages of them, copies them into a "pbi"
directory and extracts them.
This is about where I am stuck and need some more info. I am currently
going by the onlamp PBI creation tutorial as well as some poking around
currently PBI files. I have downloaded the PBICreator tool but am not
having luck running it from the command line. It still tries to connect
to an X server and bails out if it can't find one.
I am completely new to PBI creation and could use some more details on
the format if they are available. So far, I haven't found much. Is the
source code for PBICreator available ?
Any constructive criticism on the direction I am taking? =)
- John