]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - scripts/docgen.php
Merge branch 'testing' of git@gitorious.org:statusnet/mainline into 0.9.x
[quix0rs-gnu-social.git] / scripts / docgen.php
1 #!/usr/bin/env php
2 <?php
3
4 $shortoptions = '';
5 $longoptions = array('plugin=');
6
7
8 $helptext = <<<ENDOFHELP
9 Build HTML documentation from doc comments in source.
10
11 Usage: docgen.php [options] output-directory
12 Options:
13
14   --plugin=...     build docs for given plugin instead of core
15
16
17 ENDOFHELP;
18
19 define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
20 require_once INSTALLDIR.'/scripts/commandline.inc';
21
22 $pattern = "*.php *.inc";
23 $exclude = 'config.php */extlib/* */local/* */plugins/* */scripts/*';
24
25 if (isset($args[0])) {
26     $outdir = $args[0];
27     if (!is_dir($outdir)) {
28         echo "Output directory $outdir is not a directory.\n";
29         exit(1);
30     }
31 } else {
32     print $helptext;
33     exit(1);
34 }
35
36 if (have_option('p', 'plugin')) {
37     $plugin = get_option_value('plugin');
38     $exclude = "*/extlib/*";
39     $indir = INSTALLDIR . "/plugins/" . $plugin;
40     if (!is_dir($indir)) {
41         $indir = INSTALLDIR . "/plugins";
42         $filename = "{$plugin}Plugin.php";
43         if (!file_exists("$indir/$filename")) {
44             echo "Can't find plugin $plugin.\n";
45             exit(1);
46         } else {
47             $pattern = $filename;
48         }
49     }
50 } else {
51     $indir = INSTALLDIR;
52 }
53
54 $replacements = array(
55     '%%version%%' => STATUSNET_VERSION,
56     '%%indir%%' => $indir,
57     '%%pattern%%' => $pattern,
58     '%%outdir%%' => $outdir,
59     '%%htmlout%%' => $outdir,
60     '%%exclude%%' => $exclude,
61 );
62
63 var_dump($replacements);
64
65 $template = file_get_contents(dirname(__FILE__) . '/doxygen.tmpl');
66 $template = strtr($template, $replacements);
67
68 $templateFile = tempnam(sys_get_temp_dir(), 'statusnet-doxygen');
69 file_put_contents($templateFile, $template);
70
71 $cmd = "doxygen " . escapeshellarg($templateFile);
72
73 $retval = 0;
74 passthru($cmd, $retval);
75
76 if ($retval == 0) {
77     echo "Done!\n";
78     unlink($templateFile);
79     exit(0);
80 } else {
81     echo "Failed! Doxygen config left in $templateFile\n";
82     exit($retval);
83 }
84