]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - scripts/docgen.php
Merge remote-tracking branch 'upstream/master' into social-master
[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 set_include_path(INSTALLDIR . DIRECTORY_SEPARATOR . 'extlib' . PATH_SEPARATOR . get_include_path());
21
22 $pattern = "*.php *.inc";
23 $exclude = 'config.php */extlib/* */local/* */plugins/* */scripts/*';
24 $plugin = false;
25
26 require_once 'Console/Getopt.php';
27 $parser = new Console_Getopt();
28 $result = $parser->getopt($_SERVER['argv'], $shortoptions, $longoptions);
29 if (PEAR::isError($result)) {
30     print $result->getMessage() . "\n";
31     exit(1);
32 }
33 list($options, $args) = $result;
34
35 foreach ($options as $option) {
36     $arg = $option[0];
37     if ($arg == '--plugin') {
38         $plugin = $options[1];
39     } else if ($arg == 'h' || $arg == '--help') {
40         print $helptext;
41         exit(0);
42     }
43 }
44
45 if (isset($args[0])) {
46     $outdir = $args[0];
47     if (!is_dir($outdir)) {
48         echo "Output directory $outdir is not a directory.\n";
49         exit(1);
50     }
51 } else {
52     print $helptext;
53     exit(1);
54 }
55
56 if ($plugin) {
57     $exclude = "*/extlib/*";
58     $indir = INSTALLDIR . "/plugins/" . $plugin;
59     if (!is_dir($indir)) {
60         $indir = INSTALLDIR . "/plugins";
61         $filename = "{$plugin}Plugin.php";
62         if (!file_exists("$indir/$filename")) {
63             echo "Can't find plugin $plugin.\n";
64             exit(1);
65         } else {
66             $pattern = $filename;
67         }
68     }
69 } else {
70     $indir = INSTALLDIR;
71 }
72
73 function getVersion()
74 {
75     // define('GNUSOCIAL_VERSION', '0.9.1');
76     $source = file_get_contents(INSTALLDIR . '/lib/common.php');
77     if (preg_match('/^\s*define\s*\(\s*[\'"]GNUSOCIAL_VERSION[\'"]\s*,\s*[\'"](.*)[\'"]\s*\)\s*;/m', $source, $matches)) {
78         return $matches[1];
79     }
80     return 'unknown';
81 }
82
83
84 $replacements = array(
85     '%%version%%' => getVersion(),
86     '%%indir%%' => $indir,
87     '%%pattern%%' => $pattern,
88     '%%outdir%%' => $outdir,
89     '%%htmlout%%' => $outdir,
90     '%%exclude%%' => $exclude,
91 );
92
93 var_dump($replacements);
94
95 $template = file_get_contents(dirname(__FILE__) . '/doxygen.tmpl');
96 $template = strtr($template, $replacements);
97
98 $templateFile = tempnam(common_get_temp_dir(), 'statusnet-doxygen');
99 file_put_contents($templateFile, $template);
100
101 $cmd = "doxygen " . escapeshellarg($templateFile);
102
103 $retval = 0;
104 passthru($cmd, $retval);
105
106 if ($retval == 0) {
107     echo "Done!\n";
108     unlink($templateFile);
109     exit(0);
110 } else {
111     echo "Failed! Doxygen config left in $templateFile\n";
112     exit($retval);
113 }
114