Description: Support system-wide and deferred installation
 Add options --destdir and --nodedir.
Author: Jonas Smedegaard <dr@jones.dk>
Forwarded: no
Last-Update: 2011-07-09

--- a/Cakefile
+++ b/Cakefile
@@ -94,21 +94,27 @@
 
 option '-p', '--prefix [DIR]', 'set the installation prefix for `cake install`'
 
+option '-d', '--destdir [DIR]', 'set the installation destdir for `cake install`'
+
+option '-n', '--nodedir [DIR]', 'set the installation nodedir for `cake install`'
+
 task 'install', 'install CoffeeScript into /usr/local (or --prefix)', (options) ->
   base = options.prefix or '/usr/local'
+  destdir = options.destdir or ''
   lib  = "#{base}/lib/coffee-script"
   bin  = "#{base}/bin"
-  node = "~/.node_libraries/coffee-script"
-  console.log   "Installing CoffeeScript to #{lib}"
+  nodedir = options.nodedir or "~/.node_libraries"
+  node = "#{nodedir}/coffee-script"
+  console.log   "Installing CoffeeScript to #{destdir}#{lib}"
   console.log   "Linking to #{node}"
-  console.log   "Linking 'coffee' to #{bin}/coffee"
+  console.log   "Linking 'coffee' to #{destdir}#{bin}/coffee"
   exec([
-    "mkdir -p #{lib} #{bin}"
-    "cp -rf bin lib LICENSE README.md package.json src #{lib}"
-    "ln -sfn #{lib}/bin/coffee #{bin}/coffee"
-    "ln -sfn #{lib}/bin/cake #{bin}/cake"
-    "mkdir -p ~/.node_libraries"
-    "ln -sfn #{lib}/lib/coffee-script #{node}"
+    "mkdir -p #{destdir}#{lib} #{destdir}#{bin}"
+    "cp -rf bin lib LICENSE README.md package.json src #{destdir}#{lib}"
+    "ln -sfn #{lib}/bin/coffee #{destdir}#{bin}/coffee"
+    "ln -sfn #{lib}/bin/cake #{destdir}#{bin}/cake"
+    "mkdir -p #{destdir}#{nodedir}"
+    "ln -sfn #{lib}/lib/coffee-script #{destdir}#{node}"
   ].join(' && '), (err, stdout, stderr) ->
     if err then console.log stderr.trim() else log 'done', green
   )
