#!/usr/local/bin/php -qC
<?php

if (count($_SERVER["argv"]) < 3) {
   die("syntax: mergeplugins  config.php mergedplugins.php\n");
}

#-- read in config.php
$cnf = implode("", file($_SERVER["argv"][1]));
$outfn = $_SERVER["argv"][2];

#-- merge plugins
$out = "";
$cnf = preg_replace('/^\s*#.+$/m', "", $cnf);
preg_match_all('/(?:include|require)(?:_once)?\(["\'](plugin.+?)["\']\);/m', $cnf, $uu);
foreach ($uu[1] as $file) {
   if (strpos($file, "/db/")) { continue; }
   echo "+ $file\n";
   $out .= @implode("", file($file));
}

#-- write output file
$f = fopen($outfn, "w");
fwrite($f, $out);
fclose($f);

?>