echo "!!! {$file_system_root}/usr/ports/ not found.   Please run portsnap fetch extract\n";
    exit;
}
// Ensure that the All directory exists in packages staging area
if (!is_dir("{$file_system_root}/usr/ports/packages/All")) {
    system("mkdir -p {$file_system_root}/usr/ports/packages/All");
}
// Loop through all packages and build pacakge with
// build_options if the port/package has this defined.
foreach ($pkg['packages']['package'] as $pkg) {
    if (isset($options['p']) && strtolower($options['p']) != strtolower($pkg['name'])) {
        continue;
    }
    if ($pkg['build_port_path']) {
        foreach ($pkg['build_port_path'] as $build) {
            overlay_pfPort($build);
            $buildname = basename($build);
            if (isset($options['d'])) {
                $DESTDIR = "DESTDIR=/usr/pkg/{$buildname}";
                echo ">>> Using {$DESTDIR} \n";
            } else {
                $DESTDIR = "";
            }
            $build_options = "";
            if ($pkg['build_options']) {
                $build_options = $pkg['build_options'];
            }
            /*
            			if(file_exists("/var/db/ports/{$buildname}/options")) {
            				echo ">>> Using /var/db/ports/{$buildname}/options \n";
            				$portopts = split("\n", file_get_contents("/var/db/ports/{$buildname}/options"));
$j = 0;
foreach ($build_list as $build => $pbi_options) {
    $processes = 0;
    $counter = 0;
    $j++;
    overlay_pfPort($build);
    if (!empty($pbi_options['ports_before'])) {
        $overlay_list = explode(" ", $pbi_options['ports_before']);
        foreach ($overlay_list as $ol) {
            overlay_pfPort($ol);
        }
    }
    if (!empty($pbi_options['ports_after'])) {
        $overlay_list = explode(" ", $pbi_options['ports_after']);
        foreach ($overlay_list as $ol) {
            overlay_pfPort($ol);
        }
    }
    $buildname = basename($build);
    if (isset($options['d'])) {
        $DESTDIR = "DESTDIR=/usr/pkg/{$buildname}";
        echo ">>> [" . date("H:i:s") . "] Using {$DESTDIR} \n";
    } else {
        $DESTDIR = "";
    }
    /*
    	if(file_exists("/var/db/ports/{$buildname}/options")) {
    		echo ">>> Using /var/db/ports/{$buildname}/options \n";
    		$portopts = split("\n", file_get_contents("/var/db/ports/{$buildname}/options"));
    		foreach ($portopts as $po) {
    			if (substr($po, 0, 1) != '#')