php-src/pear/scripts/pearize.in

228 lines
4.2 KiB
Plaintext
Raw Normal View History

#!@prefix@/bin/php -Cq
<?php // -*- PHP -*-
main($argc, $argv);
// {{{ main()
function main(&$argc, &$argv)
{
2001-08-28 11:18:08 +00:00
global $debug;
$debug = false;
$file = check_options($argc, $argv);
2001-07-25 21:20:31 +00:00
parse_package_file($file);
make_makefile_in();
}
// }}}
// {{{ check_options()
function check_options($argc, $argv)
{
2001-08-28 11:18:08 +00:00
global $debug;
array_shift($argv);
while ($argv[0]{0} == '-' && $argv[0] != '-') {
$opt = array_shift($argv);
switch ($opt) {
case '--': {
break 2;
}
case '-d': {
$debug = true;
break;
}
default: {
die("pearize: unrecognized option `$opt'\n");
}
}
}
$file = array_shift($argv);
2001-07-25 21:20:31 +00:00
if (empty($file)) {
$file = "package.xml";
2001-08-28 11:18:08 +00:00
} elseif ($file == '-') {
$file = "php://stdin";
2001-07-25 21:20:31 +00:00
}
return $file;
}
// }}}
// {{{ make_makefile_in()
function make_makefile_in()
{
2001-08-28 11:18:08 +00:00
global $libdata, $debug;
if (sizeof($libdata) > 1) {
2001-07-25 21:20:31 +00:00
die("No support yet for multiple libraries in one package.\n");
}
2001-08-28 11:18:08 +00:00
if ($debug) {
$wp = fopen("php://stdout", "w");
} else {
$wp = @fopen("Makefile.in", "w");
}
2001-07-25 21:20:31 +00:00
if (is_resource($wp)) {
print "Creating Makefile.in...";
flush();
} else {
die("Could not create Makefile.in in current directory.\n");
}
if(!$user=getenv('USER')){
$user='defaultuser';
}
2001-08-28 11:18:08 +00:00
$when = gmdate('Y-m-d h:i');
fwrite($wp, "# This file was generated by `pearize' by $who at $when GMT\n\n");
2001-07-25 21:20:31 +00:00
foreach ($libdata as $lib => $info) {
extract($info);
2001-08-28 11:18:08 +00:00
fwrite($wp, "\
2001-07-25 21:20:31 +00:00
INCLUDES = $includes
LTLIBRARY_NAME = lib{$lib}.la
LTLIBRARY_SOURCES = $sources
LTLIBRARY_SHARED_NAME = {$lib}.la
LTLIBRARY_SHARED_LIBADD = $libadd
");
2001-08-28 11:18:08 +00:00
}
if (sizeof($libdata) > 0) {
2001-08-28 08:52:03 +00:00
fwrite($wp, "include \$(top_srcdir)/build/dynlib.mk\n");
2001-07-25 21:20:31 +00:00
}
fclose($wp);
print "done.\n";
}
// }}}
// {{{ parse_package_file()
function parse_package_file($file)
{
2001-07-25 21:20:31 +00:00
global $in_file, $curlib, $curelem, $libdata, $cdata;
2001-08-28 11:18:08 +00:00
global $currinstalldir, $baseinstalldir;
2001-07-25 21:20:31 +00:00
$in_file = false;
$curlib = '';
$curelem = '';
$libdata = array();
$cdata = array();
2001-08-28 11:18:08 +00:00
$baseinstalldir = array();
$currinstalldir = array();
2001-07-25 21:20:31 +00:00
$xp = xml_parser_create();
xml_set_element_handler($xp, "start_handler", "end_handler");
xml_set_character_data_handler($xp, "cdata_handler");
2002-01-31 08:19:34 +00:00
xml_parser_set_option($xp, XML_OPTION_CASE_FOLDING, false);
2001-07-25 21:20:31 +00:00
$fp = @fopen($file, "r");
if (!is_resource($fp)) {
die("Could not open file `$file'.\n");
}
while (!feof($fp)) {
xml_parse($xp, fread($fp, 2048), feof($fp));
}
xml_parser_free($xp);
}
// }}}
// {{{ start_handler()
function start_handler($xp, $elem, $attrs)
{
2001-08-28 11:18:08 +00:00
global $cdata, $in_file, $curelem, $curfile, $filerole;
global $baseinstalldir, $currinstalldir;
2001-07-25 21:20:31 +00:00
switch ($elem) {
2002-01-31 08:19:34 +00:00
case "file": {
2001-08-28 11:18:08 +00:00
$curfile = '';
2002-01-31 08:19:34 +00:00
$filerole = $attrs['role'];
2001-08-28 11:18:08 +00:00
switch ($filerole) {
2001-07-25 21:20:31 +00:00
case "ext": {
$in_file = true;
$cdata = array();
break;
}
case "php": default: {
break;
}
}
break;
}
2002-01-31 08:19:34 +00:00
case "dir": {
2001-08-28 11:18:08 +00:00
$cdir = $currinstalldir[sizeof($currinstalldir)-1];
$bdir = $baseinstalldir[sizeof($baseinstalldir)-1];
2002-01-31 08:19:34 +00:00
array_push($currinstalldir, "$cdir/{$attrs[name]}");
if (isset($attrs["baseinstalldir"])) {
array_push($baseinstalldir, "$bdir/{$attrs[baseinstalldir]}");
2001-08-28 11:18:08 +00:00
} else {
array_push($baseinstalldir, $bdir);
}
break;
}
2002-01-31 08:19:34 +00:00
case "includes":
case "libname":
case "libadd":
case "sources": {
2001-07-25 21:20:31 +00:00
$curelem = $elem;
break;
}
}
}
// }}}
// {{{ end_handler()
function end_handler($xp, $elem)
{
2001-07-25 21:20:31 +00:00
global $in_file, $curlib, $curelem, $libdata, $cdata;
2001-08-28 11:18:08 +00:00
global $baseinstalldir, $currinstalldir;
2001-07-25 21:20:31 +00:00
switch ($elem) {
2002-01-31 08:19:34 +00:00
case "file": {
2001-07-25 21:20:31 +00:00
if ($in_file === true) {
2002-01-31 08:19:34 +00:00
$libname = trim($cdata['libname']);
2001-07-25 21:20:31 +00:00
$libdata[$libname] = array(
2002-01-31 08:19:34 +00:00
"sources" => trim($cdata['sources']),
"includes" => trim($cdata['includes']),
"libadd" => trim($cdata['libadd']),
2001-07-25 21:20:31 +00:00
);
$in_file = false;
}
break;
}
2002-01-31 08:19:34 +00:00
case "dir": {
2001-08-28 11:18:08 +00:00
array_pop($currinstalldir);
array_pop($baseinstalldir);
break;
}
}
}
// }}}
// {{{ cdata_handler()
function cdata_handler($xp, $data)
{
2001-08-28 11:18:08 +00:00
global $curelem, $cdata, $curfile;
2001-07-25 21:20:31 +00:00
switch ($curelem) {
2002-01-31 08:19:34 +00:00
case "file": {
2001-08-28 11:18:08 +00:00
$curfile .= $data;
break;
}
2002-01-31 08:19:34 +00:00
case "includes":
case "libadd":
case "libname":
case "sources": {
2001-07-25 21:20:31 +00:00
$cdata[$curelem] .= $data;
break;
}
}
}
// }}}
2001-07-25 21:20:31 +00:00
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* indent-tabs-mode: t
* End:
*/
// vim600:syn=php
?>