--- /dev/null
+#!@prefix@/bin/php -Cq
+<?php // -*- PHP -*-
+
+main($argc, $argv, $HTTP_ENV_VARS);
+
+// {{{ main()
+
+function main(&$argc, &$argv, &$env)
+{
+ $file = check_options($argc, $argv, $env);
+ parse_package_file($file);
+ make_makefile_in($env);
+}
+
+// }}}
+// {{{ check_options()
+
+function check_options(&$argc, &$argv, &$env)
+{
+ $file = $argv[1];
+ if (empty($file)) {
+ $file = "package.xml";
+ }
+ return $file;
+}
+
+// }}}
+// {{{ make_makefile_in()
+
+function make_makefile_in(&$env)
+{
+ global $libdata;
+ if (sizeof($libdata) == 0) {
+ exit;
+ } elseif (sizeof($libdata) > 1) {
+ die("No support yet for multiple libraries in one package.\n");
+ }
+
+ $wp = @fopen("Makefile.in", "w");
+ if (is_resource($wp)) {
+ print "Creating Makefile.in...";
+ flush();
+ } else {
+ die("Could not create Makefile.in in current directory.\n");
+ }
+
+ foreach ($libdata as $lib => $info) {
+ extract($info);
+ $_who = $env["USER"];
+ $_when = gmdate('Y-m-d h:i');
+ fwrite($wp, "\
+# This file was generated by `pearize' by $_who at $_when GMT
+INCLUDES = $includes
+LTLIBRARY_NAME = lib{$lib}.la
+LTLIBRARY_SOURCES = $sources
+LTLIBRARY_SHARED_NAME = {$lib}.la
+LTLIBRARY_SHARED_LIBADD = $libadd
+
+include \$(top_srcdir)/build/dynlib.mk
+");
+ }
+ fclose($wp);
+ print "done.\n";
+}
+
+// }}}
+// {{{ parse_package_file()
+
+function parse_package_file($file)
+{
+ global $in_file, $curlib, $curelem, $libdata, $cdata;
+
+ $in_file = false;
+ $curlib = '';
+ $curelem = '';
+ $libdata = array();
+ $cdata = array();
+
+ $xp = xml_parser_create();
+ xml_set_element_handler($xp, "start_handler", "end_handler");
+ xml_set_character_data_handler($xp, "cdata_handler");
+ xml_parser_set_option($xp, XML_OPTION_CASE_FOLDING, false);
+
+ $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)
+{
+ global $cdata, $in_file, $curelem;
+ switch ($elem) {
+ case "File": {
+ switch ($attrs['Role']) {
+ case "ext": {
+ $in_file = true;
+ $cdata = array();
+ break;
+ }
+ case "php": default: {
+ break;
+ }
+ }
+ break;
+ }
+ case "Includes":
+ case "LibName":
+ case "LibAdd":
+ case "Sources": {
+ $curelem = $elem;
+ break;
+ }
+ }
+}
+
+// }}}
+// {{{ end_handler()
+
+function end_handler($xp, $elem)
+{
+ global $in_file, $curlib, $curelem, $libdata, $cdata;
+ switch ($elem) {
+ case "File": {
+ if ($in_file === true) {
+ $libname = trim($cdata['LibName']);
+ $libdata[$libname] = array(
+ "sources" => trim($cdata['Sources']),
+ "includes" => trim($cdata['Includes']),
+ "libadd" => trim($cdata['LibAdd']),
+ );
+ $in_file = false;
+ }
+ break;
+ }
+ }
+}
+
+// }}}
+// {{{ cdata_handler()
+
+function cdata_handler($xp, $data)
+{
+ global $curelem, $cdata;
+ switch ($curelem) {
+ case "Includes":
+ case "LibAdd":
+ case "LibName":
+ case "Sources": {
+ $cdata[$curelem] .= $data;
+ break;
+ }
+ }
+}
+
+// }}}
+
+?>