Index: build.php
===================================================================
RCS file: /repository/phd/build.php,v
retrieving revision 1.48
diff -u -u -r1.48 build.php
--- build.php	4 Feb 2008 23:01:27 -0000	1.48
+++ build.php	15 Feb 2008 15:23:30 -0000
@@ -25,6 +25,14 @@
 require $ROOT. "/include/PhDFormat.class.php";
 require $ROOT. "/include/PhDTheme.class.php";
 
+/* {{{ Find where we are and then cwd to the output folder. */
+$s_CurLoc = getcwd();
+if (!chdir($OPTIONS['output_dir'])) {
+    v("Could not change to '%s'", $OPTIONS['output_dir']);
+    exit;
+}
+/* }}} */
+
 /* {{{ Index the DocBook file or load from .ser cache files
        NOTE: There are two cache files:
         - index.ser     (containing the ID infos)
@@ -302,6 +310,12 @@
 
 } // foreach($OPTIONS["output_thtemes"])
 
+/* {{{ Return from whence we came. */
+if (!chdir($s_CurLoc)) {
+    v("Could not change to '%s'", $s_CurLoc);
+}
+/* }}} */
+
 /*
 * vim600: sw=4 ts=4 syntax=php et
 * vim<600: sw=4 ts=4
Index: config.php
===================================================================
RCS file: /repository/phd/config.php,v
retrieving revision 1.30
diff -u -u -r1.30 config.php
--- config.php	9 Feb 2008 22:58:01 -0000	1.30
+++ config.php	15 Feb 2008 15:16:26 -0000
@@ -51,6 +51,7 @@
   ),
   'skip_ids' => array(
   ),
+  'output_dir' => '.',
 );
 /* }}} */
 
@@ -61,6 +62,7 @@
     "theme:"   => "t:", // The theme to render (phpweb, bightml..)
     "index:"   => "i:", // Re-index or load from cache
     "docbook:" => "d:", // The Docbook XML file to render from (.manual.xml)
+    "output:"  => "o:", // The output directory
     "partial:" => "p:", // The ID to render (optionally ignoring its childrens)
     "skip:"    => "s:", // The ID to skip (optionally skipping its childrens too)
     "verbose:" => "v",  // Adjust the verbosity level
@@ -109,6 +111,22 @@
         break;
     /* }}} */
 
+    /* {{{ Output location */
+    case "o":
+    case "output":
+        if (is_array($v)) {
+            v("Only a single location can be supplied\n");
+            exit(1);
+        }
+        @mkdir($v, 0777, true);
+        if (!is_dir($v) || !is_readable($v)) {
+            v("'%s' is not a valid directory\n", $v);
+            exit(1);
+        }
+        $OPTIONS["output_dir"] = realpath($v);
+        break;
+    /* }}} */
+
     /* {{{ Build format */
     case "f":
     case "format":
@@ -301,6 +319,8 @@
   --skip <id[=bool]>         The ID to skip, optionally skipping its children chunks (default to true; skip childrens)
   -l <formats/themes>
   --list <formats/themes>    Print out the supported formats/themes (default: both)
+  -o <directory>
+  --output <directory>       The output directory (default: .)
   -V
   --version                  Print the PhD version information
   -h

